feat: implement conversation mute and favorite functionality with corresponding notification suppression.
This commit is contained in:
@@ -218,6 +218,36 @@ export class MessagesController {
|
||||
return this.messagesService.markMessagesAsRead(conversationId, userId);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// TOGGLE MUTE
|
||||
// ==========================================
|
||||
@Patch('conversations/:id/mute')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'Mute or unmute conversation notifications' })
|
||||
@ApiParam({ name: 'id', description: 'Conversation ID' })
|
||||
async toggleMute(
|
||||
@Param('id') conversationId: string,
|
||||
@CurrentUser('id') userId: string,
|
||||
@Body() dto: { muted: boolean },
|
||||
) {
|
||||
return this.messagesService.toggleMute(conversationId, userId, dto.muted);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// TOGGLE FAVORITE
|
||||
// ==========================================
|
||||
@Patch('conversations/:id/favorite')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'Star or unstar a conversation' })
|
||||
@ApiParam({ name: 'id', description: 'Conversation ID' })
|
||||
async toggleFavorite(
|
||||
@Param('id') conversationId: string,
|
||||
@CurrentUser('id') userId: string,
|
||||
@Body() dto: { favorited: boolean },
|
||||
) {
|
||||
return this.messagesService.toggleFavorite(conversationId, userId, dto.favorited);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// CLEAR CHAT (delete messages, keep conversation)
|
||||
// ==========================================
|
||||
|
||||
@@ -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