Skip to content

Commit

Permalink
feat: Allow apps to react/unreact to messages (#33001)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman authored Aug 21, 2024
1 parent 2b13061 commit ed4ea30
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-windows-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Allow apps to react/unreact to messages via bridge
22 changes: 22 additions & 0 deletions apps/meteor/app/apps/server/bridges/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IAppServerOrchestrator, IAppsMessage, IAppsUser } from '@rocket.chat/apps';
import type { Reaction } from '@rocket.chat/apps-engine/definition/messages';
import type { IRoom } from '@rocket.chat/apps-engine/definition/rooms';
import type { ITypingDescriptor } from '@rocket.chat/apps-engine/server/bridges/MessageBridge';
import { MessageBridge } from '@rocket.chat/apps-engine/server/bridges/MessageBridge';
Expand All @@ -10,6 +11,7 @@ import { deleteMessage } from '../../../lib/server/functions/deleteMessage';
import { updateMessage } from '../../../lib/server/functions/updateMessage';
import { executeSendMessage } from '../../../lib/server/methods/sendMessage';
import notifications from '../../../notifications/server/lib/Notifications';
import { executeSetReaction } from '../../../reactions/server/setReaction';

export class AppMessageBridge extends MessageBridge {
constructor(private readonly orch: IAppServerOrchestrator) {
Expand Down Expand Up @@ -118,4 +120,24 @@ export class AppMessageBridge extends MessageBridge {
throw new Error('Unrecognized typing scope provided');
}
}

private isValidReaction(reaction: Reaction): boolean {
return reaction.startsWith(':') && reaction.endsWith(':');
}

protected async addReaction(messageId: string, userId: string, reaction: Reaction): Promise<void> {
if (!this.isValidReaction(reaction)) {
throw new Error('Invalid reaction');
}

return executeSetReaction(messageId, userId, reaction, true);
}

protected async removeReaction(messageId: string, userId: string, reaction: Reaction): Promise<void> {
if (!this.isValidReaction(reaction)) {
throw new Error('Invalid reaction');
}

return executeSetReaction(messageId, userId, reaction, false);
}
}
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"author": "Rocket.Chat",
"license": "MIT",
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-services": "workspace:^",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/emitter": "~0.31.25",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
"@rocket.chat/agenda": "workspace:^",
"@rocket.chat/api-client": "workspace:^",
"@rocket.chat/apps": "workspace:^",
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/base64": "workspace:^",
"@rocket.chat/cas-validate": "workspace:^",
"@rocket.chat/core-services": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion ee/apps/ddp-streamer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"author": "Rocket.Chat",
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-services": "workspace:^",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/emitter": "~0.31.25",
Expand Down
2 changes: 1 addition & 1 deletion ee/packages/presence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@babel/core": "~7.22.20",
"@babel/preset-env": "~7.22.20",
"@babel/preset-typescript": "~7.22.15",
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/eslint-config": "workspace:^",
"@rocket.chat/rest-typings": "workspace:^",
"@types/node": "^14.18.63",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"/dist"
],
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/model-typings": "workspace:^"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"extends": "../../package.json"
},
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/icons": "^0.36.0",
"@rocket.chat/message-parser": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-typings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"/dist"
],
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/icons": "^0.36.0",
"@rocket.chat/message-parser": "workspace:^",
"@rocket.chat/ui-kit": "workspace:~"
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@babel/preset-env": "~7.22.20",
"@babel/preset-react": "~7.22.15",
"@babel/preset-typescript": "~7.22.15",
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/eslint-config": "workspace:^",
"@rocket.chat/fuselage": "^0.57.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-typings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"/dist"
],
"dependencies": {
"@rocket.chat/apps-engine": "1.44.0",
"@rocket.chat/apps-engine": "1.45.0-alpha.864",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/message-parser": "workspace:^",
"@rocket.chat/ui-kit": "workspace:~",
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8483,9 +8483,9 @@ __metadata:
languageName: unknown
linkType: soft

"@rocket.chat/apps-engine@npm:1.44.0":
version: 1.44.0
resolution: "@rocket.chat/apps-engine@npm:1.44.0"
"@rocket.chat/apps-engine@npm:1.45.0-alpha.864":
version: 1.45.0-alpha.864
resolution: "@rocket.chat/apps-engine@npm:1.45.0-alpha.864"
dependencies:
"@msgpack/msgpack": 3.0.0-beta2
adm-zip: ^0.5.9
Expand All @@ -8501,15 +8501,15 @@ __metadata:
uuid: ~8.3.2
peerDependencies:
"@rocket.chat/ui-kit": "*"
checksum: f2b1b13c6a070c8d320a6d681ede6945a5882f9e2d42f2569bfc8c098229f761c7ef358589d3f1714d17b157fafa8e4869f28752408356f4a9286f62cb517f46
checksum: 4f223dd0671d920e4eaafa465fe87584473f3295061252d1020c0d0e1c076c3b74ee98af1ee5aedfeb72b042e38c3f381d10a151b3a2abcf33a7de8ac6146fa1
languageName: node
linkType: hard

"@rocket.chat/apps@workspace:^, @rocket.chat/apps@workspace:packages/apps":
version: 0.0.0-use.local
resolution: "@rocket.chat/apps@workspace:packages/apps"
dependencies:
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/model-typings": "workspace:^"
eslint: ~8.45.0
Expand Down Expand Up @@ -8582,7 +8582,7 @@ __metadata:
"@babel/core": ~7.22.20
"@babel/preset-env": ~7.22.20
"@babel/preset-typescript": ~7.22.15
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/eslint-config": "workspace:^"
"@rocket.chat/icons": ^0.36.0
Expand All @@ -8609,7 +8609,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@rocket.chat/core-typings@workspace:packages/core-typings"
dependencies:
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/eslint-config": "workspace:^"
"@rocket.chat/icons": ^0.36.0
"@rocket.chat/message-parser": "workspace:^"
Expand Down Expand Up @@ -8681,7 +8681,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@rocket.chat/ddp-streamer@workspace:ee/apps/ddp-streamer"
dependencies:
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/core-services": "workspace:^"
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/ddp-client": "workspace:~"
Expand Down Expand Up @@ -8879,7 +8879,7 @@ __metadata:
"@babel/preset-env": ~7.22.20
"@babel/preset-react": ~7.22.15
"@babel/preset-typescript": ~7.22.15
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/eslint-config": "workspace:^"
"@rocket.chat/fuselage": ^0.57.0
Expand Down Expand Up @@ -9329,7 +9329,7 @@ __metadata:
"@rocket.chat/agenda": "workspace:^"
"@rocket.chat/api-client": "workspace:^"
"@rocket.chat/apps": "workspace:^"
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/base64": "workspace:^"
"@rocket.chat/cas-validate": "workspace:^"
"@rocket.chat/core-services": "workspace:^"
Expand Down Expand Up @@ -9953,7 +9953,7 @@ __metadata:
"@babel/core": ~7.22.20
"@babel/preset-env": ~7.22.20
"@babel/preset-typescript": ~7.22.15
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/core-services": "workspace:^"
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/eslint-config": "workspace:^"
Expand Down Expand Up @@ -10067,7 +10067,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@rocket.chat/rest-typings@workspace:packages/rest-typings"
dependencies:
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/eslint-config": "workspace:~"
"@rocket.chat/message-parser": "workspace:^"
Expand Down Expand Up @@ -36732,7 +36732,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "rocketchat-services@workspace:apps/meteor/ee/server/services"
dependencies:
"@rocket.chat/apps-engine": 1.44.0
"@rocket.chat/apps-engine": 1.45.0-alpha.864
"@rocket.chat/core-services": "workspace:^"
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/emitter": ~0.31.25
Expand Down

0 comments on commit ed4ea30

Please sign in to comment.