Skip to content
Snippets Groups Projects
Commit 7eb29051 authored by Abhinav Kumar's avatar Abhinav Kumar Committed by Guilherme Gazzo
Browse files

chore!: remove deprecated livechat:loadHistory method (#33390)

parent 363325f5
No related branches found
No related tags found
No related merge requests found
---
'@rocket.chat/meteor': patch
---
Removed deprecated method `livechat:loadHistory` method. Moving forward use the `ivechat/messages.history/:rid` endpoint
......@@ -29,7 +29,6 @@ import './methods/getAnalyticsChartData';
import './methods/getAnalyticsOverviewData';
import './methods/getNextAgent';
import './methods/getRoutingConfig';
import './methods/loadHistory';
import './methods/loginByToken';
import './methods/pageVisited';
import './methods/registerGuest';
......
import type { IMessage } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { LivechatVisitors, LivechatRooms } from '@rocket.chat/models';
import { check, Match } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import { loadMessageHistory } from '../../../lib/server/functions/loadMessageHistory';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
'livechat:loadHistory'(params: { token: string; rid: string; end?: Date; limit?: number; ls: Date }):
| {
messages: IMessage[];
firstUnread: any;
unreadNotLoaded: number;
}
| undefined;
}
}
Meteor.methods<ServerMethods>({
async 'livechat:loadHistory'({ token, rid, end, limit = 20, ls }) {
methodDeprecationLogger.method('livechat:loadHistory', '7.0.0');
check(token, String);
check(rid, String);
check(end, Date);
check(ls, Match.OneOf(String, Date));
check(limit, Number);
const visitor = await LivechatVisitors.getVisitorByToken(token, { projection: { _id: 1 } });
if (!visitor) {
throw new Meteor.Error('invalid-visitor', 'Invalid Visitor', {
method: 'livechat:loadHistory',
});
}
const room = await LivechatRooms.findOneByIdAndVisitorToken(rid, token, { projection: { _id: 1 } });
if (!room) {
throw new Meteor.Error('invalid-room', 'Invalid Room', { method: 'livechat:loadHistory' });
}
return loadMessageHistory({ userId: visitor._id, rid, end, limit, ls });
},
});
import type { ILivechatAgent } from '@rocket.chat/core-typings';
import { expect } from 'chai';
import { before, describe, it, after } from 'mocha';
import type { Response } from 'supertest';
import { getCredentials, request, methodCallAnon, credentials } from '../../../../data/api-data';
import { createAgent, makeAgentAvailable, sendMessage, startANewLivechatRoomAndTakeIt } from '../../../../data/livechat/rooms';
import { removeAgent } from '../../../../data/livechat/users';
import { updateSetting } from '../../../../data/permissions.helper';
import { adminUsername } from '../../../../data/user';
describe('livechat:loadHistory', function () {
this.retries(0);
let agent: ILivechatAgent;
before((done) => getCredentials(done));
before(async () => {
await updateSetting('Livechat_enabled', true);
agent = await createAgent(adminUsername);
await makeAgentAvailable(credentials);
});
after('remove agent', async () => {
await removeAgent(agent._id);
});
describe('loadHistory', async () => {
it('prevent getting unrelated message history using regex on rid param', async () => {
const {
room: { _id: roomId },
visitor: { token },
} = await startANewLivechatRoomAndTakeIt();
await sendMessage(roomId, 'Hello from visitor', token);
await request
.post(methodCallAnon('livechat:loadHistory'))
.send({
message: JSON.stringify({
msg: 'method',
id: 'id2',
method: 'livechat:loadHistory',
params: [
{
token,
rid: { $regex: '.*' },
},
],
}),
})
.expect(200)
.expect((res: Response) => {
expect(res.body).to.have.property('success', true);
const parsedBody = JSON.parse(res.body.message);
expect(parsedBody).to.have.property('error');
expect(parsedBody).to.not.have.property('result');
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment