-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: User model to TS #35056
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
chore: User model to TS #35056
Changes from all commits
134d6fe
463954a
9bd2a95
2027b27
a8ca51b
e2e8f28
5e787c1
f2314c0
a724f4c
361b3d5
65c85dd
840c059
c557aa0
625bc85
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import type { IUser } from '@rocket.chat/core-typings'; | ||
| import { isNotUndefined } from '@rocket.chat/core-typings'; | ||
| import { Rooms, Subscriptions, Users } from '@rocket.chat/models'; | ||
| import type { ClientSession } from 'mongodb'; | ||
|
|
||
|
|
@@ -13,8 +14,8 @@ async function getUsersWhoAreInTheSameGroupDMsAs(user: IUser) { | |
| return; | ||
| } | ||
|
|
||
| const userIds = new Set(); | ||
| const users = new Map(); | ||
| const userIds = new Set<string>(); | ||
| const users = new Map<string, IUser>(); | ||
|
|
||
| const rooms = Rooms.findGroupDMsByUids([user._id], { projection: { uids: 1 } }); | ||
| await rooms.forEach((room) => { | ||
|
|
@@ -25,9 +26,7 @@ async function getUsersWhoAreInTheSameGroupDMsAs(user: IUser) { | |
| room.uids.forEach((uid) => uid !== user._id && userIds.add(uid)); | ||
|
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. room.uids.forEach((uid) => {
if (uid !== user._id) {
userIds.add(uid);
}
});Use of the comma operator in forEach loops and other expressions reduces readability and can make the code harder to debug. This issue appears in multiple locations:
Please avoid using the comma operator in favor of separate statements or explicit control structures to improve code readability. Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
| }); | ||
|
|
||
| (await Users.findByIds([...userIds], { projection: { username: 1, name: 1 } }).toArray()).forEach((user: IUser) => | ||
| users.set(user._id, user), | ||
| ); | ||
| (await Users.findByIds([...userIds], { projection: { username: 1, name: 1 } }).toArray()).forEach((user) => users.set(user._id, user)); | ||
|
|
||
| return users; | ||
| } | ||
|
|
@@ -59,7 +58,7 @@ export const updateGroupDMsName = async ( | |
| const rooms = Rooms.findGroupDMsByUids([userThatChangedName._id], { projection: { uids: 1 }, session }); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
| const getMembers = (uids: string[]) => uids.map((uid) => users.get(uid)).filter(Boolean); | ||
| const getMembers = (uids: string[]) => uids.map((uid) => users.get(uid)).filter(isNotUndefined); | ||
|
|
||
| // loop rooms to update the subscriptions from them all | ||
| for await (const room of rooms) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import type { IMessage } from '@rocket.chat/core-typings'; | ||
| import type { IMessage, IUser } from '@rocket.chat/core-typings'; | ||
| import { Users } from '@rocket.chat/models'; | ||
|
|
||
| export async function isMessageFromBot(message: IMessage): Promise<boolean> { | ||
| export async function isMessageFromBot(message: IMessage): Promise<Pick<IUser, '_id' | 'roles'> | null> { | ||
sampaiodiego marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return Users.isUserInRole(message.u._id, 'bot'); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,6 +291,10 @@ export class LDAPEEManager extends LDAPManager { | |
| const roomOwner = settings.get<string>('LDAP_Sync_User_Data_Channels_Admin') || ''; | ||
|
|
||
| const user = await Users.findOneByUsernameIgnoringCase(roomOwner); | ||
| if (!user) { | ||
| logger.error(`Unable to find user '${roomOwner}' to be the owner of the channel '${channel}'.`); | ||
|
Member
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. not sure if this should be just a log or a |
||
| return; | ||
| } | ||
|
|
||
| const room = await createRoom('c', channel, user, [], false, false, { | ||
| customFields: { ldap: true }, | ||
|
|
||
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.
Multiple instances of missing or inadequate error handling in database queries and asynchronous operations, which could lead to unhandled promise rejections or runtime errors.
This issue appears in multiple locations:
Please ensure all database queries and asynchronous operations are wrapped in try-catch blocks to handle potential errors and prevent unhandled promise rejections.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.