diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 72233e6d922..e06f372f6cf 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -799,9 +799,9 @@ export const Commands = [ if (args) { const cli = MatrixClientPeg.get(); - const matches = args.match(/^(@[^:]+:\S+)$/); - if (matches) { - const userId = matches[1]; + const userMatches = args.match(/^(@[^:]+:\S+)$/); + if (userMatches) { + const userId = userMatches[1]; const ignoredUsers = cli.getIgnoredUsers(); ignoredUsers.push(userId); // de-duped internally in the js-sdk return success( @@ -850,6 +850,80 @@ export const Commands = [ }, category: CommandCategories.actions, }), + new Command({ + command: 'ignore-invites', + args: '<"room"|room-id>', + description: _td('Ignores all invitations from the room going forward.'), + runFn: function(commandRoomId, args) { + const cli = MatrixClientPeg.get(); + const roomMatches = args.match(/^([!][^:]+:\S+)$/); + let targetRoomId; + if (roomMatches) { + targetRoomId = roomMatches[1]; + } else if (args === "room") { + targetRoomId = commandRoomId; + } + if (Boolean(targetRoomId)) { + const ignoredInvites = cli.getIgnoredInvites(); + if (ignoredInvites.ignored_rooms === undefined) { + ignoredInvites.ignored_rooms = []; + } + const isAlreadyIgnored = Boolean(ignoredInvites.ignored_rooms + .find(ignoredRoom => ignoredRoom.room_id === targetRoomId)); + // Doesn't feel right that we don't tell them it is already ignored + // but that's what the user ignore does too so *shrug* + if (!isAlreadyIgnored) { + ignoredInvites.ignored_rooms.push({ + room_id: targetRoomId, + ts: Date.now(), // TODO: Check this is the timestamp we want? + }); + } + return success( + cli.setIgnoredInvites(ignoredInvites).then(() => { + Modal.createDialog(InfoDialog, { + title: _t('Ignored invitations from room'), + description:
+

{ _t('You are now ignoring invitations from %(roomId)s', { roomId: targetRoomId }) }

+
, + }); + }), + ); + } + }, + category: CommandCategories.actions, + }), + new Command({ + command: 'unignore-invites', + args: '', + description: _td('Stops ignoring a room, showing the invitations going forward'), + runFn: function(roomId, args) { + if (args) { + const cli = MatrixClientPeg.get(); + const roomMatches = args.match(/^([!][^:]+:\S+)$/); + if (roomMatches) { + const roomId = roomMatches[1]; + const ignoredInvites = cli.getIgnoredInvites(); + if (ignoredInvites.ignored_rooms === undefined) { + ignoredInvites.ignored_rooms = []; + } + const index = ignoredInvites.ignored_rooms.findIndex(r => r.room_id === roomId); + if (index !== -1) ignoredInvites.ignored_rooms.splice(index, 1); + return success( + cli.setIgnoredInvites(ignoredInvites).then(() => { + Modal.createDialog(InfoDialog, { + title: _t('No longer ignoring invitations from room'), + description:
+

{ _t('You are no longer ignoring invitations from %(roomId)s', { roomId }) }

+
, + }); + }), + ); + } + } + return reject(this.getUsage()); + }, + category: CommandCategories.actions, + }), new Command({ command: 'op', args: ' []', diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 906d2358d1b..7c7502dc7b3 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -428,6 +428,12 @@ "Stops ignoring a user, showing their messages going forward": "Stops ignoring a user, showing their messages going forward", "Unignored user": "Unignored user", "You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s", + "Ignores all invitations from the room going forward.": "Ignores all invitations from the room going forward.", + "Ignored invitations from room": "Ignored invitations from room", + "You are now ignoring invitations from %(roomId)s": "You are now ignoring invitations from %(roomId)s", + "Stops ignoring a room, showing the invitations going forward": "Stops ignoring a room, showing the invitations going forward", + "No longer ignoring invitations from room": "No longer ignoring invitations from room", + "You are no longer ignoring invitations from %(roomId)s": "You are no longer ignoring invitations from %(roomId)s", "Define the power level of a user": "Define the power level of a user", "Command failed: Unable to find room (%(roomId)s": "Command failed: Unable to find room (%(roomId)s", "Could not find user in room": "Could not find user in room", diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index 5f68a61b47c..9bd087bb5d7 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -99,6 +99,11 @@ "Ignored user": "Ignored user", "Stops ignoring a user, showing their messages going forward": "Stops ignoring a user, showing their messages going forward", "Ignores a user, hiding their messages from you": "Ignores a user, hiding their messages from you", + "Ignores all invitations from the room going forward.": "Ignores all invitations from the room going forward.", + "Ignored invitations from room": "Ignored invitations from room", + "You are now ignoring invitations from %(roomId)s": "You are now ignoring invitations from %(roomId)s", + "Stops ignoring a room, showing the invitations going forward": "Stops ignoring a room, showing the invitations going forward", + "You are no longer ignoring invitations from %(roomId)s": "You are no longer ignoring invitations from %(roomId)s", "Leave room": "Leave room", "Publish this room to the public in %(domain)s's room directory?": "Publish this room to the public in %(domain)s's room directory?", "Logout": "Logout",