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: Remove method meteor call on message action #26213

Merged
merged 16 commits into from Dec 6, 2022
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions apps/meteor/app/ui-utils/client/lib/MessageAction.ts
Expand Up @@ -5,22 +5,22 @@ import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import type { Icon } from '@rocket.chat/fuselage';
import type { IMessage, IUser, ISubscription, IRoom, SettingValue } from '@rocket.chat/core-typings';
import type { IMessage, IUser, ISubscription, IRoom, SettingValue, Serialized } from '@rocket.chat/core-typings';
import type { TranslationKey } from '@rocket.chat/ui-contexts';

import { Messages, Rooms, Subscriptions } from '../../../models/client';
import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';
import type { ToolboxContextValue } from '../../../../client/views/room/lib/Toolbox/ToolboxContext';

const call = (method: string, ...args: any[]): Promise<any> =>
new Promise((resolve, reject) => {
Meteor.call(method, ...args, function (err: any, data: any) {
if (err) {
return reject(err);
}
resolve(data);
});
});
import { APIClient } from '../../../utils/client';

const getMessage = async (msgId: string): Promise<Serialized<IMessage> | null> => {
try {
const { message } = await APIClient.get('/v1/chat.getMessage', { msgId });
return message;
} catch {
return null;
}
};

export const addMessageToList = (messagesList: IMessage[], message: IMessage): IMessage[] => {
// checks if the message is not already on the list
Expand Down Expand Up @@ -161,7 +161,7 @@ export const MessageAction = new (class {
throw new Error('invalid-parameter');
}

const msg = Messages.findOne(msgId) || (await call('getSingleMessage', msgId));
const msg = Messages.findOne(msgId) || (await getMessage(msgId));
if (!msg) {
throw new Error('message-not-found');
}
Expand Down