mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
allow liking their own message (#15117)
This commit is contained in:
@@ -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 () => {
|
it('Likes a chat', async () => {
|
||||||
const message = await anotherUser.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage });
|
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);
|
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 () => {
|
it('Unlikes a chat', async () => {
|
||||||
const message = await anotherUser.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage });
|
const message = await anotherUser.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage });
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@
|
|||||||
"messageGroupRequiresInvite": "Can't join a group you're not invited to.",
|
"messageGroupRequiresInvite": "Can't join a group you're not invited to.",
|
||||||
"messageGroupCannotRemoveSelf": "You cannot remove yourself!",
|
"messageGroupCannotRemoveSelf": "You cannot remove yourself!",
|
||||||
"messageGroupChatBlankMessage": "You cannot send a blank message",
|
"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",
|
"messageGroupChatFlagAlreadyReported": "You have already reported this message",
|
||||||
"messageGroupChatNotFound": "Message not found!",
|
"messageGroupChatNotFound": "Message not found!",
|
||||||
"messageGroupChatAdminClearFlagCount": "Only an admin can clear the flag count!",
|
"messageGroupChatAdminClearFlagCount": "Only an admin can clear the flag count!",
|
||||||
|
|||||||
@@ -232,7 +232,6 @@ api.postChat = {
|
|||||||
* @apiUse MessageNotFound
|
* @apiUse MessageNotFound
|
||||||
* @apiUse GroupIdRequired
|
* @apiUse GroupIdRequired
|
||||||
* @apiUse ChatIdRequired
|
* @apiUse ChatIdRequired
|
||||||
* @apiError (400) {NotFound} messageGroupChatLikeOwnMessage A user can't like their own message
|
|
||||||
*/
|
*/
|
||||||
api.likeChat = {
|
api.likeChat = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -253,10 +252,8 @@ api.likeChat = {
|
|||||||
|
|
||||||
const message = await Chat.findOne({ _id: req.params.chatId }).exec();
|
const message = await Chat.findOne({ _id: req.params.chatId }).exec();
|
||||||
if (!message) throw new NotFound(res.t('messageGroupChatNotFound'));
|
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 = {};
|
if (!message.likes) message.likes = {};
|
||||||
|
|
||||||
message.likes[user._id] = !message.likes[user._id];
|
message.likes[user._id] = !message.likes[user._id];
|
||||||
message.markModified('likes');
|
message.markModified('likes');
|
||||||
await message.save();
|
await message.save();
|
||||||
|
|||||||
Reference in New Issue
Block a user