Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

slash command to update ignored rooms list #8983

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 77 additions & 3 deletions src/SlashCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest version of the PR, ignored_rooms has become readonly.

}
const isAlreadyIgnored = Boolean(ignoredInvites.ignored_rooms
.find(ignoredRoom => ignoredRoom.room_id === targetRoomId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest version of the PR, this is an object, rather than an array.

// 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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.

});
}
return success(
cli.setIgnoredInvites(ignoredInvites).then(() => {
Modal.createDialog(InfoDialog, {
title: _t('Ignored invitations from room'),
description: <div>
<p>{ _t('You are now ignoring invitations from %(roomId)s', { roomId: targetRoomId }) }</p>
</div>,
});
}),
);
}
},
category: CommandCategories.actions,
}),
new Command({
command: 'unignore-invites',
args: '<room-id>',
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remarks.

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: <div>
<p>{ _t('You are no longer ignoring invitations from %(roomId)s', { roomId }) }</p>
</div>,
});
}),
);
}
}
return reject(this.getUsage());
},
category: CommandCategories.actions,
}),
new Command({
command: 'op',
args: '<user-id> [<power-level>]',
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/strings/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down