Skip to content

Commit

Permalink
Chore: Convert to typescript some functions from app/lib/server/funct…
Browse files Browse the repository at this point in the history
…ions (#24519)

Co-authored-by: Pierre Lehnen <pierre.lehnen@rocket.chat>
  • Loading branch information
2 people authored and ggazzo committed May 24, 2022
1 parent 8626fd0 commit d10fda7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/lib/server/functions/getStatusText.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions apps/meteor/app/lib/server/functions/setRealName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/functions/setRoomAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> {
export const setRoomAvatar = async function (rid: string, dataURI: string, user: IUser): Promise<void> {
const fileStore = FileUpload.getStore('Avatars');

const current = await Avatars.findOneByRoomId(rid);
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/lib/server/functions/setStatusText.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d10fda7

Please sign in to comment.