Visual_Novel_iOS/crush/Crush/Src/Modules/Chat/Util/IMRemoteUtil.swift

82 lines
2.3 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// IMRemoteUtil.swift
// Crush
//
// Created by Leon on 2025/8/18.
//
import NIMSDK
import UIKit
class IMRemoteUtil {
/// V2NIMMessage -> IMBaseRemoteInfo cellType
static func dealRemoteInfo(message: V2NIMMessage?) -> IMBaseRemoteInfo {
guard let msg = message else {
return IMBaseRemoteInfo()
}
// Parse serverExtension
let remote = message?.serverExtension ?? ""
let info = CodableHelper.decode(IMBaseRemoteInfo.self, from: remote) ?? IMBaseRemoteInfo()
info.displayString = message?.text
// Set default cellType according to Message type.
switch message?.messageType {
case .MESSAGE_TYPE_TEXT:
if msg.isSelf {
info.cellType = .text
} else {
info.cellType = .aimsg
}
case .MESSAGE_TYPE_TIP:
info.cellType = .tips
case .MESSAGE_TYPE_CUSTOM:
// Parse cellTypeAttachment
dealCustom(info: info, attachment: message?.attachment)
default:
info.cellType = .unknown
}
return info
}
private static func dealCustom(info: IMBaseRemoteInfo, attachment: V2NIMMessageAttachment?) {
guard let attach = attachment else {
return
}
info.cellType = .text
let attachmentString = attach.raw
// dlog("🔥 V2NIMMessageAttachment's raw:\(attach.raw)")
guard attachmentString.count > 0, let model = CodableHelper.decode(IMCustomAttachment.self, from: attachmentString) else {
return
}
info.customAttachment = model
guard let type = model.type else {
dlog("☁️❌ wrong type, attach.raw is: \(attachmentString)")
return
}
switch type {
case .IMAGE:
info.cellType = .image
info.displayString = "[Image]"
case .IM_SEND_GIFT:
info.cellType = .gift
info.displayString = "[Gift]"
case .CALL:
info.cellType = .phonecall
info.displayString = model.getDisplayString()
default:
break
}
}
// MARK: - Helper
// MARK: Call
}