瀏覽代碼

added method to load all messages without limit

nayooti 5 年之前
父節點
當前提交
89e3867eb1
共有 2 個文件被更改,包括 21 次插入6 次删除
  1. 8 2
      DcCore/DcCore/DC/Wrapper.swift
  2. 13 4
      deltachat-ios/Controller/ChatViewController.swift

+ 8 - 2
DcCore/DcCore/DC/Wrapper.swift

@@ -41,6 +41,12 @@ public class DcContext {
         return ids
     }
 
+	public func getMessageIds(chatId: Int) -> [Int] {
+		let cMessageIds = getChatMessages(chatId: chatId)
+		let ids: [Int] = DcUtils.copyAndFreeArray(inputArray: cMessageIds)
+		return ids
+	}
+
     public func createContact(name: String, email: String) -> Int {
         return Int(dc_create_contact(contextPointer, name, email))
     }
@@ -249,10 +255,10 @@ public class DcContext {
         dc_markseen_msgs(contextPointer, ptr, Int32(count))
     }
 
-    public func getChatMessages(chatId: Int) -> OpaquePointer {
+	private func getChatMessages(chatId: Int) -> OpaquePointer {
         return dc_get_chat_msgs(contextPointer, UInt32(chatId), 0, 0)
     }
-    
+
     public func getMsgInfo(msgId: Int) -> String {
         if let cString = dc_get_msg_info(self.contextPointer, UInt32(msgId)) {
             let swiftString = String(cString: cString)

+ 13 - 4
deltachat-ios/Controller/ChatViewController.swift

@@ -95,6 +95,7 @@ class ChatViewController: MessagesViewController {
         fatalError("init(coder:) has not been implemented")
     }
 
+    // MARK: - lifecycle
     override func viewDidLoad() {
         messagesCollectionView.register(InfoMessageCell.self)
         super.viewDidLoad()
@@ -252,6 +253,7 @@ class ChatViewController: MessagesViewController {
         super.viewWillTransition(to: size, with: coordinator)
     }
 
+    // MARK - update
     private func updateTitle(chat: DcChat) {
         let titleView =  ChatTitleView()
 
@@ -284,8 +286,7 @@ class ChatViewController: MessagesViewController {
         navigationItem.rightBarButtonItem = UIBarButtonItem(customView: badge)
     }
 
-    @objc
-    private func loadMoreMessages() {
+    @objc private func loadMoreMessages() {
         DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 1) {
             DispatchQueue.main.async {
                 self.messageList = self.getMessageIds(self.loadCount, from: self.messageList.count) + self.messageList
@@ -295,8 +296,7 @@ class ChatViewController: MessagesViewController {
         }
     }
 
-    @objc
-    private func refreshMessages() {
+    @objc private func refreshMessages() {
         DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 1) {
             DispatchQueue.main.async {
                 self.messageList = self.getMessageIds(self.messageList.count)
@@ -354,6 +354,15 @@ class ChatViewController: MessagesViewController {
         return dcContext.getDraft(chatId: chatId)
     }
 
+    private func getMessageIds() -> [DcMsg] {
+        let ids = dcContext.getMessageIds(chatId: chatId)
+        let markIds: [UInt32] = ids.map { UInt32($0) }
+        dcContext.markSeenMessages(messageIds: markIds, count: ids.count)
+        return ids.map {
+            DcMsg(id: $0)
+        }
+    }
+
     private func getMessageIds(_ count: Int, from: Int? = nil) -> [DcMsg] {
         let ids = dcContext.getMessageIds(chatId: chatId, count: count, from: from)
         let markIds: [UInt32] = ids.map { UInt32($0) }