Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ extension ConversationServiceImplement: ConversationService {


public func fetchSilentMode(conversationIds: [String], completion: @escaping (Dictionary<String, SilentModeResult>?, ChatError?) -> Void) {
let conversations = conversationIds.map {
ChatClient.shared().chatManager?.getConversationWithConvId($0) ?? ChatConversation()
var conversations = [ChatConversation]()
for id in conversationIds {
if let conversation = ChatClient.shared().chatManager?.getConversationWithConvId(id) {
conversations.append(conversation)
}
}
ChatClient.shared().pushManager?.getSilentMode(for: conversations,completion: { [weak self] result, error in
self?.handleResult(error: error, type: .fetchSilent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

@objcMembers open class ChatHistoryViewController: UIViewController {

public private(set) var message = ChatMessage()
public private(set) var message = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public private(set) var messages = [MessageEntity]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AVFoundation

@objcMembers open class ChatThreadCreateController: UIViewController {

public private(set) var message = ChatMessage()
public private(set) var message = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

//Thread id empty represents creating a new thread,constructing the first message, and then entering the chat thread send the first message.
public private(set) lazy var viewModel: ChatThreadViewModel = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,35 +239,36 @@ extension ForwardTargetViewController: UITableViewDelegate,UITableViewDataSource
}

@objc open func forwardMessages(indexPath: IndexPath) {
var body = self.messages.first?.body ?? ChatMessageBody()
if self.combineForward {
body = ChatCombineMessageBody(title: "Chat History".chat.localize, summary: self.forwardSummary(), compatibleText: "[Chat History]", messageIdList: self.messages.filter({ChatClient.shared().chatManager?.getMessageWithMessageId($0.messageId)?.status == .succeed}).map({ $0.messageId }))
}

var conversationId = ""
if self.searchMode {
conversationId = self.searchResults[indexPath.row].id
} else {
conversationId = self.datas[indexPath.row].id
}
let message = ChatMessage(conversationID: conversationId, body: body, ext: ChatUIKitContext.shared?.currentUser?.toJsonObject())
message.chatType = self.index == 0 ? .chat:.groupChat
ChatClient.shared().chatManager?.send(message, progress: nil, completion: { [weak self] successMessage, error in
guard let `self` = self else { return }
if error == nil {
self.forwarded = true
if let cell = self.targetsList.cellForRow(at: indexPath) as? ForwardTargetCell {
var profile = ChatUserProfile()
if let user = (self.searchMode ? self.searchResults:self.datas)[safe: indexPath.row] as? ChatUserProfile {
profile = user
}
cell.refresh(info: profile, keyword: self.searchKeyWord, forward: .forwarded)
}
if var body = self.messages.first?.body {
if self.combineForward {
body = ChatCombineMessageBody(title: "Chat History".chat.localize, summary: self.forwardSummary(), compatibleText: "[Chat History]", messageIdList: self.messages.filter({ChatClient.shared().chatManager?.getMessageWithMessageId($0.messageId)?.status == .succeed}).map({ $0.messageId }))
}

var conversationId = ""
if self.searchMode {
conversationId = self.searchResults[indexPath.row].id
} else {
self.showToast(toast: error?.errorDescription ?? "Failed to forward message")
consoleLogInfo("ForwardTargetViewController forwardMessages error:\(error?.errorDescription ?? "")", type: .error)
conversationId = self.datas[indexPath.row].id
}
})
let message = ChatMessage(conversationID: conversationId, body: body, ext: ChatUIKitContext.shared?.currentUser?.toJsonObject())
message.chatType = self.index == 0 ? .chat:.groupChat
ChatClient.shared().chatManager?.send(message, progress: nil, completion: { [weak self] successMessage, error in
guard let `self` = self else { return }
if error == nil {
self.forwarded = true
if let cell = self.targetsList.cellForRow(at: indexPath) as? ForwardTargetCell {
var profile = ChatUserProfile()
if let user = (self.searchMode ? self.searchResults:self.datas)[safe: indexPath.row] as? ChatUserProfile {
profile = user
}
cell.refresh(info: profile, keyword: self.searchKeyWord, forward: .forwarded)
}
} else {
self.showToast(toast: error?.errorDescription ?? "Failed to forward message")
consoleLogInfo("ForwardTargetViewController forwardMessages error:\(error?.errorDescription ?? "")", type: .error)
}
})
}
}

@objc open func forwardSummary() -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import UIKit

private var needRefresh: (() -> Void)?

public private(set) var message = ChatMessage()
public private(set) var message = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public private(set) var reactions = [Reaction]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import UIKit

public private(set) var cursor = ""

public private(set) var message = ChatMessage()
public private(set) var message = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public private(set) var reactions: [MessageReaction] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit

public private(set) var items: [Bool] = []

public private(set) var reportMessage: ChatMessage = ChatMessage()
public private(set) var reportMessage: ChatMessage = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public private(set) var selectIndex = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public let urlPreviewImageHeight = CGFloat(137)
super.init()
}

public var message: ChatMessage = ChatMessage()
public var message: ChatMessage = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public var urlPreview: URLPreviewManager.HTMLContent?

Expand Down Expand Up @@ -794,7 +794,7 @@ public let urlPreviewImageHeight = CGFloat(137)
super.init()
}

public var message: ChatMessage = ChatMessage()
public var message: ChatMessage = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public var showUserName: String {
if let remark = self.message.user?.remark,!remark.isEmpty {
Expand Down Expand Up @@ -846,9 +846,6 @@ extension ChatMessage {
chatUser?.nickname = cacheUser?.nickname ?? ""
}
if chatUser == nil,cacheUser != nil {
if let chatAvatarURL = chatUser?.avatarURL,!chatAvatarURL.isEmpty {
cacheUser?.avatarURL = chatAvatarURL
}
return cacheUser
}
return chatUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fileprivate let space = Int((ScreenWidth-10-CGFloat((Appearance.chat.commonReact

public private(set) var reactions = [Reaction]()

public private(set) var message = ChatMessage()
public private(set) var message = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public private(set) lazy var layout: UICollectionViewFlowLayout = {
let flow = UICollectionViewFlowLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ extension ConversationListCell: ThemeSwitchProtocol {

public var nickname: String = ""

public var lastMessage: ChatMessage? = ChatMessage()
public var lastMessage: ChatMessage? = ChatMessage(conversationID: "", body: ChatTextMessageBody(text: ""), ext: nil)

public var unreadCount: UInt = 0

Expand Down