mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 00:25:17 +00:00
Remove conversation: Can delete conversation messages
This commit is contained in:
@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user