fix docker for tauri app
This commit is contained in:
@@ -106,7 +106,7 @@ export class FamilyService {
|
||||
|
||||
|
||||
|
||||
return this.toGroup(group);
|
||||
return this.toGroup(group, ownerId);
|
||||
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ export class FamilyService {
|
||||
|
||||
});
|
||||
|
||||
return { groups: groups.map((group) => this.toGroup(group)) };
|
||||
return { groups: await Promise.all(groups.map((group) => this.toGroup(group, userId))) };
|
||||
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ export class FamilyService {
|
||||
|
||||
this.assertMember(group, requesterId);
|
||||
|
||||
return this.toGroup(group);
|
||||
return this.toGroup(group, requesterId);
|
||||
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ export class FamilyService {
|
||||
|
||||
});
|
||||
|
||||
return this.toGroup(updated);
|
||||
return this.toGroup(updated, requesterId);
|
||||
|
||||
}
|
||||
|
||||
@@ -457,23 +457,30 @@ export class FamilyService {
|
||||
throw new BadRequestException('Пользователь не найден. Выберите его из результатов поиска.');
|
||||
}
|
||||
|
||||
const inviter = await this.prisma.user.findUnique({ where: { id: requesterId } });
|
||||
const isBotInvite = isProtectedSystemAccount(invitee);
|
||||
const inviteeAlreadyInFamily = group.members.some((member) => member.userId === invitee.id);
|
||||
|
||||
if (invitee.id === requesterId) {
|
||||
throw new BadRequestException('Нельзя пригласить самого себя');
|
||||
}
|
||||
|
||||
if (group.members.some((member) => member.userId === invitee.id)) {
|
||||
if (isBotInvite) {
|
||||
const visibleBotUserIds = await this.getVisibleBotUserIds(groupId, requesterId);
|
||||
if (visibleBotUserIds.has(invitee.id)) {
|
||||
throw new BadRequestException('Этот бот уже доступен вам в семье');
|
||||
}
|
||||
} else if (inviteeAlreadyInFamily) {
|
||||
throw new BadRequestException('Пользователь уже состоит в семье');
|
||||
}
|
||||
|
||||
const existingPending = await this.prisma.familyInvite.findFirst({
|
||||
where: { groupId, inviteeUserId: invitee.id, status: 'PENDING' }
|
||||
});
|
||||
if (existingPending) {
|
||||
if (existingPending && !isBotInvite) {
|
||||
throw new BadRequestException('Приглашение уже отправлено');
|
||||
}
|
||||
|
||||
const inviter = await this.prisma.user.findUnique({ where: { id: requesterId } });
|
||||
const isBotInvite = isProtectedSystemAccount(invitee);
|
||||
if (isBotInvite) {
|
||||
const invite = await this.prisma.familyInvite.create({
|
||||
data: {
|
||||
@@ -490,7 +497,9 @@ export class FamilyService {
|
||||
inviter: true
|
||||
}
|
||||
});
|
||||
await this.addMember(groupId, invitee.id, 'bot');
|
||||
if (!inviteeAlreadyInFamily) {
|
||||
await this.addMember(groupId, invitee.id, 'bot');
|
||||
}
|
||||
await this.notifications.create(
|
||||
requesterId,
|
||||
'family_bot_added',
|
||||
@@ -537,24 +546,18 @@ export class FamilyService {
|
||||
return { users: [] };
|
||||
}
|
||||
|
||||
const excludedIds = [...group.members.map((member) => member.userId), requesterId];
|
||||
const excludedBotUsernames = new Set(
|
||||
group.members
|
||||
.map((member) => member.user?.linkedBot?.username)
|
||||
.filter((username): username is string => Boolean(username))
|
||||
);
|
||||
const excludedIds = [...group.members.filter((member) => !member.user?.linkedBotId).map((member) => member.userId), requesterId];
|
||||
const visibleBotUserIds = await this.getVisibleBotUserIds(groupId, requesterId);
|
||||
const botFatherUserId = await this.botFatherSeed.getBotFatherUserId();
|
||||
const botFatherBotId = await this.botFatherSeed.getBotFatherBotId();
|
||||
const getMyIdUserId = await this.botFatherSeed.getGetMyIdBotUserId();
|
||||
const getMyIdBotId = await this.botFatherSeed.getGetMyIdBotId();
|
||||
const botFatherMatches =
|
||||
/bot\s*father|бот\s*father|botfather/i.test(trimmed) &&
|
||||
!excludedIds.includes(botFatherUserId) &&
|
||||
!excludedBotUsernames.has(BOTFATHER_BOT_USERNAME);
|
||||
!visibleBotUserIds.has(botFatherUserId);
|
||||
const getMyIdMatches =
|
||||
/get\s*my\s*id|getmyid|мой\s*id|айди|chat[_\s-]*id/i.test(trimmed) &&
|
||||
!excludedIds.includes(getMyIdUserId) &&
|
||||
!excludedBotUsernames.has(GET_MY_ID_BOT_USERNAME);
|
||||
!visibleBotUserIds.has(getMyIdUserId);
|
||||
const digits = trimmed.replace(/\D/g, '');
|
||||
const normalizedBotQuery = normalizeBotUsername(trimmed.replace(/^@/, ''));
|
||||
|
||||
@@ -619,13 +622,12 @@ export class FamilyService {
|
||||
}> = [];
|
||||
|
||||
for (const bot of matchedBots) {
|
||||
if (excludedBotUsernames.has(bot.username)) continue;
|
||||
if (botFatherMatches && bot.username === BOTFATHER_BOT_USERNAME) continue;
|
||||
if (getMyIdMatches && bot.username === GET_MY_ID_BOT_USERNAME) continue;
|
||||
const { userId } = bot.linkedSystemUser
|
||||
? { userId: bot.linkedSystemUser.id }
|
||||
: await this.botFather.ensureBotSystemUser(bot.id);
|
||||
if (excludedIds.includes(userId)) continue;
|
||||
if (visibleBotUserIds.has(userId)) continue;
|
||||
botCandidates.push({
|
||||
id: userId,
|
||||
botId: bot.id,
|
||||
@@ -963,7 +965,7 @@ export class FamilyService {
|
||||
|
||||
|
||||
|
||||
private toGroup(group: {
|
||||
private async toGroup(group: {
|
||||
|
||||
id: string;
|
||||
|
||||
@@ -1000,7 +1002,9 @@ export class FamilyService {
|
||||
|
||||
}>;
|
||||
|
||||
}) {
|
||||
}, viewerId?: string) {
|
||||
const visibleBotUserIds = viewerId ? await this.getVisibleBotUserIds(group.id, viewerId) : new Set<string>();
|
||||
const visibleMembers = group.members.filter((member) => !member.user?.linkedBotId || visibleBotUserIds.has(member.userId));
|
||||
|
||||
return {
|
||||
|
||||
@@ -1016,13 +1020,13 @@ export class FamilyService {
|
||||
|
||||
updatedAt: group.updatedAt.toISOString(),
|
||||
|
||||
members: group.members.map((member) => this.toMember(member)),
|
||||
members: visibleMembers.map((member) => this.toMember(member)),
|
||||
|
||||
botFatherAvailable: !group.members.some(
|
||||
botFatherAvailable: !visibleMembers.some(
|
||||
(member) => member.user?.linkedBot?.username === BOTFATHER_BOT_USERNAME
|
||||
),
|
||||
|
||||
getMyIdBotAvailable: !group.members.some(
|
||||
getMyIdBotAvailable: !visibleMembers.some(
|
||||
(member) => member.user?.linkedBot?.username === GET_MY_ID_BOT_USERNAME
|
||||
)
|
||||
|
||||
@@ -1030,6 +1034,27 @@ export class FamilyService {
|
||||
|
||||
}
|
||||
|
||||
private async getVisibleBotUserIds(groupId: string, viewerId: string) {
|
||||
const rooms = await this.prisma.chatRoom.findMany({
|
||||
where: {
|
||||
groupId,
|
||||
type: 'BOT',
|
||||
members: { some: { userId: viewerId } }
|
||||
},
|
||||
include: {
|
||||
members: {
|
||||
include: { user: { select: { linkedBotId: true } } }
|
||||
}
|
||||
}
|
||||
});
|
||||
return new Set(
|
||||
rooms
|
||||
.flatMap((room) => room.members)
|
||||
.filter((member) => Boolean(member.user.linkedBotId))
|
||||
.map((member) => member.userId)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private toMember(member: {
|
||||
|
||||
Reference in New Issue
Block a user