-
Notifications
You must be signed in to change notification settings - Fork 13k
refactor: remove meteor calls from spotlight and browseChannels (server) #35836
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,18 +4,20 @@ import { Meteor } from 'meteor/meteor'; | |
|
|
||
| import { Spotlight } from '../lib/spotlight'; | ||
|
|
||
| type SpotlightType = { | ||
| users?: boolean; | ||
| rooms?: boolean; | ||
| mentions?: boolean; | ||
| includeFederatedRooms?: boolean; | ||
| }; | ||
|
|
||
| declare module '@rocket.chat/ddp-client' { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| interface ServerMethods { | ||
| spotlight( | ||
| text: string, | ||
| usernames?: string[], | ||
| type?: { | ||
| users?: boolean; | ||
| rooms?: boolean; | ||
| mentions?: boolean; | ||
| includeFederatedRooms?: boolean; | ||
| }, | ||
| type?: SpotlightType, | ||
| rid?: string, | ||
| ): { | ||
| rooms: { _id: string; name: string; t: string; uids?: string[] }[]; | ||
|
|
@@ -32,27 +34,41 @@ declare module '@rocket.chat/ddp-client' { | |
| } | ||
| } | ||
|
|
||
| Meteor.methods<ServerMethods>({ | ||
| async spotlight(text, usernames = [], type = { users: true, rooms: true, mentions: false, includeFederatedRooms: false }, rid) { | ||
| const spotlight = new Spotlight(); | ||
| const { mentions, includeFederatedRooms } = type; | ||
| export const spotlightMethod = async ({ | ||
| text, | ||
| usernames = [], | ||
| type = { users: true, rooms: true, mentions: false, includeFederatedRooms: false }, | ||
| rid, | ||
| userId, | ||
| }: { | ||
| text: string; | ||
| usernames?: string[]; | ||
| type?: SpotlightType; | ||
| rid?: string; | ||
| userId?: string | null; | ||
| }) => { | ||
| const spotlight = new Spotlight(); | ||
| const { mentions, includeFederatedRooms } = type; | ||
|
|
||
| if (text.startsWith('#')) { | ||
| type.users = false; | ||
| text = text.slice(1); | ||
| } | ||
| if (text.startsWith('#')) { | ||
| type.users = false; | ||
| text = text.slice(1); | ||
| } | ||
|
|
||
| if (text.startsWith('@')) { | ||
| type.rooms = false; | ||
| text = text.slice(1); | ||
| } | ||
| if (text.startsWith('@')) { | ||
| type.rooms = false; | ||
| text = text.slice(1); | ||
| } | ||
|
Comment on lines
+53
to
+61
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. const modifiedType = { ...type };
if (text.startsWith('#')) {
modifiedType.users = false;
text = text.slice(1);
}
if (text.startsWith('@')) {
modifiedType.rooms = false;
text = text.slice(1);
}
return {
users: modifiedType.users ? await spotlight.searchUsers({ userId, rid, text, usernames, mentions }) : [],
rooms: modifiedType.rooms ? await spotlight.searchRooms({ userId, text, includeFederatedRooms }) : []
};The This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
|
|
||
| const { userId } = this; | ||
| return { | ||
| users: type.users ? await spotlight.searchUsers({ userId, rid, text, usernames, mentions }) : [], | ||
| rooms: type.rooms ? await spotlight.searchRooms({ userId, text, includeFederatedRooms }) : [], | ||
| }; | ||
| }; | ||
|
|
||
| return { | ||
| users: type.users ? await spotlight.searchUsers({ userId, rid, text, usernames, mentions }) : [], | ||
| rooms: type.rooms ? await spotlight.searchRooms({ userId, text, includeFederatedRooms }) : [], | ||
| }; | ||
| Meteor.methods<ServerMethods>({ | ||
| async spotlight(text, usernames = [], type = { users: true, rooms: true, mentions: false, includeFederatedRooms: false }, rid) { | ||
| return spotlightMethod({ text, usernames, type, rid, userId: this.userId }); | ||
| }, | ||
| }); | ||
|
|
||
|
|
||
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.
The
browseChannelsMethodfunction returnsundefinedfor invalid inputs or unauthenticated users, which is not explicit and can hinder debugging.This issue appears in multiple locations:
Please throw descriptive errors instead of returning
undefinedto improve error handling and debugging.Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.