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 deprecated method deleteMessage #33472

Open
wants to merge 1 commit into
base: release-7.0.0
Choose a base branch
from
Open
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: 5 additions & 0 deletions .changeset/kind-clocks-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': major
---

Removed deprecated `deleteMessage` method. Moving forward, use the `chat.delete` endpoint.
1 change: 0 additions & 1 deletion apps/meteor/app/lib/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import './methods/cleanRoomHistory';
import './methods/createChannel';
import './methods/createPrivateGroup';
import './methods/createToken';
import './methods/deleteMessage';
import './methods/deleteUserOwnAccount';
import './methods/executeSlashCommandPreview';
import './startup/mentionUserNotInChannel';
Expand Down
35 changes: 0 additions & 35 deletions apps/meteor/app/lib/server/methods/deleteMessage.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/meteor/client/lib/chats/ChatAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type DataAPI = {
canUpdateMessage(message: IMessage): Promise<boolean>;
updateMessage(message: Pick<IMessage, '_id' | 't'> & Partial<Omit<IMessage, '_id' | 't'>>, previewUrls?: string[]): Promise<void>;
canDeleteMessage(message: IMessage): Promise<boolean>;
deleteMessage(mid: IMessage['_id']): Promise<void>;
deleteMessage(msgIdOrMsg: IMessage | IMessage['_id']): Promise<void>;
getDraft(mid: IMessage['_id'] | undefined): Promise<string | undefined>;
discardDraft(mid: IMessage['_id'] | undefined): Promise<void>;
saveDraft(mid: IMessage['_id'] | undefined, text: string): Promise<void>;
Expand Down
18 changes: 16 additions & 2 deletions apps/meteor/client/lib/chats/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,22 @@ export const createDataAPI = ({ rid, tmid }: { rid: IRoom['_id']; tmid: IMessage
return deleteAllowed && onTimeForDelete;
};

const deleteMessage = async (mid: IMessage['_id']): Promise<void> => {
await sdk.call('deleteMessage', { _id: mid });
const deleteMessage = async (msgIdOrMsg: IMessage | IMessage['_id']): Promise<void> => {
let msgId: string;
let roomId: string;
if (typeof msgIdOrMsg === 'string') {
msgId = msgIdOrMsg;
const msg = await findMessageByID(msgId);
if (!msg) {
throw new Error('Message not found');
}
roomId = msg.rid;
} else {
msgId = msgIdOrMsg._id;
roomId = msgIdOrMsg.rid;
}

await sdk.rest.post('/v1/chat.delete', { msgId, roomId });
};

const drafts = new Map<IMessage['_id'] | undefined, string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const requestMessageDeletion = async (chat: ChatAPI, message: IMessage):
dispatchToastMessage({ type: 'error', message: t('Message_deleting_blocked') });
return;
}
await chat.data.deleteMessage(message._id);
await chat.data.deleteMessage(message);

imperativeModal.close();

Expand Down
278 changes: 1 addition & 277 deletions apps/meteor/tests/end-to-end/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Credentials } from '@rocket.chat/api-client';
import type { IMessage, IRoom, IThreadMessage, IUser } from '@rocket.chat/core-typings';
import { Random } from '@rocket.chat/random';
import { expect } from 'chai';
import { after, before, beforeEach, describe, it } from 'mocha';
import { after, before, describe, it } from 'mocha';

import { api, credentials, getCredentials, methodCall, request } from '../../data/api-data';
import { sendSimpleMessage } from '../../data/chat.helper';
Expand Down Expand Up @@ -2519,282 +2519,6 @@ describe('Meteor.methods', () => {
});
});

