@@ -16,6 +16,7 @@ protocol UpdatableGroup:class {
1616
1717class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegate, UITableViewDataSource
1818{
19+ var onUserDisplay: ((Int)->())?
1920
2021 var tableView: UITableView = UITableView()
2122
@@ -47,6 +48,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
4748
4849 var cellData: [PostCellData] = [] {
4950 didSet {
51+ prevLast = cellData.count - 1
5052 tableView.reloadData()
5153 }
5254 }
@@ -198,7 +200,14 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
198200 }
199201
200202 func setTitleForChat(userChat: Model.UserChat){
201− navigationItem.title = "👤 \(users![userChat.user]!.fullName())"
203+ navigationItem.title = "\(users![userChat.user]!.fullName())"
204+ navigationItem.rightBarButtonItem = UIBarButtonItem(title: "👤", style: .plain, target: self, action: #selector(showPersonPage))
205+ }
206+
207+ @objc func showPersonPage(){
208+ if let id = userChat?.user{
209+ onUserDisplay?(id)
210+ }
202211 }
203212
204213 func setTitleForGroup(groupChat: Model.GroupChat){
@@ -206,6 +215,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
206215 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
207216 }
208217
218+ // onInfoShow
209219 @objc func moveToInfoVC(){
210220 let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: chatInfoViewController) as! ChatInfoViewController
211221
@@ -219,11 +229,10 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
219229 navigationController?.pushViewController(vc, animated: true)
220230 }
221231
222− var currentMessagesInChat: [Model.LastMessage]? {
223− didSet {
224− if let currentMessagesInChat = currentMessagesInChat {
225− cellData = currentMessagesInChat.map { PostCellData(attributedData: PostCellData.create(with: [$0.body])) }
226− }
232+ var currentMessagesInChat: [Model.LastMessage] = [] {
233+ didSet
234+ {
235+ cellData = currentMessagesInChat.map { PostCellData(attributedData: PostCellData.create(with: [$0.body])) }
227236 }
228237 }
229238
@@ -245,18 +254,18 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
245254 }
246255 }
247256
248− func getMessages(for dialog: Model.Dialog){
249− print("Here")
257+ func getMessages(for dialog: Model.Dialog, starting from: Int? = nil)
258+ {
250259 switch dialog {
251260 case .groupChat(let groupChat):
252− Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
253− { [unowned self] in
254− self.currentMessagesInChat = $0
261+ Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id, exclusiveFrom: from)
262+ { [weak self] in
263+ self?.currentMessagesInChat = $0
255264 }
256265 case .userChat(let userChat):
257− Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user)
258− { [unowned self] in
259− self.currentMessagesInChat = $0
266+ Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user, exclusiveFrom: from)
267+ { [weak self] in
268+ self?.currentMessagesInChat = $0
260269 }
261270 }
262271 }
@@ -270,13 +279,30 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
270279 cell.selectionStyle = .none
271280
272281
273− if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
282+ if let user = users?[currentMessagesInChat[indexPath.row].author]
274283 {
275− cell.fill(with: cellData[indexPath.row].attributedData, byUser: user, when: (currentMessagesInChat?[indexPath.row].time)!)
284+ cell.fill(with: cellData[indexPath.row].attributedData, byUser: user, when: currentMessagesInChat[indexPath.row].time)
285+
286+ cell.onUserDisplay = onUserDisplay
276287 }
277288
278289 return cell
279290 }
291+
292+ var prevLast = -1
293+ func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
294+ {
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+// }
305+ }
280306}
281307
282308