alqindiirsyam 2 tahun lalu
induk
melakukan
477e7d6834

+ 24 - 39
appbuilder-ios/AppBuilder/AppBuilder/SecondTabViewController.swift

@@ -1000,51 +1000,36 @@ 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 {
+            if let attributeText = text as? NSMutableAttributedString {
                 if data.fpin == idMe {
-                    let stringMessage = NSMutableAttributedString(string: "")
-                    let imageStatus = NSTextAttachment()
-                    let status = getRealStatus(messageId: data.messageId)
-                    if (status == "1" || status == "2" ) {
-                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "3") {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "8") {
-                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    if data.lock == "1" {
+                        messageView.attributedText = ("🚫 _"+"You were deleted this message".localized()+"_").richText()
                     } else {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                        let stringMessage = NSMutableAttributedString(string: "")
+                        let imageStatus = NSTextAttachment()
+                        let status = getRealStatus(messageId: data.messageId)
+                        if (status == "1" || status == "2" ) {
+                            imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                        } else if (status == "3") {
+                            imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                        } else if (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
                     }
-                    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 {
-                if data.fpin == idMe {
-                    let stringMessage = NSMutableAttributedString(string: "")
-                    let imageStatus = NSTextAttachment()
-                    let status = getRealStatus(messageId: data.messageId)
-                    if (status == "1" || status == "2" ) {
-                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "3") {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "8") {
-                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    if data.lock == "1" {
+                        messageView.attributedText = ("🚫 _"+"This message was deleted".localized()+"_").richText()
                     } else {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                        messageView.attributedText = attributeText
                     }
-                    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

+ 24 - 20
appbuilder-ios/NexilisLite/NexilisLite/Source/Extension.swift

@@ -657,15 +657,16 @@ extension String {
                     continue
                 }
                 if (rangeBold[i].endIndex == textUTF8.count - 1 || checkCharBeforeAfter(char: textUTF8.substring(from: rangeBold[i].endIndex + 1, to: rangeBold[i].endIndex + 1))) {
+                    let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveBoldSign)).countEmojiCharacter()
                     let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveBoldSign), to: rangeBold[i].endIndex - (2*countRemoveBoldSign)).countEmojiCharacter()
-                    totalEmoji = totalEmoji + countEmoji
-                    finalText.addAttribute(.font, value: font.bold, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign), length: rangeBold[i].endIndex - lastFirstRange + totalEmoji + 1))
+                    totalEmoji = countEmoji + countEmojiBefore
+                    finalText.addAttribute(.font, value: font.bold, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign) + countEmojiBefore, length: (rangeBold[i].endIndex + countEmoji + 1) - lastFirstRange))
                     if !isEditing{
-                        finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveBoldSign), length: 1 + countEmoji))
-                        finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: rangeBold[i].endIndex - 1 - (2*countRemoveBoldSign) + countEmoji, length: 1 + countEmoji))
+                        finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveBoldSign), length: 1))
+                        finalText.mutableString.replaceOccurrences(of: "\(boldSign)", with: "", options: .literal, range: NSRange(location: rangeBold[i].endIndex + totalEmoji - (2*countRemoveBoldSign) - 1, length: 1))
                         countRemoveBoldSign += 1
                     } else {
-                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
+                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
                         finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeBold[i].endIndex + totalEmoji, length: 1))
                     }
                     lastFirstRange = 0
@@ -694,15 +695,16 @@ extension String {
                     continue
                 }
                 if (rangeItalic[i].endIndex == textAfterbold.count - 1 || checkCharBeforeAfter(char: textAfterbold.substring(from: rangeItalic[i].endIndex + 1, to: rangeItalic[i].endIndex + 1))) {
+                    let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveItalicSign)).countEmojiCharacter()
                     let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveItalicSign), to: rangeItalic[i].endIndex - (2*countRemoveItalicSign)).countEmojiCharacter()
