feat: implement conversation mute and favorite functionality with corresponding notification suppression.
This commit is contained in:
@@ -722,4 +722,64 @@ export class MessagesService {
|
||||
return result._sum.userUnreadCount || 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle mute status for a conversation
|
||||
*/
|
||||
async toggleMute(conversationId: string, userId: string, muted: boolean) {
|
||||
const conversation = await this.prisma.conversation.findUnique({
|
||||
where: { id: conversationId },
|
||||
include: { agentProfile: { select: { userId: true } } },
|
||||
});
|
||||
|
||||
if (!conversation) throw new NotFoundException('Conversation not found');
|
||||
|
||||
const isUser = conversation.userId === userId;
|
||||
const isAgent = conversation.agentProfile.userId === userId;
|
||||
if (!isUser && !isAgent) throw new ForbiddenException('You are not part of this conversation');
|
||||
|
||||
const updated = await this.prisma.conversation.update({
|
||||
where: { id: conversationId },
|
||||
data: isUser ? { userMuted: muted } : { agentMuted: muted },
|
||||
});
|
||||
|
||||
return { id: updated.id, muted: isUser ? updated.userMuted : updated.agentMuted };
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle favorite status for a conversation
|
||||
*/
|
||||
async toggleFavorite(conversationId: string, userId: string, favorited: boolean) {
|
||||
const conversation = await this.prisma.conversation.findUnique({
|
||||
where: { id: conversationId },
|
||||
include: { agentProfile: { select: { userId: true } } },
|
||||
});
|
||||
|
||||
if (!conversation) throw new NotFoundException('Conversation not found');
|
||||
|
||||
const isUser = conversation.userId === userId;
|
||||
const isAgent = conversation.agentProfile.userId === userId;
|
||||
if (!isUser && !isAgent) throw new ForbiddenException('You are not part of this conversation');
|
||||
|
||||
const updated = await this.prisma.conversation.update({
|
||||
where: { id: conversationId },
|
||||
data: isUser ? { userFavorited: favorited } : { agentFavorited: favorited },
|
||||
});
|
||||
|
||||
return { id: updated.id, favorited: isUser ? updated.userFavorited : updated.agentFavorited };
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a conversation is muted for a specific user
|
||||
*/
|
||||
async isConversationMuted(conversationId: string, userId: string): Promise<boolean> {
|
||||
const conversation = await this.prisma.conversation.findUnique({
|
||||
where: { id: conversationId },
|
||||
include: { agentProfile: { select: { userId: true } } },
|
||||
});
|
||||
if (!conversation) return false;
|
||||
|
||||
const isUser = conversation.userId === userId;
|
||||
return isUser ? conversation.userMuted : conversation.agentMuted;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user