Skip to content

Commit

Permalink
v10.4.0 (#406)
Browse files Browse the repository at this point in the history
* add sample code

* update Podfile

* v10.4.0

---------

Co-authored-by: 张诗文 <[email protected]>
  • Loading branch information
zsw666 and 张诗文 authored Nov 1, 2024
1 parent a3b9a07 commit 4872910
Show file tree
Hide file tree
Showing 83 changed files with 740 additions and 729 deletions.
4 changes: 2 additions & 2 deletions NEChatUIKit/NEChatUIKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = 'NEChatUIKit'
s.version = '10.3.0'
s.version = '10.4.0'
s.summary = 'Chat Module of IM.'

# This description is used to generate tags and improve search results.
Expand All @@ -43,7 +43,7 @@ TODO: Add long description of the pod here.

s.resource = 'NEChatUIKit/Assets/**/*'
s.dependency 'NEChatKit'
s.dependency 'NECommonUIKit', '9.7.0'
s.dependency 'NECommonUIKit', '9.7.3'
s.dependency 'MJRefresh'
s.dependency 'SDWebImageWebPCoder'
s.dependency 'SDWebImageSVGKitPlugin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open class NEChatBaseViewController: UIViewController, UIGestureRecognizerDelega
super.viewWillAppear(animated)

// 配置项:会话界面是否展示标题栏
if !NEKitChatConfig.shared.ui.messageProperties.showTitleBar {
if !ChatUIConfig.shared.messageProperties.showTitleBar {
navigationController?.isNavigationBarHidden = true
navigationView.removeFromSuperview()
return
Expand All @@ -61,7 +61,7 @@ open class NEChatBaseViewController: UIViewController, UIGestureRecognizerDelega

override open func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = NEKitChatConfig.shared.ui.messageProperties.chatViewBackground ?? .white
view.backgroundColor = ChatUIConfig.shared.messageProperties.chatViewBackground ?? .white

if let useSystemNav = NEConfigManager.instance.getParameter(key: useSystemNav) as? Bool, useSystemNav {
topConstant = NEConstant.navigationAndStatusHeight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
isCurrentPage = true
markNeedReadMsg()

if NEKitChatConfig.shared.ui.messageProperties.showTitleBar {
if ChatUIConfig.shared.messageProperties.showTitleBar {
bodyTopViewTopConstant = topConstant
}

Expand Down Expand Up @@ -366,13 +366,14 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
let param = ["sessionId": viewModel.conversationId]
Router.shared.use("ClearAtMessageRemind", parameters: param, closure: nil)

NotificationCenter.default.removeObserver(self)
NETeamUserManager.shared.removeAllTeamInfo()
}
}

open func setMoreButton() {
if NEKitChatConfig.shared.ui.messageProperties.showTitleBarRightIcon {
let image = NEKitChatConfig.shared.ui.messageProperties.titleBarRightRes ?? UIImage.ne_imageNamed(name: "three_point")
if ChatUIConfig.shared.messageProperties.showTitleBarRightIcon {
let image = ChatUIConfig.shared.messageProperties.titleBarRightRes ?? UIImage.ne_imageNamed(name: "three_point")
addRightAction(image, #selector(toSetting), self)
navigationView.setMoreButtonImage(image)
} else {
Expand Down Expand Up @@ -460,7 +461,7 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD

expandMoreAction()

if let customController = NEKitChatConfig.shared.ui.customController {
if let customController = ChatUIConfig.shared.customController {
customController(self)
}
}
Expand Down Expand Up @@ -609,8 +610,8 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
}

// 配置项自定义 items
if let chatPopMenu = NEKitChatConfig.shared.ui.chatPopMenu {
chatPopMenu(&items, model)
if let chatPopMenu = ChatUIConfig.shared.chatPopMenu {
chatPopMenu(self, &items, model)
}

// 供用户自定义 items
Expand Down Expand Up @@ -731,8 +732,8 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
/// 设置按钮点击事件
override open func toSetting() {
// 自定义设置按钮点击事件
if let block = NEKitChatConfig.shared.ui.messageProperties.titleBarRightClick {
block()
if let block = ChatUIConfig.shared.messageProperties.titleBarRightClick {
block(self)
return
}

Expand Down Expand Up @@ -1137,9 +1138,9 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
}

open func didSelectMoreCell(cell: NEInputMoreCell) {
if let delegate = cell.cellData?.customDelegate as? AnyObject, let action = cell.cellData?.action {
if let action = cell.cellData?.action {
// 用户自定义更多面板按钮
_ = delegate.perform(action)
action(self, cell.cellData)
return
}

Expand Down Expand Up @@ -1534,8 +1535,8 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
if isFile == true {
let imgSize_MB = Double(pngImage?.count ?? 0) / 1e6
NEALog.infoLog(ModuleName + " " + ChatViewController.className(), desc: #function + "imgSize_MB: \(imgSize_MB) MB")
if imgSize_MB > NEKitChatConfig.shared.ui.fileSizeLimit {
showToast(String(format: chatLocalizable("fileSize_over_limit"), "\(NEKitChatConfig.shared.ui.fileSizeLimit)"))
if imgSize_MB > ChatUIConfig.shared.fileSizeLimit {
showToast(String(format: chatLocalizable("fileSize_over_limit"), "\(ChatUIConfig.shared.fileSizeLimit)"))
} else {
viewModel.sendFileMessage(filePath: imageUrl.relativePath,
displayName: imageName) { [weak self] message, error, progress in
Expand Down Expand Up @@ -1640,8 +1641,8 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
let fileAttributes = try FileManager.default.attributesOfItem(atPath: desPath)
if let size_B = fileAttributes[FileAttributeKey.size] as? Double {
let size_MB = size_B / 1e6
if size_MB > NEKitChatConfig.shared.ui.fileSizeLimit {
showToast(String(format: chatLocalizable("fileSize_over_limit"), "\(NEKitChatConfig.shared.ui.fileSizeLimit)"))
if size_MB > ChatUIConfig.shared.fileSizeLimit {
showToast(String(format: chatLocalizable("fileSize_over_limit"), "\(ChatUIConfig.shared.fileSizeLimit)"))
try? FileManager.default.removeItem(atPath: desPath)
} else {
viewModel.sendFileMessage(filePath: desPath,
Expand Down Expand Up @@ -1692,17 +1693,30 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
controller.dismiss(animated: true)
}

// MARK: - ChatviewModelDelegate
// MARK: - ChatViewModelDelegate

/// 本端即将发送消息状态回调,此时消息还未发送,可对消息进行修改或者拦截发送
/// 来源: 发送消息, 插入消息
/// - Parameter message: 消息
/// - Parameter completion: 是否继续发送消息
public func readySendMessage(_ message: V2NIMMessage, _ completion: @escaping (Bool) -> Void) {
if let block = NEKitChatConfig.shared.ui.onSendMessage {
completion(block(message, self))
/// - Parameter param: 消息参数,包含消息和发送参数
/// - Returns: (修改后的)消息参数,若消息参数为 nil,则表示拦截该消息不发送
public func beforeSend(_ param: MessageSendParams) -> MessageSendParams? {
if let block = ChatKitClient.shared.beforeSend {
let p = block(self, param)
return p
} else {
return param
}
}

/// 本端即将发送消息状态回调,此时消息还未发送,可对消息进行修改或者拦截发送
/// 来源: 发送消息, 插入消息
/// - Parameter param: 消息参数,包含消息和发送参数
/// - Parameter completion: (修改后的)消息参数,若消息参数为 nil,则表示拦截该消息不发送
public func beforeSend(_ param: MessageSendParams, _ completion: @escaping (MessageSendParams?) -> Void) {
if let block = ChatKitClient.shared.beforeSendCompletion {
block(self, param, completion)
} else {
completion(true)
completion(param)
}
}

Expand Down Expand Up @@ -2152,8 +2166,8 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
removeOperationView()

// 配置项拦截
if let popMenuClick = NEKitChatConfig.shared.ui.popMenuClick {
popMenuClick(item)
if let popMenuClick = ChatUIConfig.shared.popMenuClick {
popMenuClick(self, item)
return
}

Expand Down Expand Up @@ -2299,6 +2313,15 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
}

if let message = weakSelf?.viewModel.operationModel?.message {
// 校验消息可撤回时间
let date = Date()
let currentTime = date.timeIntervalSince1970
let reTime = ChatUIConfig.shared.getReeditTimeGap()
if Int(currentTime - message.createTime) >= reTime * 60 {
weakSelf?.showToast(chatLocalizable("ravokable_time_expired"))
return
}

if weakSelf?.viewModel.operationModel?.type == .text {
weakSelf?.viewModel.operationModel?.isReedit = true
}
Expand Down Expand Up @@ -2816,7 +2839,7 @@ open class ChatViewController: NEChatBaseViewController, UINavigationControllerD
/// 输入框【更多】按钮点击事件,子类重写
@discardableResult
open func expandMoreAction() -> [NEMoreItemModel] {
var items = NEChatUIKitClient.instance.getMoreActionData(sessionType: V2NIMConversationIdUtil.conversationType(viewModel.conversationId))
var items = NEChatUIKitClient.instance.getMoreActionData(sessionType: V2NIMConversationIdUtil.conversationType(viewModel.conversationId), self)
if NEChatKitClient.instance.delegate == nil {
items = items.filter { item in
if item.type == .location {
Expand Down Expand Up @@ -3498,8 +3521,8 @@ extension ChatViewController: ChatBaseCellDelegate {
}

open func didTapMessageView(_ cell: UITableViewCell, _ model: MessageContentModel?, _ replyModel: MessageModel?) {
if let tapClick = NEKitChatConfig.shared.ui.messageItemClick {
tapClick(cell, model)
if let tapClick = ChatUIConfig.shared.messageItemClick {
tapClick(self, cell, model)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ open class MultiForwardViewController: NEChatBaseViewController, UINavigationCon
// MARK: ChatBaseCellDelegate

open func didTapMessageView(_ cell: UITableViewCell, _ model: MessageContentModel?, _ replyModel: MessageModel?) {
if let tapClick = NEKitChatConfig.shared.ui.messageItemClick {
tapClick(cell, model)
if let tapClick = ChatUIConfig.shared.messageItemClick {
tapClick(self, cell, model)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ open class NEEmotionTool: NSObject {
/// - offset: 偏移量
/// - Returns: 替换表情后的富文本
class func getAttWithStr(str: String, font: UIFont,
_ offset: CGPoint = CGPoint(x: 0, y: -3)) -> NSMutableAttributedString {
_ offset: CGPoint = CGPoint(x: 0, y: -4)) -> NSMutableAttributedString {
let regularArr = getRegularArray(str: str)
let emoticons = NIMInputEmoticonManager.shared
.emoticonCatalog(catalogID: NIMKit_EmojiCatalog)?.emoticons
let attStr = NSMutableAttributedString(string: str, attributes: [
NSAttributedString.Key.font: font,
.foregroundColor: NEKitChatConfig.shared.ui.messageProperties.messageTextColor,
.foregroundColor: ChatUIConfig.shared.messageProperties.messageTextColor,
])

if let regArr = regularArr, regArr.count > 0, let targetEmotions = emoticons {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public class ChatMessageHelper: NSObject {
}

let text = message?.text ?? ""
let messageTextFont = UIFont.systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.messageTextSize)
let messageTextFont = UIFont.systemFont(ofSize: ChatUIConfig.shared.messageProperties.messageTextSize)

// 兼容老的表情消息,如果前面有表情而位置计算异常则回退回老的解析
var notFound = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ open class CollectionMessageModel: NSObject {

open func cellHeight(contenttMaxW: CGFloat) -> CGFloat {
var height = chatmodel.contentSize.height
let titleFont: UIFont = .systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.pinMessageTextSize, weight: .semibold)
let bodyFont: UIFont = .systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.pinMessageTextSize)
let titleFont: UIFont = .systemFont(ofSize: ChatUIConfig.shared.messageProperties.pinMessageTextSize, weight: .semibold)
let bodyFont: UIFont = .systemFont(ofSize: ChatUIConfig.shared.messageProperties.pinMessageTextSize)
let maxSize = CGSize(width: contenttMaxW, height: CGFloat.greatestFiniteMagnitude)

if let textModel = chatmodel as? MessageTextModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class MessageCallRecordModel: MessageContentModel {

attributeStr?.addAttribute(NSAttributedString.Key.font, value: messageTextFont, range: NSMakeRange(0, attributeStr?.length ?? 0))

attributeStr?.addAttribute(NSAttributedString.Key.foregroundColor, value: NEKitChatConfig.shared.ui.messageProperties.messageTextColor, range: NSMakeRange(0, attributeStr?.length ?? 0))
attributeStr?.addAttribute(NSAttributedString.Key.foregroundColor, value: ChatUIConfig.shared.messageProperties.messageTextColor, range: NSMakeRange(0, attributeStr?.length ?? 0))
}

let textSize = NSAttributedString.getRealSize(attributeStr, messageTextFont, messageMaxSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ open class MessageContentModel: NSObject, MessageModel {
didSet {
if isRevoked {
type = .revoke

// 校验撤回消息可编辑时间
if let time = message?.createTime {
let date = Date()
let currentTime = date.timeIntervalSince1970
if currentTime - time > 60 * 2 {
if Int(currentTime - time) > ChatUIConfig.shared.revokeEditTimeGap * 60 {
timeOut = true
}
}

// 只有文本消息,才计算可编辑按钮的宽度
if let isSend = message?.isSelf, isSend, message?.messageType == .MESSAGE_TYPE_TEXT, timeOut == false {
contentSize = CGSize(width: 218, height: chat_min_h)
Expand Down Expand Up @@ -121,15 +124,15 @@ open class MessageContentModel: NSObject, MessageModel {
}
}

public let messageTextFont = UIFont.systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.messageTextSize)
public let messageTextFont = UIFont.systemFont(ofSize: ChatUIConfig.shared.messageProperties.messageTextSize)
public let messageMaxSize = CGSize(width: chat_content_maxW, height: CGFloat.greatestFiniteMagnitude)

public required init(message: V2NIMMessage?) {
self.message = message
if message?.conversationType == .CONVERSATION_TYPE_TEAM,
let senderId = ChatMessageHelper.getSenderId(message),
!IMKitClient.instance.isMe(senderId) {
fullNameHeight = NEKitChatConfig.shared.ui.messageProperties.showTeamMessageNick ? 20 : 0
fullNameHeight = ChatUIConfig.shared.messageProperties.showTeamMessageNick ? 20 : 0
}
height = contentSize.height + chat_content_margin * 2 + fullNameHeight + chat_pin_height
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class MessageRichTextModel: MessageTextModel {
type = .custom
customType = customRichTextType

let font = UIFont.systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.messageTextSize, weight: .semibold)
let font = UIFont.systemFont(ofSize: ChatUIConfig.shared.messageProperties.messageTextSize, weight: .semibold)
titleAttributeStr = NEEmotionTool.getAttWithStr(
str: title,
font: font
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ open class MessageTipsModel: MessageContentModel {
}
}

var font: UIFont = .systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.timeTextSize)
var font: UIFont = .systemFont(ofSize: ChatUIConfig.shared.messageProperties.timeTextSize)
if ChatMessageHelper.isAISender(message) {
font = .systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.messageTextSize)
font = .systemFont(ofSize: ChatUIConfig.shared.messageProperties.messageTextSize)
}

let textSize = String.getRealSize(text, font, messageMaxSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ open class NEMoreItemModel: NSObject {
// 对应的单元类型
public var type: NEMoreActionType?

// 代理类
public weak var customDelegate: AnyObject?

// 动态事件
public var action: Selector?
public var action: ((ChatViewController, NEMoreItemModel?) -> Void)?

// 自定义图标
public var customImage: UIImage?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ open class NEPinMessageModel: NSObject {

open func cellHeight(pinContentMaxW: CGFloat) -> CGFloat {
var height = chatmodel.contentSize.height
let titleFont: UIFont = .systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.pinMessageTextSize, weight: .semibold)
let bodyFont: UIFont = .systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.pinMessageTextSize)
let titleFont: UIFont = .systemFont(ofSize: ChatUIConfig.shared.messageProperties.pinMessageTextSize, weight: .semibold)
let bodyFont: UIFont = .systemFont(ofSize: ChatUIConfig.shared.messageProperties.pinMessageTextSize)
let maxSize = CGSize(width: pinContentMaxW, height: CGFloat.greatestFiniteMagnitude)

if let textModel = chatmodel as? MessageTextModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class NEBaseCollectionMessageAudioCell: NEBaseCollectionMessageCell {
override open func setupCommonUI() {
super.setupCommonUI()

let receiveImage = NEKitChatConfig.shared.ui.messageProperties.leftBubbleBg ?? UIImage.ne_imageNamed(name: "chat_message_receive")
let receiveImage = ChatUIConfig.shared.messageProperties.leftBubbleBg ?? UIImage.ne_imageNamed(name: "chat_message_receive")
bubbleImage.image = receiveImage?
.resizableImage(withCapInsets: NEKitChatConfig.shared.ui.messageProperties.backgroundImageCapInsets)
.resizableImage(withCapInsets: ChatUIConfig.shared.messageProperties.backgroundImageCapInsets)
bubbleImage.translatesAutoresizingMaskIntoConstraints = false
backView.addSubview(bubbleImage)
contentWidth = bubbleImage.widthAnchor.constraint(equalToConstant: chat_content_maxW)
Expand All @@ -60,7 +60,7 @@ class NEBaseCollectionMessageAudioCell: NEBaseCollectionMessageCell {
audioImageView.heightAnchor.constraint(equalToConstant: 28),
])

audioTimeLabel.font = UIFont.systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.pinMessageTextSize)
audioTimeLabel.font = UIFont.systemFont(ofSize: ChatUIConfig.shared.messageProperties.pinMessageTextSize)
audioTimeLabel.textAlignment = .left
audioTimeLabel.textColor = UIColor.ne_darkText
audioTimeLabel.translatesAutoresizingMaskIntoConstraints = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NEBaseCollectionMessageRichTextCell: NEBaseCollectionMessageTextCell {
/// 换行文本
public lazy var collectionTitleLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.pinMessageTextSize)
label.font = UIFont.systemFont(ofSize: ChatUIConfig.shared.messageProperties.pinMessageTextSize)
label.textColor = .ne_darkText
label.translatesAutoresizingMaskIntoConstraints = false
label.isUserInteractionEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NEBaseCollectionMessageTextCell: NEBaseCollectionMessageCell {
/// 内容文本
public lazy var collectionContentLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: NEKitChatConfig.shared.ui.messageProperties.pinMessageTextSize)
label.font = UIFont.systemFont(ofSize: ChatUIConfig.shared.messageProperties.pinMessageTextSize)
label.textColor = .ne_darkText
label.translatesAutoresizingMaskIntoConstraints = false
label.isUserInteractionEnabled = true
Expand Down
Loading

0 comments on commit 4872910

Please sign in to comment.