Skip to content

Commit

Permalink
Workaround to deal with chat view messages not layouted properly #bea…
Browse files Browse the repository at this point in the history
…gleim-156
  • Loading branch information
hantu85 committed Oct 21, 2019
1 parent 0e999aa commit f677741
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion BeagleIM/chat/AbstractChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,14 @@ class AbstractChatViewController: NSViewController, NSTableViewDataSource, ChatV
}

func markAsReadUpToNewestVisibleRow() {
let visibleRows = self.tableView.rows(in: self.tableView.visibleRect);
if visibleRows.contains(0) {
self.dataSource.trimStore();
}
guard self.hasFocus && self.chat.unread > 0 else {
return;
}

let visibleRows = self.tableView.rows(in: self.tableView.visibleRect);
var ts: Date? = dataSource.getItem(at: visibleRows.lowerBound)?.timestamp;
if let tmp = dataSource.getItem(at: visibleRows.upperBound-1)?.timestamp {
if ts == nil {
Expand Down
13 changes: 9 additions & 4 deletions BeagleIM/chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,16 @@ class ChatViewTableView: NSTableView {
}
override func scrollRowToVisible(_ row: Int) {
super.scrollRowToVisible(row);
if !self.rows(in: self.visibleRect).contains(row) {
super.scrollRowToVisible(row);
let visibleRows = self.rows(in: self.visibleRect);
if !visibleRows.contains(row) {
print("visible rows:", visibleRows, "need:", row);
DispatchQueue.main.async {
self.scrollRowToVisible(row);
}
} else {
print("scrollRowToVisible called!");
NotificationCenter.default.post(name: ChatViewTableView.didScrollRowToVisible, object: self);
}
print("scrollRowToVisible called!");
NotificationCenter.default.post(name: ChatViewTableView.didScrollRowToVisible, object: self);
}
}

Expand Down
5 changes: 3 additions & 2 deletions BeagleIM/chat/ChatViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class ChatViewDataSource {
if let it = store.item(at: store.count - 1) {
loadItems(before: it.id, limit: 100, completionHandler: nil);
}
} else if (row == 0) {
trimStore();
// } else if (row == 0) {
// this causes issues!! we are loading row 0 during initial scrollRowToVisible!
//trimStore();
}
} else {
print("no item for row:", row, "index:", 0, "store.count:", store.count);
Expand Down

0 comments on commit f677741

Please sign in to comment.