mobile: show errors when joining group (#861)

* mobile: show errors when joining group

* correct titles

Co-authored-by: JRoberts <8711996+jr-simplex@users.noreply.github.com>

* improvements

Co-authored-by: JRoberts <8711996+jr-simplex@users.noreply.github.com>
This commit is contained in:
Evgeny Poberezkin
2022-08-01 08:34:07 +01:00
committed by GitHub
parent ce91dcde7f
commit cc0a74fae4
7 changed files with 75 additions and 24 deletions
+11 -10
View File
@@ -579,19 +579,20 @@ func apiAddMember(groupId: Int64, contactId: Int64, memberRole: GroupMemberRole)
throw r
}
func joinGroup(_ groupId: Int64) async {
do {
let groupInfo = try await apiJoinGroup(groupId)
DispatchQueue.main.async { ChatModel.shared.updateGroup(groupInfo) }
} catch let error {
logger.error("joinGroup error: \(responseError(error))")
}
enum JoinGroupResult {
case joined(groupInfo: GroupInfo)
case invitationRemoved
case groupNotFound
}
func apiJoinGroup(_ groupId: Int64) async throws -> GroupInfo {
func apiJoinGroup(_ groupId: Int64) async throws -> JoinGroupResult {
let r = await chatSendCmd(.apiJoinGroup(groupId: groupId))
if case let .userAcceptedGroupSent(groupInfo) = r { return groupInfo }
throw r
switch r {
case let .userAcceptedGroupSent(groupInfo): return .joined(groupInfo: groupInfo)
case .chatCmdError(.errorAgent(.SMP(.AUTH))): return .invitationRemoved
case .chatCmdError(.errorStore(.groupNotFound)): return .groupNotFound
default: throw r
}
}
func apiRemoveMember(groupId: Int64, memberId: Int64) async throws -> GroupMember {