describe('[@deleteMessage]', () => {
let rid: IRoom['_id'];
let messageId: IMessage['_id'];

before('create room', (done) => {
const channelName = `methods-test-channel-${Date.now()}`;
void request
.post(api('groups.create'))
.set(credentials)
.send({
name: channelName,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('group._id');
expect(res.body).to.have.nested.property('group.name', channelName);
expect(res.body).to.have.nested.property('group.t', 'p');
expect(res.body).to.have.nested.property('group.msgs', 0);
rid = res.body.group._id;
})
.end(done);
});

beforeEach('send message with URL', (done) => {
void request
.post(methodCall('sendMessage'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'sendMessage',
params: [
{
_id: `${Date.now() + Math.random()}`,
rid,
msg: 'test message with https://github.com',
},
],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');

const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('result').that.is.an('object');
expect(data.result).to.have.a.property('urls').that.is.an('array');
expect(data.result.urls[0].url).to.equal('https://github.com');
messageId = data.result._id;
})
.end(done);
});

after(() =>
Promise.all([
deleteRoom({ type: 'p', roomId: rid }),
updatePermission('bypass-time-limit-edit-and-delete', ['bot', 'app']),
updateSetting('Message_AllowEditing_BlockEditInMinutes', 0),
]),
);

it('should delete a message', (done) => {
void request
.post(methodCall('deleteMessage'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'deleteMessage',
params: [{ _id: messageId, rid }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
})
.end(done);
});

it('should delete a message when bypass time limits permission is enabled', async () => {
await Promise.all([
updatePermission('bypass-time-limit-edit-and-delete', ['admin']),
updateSetting('Message_AllowEditing_BlockEditInMinutes', 0.01),
]);

await request
.post(methodCall('deleteMessage'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'deleteMessage',
params: [{ _id: messageId, rid }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
});

await Promise.all([
updatePermission('bypass-time-limit-edit-and-delete', ['bot', 'app']),
updateSetting('Message_AllowEditing_BlockEditInMinutes', 0),
]);
});

describe('message deletion when user is not part of the room', () => {
let ridTestRoom: IRoom['_id'];
let messageIdTestRoom: IMessage['_id'];
let testUser: TestUser<IUser>;
let testUserCredentials: Credentials;

before('create room, add new owner, and leave room', async () => {
testUser = await createUser();
testUserCredentials = await login(testUser.username, password);
const channelName = `methods-test-channel-${Date.now()}`;

await request
.post(api('groups.create'))
.set(testUserCredentials)
.send({
name: channelName,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('group._id');
expect(res.body).to.have.nested.property('group.name', channelName);
expect(res.body).to.have.nested.property('group.t', 'p');
expect(res.body).to.have.nested.property('group.msgs', 0);
ridTestRoom = res.body.group._id;
});

await request
.post(methodCall('sendMessage'))
.set(testUserCredentials)
.send({
message: JSON.stringify({
method: 'sendMessage',
params: [
{
_id: `${Date.now() + Math.random()}`,
rid: ridTestRoom,
msg: 'just a random test message',
},
],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('result').that.is.an('object');
messageIdTestRoom = data.result._id;
});

await request
.post(methodCall('addUsersToRoom'))
.set(testUserCredentials)
.send({
message: JSON.stringify({
method: 'addUsersToRoom',
params: [
{
rid: ridTestRoom,
users: ['rocket.cat'],
},
],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
});

await request
.post(api('groups.addOwner'))
.set(testUserCredentials)
.send({
roomId: ridTestRoom,
userId: 'rocket.cat',
})
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
});

await request
.post(api('groups.leave'))
.set(testUserCredentials)
.send({
roomId: ridTestRoom,
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
});
});

it('should not delete a message if the user is no longer member of the room', async () => {
await request
.post(methodCall('deleteMessage'))
.set(testUserCredentials)
.send({
message: JSON.stringify({
method: 'deleteMessage',
params: [{ _id: messageIdTestRoom, rid: ridTestRoom }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
expect(data.error).to.have.a.property('error', 'error-action-not-allowed');
});
});

it('should not delete a message if the user was never part of the room', async () => {
await request
.post(methodCall('deleteMessage'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'deleteMessage',
params: [{ _id: messageIdTestRoom, rid: ridTestRoom }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
expect(data.error).to.have.a.property('error', 'error-action-not-allowed');
});
});

after(() => Promise.all([deleteRoom({ type: 'p', roomId: ridTestRoom }), deleteUser(testUser)]));
});
});

describe('[@setUserActiveStatus]', () => {
let testUser: TestUser<IUser>;
let testUser2: TestUser<IUser>;
Expand Down
Loading