-                    totalEmoji = totalEmoji + countEmoji
-                    finalText.addAttribute(.font, value: font.italic, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign), length: rangeItalic[i].endIndex - lastFirstRange + totalEmoji + 1))
+                    totalEmoji = countEmoji + countEmojiBefore
+                    finalText.addAttribute(.font, value: font.italic, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign) + countEmojiBefore, length: (rangeItalic[i].endIndex + countEmoji + 1) - lastFirstRange))
                     if !isEditing{
-                        finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveItalicSign), length: 1 + countEmoji))
-                        finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex - 1 - (2*countRemoveItalicSign) + countEmoji, length: 1 + countEmoji))
+                        finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveItalicSign), length: 1))
+                        finalText.mutableString.replaceOccurrences(of: "\(italicSign)", with: "", options: .literal, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji - (2*countRemoveItalicSign) - 1, length: 1))
                         countRemoveItalicSign += 1
                     } else {
-                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
+                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
                         finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeItalic[i].endIndex + totalEmoji, length: 1))
                     }
                     lastFirstRange = 0
@@ -731,15 +733,16 @@ extension String {
                     continue
                 }
                 if (rangeUnderline[i].endIndex == textAfterItalic.count - 1 || checkCharBeforeAfter(char: textAfterItalic.substring(from: rangeUnderline[i].endIndex + 1, to: rangeUnderline[i].endIndex + 1))) {
+                    let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveUnderlineSign)).countEmojiCharacter()
                     let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveUnderlineSign), to: rangeUnderline[i].endIndex - (2*countRemoveUnderlineSign)).countEmojiCharacter()
-                    totalEmoji = totalEmoji + countEmoji
-                    finalText.addAttribute(.underlineStyle, value: NSUnderlineStyle.thick.rawValue, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign), length: rangeUnderline[i].endIndex - lastFirstRange + totalEmoji + 1))
+                    totalEmoji = countEmoji + countEmojiBefore
+                    finalText.addAttribute(.underlineStyle, value: NSUnderlineStyle.thick.rawValue, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign) + countEmojiBefore + 1, length: (rangeUnderline[i].endIndex + countEmoji - 1) - lastFirstRange))
                     if !isEditing{
-                        finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveUnderlineSign), length: 1 + countEmoji))
-                        finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: rangeUnderline[i].endIndex - 1 - (2*countRemoveUnderlineSign) + countEmoji, length: 1 + countEmoji))
+                        finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveUnderlineSign), length: 1))
+                        finalText.mutableString.replaceOccurrences(of: "\(underlineSign)", with: "", options: .literal, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji - (2*countRemoveUnderlineSign) - 1, length: 1))
                         countRemoveUnderlineSign += 1
                     } else {
-                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
+                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
                         finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeUnderline[i].endIndex + totalEmoji, length: 1))
                     }
                     lastFirstRange = 0
@@ -768,15 +771,16 @@ extension String {
                     continue
                 }
                 if (rangeStrikethrough[i].endIndex == textAfterUnderline.count - 1 || checkCharBeforeAfter(char: textAfterUnderline.substring(from: rangeStrikethrough[i].endIndex + 1, to: rangeStrikethrough[i].endIndex + 1))) {
+                    let countEmojiBefore = finalText.string.substring(from: 0, to: lastFirstRange - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
                     let countEmoji = finalText.string.substring(from: lastFirstRange - (2*countRemoveStrikethroughSign), to: rangeStrikethrough[i].endIndex - (2*countRemoveStrikethroughSign)).countEmojiCharacter()
-                    totalEmoji = totalEmoji + countEmoji
-                    finalText.addAttribute(.strikethroughStyle, value: 2, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign), length: rangeStrikethrough[i].endIndex - lastFirstRange + totalEmoji + 1))
+                    totalEmoji = countEmoji + countEmojiBefore
+                    finalText.addAttribute(.strikethroughStyle, value: 2, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign) + countEmojiBefore + 1, length: (rangeStrikethrough[i].endIndex + countEmoji - 1) - lastFirstRange))
                     if !isEditing{
-                        finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange - (2*countRemoveStrikethroughSign), length: 1 + countEmoji))
-                        finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: rangeStrikethrough[i].endIndex - 1 - (2*countRemoveStrikethroughSign) + countEmoji, length: 1 + countEmoji))
+                        finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: lastFirstRange + countEmojiBefore - (2*countRemoveStrikethroughSign), length: 1))
+                        finalText.mutableString.replaceOccurrences(of: "\(strikethroughSign)", with: "", options: .literal, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji - (2*countRemoveStrikethroughSign) - 1, length: 1))
                         countRemoveStrikethroughSign += 1
                     } else {
-                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + (totalEmoji == 0 ? 0 : totalEmoji - 1), length: 1))
+                        finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: lastFirstRange + countEmojiBefore, length: 1))
                         finalText.addAttribute(.foregroundColor, value: UIColor.gray, range: NSRange(location: rangeStrikethrough[i].endIndex + totalEmoji, length: 1))
                     }
                     lastFirstRange = 0

