Procházet zdrojové kódy

fix: 修复 挂断自己发起的通话时,消息会变成对方的消息 的问题

陈文艺 před 1 měsícem
rodič
revize
fad6a3c817

+ 12 - 0
Lanu/Common/Extension/AppUtils.swift

@@ -83,3 +83,15 @@ func openAppSetting() {
     guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
     UIApplication.shared.open(url)
 }
+
+var isDebuggerAttached: Bool {
+    var info = kinfo_proc()
+    var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
+    var size = MemoryLayout<kinfo_proc>.stride
+    let result = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
+    
+    guard result == 0 else {
+        return false
+    }
+    return (info.kp_proc.p_flag & P_TRACED) != 0
+}

+ 2 - 2
Lanu/Localizable.xcstrings

@@ -3738,8 +3738,8 @@
         },
         "id" : {
           "stringUnit" : {
-            "state" : "needs_review",
-            "value" : "Komentar (%d)"
+            "state" : "translated",
+            "value" : "Komentar"
           }
         },
         "zh-Hans" : {

+ 19 - 14
Lanu/Manager/IM/LNIMManager.swift

@@ -79,11 +79,8 @@ class LNIMManager: NSObject {
     }
     var offlinePushAppId: Int32 {
         if LNAppConfig.shared.curEnv == .test {
-            //#if DEBUG
-            //        17229 // 本地调试使用这个
-            //#else
+//            15846 // 本地调试使用这个
             15847 // 打包 ipa 只能用这个
-            //#endif
         } else {
             15845
         }
@@ -146,14 +143,7 @@ extension LNIMManager {
             
             V2TIMManager.sharedInstance().subscribeUserStatus(userIDList: list.compactMap({ $0.userID }), succ: nil)
             loadUsersOnlineStatus()
-            getUsersRemark(uids: list.compactMap({ $0.userID })) { [weak self] remarks in
-                guard let remarks else { return }
-                guard let self else { return }
-                for item in remarks {
-                    list.first { $0.userID == item.userNo }?.extraInfo?.remark = item.note
-                }
-                notifyConversationListChanged()
-            }
+            loadUsersRemark()
         } fail: { code, err in
             handler?(false)
         }
@@ -235,6 +225,20 @@ extension LNIMManager {
             }
         } fail: { _, _ in }
     }
+    
+    private func loadUsersRemark() {
+        let newItems = conversationList.filter({ $0.extraInfo?.remark == nil })
+        guard !newItems.isEmpty else { return }
+        
+        getUsersRemark(uids: newItems.compactMap({ $0.userID })) { [weak self] remarks in
+            guard let remarks else { return }
+            guard let self else { return }
+            for item in newItems {
+                item.extraInfo?.remark = remarks.first(where: { $0.userNo == item.userID })?.note ?? ""
+            }
+            notifyConversationListChanged()
+        }
+    }
 }
 
 // MARK: 用户在线状态变化回调 V2TIMSDKListener
@@ -374,9 +378,9 @@ extension LNIMManager {
         }
     }
     
