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

Commit

Permalink
As requested, change to ignore-invites rather than ignore-room.
Browse files Browse the repository at this point in the history
The command is much the same but the actual implementation
matrix-org/matrix-js-sdk#2496 will now only
hide invitations.

We now have a command to unignore invitations from a room.
  • Loading branch information
Gnuxie committed Jul 6, 2022
1 parent a757a8d commit 26d3de7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 32 deletions.
102 changes: 74 additions & 28 deletions src/SlashCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: <div>
<p>{ _t('You are now ignoring %(roomId)s', { roomId }) }</p>
</div>,
});
}),
);
}
}
return reject(this.getUsage());
},
Expand Down Expand Up @@ -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: <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) {
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
8 changes: 6 additions & 2 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/i18n/strings/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 26d3de7

Please sign in to comment.