Fixed message deletion error and layout changes for the message input box.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "ConversationHiddenMessage" ADD COLUMN "scope" TEXT NOT NULL DEFAULT 'all';
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "ConversationHiddenMessage_organizationId_externalRoomId_messageId_key";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "ConversationHiddenMessage_organizationId_externalRoomId_messageId_scope_hiddenByUserId_key" ON "ConversationHiddenMessage"("organizationId", "externalRoomId", "messageId", "scope", "hiddenByUserId");
|
||||
@@ -2097,7 +2097,8 @@ model ConversationRoom {
|
||||
@@index([organizationId, kind])
|
||||
}
|
||||
|
||||
/// پیامهای حذفشده برای همه در CRM (سرویس چت خارجی حذف پایدار ندارد)
|
||||
/// پیامهای حذفشده در CRM (سرویس چت خارجی حذف پایدار ندارد)
|
||||
/// scope=all → برای همه؛ scope=self → فقط برای hiddenByUserId
|
||||
model ConversationHiddenMessage {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
@@ -2105,8 +2106,10 @@ model ConversationHiddenMessage {
|
||||
externalRoomId String
|
||||
messageId String
|
||||
hiddenByUserId String
|
||||
/// all = حذف برای همه | self = حذف فقط برای کاربر
|
||||
scope String @default("all")
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([organizationId, externalRoomId, messageId])
|
||||
@@unique([organizationId, externalRoomId, messageId, scope, hiddenByUserId])
|
||||
@@index([organizationId, externalRoomId])
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ export class ConversationsController {
|
||||
user.role,
|
||||
dto.externalRoomId,
|
||||
dto.messageIds,
|
||||
dto.forEveryone !== false,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -500,7 +500,8 @@ export class ConversationsService {
|
||||
role: string,
|
||||
externalRoomId: string,
|
||||
messageIds: string[],
|
||||
): Promise<{ messageIds: string[] }> {
|
||||
forEveryone = true,
|
||||
): Promise<{ messageIds: string[]; scope: 'all' | 'self' }> {
|
||||
await this.loadAccess(userId, organizationId, role);
|
||||
const roomId = externalRoomId.trim();
|
||||
if (!roomId) throw new BadRequestException('شناسه اتاق خالی است');
|
||||
@@ -513,17 +514,19 @@ export class ConversationsService {
|
||||
].slice(0, 100);
|
||||
if (!ids.length) throw new BadRequestException('شناسه پیام خالی است');
|
||||
|
||||
const scope = forEveryone ? 'all' : 'self';
|
||||
await this.prisma.conversationHiddenMessage.createMany({
|
||||
data: ids.map((messageId) => ({
|
||||
organizationId,
|
||||
externalRoomId: roomId,
|
||||
messageId,
|
||||
hiddenByUserId: userId,
|
||||
scope,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
return { messageIds: ids };
|
||||
return { messageIds: ids, scope };
|
||||
}
|
||||
|
||||
async listHiddenMessageIds(
|
||||
@@ -537,10 +540,14 @@ export class ConversationsService {
|
||||
if (!roomId) throw new BadRequestException('شناسه اتاق خالی است');
|
||||
|
||||
const rows = await this.prisma.conversationHiddenMessage.findMany({
|
||||
where: { organizationId, externalRoomId: roomId },
|
||||
where: {
|
||||
organizationId,
|
||||
externalRoomId: roomId,
|
||||
OR: [{ scope: 'all' }, { scope: 'self', hiddenByUserId: userId }],
|
||||
},
|
||||
select: { messageId: true },
|
||||
take: 5000,
|
||||
});
|
||||
return { messageIds: rows.map((r) => r.messageId) };
|
||||
return { messageIds: [...new Set(rows.map((r) => r.messageId))] };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
@@ -61,4 +62,9 @@ export class HideConversationMessagesDto {
|
||||
@ArrayMaxSize(100)
|
||||
@IsString({ each: true })
|
||||
messageIds!: string[];
|
||||
|
||||
/** true = حذف برای همه؛ false = فقط برای کاربر جاری */
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
forEveryone?: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user