From 26d3de705f7c7a928d3d16aa58aba188995388b6 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Wed, 6 Jul 2022 17:18:43 +0100 Subject: [PATCH] As requested, change to ignore-invites rather than ignore-room. The command is much the same but the actual implementation https://github.com/matrix-org/matrix-js-sdk/pull/2496 will now only hide invitations. We now have a command to unignore invitations from a room. --- src/SlashCommands.tsx | 102 ++++++++++++++++++++++++++---------- src/i18n/strings/en_EN.json | 8 ++- src/i18n/strings/en_US.json | 7 ++- 3 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index f61f2d6a7d0..e06f372f6cf 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -815,34 +815,6 @@ export const Commands = [ }), ); } - const roomMatches = args.match(/^([!][^:]+:\S+)$/); - if (roomMatches) { - const roomId = roomMatches[1]; - const ignoredInvites = cli.getIgnoredInvites(); - if (ignoredInvites.ignored_rooms === undefined) { - ignoredInvites.ignored_rooms = []; - } - const isAlreadyIgnored = Boolean(ignoredInvites.ignored_rooms - .find(ignoredRoom => ignoredRoom.room_id === roomId)); - // 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: roomId, - ts: Date.now(), // TODO: Check this is the timestamp we want? - }); - } - return success( - cli.setIgnoredInvites(ignoredInvites).then(() => { - Modal.createDialog(InfoDialog, { - title: _t('Ignored room'), - description:
-

{ _t('You are now ignoring %(roomId)s', { roomId }) }

-
, - }); - }), - ); - } } return reject(this.getUsage()); }, @@ -878,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 c0100b68736..7c7502dc7b3 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -428,8 +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", - "Ignored room": "Ignored room", - "You are now ignoring %(roomId)s": "You are now ignoring %(roomId)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 ed423b0eee8..9bd087bb5d7 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -99,8 +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", - "Ignored room": "Ignored room", - "You are now ignoring %(roomId)s": "You are now ignoring %(roomId)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", + "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",