fix docker for tauri app
This commit is contained in:
@@ -208,7 +208,7 @@ export class BotApiService {
|
||||
return message;
|
||||
}
|
||||
|
||||
async listBotChatMessages(userId: string, botRef: string) {
|
||||
async listBotChatMessages(userId: string, botRef: string, roomId?: string) {
|
||||
const sender = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { isSystemAccount: true, linkedBotId: true, deletedAt: true, status: true }
|
||||
@@ -247,10 +247,12 @@ export class BotApiService {
|
||||
};
|
||||
}
|
||||
|
||||
const chat = await this.prisma.botChat.findUnique({
|
||||
where: { botId_recipientUserId: { botId: bot.id, recipientUserId: userId } },
|
||||
include: { menuButton: true }
|
||||
});
|
||||
const chat = roomId
|
||||
? await this.resolveSharedFamilyBotChat(bot.id, userId, roomId)
|
||||
: await this.prisma.botChat.findUnique({
|
||||
where: { botId_recipientUserId: { botId: bot.id, recipientUserId: userId } },
|
||||
include: { menuButton: true }
|
||||
});
|
||||
|
||||
const composer = this.resolveComposerForBot(bot, chat?.menuButton?.menuButton ?? null);
|
||||
const emptyResponse = {
|
||||
@@ -336,6 +338,30 @@ export class BotApiService {
|
||||
};
|
||||
}
|
||||
|
||||
private async resolveSharedFamilyBotChat(botId: string, viewerUserId: string, roomId: string) {
|
||||
const room = await this.prisma.chatRoom.findUnique({
|
||||
where: { id: roomId },
|
||||
include: {
|
||||
members: { include: { user: { select: { linkedBotId: true } } } }
|
||||
}
|
||||
});
|
||||
if (!room || room.type !== 'BOT' || !room.members.some((member) => member.userId === viewerUserId)) {
|
||||
return null;
|
||||
}
|
||||
const botMember = room.members.find((member) => member.user.linkedBotId === botId);
|
||||
if (!botMember || room.peerUserId !== botMember.userId) {
|
||||
return null;
|
||||
}
|
||||
const ownerUserId =
|
||||
room.createdById ??
|
||||
room.members.find((member) => !member.user.linkedBotId)?.userId ??
|
||||
viewerUserId;
|
||||
return this.prisma.botChat.findUnique({
|
||||
where: { botId_recipientUserId: { botId, recipientUserId: ownerUserId } },
|
||||
include: { menuButton: true }
|
||||
});
|
||||
}
|
||||
|
||||
private async setChatMenuButton(bot: ValidatedBot, payload: SetChatMenuButtonPayload) {
|
||||
const chatIdRaw = payload.chat_id;
|
||||
const parsedMenuButton = parseMenuButtonInput(payload.menu_button);
|
||||
@@ -865,7 +891,7 @@ export class BotApiService {
|
||||
mediaUrl?: string
|
||||
) {
|
||||
const payloadMarkup = this.serializer.readPayload(message.payload);
|
||||
await this.notifications.publishRealtime(userId, 'bot_message', bot.name, message.text ?? '', {
|
||||
const payload = {
|
||||
botId: bot.id,
|
||||
botUsername: bot.username,
|
||||
chatId: chat.telegramChatId.toString(),
|
||||
@@ -875,7 +901,9 @@ export class BotApiService {
|
||||
mediaUrl: message.mediaUrl ?? mediaUrl ?? null,
|
||||
replyMarkup: replyMarkup ?? payloadMarkup.replyMarkup ?? null,
|
||||
telegramReplyMarkup: payloadMarkup.telegramReplyMarkup ?? null
|
||||
});
|
||||
};
|
||||
await this.notifications.publishRealtime(userId, 'bot_message', bot.name, message.text ?? '', payload);
|
||||
await this.publishToSharedBotRoomMembers(userId, bot, 'bot_message', message.text ?? '', payload);
|
||||
}
|
||||
|
||||
private async publishBotMessagePinned(
|
||||
@@ -888,14 +916,16 @@ export class BotApiService {
|
||||
pinnedAt?: Date | null;
|
||||
}
|
||||
) {
|
||||
await this.notifications.publishRealtime(userId, 'bot_message_pinned', bot.name, '', {
|
||||
const payload = {
|
||||
botId: bot.id,
|
||||
botUsername: bot.username,
|
||||
chatId: chat.telegramChatId.toString(),
|
||||
messageId: message.telegramMsgId,
|
||||
isPinned: Boolean(message.isPinned),
|
||||
pinnedAt: message.pinnedAt?.toISOString() ?? null
|
||||
});
|
||||
};
|
||||
await this.notifications.publishRealtime(userId, 'bot_message_pinned', bot.name, '', payload);
|
||||
await this.publishToSharedBotRoomMembers(userId, bot, 'bot_message_pinned', '', payload);
|
||||
}
|
||||
|
||||
private async publishBotMessageEdited(
|
||||
@@ -913,7 +943,7 @@ export class BotApiService {
|
||||
replyMarkup: unknown
|
||||
) {
|
||||
const payloadMarkup = this.serializer.readPayload(message.payload);
|
||||
await this.notifications.publishRealtime(userId, 'bot_message_edited', bot.name, message.text ?? '', {
|
||||
const payload = {
|
||||
botId: bot.id,
|
||||
botUsername: bot.username,
|
||||
chatId: chat.telegramChatId.toString(),
|
||||
@@ -924,7 +954,41 @@ export class BotApiService {
|
||||
replyMarkup: replyMarkup ?? payloadMarkup.replyMarkup ?? null,
|
||||
telegramReplyMarkup: payloadMarkup.telegramReplyMarkup ?? null,
|
||||
editedAt: message.editedAt?.toISOString() ?? new Date().toISOString()
|
||||
};
|
||||
await this.notifications.publishRealtime(userId, 'bot_message_edited', bot.name, message.text ?? '', payload);
|
||||
await this.publishToSharedBotRoomMembers(userId, bot, 'bot_message_edited', message.text ?? '', payload);
|
||||
}
|
||||
|
||||
private async publishToSharedBotRoomMembers(
|
||||
ownerUserId: string,
|
||||
bot: ValidatedBot,
|
||||
eventType: string,
|
||||
message: string,
|
||||
payload: Record<string, unknown>
|
||||
) {
|
||||
const rooms = await this.prisma.chatRoom.findMany({
|
||||
where: {
|
||||
type: 'BOT',
|
||||
botUsername: bot.username,
|
||||
createdById: ownerUserId
|
||||
},
|
||||
include: {
|
||||
members: { include: { user: { select: { linkedBotId: true } } } }
|
||||
}
|
||||
});
|
||||
|
||||
const recipients = new Set<string>();
|
||||
for (const room of rooms) {
|
||||
for (const member of room.members) {
|
||||
if (member.userId !== ownerUserId && !member.user.linkedBotId) {
|
||||
recipients.add(member.userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
[...recipients].map((recipientId) => this.notifications.publishRealtime(recipientId, eventType, bot.name, message, payload))
|
||||
);
|
||||
}
|
||||
|
||||
private mergePayload(existing: unknown, parsed: ReturnType<TelegramSerializerService['parseReplyMarkup']>) {
|
||||
|
||||
Reference in New Issue
Block a user