+ 17 - 12
appbuilder-ios/NexilisLite/NexilisLite/Source/OutgoingThread.swift

@@ -247,22 +247,27 @@ class OutgoingThread {
                 _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "message_id = '\(messageId)'")
                 let l_pin = message.getBody(key: CoreMessage_TMessageKey.L_PIN)
                 let chat = message.getBody(key: CoreMessage_TMessageKey.CHAT_ID)
-                var lastMessage: String?
-                if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where opposite_pin = '\(l_pin)' order by server_date desc limit 1"), cursor.next() {
-                    lastMessage = cursor.string(forColumnIndex: 0)
-                    cursor.close()
-                }
-                if let l = lastMessage {
-                    do {
+                do {
+                    var pin = l_pin
+                    if !chat.isEmpty {
+                        pin = chat
+                    }
+                    let queryGetLastMessageId = "SELECT message_id FROM MESSAGE where opposite_pin = '\(pin)' OR l_pin = '\(pin)' order by server_date desc LIMIT 1"
+                    var messageId = ""
+                    if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: queryGetLastMessageId), cursorData.next() {
+                        messageId = cursorData.string(forColumnIndex: 0) ?? ""
+                        cursorData.close()
+                    }
+                    if !messageId.isEmpty {
                         _ = try Database.shared.insertRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", cvalues: [
-                            "l_pin" : chat.isEmpty ? l_pin : chat,
-                            "message_id" : l,
+                            "l_pin" : pin,
+                            "message_id" : messageId,
                             "counter" : 0
                         ], replace: true)
-                    } catch {
-                        rollback.pointee = true
-                        print(error)
                     }
+                } catch {
+                    rollback.pointee = true
+                    print(error)
                 }
                 self.delOutgoing(fmdb: fmdb, messageId: messageId)
             }

+ 24 - 39
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ContactChatViewController.swift

@@ -861,51 +861,36 @@ 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 {
+            if let attributeText = text as? NSMutableAttributedString {
                 if data.fpin == idMe {
-                    let stringMessage = NSMutableAttributedString(string: "")
-                    let imageStatus = NSTextAttachment()
-                    let status = getRealStatus(messageId: data.messageId)
-                    if (status == "1" || status == "2" ) {
-                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "3") {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "8") {
-                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    if data.lock == "1" {
+                        messageView.attributedText = ("🚫 _"+"You were deleted this message".localized()+"_").richText()
                     } else {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                        let stringMessage = NSMutableAttributedString(string: "")
+                        let imageStatus = NSTextAttachment()
+                        let status = getRealStatus(messageId: data.messageId)
+                        if (status == "1" || status == "2" ) {
+                            imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                        } else if (status == "3") {
+                            imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
+                        } else if (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
                     }
-                    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 {
-                if data.fpin == idMe {
-                    let stringMessage = NSMutableAttributedString(string: "")
-                    let imageStatus = NSTextAttachment()
-                    let status = getRealStatus(messageId: data.messageId)
-                    if (status == "1" || status == "2" ) {
-                        imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "3") {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
-                    } else if (status == "8") {
-                        imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
+                    if data.lock == "1" {
+                        messageView.attributedText = ("🚫 _"+"This message was deleted".localized()+"_").richText()
                     } else {
-                        imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
+                        messageView.attributedText = attributeText
                     }
-                    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