refactor: remove getReadReceipts method calls (server) (#34891)

pull/34922/head^2
Marcos Spessatto Defendi 12 months ago committed by GitHub
parent f7f35c39af
commit baaee3ff61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      apps/meteor/ee/server/api/chat.ts
  2. 41
      apps/meteor/ee/server/methods/getReadReceipts.ts

@ -3,6 +3,7 @@ import { License } from '@rocket.chat/license';
import { Meteor } from 'meteor/meteor';
import { API } from '../../../app/api/server/api';
import { getReadReceiptsFunction } from '../methods/getReadReceipts';
type GetMessageReadReceiptsProps = {
messageId: IMessage['_id'];
@ -36,7 +37,7 @@ API.v1.addRoute(
}
return API.v1.success({
receipts: await Meteor.callAsync('getReadReceipts', { messageId }),
receipts: await getReadReceiptsFunction(messageId, this.userId),
});
},
},

@ -15,16 +15,28 @@ declare module '@rocket.chat/ddp-client' {
}
}
Meteor.methods<ServerMethods>({
async getReadReceipts({ messageId }) {
if (!License.hasModule('message-read-receipt')) {
throw new Meteor.Error('error-action-not-allowed', 'This is an enterprise feature', { method: 'getReadReceipts' });
}
export const getReadReceiptsFunction = async function (messageId: IMessage['_id'], userId: string): Promise<ReadReceiptType[]> {
if (!License.hasModule('message-read-receipt')) {
throw new Meteor.Error('error-action-not-allowed', 'This is an enterprise feature', { method: 'getReadReceipts' });
}
check(messageId, String);
if (!messageId) {
throw new Meteor.Error('error-invalid-message', "The required 'messageId' param is missing.", { method: 'getReadReceipts' });
}
const message = await Messages.findOneById(messageId);
if (!message) {
throw new Meteor.Error('error-invalid-message', 'Invalid message', {
method: 'getReadReceipts',
});
}
if (!(await canAccessRoomIdAsync(message.rid, userId))) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getReadReceipts' });
}
return ReadReceipt.getReceipts(message);
};
Meteor.methods<ServerMethods>({
async getReadReceipts({ messageId }) {
check(messageId, String);
const uid = Meteor.userId();
@ -32,17 +44,6 @@ Meteor.methods<ServerMethods>({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getReadReceipts' });
}
const message = await Messages.findOneById(messageId);
if (!message) {
throw new Meteor.Error('error-invalid-message', 'Invalid message', {
method: 'getReadReceipts',
});
}
if (!(await canAccessRoomIdAsync(message.rid, uid))) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getReadReceipts' });
}
return ReadReceipt.getReceipts(message);
return getReadReceiptsFunction(messageId, uid);
},
});

Loading…
Cancel
Save