global fix and update bot Api

This commit is contained in:
lendry
2026-06-26 13:01:52 +03:00
parent d3ea470d02
commit aa228d84eb
29 changed files with 980 additions and 221 deletions

View File

@@ -607,6 +607,33 @@ export class ChatService {
return response;
}
async setMessagePinned(userId: string, messageId: string, pinned: boolean) {
const message = await this.prisma.chatMessage.findUnique({
where: { id: messageId },
include: { room: { include: { members: true } } }
});
if (!message || message.deletedAt) {
throw new NotFoundException('Сообщение не найдено');
}
if (message.room.type === 'BOT') {
throw new BadRequestException('Сообщения бота закрепляются через Bot API');
}
if (!message.room.members.some((member) => member.userId === userId)) {
throw new ForbiddenException('Вы не состоите в этом чате');
}
await this.prisma.chatMessage.update({
where: { id: messageId },
data: pinned
? { isPinned: true, pinnedAt: new Date(), pinnedById: userId }
: { isPinned: false, pinnedAt: null, pinnedById: null }
});
const response = await this.loadMessageResponse(messageId, userId);
await this.publishRoomEvent(message.room, 'chat_message_updated', response);
return response;
}
async toggleMessageReaction(userId: string, messageId: string, emoji: string) {
const normalizedEmoji = emoji.trim();
if (!normalizedEmoji || normalizedEmoji.length > 16) {
@@ -1016,6 +1043,9 @@ export class ChatService {
storageKey: string | null;
mimeType: string | null;
metadata: unknown;
isPinned?: boolean;
pinnedAt?: Date | null;
pinnedById?: string | null;
createdAt: Date;
editedAt?: Date | null;
deletedAt?: Date | null;
@@ -1060,6 +1090,9 @@ export class ChatService {
isDeleted,
readByAll: message.senderId === viewerId ? readByAll : undefined,
reactions: isDeleted ? [] : this.buildReactionResponses(message.metadata, viewerId),
isPinned: !isDeleted && Boolean(message.isPinned),
pinnedAt: !isDeleted ? message.pinnedAt?.toISOString() : undefined,
pinnedById: !isDeleted ? message.pinnedById ?? undefined : undefined,
poll: !isDeleted && message.poll
? {
id: message.poll.id,
@@ -1202,6 +1235,9 @@ export class ChatService {
isDeleted: false,
readByAll: undefined,
reactions: [],
isPinned: false,
pinnedAt: undefined,
pinnedById: undefined,
poll: undefined
};
}