-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2462d5c
commit 06a3ebb
Showing
2 changed files
with
61 additions
and
30 deletions.
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
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 |
---|---|---|
@@ -1,44 +1,72 @@ | ||
import { api } from '@rocket.chat/core-services'; | ||
import type { IUiKitCoreApp } from '@rocket.chat/core-services'; | ||
import type { IMessage } from '@rocket.chat/core-typings'; | ||
|
||
// import { VideoConf } from '@rocket.chat/core-services'; | ||
import { addUsersToRoomMethod } from '../../../app/lib/server/methods/addUsersToRoom'; | ||
// import { i18n } from '../../lib/i18n'; | ||
import { i18n } from '../../lib/i18n'; | ||
|
||
const retrieveMentionsFromPayload = (stringifiedMentions: string): Exclude<IMessage['mentions'], undefined> => { | ||
try { | ||
const mentions = JSON.parse(stringifiedMentions); | ||
console.log('mentions', mentions); | ||
if (!Array.isArray(mentions) || !mentions.length || !('username' in mentions[0])) { | ||
throw new Error('Invalid payload'); | ||
} | ||
return mentions; | ||
} catch (error) { | ||
throw new Error('Invalid payload'); | ||
} | ||
}; | ||
|
||
export class MentionModule implements IUiKitCoreApp { | ||
appId = 'mention-core'; | ||
|
||
async blockAction(payload: any): Promise<any> { | ||
const { | ||
// triggerId, | ||
actionId, | ||
payload: { value: commaSeparatedUsernames }, | ||
// user: { _id: userId }, | ||
payload: { value: stringifiedMentions }, | ||
} = payload; | ||
|
||
console.log('payload', payload); | ||
|
||
const mentions = retrieveMentionsFromPayload(stringifiedMentions); | ||
|
||
const usernames = mentions.map(({ username }) => username); | ||
|
||
if (actionId === 'dismiss') { | ||
// TODO: Remove actions from ephemeral message | ||
// TODO: Update message after interaction. | ||
// You mentioned Rachel Berry, but they’re not in this room. (if mentioned user is added to room remove actions) | ||
console.log('ignore'); | ||
// do nothing button | ||
void api.broadcast('notify.ephemeralMessage', payload.user._id, payload.room, { | ||
msg: i18n.t('You_mentioned___mentions__but_theyre_not_in_this_room', { | ||
mentions: `@${usernames.join(', @')}`, | ||
}), | ||
_id: payload.message, | ||
mentions, | ||
}); | ||
return; | ||
} | ||
|
||
const usernames = commaSeparatedUsernames.split(','); | ||
if (actionId === 'add-users') { | ||
// TODO: Remove actions from ephemeral message | ||
console.log('add-users'); | ||
void addUsersToRoomMethod(payload.user._id, { rid: payload.room, users: usernames }, payload.user); | ||
// add users to channel | ||
void addUsersToRoomMethod(payload.user._id, { rid: payload.room, users: usernames as string[] }, payload.user); | ||
void api.broadcast('notify.ephemeralMessage', payload.user._id, payload.room, { | ||
msg: i18n.t('You_mentioned___mentions__but_theyre_not_in_this_room', { | ||
mentions: `@${usernames.join(', @')}`, | ||
}), | ||
_id: payload.message, | ||
mentions, | ||
}); | ||
return; | ||
} | ||
|
||
if (actionId === 'share-message') { | ||
// TODO: Remove actions from ephemeral message | ||
// TODO: update ephemeral message to have the following key | ||
// You_mentioned___mentions__but_theyre_not_in_this_room_You_let_them_know_via_dm | ||
console.log('share-message'); | ||
// let them know button | ||
// const messagePayload = | ||
// mentions.forEach( | ||
|
||
// ); | ||
void api.broadcast('notify.ephemeralMessage', payload.user._id, payload.room, { | ||
msg: i18n.t('You_mentioned___mentions__but_theyre_not_in_this_room_You_let_them_know_via_dm', { | ||
mentions: `@${usernames.join(', @')}`, | ||
}), | ||
_id: payload.message, | ||
mentions, | ||
}); | ||
} | ||
} | ||
} |