From fd57d74f47d9ffedde000c5f19effa94b9376a6c Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Tue, 1 Oct 2024 06:32:36 +0530 Subject: [PATCH] chore!: remove deprecated livechat:loadHistory method (#33390) Signed-off-by: Abhinav Kumar --- .changeset/slow-crabs-run.md | 5 ++ apps/meteor/app/livechat/server/index.ts | 1 - .../livechat/server/methods/loadHistory.ts | 48 --------------- .../api/livechat/methods/loadHistory.ts | 61 ------------------- 4 files changed, 5 insertions(+), 110 deletions(-) create mode 100644 .changeset/slow-crabs-run.md delete mode 100644 apps/meteor/app/livechat/server/methods/loadHistory.ts delete mode 100644 apps/meteor/tests/end-to-end/api/livechat/methods/loadHistory.ts diff --git a/.changeset/slow-crabs-run.md b/.changeset/slow-crabs-run.md new file mode 100644 index 0000000000000..8df05f8937d6b --- /dev/null +++ b/.changeset/slow-crabs-run.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Removed deprecated method `livechat:loadHistory` method. Moving forward use the `ivechat/messages.history/:rid` endpoint diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index 357d444ac4742..675f0531996d0 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -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'; diff --git a/apps/meteor/app/livechat/server/methods/loadHistory.ts b/apps/meteor/app/livechat/server/methods/loadHistory.ts deleted file mode 100644 index 1004f9dd604dd..0000000000000 --- a/apps/meteor/app/livechat/server/methods/loadHistory.ts +++ /dev/null @@ -1,48 +0,0 @@ -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({ - 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 }); - }, -}); diff --git a/apps/meteor/tests/end-to-end/api/livechat/methods/loadHistory.ts b/apps/meteor/tests/end-to-end/api/livechat/methods/loadHistory.ts deleted file mode 100644 index f251d7ebe92da..0000000000000 --- a/apps/meteor/tests/end-to-end/api/livechat/methods/loadHistory.ts +++ /dev/null @@ -1,61 +0,0 @@ -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'); - }); - }); - }); -});