alqindiirsyam 3 years ago
parent
commit
cc4cec47cc

+ 43 - 2
appbuilder-ios/AppBuilder/AppBuilder/SecondTabViewController.swift

@@ -801,10 +801,51 @@ extension SecondTabViewController: UITableViewDelegate, UITableViewDataSource {
             ])
             messageView.textColor = .gray
             let text = Utils.previewMessageText(chat: data)
+            let idMe = UserDefaults.standard.string(forKey: "me") as String?
             if let attributeText = text as? NSAttributedString {
-                messageView.attributedText = attributeText
+                if data.fpin == idMe {
+                    let stringMessage = NSMutableAttributedString(string: "")
+                    let imageStatus = NSTextAttachment()
+                    if (data.status == "1" || data.status == "2" ) {
+                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "3") {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "8") {
+                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    } else {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                    }
+                    imageStatus.bounds = CGRect(x: 0, y: 0, width: 15, height: 15)
+                    let imageStatusString = NSAttributedString(attachment: imageStatus)
+                    stringMessage.append(imageStatusString)
+                    stringMessage.append(NSAttributedString(string: " "))
+                    stringMessage.append(attributeText)
+                    messageView.attributedText = stringMessage
+                } else {
+                    messageView.attributedText = attributeText
+                }
             } else if let stringText = text as? String {
-                messageView.text = stringText
+                if data.fpin == idMe {
+                    let stringMessage = NSMutableAttributedString(string: "")
+                    let imageStatus = NSTextAttachment()
+                    if (data.status == "1" || data.status == "2" ) {
+                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "3") {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "8") {
+                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    } else {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                    }
+                    imageStatus.bounds = CGRect(x: 0, y: 0, width: 15, height: 15)
+                    let imageStatusString = NSAttributedString(attachment: imageStatus)
+                    stringMessage.append(imageStatusString)
+                    stringMessage.append(NSAttributedString(string: " "))
+                    stringMessage.append(NSAttributedString(string: stringText))
+                    messageView.attributedText = stringMessage
+                } else {
+                    messageView.text = stringText
+                }
             }
             messageView.numberOfLines = 2
             

+ 26 - 18
appbuilder-ios/NexilisLite/NexilisLite/Source/Model/Chat.swift

@@ -9,6 +9,7 @@ import Foundation
 
 public class Chat: Model {
     
+    public let fpin: String
     public let pin: String
     public let messageId: String
     public let counter: String
@@ -22,8 +23,10 @@ public class Chat: Model {
     public let name: String
     public let profile: String
     public let official: String
+    public let status: String
     
     public init(pin: String) {
+        self.fpin = ""
         self.pin = pin
         self.messageId = ""
         self.counter = ""
@@ -37,9 +40,11 @@ public class Chat: Model {
         self.name = ""
         self.profile = ""
         self.official = ""
+        self.status = ""
     }
     
-    public init(pin: String, messageId: String, counter: String, messageText: String, serverDate: String, image: String, video: String, file: String, attachmentFlag: String, messageScope: String, name: String, profile: String, official: String ) {
+    public init(fpin:String, pin: String, messageId: String, counter: String, messageText: String, serverDate: String, image: String, video: String, file: String, attachmentFlag: String, messageScope: String, name: String, profile: String, official: String, status: String ) {
+        self.fpin = fpin
         self.pin = pin
         self.messageId = messageId
         self.counter = counter
@@ -53,6 +58,7 @@ public class Chat: Model {
         self.name = name
         self.profile = profile
         self.official = official
+        self.status = status
     }
     
     public static func == (lhs: Chat, rhs: Chat) -> Bool {
@@ -68,30 +74,32 @@ public class Chat: Model {
         Database.shared.database?.inTransaction({ (fmdb, rollback) in
             do {
                 let query = """
-                            select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.first_name || ' ' || ifnull(b.last_name, '') name, b.image_id profile, b.official_account from MESSAGE_SUMMARY ms, MESSAGE m, BUDDY b where ms.message_id = m.message_id and ms.l_pin = b.f_pin \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
+                            select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.first_name || ' ' || ifnull(b.last_name, '') name, b.image_id profile, b.official_account, m.status from MESSAGE_SUMMARY ms, MESSAGE m, BUDDY b where ms.message_id = m.message_id and ms.l_pin = b.f_pin \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
                             union
-                            select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, 'Bot' name, '' profile, '' from MESSAGE_SUMMARY ms, MESSAGE m where ms.message_id = m.message_id and ms.l_pin = '-999' \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
+                            select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, 'Bot' name, '' profile, '', m.status from MESSAGE_SUMMARY ms, MESSAGE m where ms.message_id = m.message_id and ms.l_pin = '-999' \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
                             union
-                            select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.f_name || ' (\("Lounge".localized()))', b.image_id profile, b.official from MESSAGE_SUMMARY ms, MESSAGE m, GROUPZ b where ms.message_id = m.message_id and ms.l_pin = b.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
+                            select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, b.f_name || ' (\("Lounge".localized()))', b.image_id profile, b.official, m.status from MESSAGE_SUMMARY ms, MESSAGE m, GROUPZ b where ms.message_id = m.message_id and ms.l_pin = b.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
                             union
-                            select ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, c.f_name || ' (' || b.title || ')', b.thumb profile, '' from MESSAGE_SUMMARY ms, MESSAGE m, DISCUSSION_FORUM b, GROUPZ c where ms.message_id = m.message_id and ms.l_pin = b.chat_id and b.group_id = c.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
+                            select m.f_pin, ms.l_pin, ms.message_id, ms.counter, m.message_text, m.server_date, m.image_id, m.video_id, m.file_id, m.attachment_flag, m.message_scope_id, c.f_name || ' (' || b.title || ')', b.thumb profile, '', m.status from MESSAGE_SUMMARY ms, MESSAGE m, DISCUSSION_FORUM b, GROUPZ c where ms.message_id = m.message_id and ms.l_pin = b.chat_id and b.group_id = c.group_id \(messageId.isEmpty ? "" : " and m.message_id = '\(messageId)'")
                             order by 5 desc
                             """
                 if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
                     while cursorData.next() {
-                        let chat = Chat(pin: cursorData.string(forColumnIndex: 0) ?? "",
-                                        messageId: cursorData.string(forColumnIndex: 1) ?? "",
-                                        counter: cursorData.string(forColumnIndex: 2) ?? "",
-                                        messageText: cursorData.string(forColumnIndex: 3) ?? "",
-                                        serverDate: cursorData.string(forColumnIndex: 4) ?? "",
-                                        image: cursorData.string(forColumnIndex: 5) ?? "",
-                                        video: cursorData.string(forColumnIndex: 6) ?? "",
-                                        file: cursorData.string(forColumnIndex: 7) ?? "",
-                                        attachmentFlag: cursorData.string(forColumnIndex: 8) ?? "",
-                                        messageScope: cursorData.string(forColumnIndex: 9) ?? "",
-                                        name: cursorData.string(forColumnIndex: 10) ?? "",
-                                        profile: cursorData.string(forColumnIndex: 11) ?? "",
-                                        official: cursorData.string(forColumnIndex: 12) ?? "")
+                        let chat = Chat(fpin: cursorData.string(forColumnIndex: 0) ?? "",
+                                        pin: cursorData.string(forColumnIndex: 1) ?? "",
+                                        messageId: cursorData.string(forColumnIndex: 2) ?? "",
+                                        counter: cursorData.string(forColumnIndex: 3) ?? "",
+                                        messageText: cursorData.string(forColumnIndex: 4) ?? "",
+                                        serverDate: cursorData.string(forColumnIndex: 5) ?? "",
+                                        image: cursorData.string(forColumnIndex: 6) ?? "",
+                                        video: cursorData.string(forColumnIndex: 7) ?? "",
+                                        file: cursorData.string(forColumnIndex: 8) ?? "",
+                                        attachmentFlag: cursorData.string(forColumnIndex: 9) ?? "",
+                                        messageScope: cursorData.string(forColumnIndex: 10) ?? "",
+                                        name: cursorData.string(forColumnIndex: 11) ?? "",
+                                        profile: cursorData.string(forColumnIndex: 12) ?? "",
+                                        official: cursorData.string(forColumnIndex: 13) ?? "",
+                                        status: cursorData.string(forColumnIndex: 14) ?? "")
                         chats.append(chat)
                     }
                     cursorData.close()

+ 43 - 2
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ContactChatViewController.swift

@@ -705,10 +705,51 @@ extension ContactChatViewController {
             ])
             messageView.textColor = .gray
             let text = Utils.previewMessageText(chat: data)
+            let idMe = UserDefaults.standard.string(forKey: "me") as String?
             if let attributeText = text as? NSAttributedString {
-                messageView.attributedText = attributeText
+                if data.fpin == idMe {
+                    let stringMessage = NSMutableAttributedString(string: "")
+                    let imageStatus = NSTextAttachment()
+                    if (data.status == "1" || data.status == "2" ) {
+                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "3") {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "8") {
+                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    } else {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                    }
+                    imageStatus.bounds = CGRect(x: 0, y: 0, width: 15, height: 15)
+                    let imageStatusString = NSAttributedString(attachment: imageStatus)
+                    stringMessage.append(imageStatusString)
+                    stringMessage.append(NSAttributedString(string: " "))
+                    stringMessage.append(attributeText)
+                    messageView.attributedText = stringMessage
+                } else {
+                    messageView.attributedText = attributeText
+                }
             } else if let stringText = text as? String {
-                messageView.text = stringText
+                if data.fpin == idMe {
+                    let stringMessage = NSMutableAttributedString(string: "")
+                    let imageStatus = NSTextAttachment()
+                    if (data.status == "1" || data.status == "2" ) {
+                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "3") {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                    } else if (data.status == "8") {
+                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    } else {
+                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                    }
+                    imageStatus.bounds = CGRect(x: 0, y: 0, width: 15, height: 15)
+                    let imageStatusString = NSAttributedString(attachment: imageStatus)
+                    stringMessage.append(imageStatusString)
+                    stringMessage.append(NSAttributedString(string: " "))
+                    stringMessage.append(NSAttributedString(string: stringText))
+                    messageView.attributedText = stringMessage
+                } else {
+                    messageView.text = stringText
+                }
             }
             messageView.numberOfLines = 2