Skip to content

Commit

Permalink
Actually make loading pages work.
Browse files Browse the repository at this point in the history
  • Loading branch information
aforge committed Mar 2, 2023
1 parent ebbfd1f commit 63a3260
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Tinodios/MessageInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,6 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message
head = ["replace": .string(":" + String(replaceSeq))]
}
}
while self.messages.count >= self.pagesToLoad * MessageInteractor.kMessagesPerPage {
self.pagesToLoad += 1
}
topic.publish(content: message, withExtraHeaders: head).then(
onSuccess: { [weak self] _ in
self?.loadMessagesFromCache()
Expand Down Expand Up @@ -417,6 +414,10 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message
return
}

if self.messages.count <= self.pagesToLoad * MessageInteractor.kMessagesPerPage {
self.pagesToLoad += 1
}

self.messageInteractorQueue.async {
t.loadMessagePage(startWithSeq: firstSeqId, pageSize: MessageInteractor.kMessagesPerPage, forward: false, onLoaded: { [weak self] (messagePage, error) in
self?.presenter?.endRefresh()
Expand All @@ -441,7 +442,6 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message
guard let topic = topic, let store = topic.store else {
return
}
let origCount = self.messages.count
var seqIds: [Int] = []
if let replSeq = message.replacesSeq, let versionSeqIds = topic.store?.getAllMsgVersions(fromTopic: topic, forSeq: replSeq, limit: nil) {
for seq in versionSeqIds {
Expand Down Expand Up @@ -773,9 +773,6 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message
override func onData(data: MsgServerData?) {
guard let data = data, let topic = topic else { return }
let newData = data.getSeq >= (topic.seq ?? 0)
if self.messages.count + (newData ? 1 : 0) > self.pagesToLoad * MessageInteractor.kMessagesPerPage {
self.pagesToLoad += 1
}
self.loadMessagesFromCache(scrollToMostRecentMessage: newData)
if let from = data.from, let seq = data.seq, !Cache.tinode.isMe(uid: from) {
sendReadNotification(explicitSeq: seq, when: .now() + .seconds(1))
Expand Down

0 comments on commit 63a3260

Please # to comment.