From d10fda7bcf3fdcfa82bd4f96a9c5e69906b9201c Mon Sep 17 00:00:00 2001 From: eduardofcabrera <64327259+eduardofcabrera@users.noreply.github.com> Date: Mon, 23 May 2022 12:50:12 -0300 Subject: [PATCH] Chore: Convert to typescript some functions from app/lib/server/functions (#24519) Co-authored-by: Pierre Lehnen --- .../app/lib/server/functions/addUserToDefaultChannels.ts | 2 +- apps/meteor/app/lib/server/functions/getStatusText.ts | 4 ++-- apps/meteor/app/lib/server/functions/setRealName.ts | 8 ++++++-- apps/meteor/app/lib/server/functions/setRoomAvatar.ts | 2 +- apps/meteor/app/lib/server/functions/setStatusText.ts | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/meteor/app/lib/server/functions/addUserToDefaultChannels.ts b/apps/meteor/app/lib/server/functions/addUserToDefaultChannels.ts index c7a47067ce620..62906fa893c1b 100644 --- a/apps/meteor/app/lib/server/functions/addUserToDefaultChannels.ts +++ b/apps/meteor/app/lib/server/functions/addUserToDefaultChannels.ts @@ -3,7 +3,7 @@ import type { IRoom, IUser } from '@rocket.chat/core-typings'; import { Rooms, Subscriptions, Messages } from '../../../models/server'; import { callbacks } from '../../../../lib/callbacks'; -export const addUserToDefaultChannels = function (user: IUser, silenced: boolean): void { +export const addUserToDefaultChannels = function (user: IUser, silenced?: boolean): void { callbacks.run('beforeJoinDefaultChannels', user); const defaultRooms = Rooms.findByDefaultAndTypes(true, ['c', 'p'], { fields: { usernames: 0 }, diff --git a/apps/meteor/app/lib/server/functions/getStatusText.ts b/apps/meteor/app/lib/server/functions/getStatusText.ts index af154b24d3fe9..ad5ffcd84b4f2 100644 --- a/apps/meteor/app/lib/server/functions/getStatusText.ts +++ b/apps/meteor/app/lib/server/functions/getStatusText.ts @@ -1,8 +1,8 @@ import { Users } from '../../../models/server'; -export const getStatusText = function (userId: string): unknown { +export const getStatusText = function (userId: string): string | undefined { if (!userId) { - return undefined; + return; } const fields = { diff --git a/apps/meteor/app/lib/server/functions/setRealName.ts b/apps/meteor/app/lib/server/functions/setRealName.ts index 21c1c9b7362ea..493b211aab02f 100644 --- a/apps/meteor/app/lib/server/functions/setRealName.ts +++ b/apps/meteor/app/lib/server/functions/setRealName.ts @@ -8,15 +8,19 @@ import { hasPermission } from '../../../authorization/server'; import { RateLimiter } from '../lib'; import { api } from '../../../../server/sdk/api'; -export const _setRealName = function (userId: string, name: string, fullUser: IUser): unknown { +export const _setRealName = function (userId: string, name: string, fullUser: IUser): IUser | undefined { name = s.trim(name); if (!userId || (settings.get('Accounts_RequireNameForSignUp') && !name)) { - return false; + return; } const user = fullUser || Users.findOneById(userId); + if (!user) { + return; + } + // User already has desired name, return if (user.name && s.trim(user.name) === name) { return user; diff --git a/apps/meteor/app/lib/server/functions/setRoomAvatar.ts b/apps/meteor/app/lib/server/functions/setRoomAvatar.ts index 2873443e1fd31..1cd2a2442b75b 100644 --- a/apps/meteor/app/lib/server/functions/setRoomAvatar.ts +++ b/apps/meteor/app/lib/server/functions/setRoomAvatar.ts @@ -7,7 +7,7 @@ import { Rooms, Messages } from '../../../models/server'; import { Avatars } from '../../../models/server/raw'; import { api } from '../../../../server/sdk/api'; -export const setRoomAvatar = async function (rid: string, dataURI: string, user: IUser): Promise { +export const setRoomAvatar = async function (rid: string, dataURI: string, user: IUser): Promise { const fileStore = FileUpload.getStore('Avatars'); const current = await Avatars.findOneByRoomId(rid); diff --git a/apps/meteor/app/lib/server/functions/setStatusText.ts b/apps/meteor/app/lib/server/functions/setStatusText.ts index ee8e533a81a4a..23bda14636026 100644 --- a/apps/meteor/app/lib/server/functions/setStatusText.ts +++ b/apps/meteor/app/lib/server/functions/setStatusText.ts @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import s from 'underscore.string'; +import type { IUser } from '@rocket.chat/core-typings'; import { Users } from '../../../models/server'; import { Users as UsersRaw } from '../../../models/server/raw'; @@ -34,7 +35,7 @@ export const _setStatusTextPromise = async function (userId: string, statusText: return true; }; -export const _setStatusText = function (userId: any, statusText: string): unknown { +export const _setStatusText = function (userId: any, statusText: string): IUser | boolean { statusText = s.trim(statusText); if (statusText.length > 120) { statusText = statusText.substr(0, 120);