fix: Automatic leave broken invites

This commit is contained in:
Christian Pauly 2020-11-06 09:06:49 +01:00
parent cbae6b9c84
commit 793d398d72
1 changed files with 18 additions and 9 deletions

View File

@ -798,7 +798,7 @@ class Room {
/// Call the Matrix API to join this room if the user is not already a member. /// Call the Matrix API to join this room if the user is not already a member.
/// If this room is intended to be a direct chat, the direct chat flag will /// If this room is intended to be a direct chat, the direct chat flag will
/// automatically be set. /// automatically be set.
Future<void> join({bool removeIfNotFound = true}) async { Future<void> join({bool leaveIfNotFound = true}) async {
try { try {
await client.joinRoom(id); await client.joinRoom(id);
final invitation = getState(EventTypes.RoomMember, client.userID); final invitation = getState(EventTypes.RoomMember, client.userID);
@ -808,9 +808,25 @@ class Room {
await addToDirectChat(invitation.sender.id); await addToDirectChat(invitation.sender.id);
} }
} on MatrixException catch (exception) { } on MatrixException catch (exception) {
if (removeIfNotFound && if (leaveIfNotFound &&
[MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN] [MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN]
.contains(exception.error)) { .contains(exception.error)) {
await leave();
}
rethrow;
}
return;
}
/// Call the Matrix API to leave this room. If this room is set as a direct
/// chat, this will be removed too.
Future<void> leave() async {
if (directChatMatrixID != '') await removeFromDirectChat();
try {
await client.leaveRoom(id);
} on MatrixException catch (exception) {
if ([MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN]
.contains(exception.error)) {
await _handleFakeSync( await _handleFakeSync(
SyncUpdate() SyncUpdate()
..rooms = (RoomsUpdate() ..rooms = (RoomsUpdate()
@ -821,13 +837,6 @@ class Room {
} }
rethrow; rethrow;
} }
}
/// Call the Matrix API to leave this room. If this room is set as a direct
/// chat, this will be removed too.
Future<void> leave() async {
if (directChatMatrixID != '') await removeFromDirectChat();
await client.leaveRoom(id);
return; return;
} }