Skip to content
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: Convert to typescript some functions from app/lib/server/functions #24519

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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