-
Notifications
You must be signed in to change notification settings - Fork 13.2k
feat(apps): Implement deleteNotifyUser to remove ephemeral mess… #38413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yush-1018
wants to merge
5
commits into
RocketChat:develop
Choose a base branch
from
yush-1018:feat/delete-notification-messages
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+192
−2
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b1bea9
feat(App Engine): Implement deleteNotifyUser to remove ephemeral mess…
yush-1018 18b2274
Merge branch 'develop' into feat/delete-notification-messages
d-gubert 0e702e5
Implement deleteNotifyUser and deleteNotifyRoom APIs for ephemeral me…
yush-1018 b4f75b0
feat: use robust composite key for ephemeral message IDs in example app
yush-1018 16fa490
Merge branch 'develop' into feat/delete-notification-messages
yush-1018 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
|
|
||
| import { | ||
| IAppAccessors, | ||
| IConfigurationExtend, | ||
| IHttp, | ||
| ILogger, | ||
| IModify, | ||
| IPersistence, | ||
| IRead, | ||
| } from '@rocket.chat/apps-engine/definition/accessors'; | ||
| import { App } from '@rocket.chat/apps-engine/definition/App'; | ||
| import { IMessage } from '@rocket.chat/apps-engine/definition/messages'; | ||
| import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata'; | ||
| import { | ||
| ISlashCommand, | ||
| SlashCommandContext, | ||
| } from '@rocket.chat/apps-engine/definition/slashcommands'; | ||
|
|
||
| export class DeleteNotifyUserApp extends App { | ||
| constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { | ||
| super(info, logger, accessors); | ||
| } | ||
|
|
||
| public async extendConfiguration( | ||
| configuration: IConfigurationExtend | ||
| ): Promise<void> { | ||
| await configuration.slashCommands.provideSlashCommand( | ||
| new TestDeleteCommand() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class TestDeleteCommand implements ISlashCommand { | ||
| public command = 'test-delete-notify'; | ||
| public i18nParamsExample = ''; | ||
| public i18nDescription = 'Tests the deleteNotifyUser API'; | ||
| public providesPreview = false; | ||
|
|
||
| public async executor( | ||
| context: SlashCommandContext, | ||
| read: IRead, | ||
| modify: IModify, | ||
| http: IHttp, | ||
| persis: IPersistence | ||
| ): Promise<void> { | ||
| const user = context.getSender(); | ||
| const room = context.getRoom(); | ||
| const notifier = modify.getNotifier(); | ||
|
|
||
| // 1. Construct the message | ||
| const message: IMessage = notifier | ||
| .getMessageBuilder() | ||
| .setRoom(room) | ||
| .setText('This message will be deleted in 3 seconds.') | ||
| .getMessage(); | ||
|
|
||
| // VERY IMPORTANT: | ||
| // Because ephemeral messages are not stored in the database, the bridge does not | ||
| // return an ID for them. We must assign an ID manually to ensure we can | ||
| // reference the SAME message in the delete call. | ||
| message.id = user.id + '-' + Date.now(); | ||
|
|
||
| // 2. Notify the user | ||
| await notifier.notifyUser(user, message); | ||
|
|
||
| // 3. Wait for 3 seconds | ||
| await new Promise((resolve) => setTimeout(resolve, 3000)); | ||
|
|
||
| // 4. Delete the notification | ||
| await notifier.deleteNotifyUser(user, message); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Validate a message id before broadcasting deletion.
If Line 88’s conversion yields a message without
_id, the client can’t match and remove the notification, turning the delete into a silent no-op. Consider guarding for a missing id.🛠️ Proposed guard
const msg = await this.orch.getConverters()?.get('messages').convertAppMessage(message); if (!msg) { return; } + + if (!msg._id) { + this.orch.debugLog(`The App ${appId} attempted to delete a notification without a message id.`); + return; + } void api.broadcast('notify.ephemeralMessage', user.id, msg.rid, { ...msg, _deleted: true, });🤖 Prompt for AI Agents