Fixing the issue with complete deletion from the database

This commit is contained in:
2026-09-29 21:46:41 +03:30
parent 88dc7c5a1c
commit 5bb8e68521
6 changed files with 276 additions and 52 deletions
@@ -443,6 +443,9 @@ export class ConversationsService {
let preview = lastMsg
? String(lastMsg.content ?? lastMsg.text ?? lastMsg.body ?? '').trim()
: '';
if (/^__MENTO_HIDE__:/i.test(preview) || /MENTO_DEL/i.test(preview)) {
preview = '';
}
if (lastType === 'image' || lastType === 'photo' || lastType === 'img') {
if (/(?:^|[\\/._-])vid-\d+/i.test(preview) || /\.(mp4|mov|m4v|mkv|avi|3gp)(?:\?|$)/i.test(preview)) {
preview = 'ویدیو';
@@ -490,4 +493,54 @@ export class ConversationsService {
peerUserId,
};
}
async hideMessages(
userId: string,
organizationId: string,
role: string,
externalRoomId: string,
messageIds: string[],
): Promise<{ messageIds: string[] }> {
await this.loadAccess(userId, organizationId, role);
const roomId = externalRoomId.trim();
if (!roomId) throw new BadRequestException('شناسه اتاق خالی است');
const ids = [
...new Set(
messageIds
.map((id) => String(id || '').trim())
.filter((id) => id.length > 0 && id.length <= 200),
),
].slice(0, 100);
if (!ids.length) throw new BadRequestException('شناسه پیام خالی است');
await this.prisma.conversationHiddenMessage.createMany({
data: ids.map((messageId) => ({
organizationId,
externalRoomId: roomId,
messageId,
hiddenByUserId: userId,
})),
skipDuplicates: true,
});
return { messageIds: ids };
}
async listHiddenMessageIds(
userId: string,
organizationId: string,
role: string,
externalRoomId: string,
): Promise<{ messageIds: string[] }> {
await this.loadAccess(userId, organizationId, role);
const roomId = externalRoomId.trim();
if (!roomId) throw new BadRequestException('شناسه اتاق خالی است');
const rows = await this.prisma.conversationHiddenMessage.findMany({
where: { organizationId, externalRoomId: roomId },
select: { messageId: true },
take: 5000,
});
return { messageIds: rows.map((r) => r.messageId) };
}
}