mobile: leave & delete group; ios: fix group preview interaction (#819)

This commit is contained in:
JRoberts
2022-07-19 18:21:15 +04:00
committed by GitHub
parent cf1f921aed
commit 0e84e131cd
16 changed files with 319 additions and 146 deletions
+26
View File
@@ -350,9 +350,20 @@ func apiDeleteChat(type: ChatType, id: Int64) async throws {
let r = await chatSendCmd(.apiDeleteChat(type: type, id: id), bgTask: false)
if case .direct = type, case .contactDeleted = r { return }
if case .contactConnection = type, case .contactConnectionDeleted = r { return }
if case .group = type, case .groupDeletedUser = r { return }
throw r
}
func deleteChat(_ chat: Chat) async {
do {
let cInfo = chat.chatInfo
try await apiDeleteChat(type: cInfo.chatType, id: cInfo.apiId)
DispatchQueue.main.async { ChatModel.shared.removeChat(cInfo.id) }
} catch {
logger.error("deleteChat apiDeleteChat error: \(responseError(error))")
}
}
func apiClearChat(type: ChatType, id: Int64) async throws -> ChatInfo {
let r = await chatSendCmd(.apiClearChat(type: type, id: id), bgTask: false)
if case let .chatCleared(updatedChatInfo) = r { return updatedChatInfo }
@@ -541,6 +552,21 @@ func apiJoinGroup(groupId: Int64) async throws -> GroupInfo {
throw r
}
func leaveGroup(groupId: Int64) async {
do {
let groupInfo = try await apiLeaveGroup(groupId: groupId)
DispatchQueue.main.async { ChatModel.shared.updateGroup(groupInfo) }
} catch let error {
logger.error("leaveGroup error: \(responseError(error))")
}
}
func apiLeaveGroup(groupId: Int64) async throws -> GroupInfo {
let r = await chatSendCmd(.apiLeaveGroup(groupId: groupId), bgTask: false)
if case let .leftMemberUser(groupInfo) = r { return groupInfo }
throw r
}
func initializeChat(start: Bool) throws {
logger.debug("initializeChat")
do {