@@ -16,6 +16,7 @@ protocol UpdatableGroup:class {
17class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegate, UITableViewDataSource
17class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegate, UITableViewDataSource
19+ var onUserDisplay: ((Int)->())?
20 var tableView: UITableView = UITableView()
21 var tableView: UITableView = UITableView()
@@ -47,6 +48,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
48 var cellData: [PostCellData] = [] {
49 var cellData: [PostCellData] = [] {
51+ prevLast = cellData.count - 1
50 tableView.reloadData()
52 tableView.reloadData()
@@ -198,7 +200,14 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
200 func setTitleForChat(userChat: Model.UserChat){
202 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))
207+ @objc func showPersonPage(){
208+ if let id = userChat?.user{
204 func setTitleForGroup(groupChat: Model.GroupChat){
213 func setTitleForGroup(groupChat: Model.GroupChat){
@@ -206,6 +215,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
206 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
215 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
209 @objc func moveToInfoVC(){
219 @objc func moveToInfoVC(){
210 let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: chatInfoViewController) as! ChatInfoViewController
220 let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: chatInfoViewController) as! ChatInfoViewController
@@ -219,11 +229,10 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
219 navigationController?.pushViewController(vc, animated: true)
229 navigationController?.pushViewController(vc, animated: true)
222− var currentMessagesInChat: [Model.LastMessage]? {
232+ var currentMessagesInChat: [Model.LastMessage] = [] {
224− if let currentMessagesInChat = currentMessagesInChat {
234+ {
225− cellData = currentMessagesInChat.map { PostCellData(attributedData: PostCellData.create(with: [$0.body])) }
235+ cellData = currentMessagesInChat.map { PostCellData(attributedData: PostCellData.create(with: [$0.body])) }
@@ -245,18 +254,18 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
248− func getMessages(for dialog: Model.Dialog){
257+ func getMessages(for dialog: Model.Dialog, starting from: Int? = nil)
250 switch dialog {
259 switch dialog {
251 case .groupChat(let groupChat):
260 case .groupChat(let groupChat):
252− Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
261+ Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id, exclusiveFrom: from)
253− { [unowned self] in
262+ { [weak self] in
254− self.currentMessagesInChat = $0
263+ self?.currentMessagesInChat = $0
256 case .userChat(let userChat):
265 case .userChat(let userChat):
257− Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user)
266+ Model.getMessagesFor(typeOfChat: Model.Dialog.userChat(userChat), chat: userChat.user, exclusiveFrom: from)
258− { [unowned self] in
267+ { [weak self] in
259− self.currentMessagesInChat = $0
268+ self?.currentMessagesInChat = $0
@@ -270,13 +279,30 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
270 cell.selectionStyle = .none
279 cell.selectionStyle = .none
273− if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
282+ if let user = users?[currentMessagesInChat[indexPath.row].author]
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)
286+ cell.onUserDisplay = onUserDisplay
278 return cell
289 return cell
293+ func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
296+// if indexPath.row == cellData.count - 1 && prevLast != indexPath.row
298+// if let dialog = dialog
300+// getMessages(for: dialog, starting: prevLast)
303+// prevLast = indexPath.row