- 添加 expiresAt 和 refreshUserSig 参数支持自动续签 - 修改 PushSDK 初始化方式,自动完成设备注册和厂商初始化 - 调整过期续签策略,从提前 15 分钟改为提前 5 分钟触发 - 重构 RN SDK 文档结构,简化安装和使用方式 - 更新统一登录流程,支持 profile 信息传递 - 添加 IM 数据库自动隔离功能 - 修复 Android 群消息聚合问题 - 补充自动化测试验证和错误处理机制
77 行
2.5 KiB
Swift
77 行
2.5 KiB
Swift
import Foundation
|
|
import XuqmSDK
|
|
|
|
@MainActor
|
|
final class ConversationViewModel: ObservableObject {
|
|
@Published var conversations: [ConversationData] = []
|
|
@Published var state: ConversationLoadState = .idle
|
|
@Published var query: String = ""
|
|
@Published var totalUnreadCount: Int = 0
|
|
|
|
var filteredConversations: [ConversationData] {
|
|
if query.isEmpty { return conversations }
|
|
let keyword = query.trimmingCharacters(in: .whitespaces)
|
|
return conversations.filter {
|
|
$0.targetId.localizedCaseInsensitiveContains(keyword)
|
|
|| conversationPreview($0).localizedCaseInsensitiveContains(keyword)
|
|
}
|
|
}
|
|
|
|
func load() {
|
|
state = .loading
|
|
Task {
|
|
do {
|
|
conversations = try await ImSDK.shared.listConversations()
|
|
totalUnreadCount = conversations.reduce(0) { $0 + $1.unreadCount }
|
|
state = .loaded
|
|
} catch {
|
|
state = .error(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
|
|
func refresh() {
|
|
Task {
|
|
do {
|
|
conversations = try await ImSDK.shared.listConversations()
|
|
totalUnreadCount = conversations.reduce(0) { $0 + $1.unreadCount }
|
|
} catch {
|
|
state = .error(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
|
|
func deleteConversation(_ conversation: ConversationData) {
|
|
Task {
|
|
do {
|
|
try await ImSDK.shared.deleteConversation(targetId: conversation.targetId, chatType: conversation.chatType)
|
|
await refresh()
|
|
} catch {
|
|
state = .error(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
|
|
func togglePinned(_ conversation: ConversationData) {
|
|
Task {
|
|
do {
|
|
try await ImSDK.shared.setConversationPinned(targetId: conversation.targetId, chatType: conversation.chatType, pinned: !conversation.isPinned)
|
|
await refresh()
|
|
} catch {
|
|
state = .error(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
|
|
func toggleMuted(_ conversation: ConversationData) {
|
|
Task {
|
|
do {
|
|
try await ImSDK.shared.setConversationMuted(targetId: conversation.targetId, chatType: conversation.chatType, muted: !conversation.isMuted)
|
|
await refresh()
|
|
} catch {
|
|
state = .error(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|
|
}
|