Editing correction (in progress)
This commit is contained in:
@@ -62,6 +62,10 @@ export class ConversationsController {
|
||||
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
||||
@Query('externalRoomId') externalRoomId: string,
|
||||
) {
|
||||
// بدون roomId → همه اتاقهای سازمان (لیست گفتگو)
|
||||
if (!externalRoomId?.trim()) {
|
||||
return this.conversations.listTypingAll(user.userId, user.organizationId, user.role);
|
||||
}
|
||||
return this.conversations.listTyping(
|
||||
user.userId,
|
||||
user.organizationId,
|
||||
|
||||
@@ -98,6 +98,61 @@ export class ConversationsService {
|
||||
}));
|
||||
}
|
||||
|
||||
/** typing همه اتاقهای سازمان (برای پیشنمایش لیست گفتگو) */
|
||||
async listTypingAll(
|
||||
userId: string,
|
||||
organizationId: string,
|
||||
role: string,
|
||||
): Promise<
|
||||
Array<{ externalRoomId: string; userId: string; fullName: string; chatUserId: string }>
|
||||
> {
|
||||
await this.loadAccess(userId, organizationId, role);
|
||||
const now = Date.now();
|
||||
this.sweepTypingPresence(now);
|
||||
const orgPrefix = `${organizationId}|`;
|
||||
const byRoom = new Map<string, string[]>();
|
||||
for (const [k, at] of this.typingPresence) {
|
||||
if (!k.startsWith(orgPrefix)) continue;
|
||||
if (now - at > 4000) {
|
||||
this.typingPresence.delete(k);
|
||||
continue;
|
||||
}
|
||||
const rest = k.slice(orgPrefix.length);
|
||||
const sep = rest.lastIndexOf('|');
|
||||
if (sep <= 0) continue;
|
||||
const roomId = rest.slice(0, sep);
|
||||
const uid = rest.slice(sep + 1);
|
||||
if (!roomId || !uid || uid === userId) continue;
|
||||
const list = byRoom.get(roomId) || [];
|
||||
list.push(uid);
|
||||
byRoom.set(roomId, list);
|
||||
}
|
||||
if (!byRoom.size) return [];
|
||||
const allIds = [...new Set([...byRoom.values()].flat())];
|
||||
const users = await this.prisma.user.findMany({
|
||||
where: { id: { in: allIds } },
|
||||
select: { id: true, fullName: true },
|
||||
});
|
||||
const nameById = new Map(users.map((u) => [u.id, u.fullName || 'کاربر']));
|
||||
const out: Array<{
|
||||
externalRoomId: string;
|
||||
userId: string;
|
||||
fullName: string;
|
||||
chatUserId: string;
|
||||
}> = [];
|
||||
for (const [roomId, ids] of byRoom) {
|
||||
for (const uid of ids) {
|
||||
out.push({
|
||||
externalRoomId: roomId,
|
||||
userId: uid,
|
||||
fullName: nameById.get(uid) || 'کاربر',
|
||||
chatUserId: buildChatUserId(organizationId, uid),
|
||||
});
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
async getAccess(userId: string, organizationId: string, role: string): Promise<ConversationAccessDto> {
|
||||
const access = await this.loadAccess(userId, organizationId, role);
|
||||
return access;
|
||||
|
||||
Reference in New Issue
Block a user