-    public func createOfflinePushInfo() -> TUIOfflinePushInfo {
+    private func createOfflinePushInfo() -> TUIOfflinePushInfo {
         let pushInfo: TUIOfflinePushInfo = TUIOfflinePushInfo()
-        pushInfo.title = ""
+        pushInfo.title = myUserInfo.nickname
         pushInfo.desc = .init(key: "C00013")
         // iOS push type: if you want user VoIP, please modify type to TUICallIOSOfflinePushTypeVoIP
         pushInfo.iOSPushType = .voIP
@@ -387,6 +391,7 @@ extension LNIMManager {
         pushInfo.androidVIVOClassification = 1
         // HuaWei message type: https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/message-classification-0000001149358835
         pushInfo.androidHuaWeiCategory = "IM"
+        
         return pushInfo
     }
 }

+ 8 - 13
Lanu/Manager/IM/LNIMMessageData.swift

@@ -36,13 +36,13 @@ extension SignalingActionType: @retroactive Decodable { }
 
 @AutoCodable
 class LNIMVoiceCallMessage: Decodable {
+    var inviter: String = ""
     var actionType: SignalingActionType?
     var businessID: Int = 0
     var inviteID: String = ""
     var data: String = ""
     
     private var decodedData: LNIMVoiceCallData?
-    var isSelf = false
     
     var callData: LNIMVoiceCallData? {
         if let decodedData {
@@ -57,13 +57,6 @@ class LNIMVoiceCallMessage: Decodable {
         return decodedData
     }
     
-    var showOnList: Bool {
-        (actionType == .invite && callData?.data?.cmd == "hangup")
-        || actionType == .cancel_Invite
-        || actionType == .reject_Invite
-        || actionType == .invite_Timeout
-    }
-    
     var contentDesc: String {
         guard let callData else { return "" }
         
@@ -71,27 +64,27 @@ class LNIMVoiceCallMessage: Decodable {
            let data = callData.data, data.cmd == "hangup" {
             .init(key: "C00001") + " " + callData.call_end.timeCountDisplay
         } else if actionType == SignalingActionType.cancel_Invite {
-            if isSelf {
+            if inviter.isMyUid {
                 .init(key: "A00152")
             } else {
                 .init(key: "A00142")
             }
         } else if actionType == SignalingActionType.reject_Invite {
             if callData.data?.cmd == "line_busy" {
-                if isSelf {
+                if inviter.isMyUid {
                     .init(key: "C00004")
                 } else {
                     .init(key: "C00011")
                 }
             } else {
-                if isSelf {
+                if inviter.isMyUid {
                     .init(key: "C00005")
                 } else {
                     .init(key: "C00009")
                 }
             }
         } else if actionType == SignalingActionType.invite_Timeout {
-            if isSelf {
+            if inviter.isMyUid {
                 .init(key: "C00010")
             } else {
                 .init(key: "C00002")
@@ -161,10 +154,12 @@ class LNIMMessageData: NSObject {
     private var customMessage: (any Decodable)?
     
     var readReceipt: V2TIMMessageReceipt?
+    var isSelf: Bool
     
     init(imMessage: V2TIMMessage) {
         self.imMessage = imMessage
         self.type = imMessage.elemType.toDataType
+        self.isSelf = imMessage.isSelf
         super.init()
         
         switch imMessage.elemType {
@@ -184,7 +179,7 @@ class LNIMMessageData: NSObject {
         
         guard let data = imMessage.customElem?.data else { return nil }
         let decoder = JSONDecoder()
-        decoder.keyDecodingStrategy = .useDefaultKeys // 处理蛇形命名
+        decoder.keyDecodingStrategy = .useDefaultKeys
         let result = try? decoder.decode(T.self, from: data)
         if let result {
             customMessage = result

+ 1 - 1
Lanu/Views/IM/Chat/Cells/LNIMChatBaseMessageCell.swift

@@ -38,7 +38,7 @@ class LNIMChatBaseMessageCell: UITableViewCell {
     }
     
     func update(_ data: LNIMMessageData, viewModel: LNIMChatViewModel) {
-        if data.imMessage.isSelf == true {
+        if data.isSelf == true {
             bubbleView.snp.remakeConstraints { make in
                 make.trailing.equalToSuperview()
                 make.top.bottom.equalToSuperview()

+ 11 - 6
Lanu/Views/IM/Chat/ViewModel/LNIMChatViewModel.swift

@@ -298,8 +298,12 @@ extension LNIMChatViewModel {
         var datas: [LNIMMessageData] = []
         
         for message in messages.reversed() {
-            let data = LNIMMessageData(imMessage: message)
+            // 被标记不展示
+            if message.isExcludedFromLastMessage || message.isExcludedFromUnreadCount {
+                continue
+            }
             
+            let data = LNIMMessageData(imMessage: message)
             if case .order = data.type {
                 guard let orderMessage: LNIMOrderMessage = data.decodeCustomMessage() else {
                     continue // 解析失败,忽略
@@ -323,11 +327,12 @@ extension LNIMChatViewModel {
                 guard let callMessage: LNIMVoiceCallMessage = data.decodeCustomMessage() else {
                     continue // 解析失败,忽略
                 }
-                callMessage.isSelf = message.isSelf
-                // 被标记不展示
-                if !callMessage.showOnList {
-                    continue
-                }
+                
+                // ->>>>> ⚠️ 挂断自己发起的通话,消息发送者会变成对方
+                // ->>>>> ⚠️ 这里需要纠正发送者
+                data.isSelf = callMessage.inviter.isMyUid
+                // ->>>>> ⚠️
+                
                 if let oldMessage = callMessageCache[callId] {
                     // 存在旧的订单信息
                     if (oldMessage.imMessage.timestamp?.timeIntervalSince1970 ?? 0)