Skip to content

Commit

Permalink
pagination is mostly OK now
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Jun 8, 2022
1 parent bd84a2f commit f3736da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
15 changes: 6 additions & 9 deletions Tinodios/MessageInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,13 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message

/// Load the most recent `kMessagesPerPage` messages from cache.
func loadMessagesFromCache(scrollToMostRecentMessage: Bool = true) {
guard let t = self.topic else { return }
self.messageInteractorQueue.async {
self.topic?.loadMessagePage(startWithSeq: Int.max, pageSize: MessageInteractor.kMessagesPerPage, forward: false, onLoaded: {(messagePage, error) in
if let err = error {
Cache.log.error("Failed to load message page: %@", err.localizedDescription)
} else {
// Replace messages with the new page.
self.messages = messagePage!.map { $0 as! StoredMessage }.reversed()
self.presenter?.presentMessages(messages: self.messages, scrollToMostRecentMessage)
}
})
if let messagePage = BaseDb.sharedInstance.sqlStore?.getMessagePage(topic: t, from: Int.max, limit: MessageInteractor.kMessagesPerPage, forward: false) {
// Replace messages with the new page.
self.messages = messagePage.map { $0 as! StoredMessage }.reversed()
self.presenter?.presentMessages(messages: self.messages, scrollToMostRecentMessage)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion TinodiosDB/BaseDb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// BaseDb.swift
// ios
//
// Copyright © 2019 Tinode. All rights reserved.
// Copyright © 2019-2022 Tinode. All rights reserved.
//

import Foundation
Expand Down
1 change: 1 addition & 0 deletions TinodiosDB/MessageDb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public class MessageDb {
}
return nil
}

func queryDeleted(topicId: Int64?, hard: Bool) -> [MsgRange]? {
guard let topicId = topicId else { return nil }
let status = hard ? BaseDb.Status.deletedHard : BaseDb.Status.deletedSoft
Expand Down

0 comments on commit f3736da

Please sign in to comment.