mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Remove conversation: Can delete conversation messages
This commit is contained in:
parent
c9ee727629
commit
5a253f114c
@ -306,6 +306,19 @@ export class ConversationsController {
|
||||
h.send(list.map(e => this.UnreadConversationToAPI(e)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a conversation
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async DeleteConversation(h: RequestHandler) {
|
||||
const convID = await this.GetPostConversationId("conversationID", h);
|
||||
|
||||
await ConversationsHelper.RemoveUserFromConversation(h.getUserId(), convID);
|
||||
|
||||
h.success("The conversation has been deleted.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return safely a conversation ID specified in a $_POST Request
|
||||
*
|
||||
|
@ -70,6 +70,8 @@ export const Routes : Route[] = [
|
||||
{path: "/conversations/get_number_unread", cb: (h) => ConversationsController.CountUnreadForUser(h)},
|
||||
|
||||
{path: "/conversations/get_list_unread", cb: (h) => ConversationsController.GetListUnread(h)},
|
||||
|
||||
{path: "/conversations/delete", cb: (h) => ConversationsController.DeleteConversation(h)},
|
||||
|
||||
|
||||
// Search controller
|
||||
|
@ -43,4 +43,8 @@ export class ConversationMessage implements ConversationMessageInfo {
|
||||
get imageURL() : string {
|
||||
return pathUserData(this.imagePath);
|
||||
}
|
||||
|
||||
get imageSysPath() : string {
|
||||
return pathUserData(this.imagePath, true);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { time } from "../utils/DateUtils";
|
||||
import { ConversationMessage, BaseConversationMessage } from "../entities/ConversationMessage";
|
||||
import { UnreadConversation } from "../entities/UnreadConversation";
|
||||
import { existsSync, unlinkSync } from "fs";
|
||||
|
||||
/**
|
||||
* Conversations helper
|
||||
@ -456,6 +457,64 @@ export class ConversationsHelper {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user from a conversation
|
||||
*
|
||||
* @param userID Target user ID
|
||||
* @param convID Target conversation ID
|
||||
*/
|
||||
public static async RemoveUserFromConversation(userID: number, convID: number) {
|
||||
if(await this.IsUserModerator(userID, convID))
|
||||
await this.DeleteConversations(convID);
|
||||
//else
|
||||
// Delete the membersip fot
|
||||
// TODO : implement
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a conversation
|
||||
*
|
||||
* @param convID The ID of the conversation to delete
|
||||
*/
|
||||
private static async DeleteConversations(convID: number) {
|
||||
// Get all the messages of the conversations
|
||||
const messages = await this.GetNewMessages(convID, 0);
|
||||
|
||||
for (const message of messages) {
|
||||
await this.DeleteMessage(message);
|
||||
}
|
||||
|
||||
// Delete all the members of the conversation
|
||||
// TODO
|
||||
|
||||
// Delete the conversation entry itself
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a conversation message from the database
|
||||
*
|
||||
* @param m The message to delete
|
||||
*/
|
||||
private static async DeleteMessage(m: ConversationMessage) {
|
||||
|
||||
// Delete conversation message image (if any)
|
||||
if(m.hasImage) {
|
||||
if(existsSync(m.imageSysPath))
|
||||
unlinkSync(m.imageSysPath);
|
||||
}
|
||||
|
||||
// Delete the message from the database
|
||||
await DatabaseHelper.DeleteRows(
|
||||
MESSAGES_TABLE,
|
||||
{
|
||||
ID: m.id
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of members of a conversation
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user