Merge pull request #2150 from famedly/krille/leave-rooms-on-ignore-user
feat: Leave DM rooms and invite when ignoring a user
This commit is contained in:
commit
a44dfbe58f
|
|
@ -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, {})),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue