diff --git a/test/api/v3/integration/chat/POST-chat.like.test.js b/test/api/v3/integration/chat/POST-chat.like.test.js index 82a2af883c..f06455566d 100644 --- a/test/api/v3/integration/chat/POST-chat.like.test.js +++ b/test/api/v3/integration/chat/POST-chat.like.test.js @@ -39,17 +39,6 @@ describe('POST /chat/:chatId/like', () => { }); }); - it('Returns an error when user tries to like their own message', async () => { - const message = await user.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage }); - - await expect(user.post(`/groups/${groupWithChat._id}/chat/${message.message.id}/like`)) - .to.eventually.be.rejected.and.eql({ - code: 404, - error: 'NotFound', - message: t('messageGroupChatLikeOwnMessage'), - }); - }); - it('Likes a chat', async () => { const message = await anotherUser.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage }); @@ -63,6 +52,19 @@ describe('POST /chat/:chatId/like', () => { expect(messageToCheck.likes[user._id]).to.equal(true); }); + it('Allows to likes their own chat message', async () => { + const message = await user.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage }); + + const likeResult = await user.post(`/groups/${groupWithChat._id}/chat/${message.message.id}/like`); + + expect(likeResult.likes[user._id]).to.equal(true); + + const groupWithChatLikes = await user.get(`/groups/${groupWithChat._id}`); + + const messageToCheck = find(groupWithChatLikes.chat, { id: message.message.id }); + expect(messageToCheck.likes[user._id]).to.equal(true); + }); + it('Unlikes a chat', async () => { const message = await anotherUser.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage }); diff --git a/website/common/locales/en/messages.json b/website/common/locales/en/messages.json index 649e613e7f..86a263b112 100644 --- a/website/common/locales/en/messages.json +++ b/website/common/locales/en/messages.json @@ -41,7 +41,6 @@ "messageGroupRequiresInvite": "Can't join a group you're not invited to.", "messageGroupCannotRemoveSelf": "You cannot remove yourself!", "messageGroupChatBlankMessage": "You cannot send a blank message", - "messageGroupChatLikeOwnMessage": "Can't like your own message. Don't be that person.", "messageGroupChatFlagAlreadyReported": "You have already reported this message", "messageGroupChatNotFound": "Message not found!", "messageGroupChatAdminClearFlagCount": "Only an admin can clear the flag count!", diff --git a/website/server/controllers/api-v3/chat.js b/website/server/controllers/api-v3/chat.js index 1e0d650497..60a6001ed1 100644 --- a/website/server/controllers/api-v3/chat.js +++ b/website/server/controllers/api-v3/chat.js @@ -232,7 +232,6 @@ api.postChat = { * @apiUse MessageNotFound * @apiUse GroupIdRequired * @apiUse ChatIdRequired - * @apiError (400) {NotFound} messageGroupChatLikeOwnMessage A user can't like their own message */ api.likeChat = { method: 'POST', @@ -253,10 +252,8 @@ api.likeChat = { const message = await Chat.findOne({ _id: req.params.chatId }).exec(); if (!message) throw new NotFound(res.t('messageGroupChatNotFound')); - // @TODO correct this error type - if (message.uuid === user._id) throw new NotFound(res.t('messageGroupChatLikeOwnMessage')); - if (!message.likes) message.likes = {}; + message.likes[user._id] = !message.likes[user._id]; message.markModified('likes'); await message.save();