@@ -48,8 +48,8 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
4848
4949 var cellData: [PostCellData] = [] {
5050 didSet {
51− prevLast = cellData.count - 1
5251 tableView.reloadData()
52+ canBePaginated = true
5353 }
5454 }
5555
@@ -62,7 +62,6 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
6262 self.tableView.delegate = self
6363 self.tableView.dataSource = self
6464
65− tabBarController?.tabBar.isHidden = true
6665 navigationItem.largeTitleDisplayMode = .never
6766
6867 tableView.keyboardDismissMode = .onDrag
@@ -132,9 +131,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
132131 if let destination = destination
133132 {
134133 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
135− self.getMessages(for: self.dialog!)
134+
135+ self.getMessagesNew(for: self.dialog!)
136136 self.messageTextView.text = ""
137137 }
138+
139+ prevLast = -1
138140 }
139141 }
140142
@@ -248,6 +250,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
248250
249251 override func viewWillAppear(_ animated: Bool) {
250252 super.viewWillAppear(animated)
253+ tabBarController?.tabBar.isHidden = true
251254
252255 if let dialog = dialog {
253256 getMessages(for: dialog)
@@ -255,6 +258,23 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
255258 }
256259
257260 func getMessages(for dialog: Model.Dialog, starting from: Int? = nil)
261+ {
262+ switch dialog {
263+ case .groupChat(let groupChat):
264+ Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id, exclusiveFrom: from)
265+ { [weak self] in
266+ self?.currentMessagesInChat.append(contentsOf: $0)
267+ }
268+ case .userChat(let userChat):
269+ Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user, exclusiveFrom: from)
270+ { [weak self] in
271+ self?.currentMessagesInChat.append(contentsOf: $0)
272+ }
273+ }
274+ }
275+
276+
277+ func getMessagesNew(for dialog: Model.Dialog, starting from: Int? = nil)
258278 {
259279 switch dialog {
260280 case .groupChat(let groupChat):
@@ -290,18 +310,19 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
290310 }
291311
292312 var prevLast = -1
313+ var canBePaginated = false
293314 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
294315 {
295− // pagination
296−// if indexPath.row == cellData.count - 1 && prevLast != indexPath.row
297−// {
298−// if let dialog = dialog
299−// {
300−// getMessages(for: dialog, starting: prevLast)
301−// }
302−//
303−// prevLast = indexPath.row
304−// }
316+ if indexPath.row == cellData.count - 1 && prevLast != indexPath.row && canBePaginated
317+ {
318+ print("exclusiveFrom \(currentMessagesInChat.last?.id ?? 0)")
319+ if let dialog = dialog
320+ {
321+ getMessages(for: dialog, starting: currentMessagesInChat.last?.id)
322+ }
323+
324+ prevLast = indexPath.row
325+ }
305326 }
306327}
307328