feat: Leave DM rooms and invite when ignoring a user

This commit is contained in:
Christian Kußowski 2025-09-19 10:01:52 +02:00
parent cde303c939
commit 68f2fb9ddb
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652
2 changed files with 22 additions and 2 deletions

View File

@ -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<void> ignoreUser(String userId) async {
Future<void> 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, {})),

View File

@ -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<String> userIds, bool room}) get mentions {