fix docker for tauri app

This commit is contained in:
lendry
2026-06-26 16:43:17 +03:00
parent f1068edc89
commit 3ab48d8537
11 changed files with 220 additions and 76 deletions

View File

@@ -127,8 +127,6 @@ export class ChatService {
});
const humans = members.filter((member) => !member.user.linkedBotId);
const bots = members.filter((member) => member.user.linkedBotId);
const legacyRooms = await this.prisma.chatRoom.findMany({
where: { groupId, type: 'GROUP' },
include: { members: true }
@@ -177,17 +175,23 @@ export class ChatService {
}
}
for (const botMember of bots) {
for (const human of humans) {
await this.ensureBotRoom(
groupId,
human.userId,
botMember.userId,
botMember.user.linkedBot!.username,
botMember.user.displayName
);
}
// BOT-чаты создаются только для тех людей, которым явно выдали доступ к боту.
// Не создаём комнаты "каждый человек x каждый бот", иначе бот становится видимым всей семье.
}
async ensureBotRoomForMember(groupId: string, requesterId: string, botUserId: string) {
const group = await this.family.assertFamilyMember(groupId, requesterId);
const botMember = group.members.find((member) => member.userId === botUserId);
if (!botMember?.user?.linkedBotId || !botMember.user.linkedBot) {
throw new BadRequestException('Бот не найден в этой семье');
}
return this.ensureBotRoom(
groupId,
requesterId,
botUserId,
botMember.user.linkedBot.username,
botMember.user.displayName
);
}
async createRoom(userId: string, groupId: string, name: string, memberUserIds: string[]) {
@@ -313,7 +317,7 @@ export class ChatService {
if (room.type === 'GENERAL') {
throw new BadRequestException('В общий чат нельзя добавлять участников вручную');
}
if (room.type === 'DIRECT' || room.type === 'BOT' || room.type === 'E2E') {
if (room.type === 'DIRECT' || room.type === 'E2E') {
throw new BadRequestException('Нельзя изменять состав личного чата или чата с ботом');
}
if (room.members.some((member) => member.userId === memberUserId)) {
@@ -322,6 +326,15 @@ export class ChatService {
if (!room.group.members.some((member) => member.userId === memberUserId)) {
throw new BadRequestException('Пользователь должен состоять в семье');
}
if (room.type === 'BOT') {
const targetUser = await this.prisma.user.findUnique({
where: { id: memberUserId },
select: { linkedBotId: true, isSystemAccount: true }
});
if (!targetUser || targetUser.linkedBotId || targetUser.isSystemAccount) {
throw new BadRequestException('В чат с ботом можно добавить только обычного участника семьи');
}
}
await this.prisma.chatRoomMember.create({
data: { roomId, userId: memberUserId }
@@ -335,21 +348,24 @@ export class ChatService {
if (room.type === 'GENERAL') {
throw new BadRequestException('Нельзя удалить участника из общего чата');
}
if (room.type === 'DIRECT' || room.type === 'BOT' || room.type === 'E2E') {
if (room.type === 'DIRECT' || room.type === 'E2E') {
throw new BadRequestException('Нельзя изменять состав личного чата или чата с ботом');
}
const isFamilyOwner = room.group.ownerId === userId;
const isChatCreator = room.createdById === userId;
if (!isFamilyOwner && !isChatCreator) {
if (room.type !== 'BOT' && !isFamilyOwner && !isChatCreator) {
throw new ForbiddenException('Недостаточно прав для удаления участника из чата');
}
if (room.type === 'BOT' && memberUserId === room.peerUserId) {
throw new BadRequestException('Нельзя удалить бота из его чата');
}
if (memberUserId === room.createdById && !isFamilyOwner) {
throw new BadRequestException('Создателя чата может удалить только создатель семьи');
}
if (memberUserId === userId && room.members.length <= 1) {
if (memberUserId === userId && room.members.length <= (room.type === 'BOT' ? 2 : 1)) {
throw new BadRequestException('В чате должен остаться хотя бы один участник');
}
@@ -915,7 +931,7 @@ export class ChatService {
userId: string;
notificationsMuted: boolean;
pinnedAt?: Date | null;
user: { displayName: string; avatarStorageKey: string | null; isVerified: boolean; verificationIcon: string | null };
user: { displayName: string; avatarStorageKey: string | null; isVerified: boolean; verificationIcon: string | null; linkedBotId?: string | null };
}>;
},
familyRoleByUserId: Map<string, string>,
@@ -924,9 +940,11 @@ export class ChatService {
) {
const viewerMembership = viewerId ? room.members.find((member) => member.userId === viewerId) : undefined;
const peerMember =
viewerId && (room.type === 'DIRECT' || room.type === 'BOT' || room.type === 'E2E')
? room.members.find((member) => member.userId !== viewerId)
: undefined;
room.type === 'BOT'
? room.members.find((member) => Boolean(member.user.linkedBotId))
: viewerId && (room.type === 'DIRECT' || room.type === 'E2E')
? room.members.find((member) => member.userId !== viewerId)
: undefined;
return {
id: room.id,
@@ -1195,6 +1213,7 @@ export class ChatService {
name: botDisplayName,
peerUserId: botUserId,
botUsername,
createdById: humanUserId,
isE2E: false,
members: {
create: [{ userId: humanUserId }, { userId: botUserId }]