Repository navigation
chore: Migrate notifyUsersOnMessage to TypeScript #31877
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
Merged
kodiakhq
merged 22 commits into
develop
from
refactor/migrate-notifyUsersOnMessage-to-typescript
Mar 7, 2024
Merged
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2e68af4
refactor: migrate notifyUsersOnMessage to typescript
ricardogarim f6ad177
refactor: remove useless loops on beforeGetMentions
ricardogarim 6835ee6
refactor: rename beforeGetMentions to beforeGetTeamMentions
ricardogarim edee67b
chore: remove unnecessary comment
ricardogarim 60aac2c
fix: add type importing on interfaces and types loading
ricardogarim 2c18390
fix: isolate teamsMentions into a new array filter
ricardogarim 08111f5
chore: add UnreadCountType type checking
ricardogarim a6d0be8
chore: update setLastReplyForRoomIdAndUserIds signature to comply wit…
ricardogarim 359e5dc
chore: update notifyUsersOnMessage message input type from IMessage t…
ricardogarim f263593
chore: update incMsgCountAndSetLastMessageById signature to accept me…
ricardogarim 24287f1
chore: update getMentionedTeamMembers signature
ricardogarim 8692b50
chore: update updateThreadUsersSubscriptions and notifyUsersOnReply s…
ricardogarim df50912
fix: add message related imports to fix packages building
ricardogarim 5f39dfc
fix: eslint and typecheck minors
ricardogarim 500a401
Merge branch 'develop' into refactor/migrate-notifyUsersOnMessage-to-…
3465796
chore: add callback beforeGetTeamMentions types definition
ricardogarim ebae2c9
fix: rewrite beforeGetTeamMentions length check and remove useless ty…
ricardogarim 1575b2a
revert: changes out of js > ts migration scope
ricardogarim e902254
undo some changes
sampaiodiego cfac4bf
Merge branch 'develop' into refactor/migrate-notifyUsersOnMessage-to-…
ricardogarim 31ccfce
Merge branch 'develop' into refactor/migrate-notifyUsersOnMessage-to-…
ricardogarim 2781ec8
Merge branch 'develop' into refactor/migrate-notifyUsersOnMessage-to-…
ricardogarim 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
36 changes: 14 additions & 22 deletions
36
apps/meteor/app/mentions/server/getMentionedTeamMembers.ts
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 |
|---|---|---|
| @@ -1,35 +1,27 @@ | ||
| import { Team } from '@rocket.chat/core-services'; | ||
| import type { IMessage } from '@rocket.chat/core-typings'; | ||
|
|
||
| import { callbacks } from '../../../lib/callbacks'; | ||
| import { settings } from '../../settings/server'; | ||
|
|
||
| interface IExtraDataForNotification { | ||
| userMentions: any[]; | ||
| otherMentions: any[]; | ||
| message: IMessage; | ||
| interface ITeamMention { | ||
| _id: string; | ||
| name: string; | ||
| type: string; | ||
|
ricardogarim marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| const beforeGetMentions = async (mentionIds: string[], extra?: IExtraDataForNotification) => { | ||
| const { otherMentions } = extra ?? {}; | ||
|
|
||
| const teamIds = otherMentions?.filter(({ type }) => type === 'team').map(({ _id }) => _id); | ||
|
|
||
| if (!teamIds?.length) { | ||
| return mentionIds; | ||
| } | ||
|
|
||
| const members = await Team.getMembersByTeamIds(teamIds, { projection: { userId: 1 } }); | ||
| mentionIds.push(...new Set(members.map(({ userId }) => userId).filter((userId) => !mentionIds.includes(userId)))); | ||
|
|
||
| return mentionIds; | ||
| const beforeGetTeamMentions = async (mentionIds: string[], teamMentions: ITeamMention[]): Promise<string[]> => { | ||
|
ricardogarim marked this conversation as resolved.
Outdated
|
||
| const teamsIds = teamMentions.map(({ _id }) => _id); | ||
|
ricardogarim marked this conversation as resolved.
|
||
| const members = await Team.getMembersByTeamIds(teamsIds, { projection: { userId: 1 } }); | ||
| return [...new Set([...mentionIds, ...members.map(({ userId }) => userId)])]; | ||
| }; | ||
|
|
||
| settings.watch<boolean>('Troubleshoot_Disable_Teams_Mention', (value) => { | ||
| if (value) { | ||
| callbacks.remove('beforeGetMentions', 'before-get-mentions-get-teams'); | ||
| return; | ||
| callbacks.remove('beforeGetTeamMentions', 'before-get-mentions-get-teams'); | ||
| } else { | ||
| callbacks.add('beforeGetTeamMentions', | ||
| beforeGetTeamMentions, | ||
| callbacks.priority.MEDIUM, | ||
| 'before-get-team-mentions-get-teams'); | ||
| } | ||
|
|
||
| callbacks.add('beforeGetMentions', beforeGetMentions, callbacks.priority.MEDIUM, 'before-get-mentions-get-teams'); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.