diff --git a/lib/src/client.dart b/lib/src/client.dart index 5d0c0453..cea838e5 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -3771,10 +3771,30 @@ class Client extends MatrixApi { /// Ignore another user. This will clear the local cached messages to /// hide all previous messages from this user. - Future ignoreUser(String userId) async { + Future ignoreUser( + String userId, { + /// Whether to also decline all invites and leave DM rooms with this user. + bool leaveRooms = true, + }) async { if (!userId.isValidMatrixId) { throw Exception('$userId is not a valid mxid!'); } + + if (leaveRooms) { + for (final room in rooms) { + final isInviteFromUser = room.membership == Membership.invite && + room.getState(EventTypes.RoomMember, userID!)?.senderId == userId; + + if (room.directChatMatrixID == userId || isInviteFromUser) { + try { + await room.leave(); + } catch (e, s) { + Logs().w('Unable to leave room with blocked user $userId', e, s); + } + } + } + } + await setAccountData(userID!, 'm.ignored_user_list', { 'ignored_users': Map.fromEntries( (ignoredUsers..add(userId)).map((key) => MapEntry(key, {})), diff --git a/lib/src/event.dart b/lib/src/event.dart index 3cb2da50..14b49e9a 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -1181,7 +1181,7 @@ class Event extends MatrixEvent { ); } - /// Returns the mentioned userIds and wether the event includes an @room + /// Returns the mentioned userIds and whether the event includes an @room /// mention. This is only determined by the `m.mention` object in the event /// content. ({List userIds, bool room}) get mentions {