This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
slash command to update ignored rooms list #8983
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 becomereadonly
.