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: replace meteor.call -> sdk.call #29318

Merged
merged 6 commits into from
Jun 6, 2023
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
5 changes: 3 additions & 2 deletions apps/meteor/app/autotranslate/client/lib/actionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
hasTranslationLanguageInMessage,
} from '../../../../client/views/room/MessageList/lib/autoTranslate';
import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';
import { sdk } from '../../../utils/client/lib/SDKClient';

Meteor.startup(() => {
AutoTranslate.init();
Expand All @@ -29,7 +30,7 @@ Meteor.startup(() => {
if (!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)) {
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
void sdk.call('autoTranslate.translateMessage', message, language);
}
const action = 'autoTranslateShowInverse' in message ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
Expand Down Expand Up @@ -63,7 +64,7 @@ Meteor.startup(() => {
if (!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)) {
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
void sdk.call('autoTranslate.translateMessage', message, language);
}
const action = 'autoTranslateShowInverse' in message ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/autotranslate/client/lib/autotranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { isTranslatedMessageAttachment } from '@rocket.chat/core-typings';

import { Subscriptions, Messages } from '../../../models/client';
import { hasPermission } from '../../../authorization/client';
import { call } from '../../../../client/lib/utils/call';
import {
hasTranslationLanguageInAttachments,
hasTranslationLanguageInMessage,
} from '../../../../client/views/room/MessageList/lib/autoTranslate';
import { sdk } from '../../../utils/client/lib/SDKClient';

let userLanguage = 'en';
let username = '';
Expand Down Expand Up @@ -110,8 +110,8 @@ export const AutoTranslate = {

try {
[this.providersMetadata, this.supportedLanguages] = await Promise.all([
call('autoTranslate.getProviderUiMetadata'),
call('autoTranslate.getSupportedLanguages', 'en'),
sdk.call('autoTranslate.getProviderUiMetadata'),
sdk.call('autoTranslate.getSupportedLanguages', 'en'),
]);
} catch (e: unknown) {
// Avoid unwanted error message on UI when autotranslate is disabled while fetching data
Expand Down
12 changes: 6 additions & 6 deletions apps/meteor/app/custom-sounds/client/lib/CustomSounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ICustomSound } from '@rocket.chat/core-typings';

import { CachedCollectionManager } from '../../../ui-cached-collection/client';
import { getURL } from '../../../utils/client';
import { sdk } from '../../../utils/client/lib/SDKClient';

const getCustomSoundId = (soundId: ICustomSound['_id']) => `custom-sound-${soundId}`;

Expand Down Expand Up @@ -133,11 +134,10 @@ class CustomSoundsClass {
export const CustomSounds = new CustomSoundsClass();

Meteor.startup(() =>
CachedCollectionManager.onLogin(() => {
Meteor.call('listCustomSounds', (_error: Error, result: ICustomSound[]) => {
for (const sound of result) {
CustomSounds.add(sound);
}
});
CachedCollectionManager.onLogin(async () => {
const result = await sdk.call('listCustomSounds');
for (const sound of result) {
CustomSounds.add(sound);
}
}),
);
8 changes: 4 additions & 4 deletions apps/meteor/app/e2e/client/rocketchat.e2e.room.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { Notifications } from '../../notifications/client';
import { ChatRoom, Subscriptions, Messages } from '../../models/client';
import { log, logError } from './logger';
import { E2ERoomState } from './E2ERoomState';
import { call } from '../../../client/lib/utils/call';
import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
import { RoomSettingsEnum } from '../../../definition/IRoomTypeConfig';
import { RoomManager } from '../../../client/lib/RoomManager';
import { sdk } from '../../utils/client/lib/SDKClient';

const KEY_ID = Symbol('keyID');
const PAUSED = Symbol('PAUSED');
Expand Down Expand Up @@ -297,7 +297,7 @@ export class E2ERoom extends Emitter {
this.sessionKeyExportedString = JSON.stringify(sessionKeyExported);
this.keyID = Base64.encode(this.sessionKeyExportedString).slice(0, 12);

await call('e2e.setRoomKeyID', this.roomId, this.keyID);
await sdk.call('e2e.setRoomKeyID', this.roomId, this.keyID);
await this.encryptKeyForOtherParticipants();
} catch (error) {
this.error('Error exporting group key: ', error);
Expand All @@ -308,7 +308,7 @@ export class E2ERoom extends Emitter {
async encryptKeyForOtherParticipants() {
// Encrypt generated session key for every user in room and publish to subscription model.
try {
const { users } = await call('e2e.getUsersOfRoomWithoutKey', this.roomId);
const { users } = await sdk.call('e2e.getUsersOfRoomWithoutKey', this.roomId);
users.forEach((user) => this.encryptForParticipant(user));
} catch (error) {
return this.error('Error getting room users: ', error);
Expand All @@ -328,7 +328,7 @@ export class E2ERoom extends Emitter {
try {
const encryptedUserKey = await encryptRSA(userKey, toArrayBuffer(this.sessionKeyExportedString));
// Key has been encrypted. Publish to that user's subscription model for this room.
await call('e2e.updateGroupKey', this.roomId, user._id, this.keyID + Base64.encode(new Uint8Array(encryptedUserKey)));
await sdk.call('e2e.updateGroupKey', this.roomId, user._id, this.keyID + Base64.encode(new Uint8Array(encryptedUserKey)));
} catch (error) {
return this.error('Error encrypting user key: ', error);
}
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/e2e/client/rocketchat.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { waitUntilFind } from '../../../client/lib/utils/waitUntilFind';
import { imperativeModal } from '../../../client/lib/imperativeModal';
import SaveE2EPasswordModal from '../../../client/views/e2e/SaveE2EPasswordModal';
import EnterE2EPasswordModal from '../../../client/views/e2e/EnterE2EPasswordModal';
import { call } from '../../../client/lib/utils/call';
import { getUserAvatarURL } from '../../utils/client';
import { createQuoteAttachment } from '../../../lib/createQuoteAttachment';
import { mapMessageFromApi } from '../../../client/lib/utils/mapMessageFromApi';
Expand Down Expand Up @@ -316,7 +315,7 @@ class E2E extends Emitter {
}

async requestSubscriptionKeys(): Promise<void> {
await call('e2e.requestSubscriptionKeys');
await sdk.call('e2e.requestSubscriptionKeys');
}

async createRandomPassword(): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/lib/server/methods/getUserRoles.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Meteor } from 'meteor/meteor';
import { Authorization } from '@rocket.chat/core-services';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import type { IUser } from '@rocket.chat/core-typings';
import type { IUser, IRocketChatRecord } from '@rocket.chat/core-typings';

declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
getUserRoles(): Pick<IUser, '_id' | 'roles' | 'username'>[];
getUserRoles(): (IRocketChatRecord & Pick<IUser, '_id' | 'roles' | 'username'>)[];
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/methods/saveSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { twoFactorRequired } from '../../../2fa/server/twoFactorRequired';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
saveSetting(_id: string, value: SettingValue, editor: string): Promise<boolean>;
saveSetting(_id: string, value: SettingValue, editor?: string): Promise<boolean>;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';

import { generateKey } from './crypto';
import { sdk } from '../../../utils/client/lib/SDKClient';

Meteor.methods<ServerMethods>({
async omnichannelExternalFrameGenerateKey() {
const key = await generateKey();
await Meteor.callAsync('saveSetting', 'Omnichannel_External_Frame_Encryption_JWK', key);
await sdk.call('saveSetting', 'Omnichannel_External_Frame_Encryption_JWK', key);
},
});
16 changes: 9 additions & 7 deletions apps/meteor/app/message-mark-as-unread/client/actionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ import { messageArgs } from '../../../client/lib/utils/messageArgs';
import { ChatSubscription } from '../../models/client';
import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
import { dispatchToastMessage } from '../../../client/lib/toast';
import { sdk } from '../../utils/client/lib/SDKClient';

Meteor.startup(() => {
MessageAction.addButton({
id: 'mark-message-as-unread',
icon: 'flag',
label: 'Mark_unread',
context: ['message', 'message-mobile', 'threads'],
action(_, props) {
async action(_, props) {
const { message = messageArgs(this).msg } = props;
return Meteor.call('unreadMessages', message, async function (error: unknown) {
if (error) {
dispatchToastMessage({ type: 'error', message: error });
return;
}

try {
await sdk.call('unreadMessages', message);
const subscription = ChatSubscription.findOne({
rid: message.rid,
});

if (subscription == null) {
return;
}
await LegacyRoomManager.close(subscription.t + subscription.name);
return FlowRouter.go('home');
});
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
},
condition({ message, user, room }) {
const isLivechatRoom = roomCoordinator.isLivechatRoom(room.t);
Expand Down
27 changes: 16 additions & 11 deletions apps/meteor/app/meteor-accounts-saml/client/saml_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Accounts } from 'meteor/accounts-base';
import { Random } from '@rocket.chat/random';
import { ServiceConfiguration } from 'meteor/service-configuration';

import { sdk } from '../../utils/client/lib/SDKClient';

if (!Accounts.saml) {
Accounts.saml = {};
}
Expand Down Expand Up @@ -53,19 +55,22 @@ Meteor.loginWithSaml = function (options /* , callback*/) {

Meteor.logoutWithSaml = function (options /* , callback*/) {
// Accounts.saml.idpInitiatedSLO(options, callback);
Meteor.call('samlLogout', options.provider, function (err, result) {
if (err || !result) {
MeteorLogout.apply(Meteor);
return;
}
sdk
.call('samlLogout', options.provider)
.then((result) => {
if (!result) {
MeteorLogout.apply(Meteor);
return;
}

// Remove the userId from the client to prevent calls to the server while the logout is processed.
// If the logout fails, the userId will be reloaded on the resume call
Meteor._localStorage.removeItem(Accounts.USER_ID_KEY);
// Remove the userId from the client to prevent calls to the server while the logout is processed.
// If the logout fails, the userId will be reloaded on the resume call
Meteor._localStorage.removeItem(Accounts.USER_ID_KEY);

// A nasty bounce: 'result' has the SAML LogoutRequest but we need a proper 302 to redirected from the server.
window.location.replace(Meteor.absoluteUrl(`_saml/sloRedirect/${options.provider}/?redirect=${encodeURIComponent(result)}`));
});
// A nasty bounce: 'result' has the SAML LogoutRequest but we need a proper 302 to redirected from the server.
window.location.replace(Meteor.absoluteUrl(`_saml/sloRedirect/${options.provider}/?redirect=${encodeURIComponent(result)}`));
})
.catch(() => MeteorLogout.apply(Meteor));
};

Meteor.loginWithSamlToken = function (token, userCallback) {
Expand Down
10 changes: 7 additions & 3 deletions apps/meteor/app/otr/client/OTRRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export class OTRRoom implements IOTRRoom {
refresh,
});
if (refresh) {
await Meteor.callAsync('sendSystemMessages', this._roomId, Meteor.user(), otrSystemMessages.USER_REQUESTED_OTR_KEY_REFRESH);
const user = Meteor.user();
if (!user) {
return;
}
await sdk.call('sendSystemMessages', this._roomId, user.username, otrSystemMessages.USER_REQUESTED_OTR_KEY_REFRESH);
this.isFirstOTR = false;
}
} catch (e) {
Expand Down Expand Up @@ -129,7 +133,7 @@ export class OTRRoom implements IOTRRoom {
this._keyPair = null;
this._exportedPublicKey = {};
this._sessionKey = null;
Meteor.call('deleteOldOTRMessages', this._roomId);
void sdk.call('deleteOldOTRMessages', this._roomId);
}

async generateKeyPair(): Promise<void> {
Expand Down Expand Up @@ -159,7 +163,7 @@ export class OTRRoom implements IOTRRoom {
this._exportedPublicKey = await exportKey(this._keyPair.publicKey);

// Once we have generated new keys, it's safe to delete old messages
Meteor.call('deleteOldOTRMessages', this._roomId);
void sdk.call('deleteOldOTRMessages', this._roomId);
} catch (e) {
this.setState(OtrRoomState.ERROR);
throw e;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/otr/server/methods/sendSystemMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Meteor } from 'meteor/meteor';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
sendSystemMessages(rid: string, user: string, id: string): void;
sendSystemMessages(rid: string, user: string | undefined, id: string): void;
}
}

Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/reactions/client/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meteor } from 'meteor/meteor';
import { MessageAction } from '../../ui-utils/client';
import { messageArgs } from '../../../client/lib/utils/messageArgs';
import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
import { sdk } from '../../utils/client/lib/SDKClient';

Meteor.startup(function () {
MessageAction.addButton({
Expand All @@ -13,7 +14,7 @@ Meteor.startup(function () {
action(event, props) {
event.stopPropagation();
const { message = messageArgs(this).msg, chat } = props;
chat?.emojiPicker.open(event.currentTarget, (emoji) => Meteor.call('setReaction', `:${emoji}:`, message._id));
chat?.emojiPicker.open(event.currentTarget, (emoji) => sdk.call('setReaction', `:${emoji}:`, message._id));
},
condition({ message, user, room, subscription }) {
if (!room) {
Expand Down
16 changes: 12 additions & 4 deletions apps/meteor/app/settings/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Meteor } from 'meteor/meteor';
import _ from 'underscore';
import type { SettingValue } from '@rocket.chat/core-typings';

import { sdk } from '../../utils/client/lib/SDKClient';

type SettingComposedValue<T extends SettingValue = SettingValue> = { key: string; value: T };
type SettingCallback = (key: string, value: SettingValue, initialLoad?: boolean) => void;

Expand Down Expand Up @@ -79,12 +81,18 @@ export class SettingsBase {
return Meteor.settings?.[_id];
}

set(_id: string, value: SettingValue, callback: () => void): void {
Meteor.call('saveSetting', _id, value, callback);
set(_id: string, value: SettingValue, callback: (err?: unknown, result?: any) => void): void {
sdk
.call('saveSetting', _id, value)
.then((result) => callback(undefined, result))
.catch(callback);
}

batchSet(settings: Array<{ _id: string; value: SettingValue }>, callback: () => void): void {
Meteor.call('saveSettings', settings, callback);
batchSet(settings: Array<{ _id: string; value: SettingValue }>, callback: (err?: unknown, result?: any) => void): void {
sdk
.call('saveSettings', settings)
.then((result) => callback(undefined, result))
.catch(callback);
}

load(key: string, value: SettingValue, initialLoad: boolean): void {
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/app/slashcommand-asciiarts/client/gimme.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Meteor } from 'meteor/meteor';
import type { SlashCommandCallbackParams } from '@rocket.chat/core-typings';

import { slashCommands } from '../../utils/lib/slashCommand';
import { sdk } from '../../utils/client/lib/SDKClient';
/*
* Gimme is a named function that will replace /gimme commands
* @param {Object} message - The message object
*/
async function Gimme({ message, params }: SlashCommandCallbackParams<'gimme'>): Promise<void> {
const msg = message;
msg.msg = `༼ つ ◕_◕ ༽つ ${params}`;
await Meteor.callAsync('sendMessage', msg);
await sdk.call('sendMessage', { ...msg, msg: `༼ つ ◕_◕ ༽つ ${params}` });
}

slashCommands.add({
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/app/slashcommand-asciiarts/client/lenny.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { SlashCommandCallbackParams } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { slashCommands } from '../../utils/lib/slashCommand';
import { sdk } from '../../utils/client/lib/SDKClient';
/*
* Lenny is a named function that will replace /lenny commands
* @param {Object} message - The message object
*/

async function LennyFace({ message, params }: SlashCommandCallbackParams<'lenny'>): Promise<void> {
const msg = message;
msg.msg = `${params} ( ͡° ͜ʖ ͡°)`;
await Meteor.callAsync('sendMessage', msg);
await sdk.call('sendMessage', { ...msg, msg: `${params} ( ͡° ͜ʖ ͡°)` });
}

slashCommands.add({
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/app/slashcommand-asciiarts/client/shrug.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import type { SlashCommandCallbackParams } from '@rocket.chat/core-typings';

import { slashCommands } from '../../utils/lib/slashCommand';
import { sdk } from '../../utils/client/lib/SDKClient';
/*
* Shrug is a named function that will replace /shrug commands
* @param {Object} message - The message object
Expand All @@ -11,8 +11,7 @@ slashCommands.add({
command: 'shrug',
callback: async ({ message, params }: SlashCommandCallbackParams<'shrug'>): Promise<void> => {
const msg = message;
msg.msg = `${params} ¯\\\\_(ツ)_/¯`;
await Meteor.callAsync('sendMessage', msg);
await sdk.call('sendMessage', { ...msg, msg: `${params} ¯\\\\_(ツ)_/¯` });
},
options: {
description: 'Slash_Shrug_Description',
Expand Down
Loading