From 76847d3e147cc7af5bc33fa2f3fedadc174f9587 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Mon, 4 Jul 2022 11:39:36 +0100 Subject: [PATCH 1/3] slash command to update ignored rooms list Based on https://github.com/matrix-org/matrix-js-sdk/pull/2483 Doens't actually ignore anything yet though... --- src/SlashCommands.tsx | 22 ++++++++++++++++++++++ src/i18n/strings/en_EN.json | 2 ++ src/i18n/strings/en_US.json | 2 ++ 3 files changed, 26 insertions(+) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 72233e6d922..168bbe345e8 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -815,6 +815,28 @@ 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 = []; + } + ignoredInvites.ignored_rooms.push({ + room_id: roomId, + ts: Date.now(), // TODO: Check this is the timestamp we want? + }); // TODO: figure out whether we're deduplicating or not https://github.com/matrix-org/matrix-js-sdk/pull/2483#discussion_r913013654 + 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()); }, diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 906d2358d1b..c0100b68736 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -428,6 +428,8 @@ "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", "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..ed423b0eee8 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -99,6 +99,8 @@ "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", "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", From a757a8d3e0633c6ea2e5e1f26e35969cd8bc57f8 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Tue, 5 Jul 2022 13:05:25 +0100 Subject: [PATCH 2/3] Feedback from review --- src/SlashCommands.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 168bbe345e8..f61f2d6a7d0 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( @@ -822,10 +822,16 @@ export const Commands = [ if (ignoredInvites.ignored_rooms === undefined) { ignoredInvites.ignored_rooms = []; } - ignoredInvites.ignored_rooms.push({ - room_id: roomId, - ts: Date.now(), // TODO: Check this is the timestamp we want? - }); // TODO: figure out whether we're deduplicating or not https://github.com/matrix-org/matrix-js-sdk/pull/2483#discussion_r913013654 + 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, { From 26d3de705f7c7a928d3d16aa58aba188995388b6 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Wed, 6 Jul 2022 17:18:43 +0100 Subject: [PATCH 3/3] 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",