mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-28 14:38:52 +00:00
Can update conversation message content
This commit is contained in:
parent
fad098114a
commit
327cbe434d
@ -319,6 +319,27 @@ export class ConversationsController {
|
||||
h.success("The conversation has been deleted.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the content of a conversation message
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async UpdateMessage(h: RequestHandler) {
|
||||
const messageID = h.postInt("messageID");
|
||||
const newContent = h.postString("content");
|
||||
|
||||
if(newContent.length < 3)
|
||||
h.error(401, "Invalid new message content!");
|
||||
|
||||
// Check out whether the user own the message or not
|
||||
if(!await ConversationsHelper.IsUserMessageOwner(h.getUserId(), messageID))
|
||||
h.error(401, "You do not own this conversation message!");
|
||||
|
||||
await ConversationsHelper.UpdateMessageContent(messageID, newContent);
|
||||
|
||||
h.success("Conversation message content successfully update");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return safely a conversation ID specified in a $_POST Request
|
||||
*
|
||||
|
@ -72,6 +72,8 @@ export const Routes : Route[] = [
|
||||
{path: "/conversations/get_list_unread", cb: (h) => ConversationsController.GetListUnread(h)},
|
||||
|
||||
{path: "/conversations/delete", cb: (h) => ConversationsController.DeleteConversation(h)},
|
||||
|
||||
{path: "/conversations/updateMessage", cb: (h) => ConversationsController.UpdateMessage(h)},
|
||||
|
||||
|
||||
// Search controller
|
||||
|
@ -243,6 +243,22 @@ export class ConversationsHelper {
|
||||
}) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether a user is the owner of a message or not
|
||||
*
|
||||
* @param userID Target user ID
|
||||
* @param messageID Target message ID
|
||||
*/
|
||||
public static async IsUserMessageOwner(userID: number, messageID: number) : Promise<boolean> {
|
||||
return (await DatabaseHelper.Count({
|
||||
table: MESSAGES_TABLE,
|
||||
where: {
|
||||
id: messageID,
|
||||
user_id: userID
|
||||
}
|
||||
})) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last messages of a conversation
|
||||
*
|
||||
@ -382,6 +398,24 @@ export class ConversationsHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update message content
|
||||
*
|
||||
* @param messageID Target message ID
|
||||
* @param newContent New message content
|
||||
*/
|
||||
public static async UpdateMessageContent(messageID: number, newContent: string) {
|
||||
await DatabaseHelper.UpdateRows({
|
||||
table: MESSAGES_TABLE,
|
||||
where: {
|
||||
id: messageID
|
||||
},
|
||||
set: {
|
||||
message: newContent
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for private conversations between two users
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user