From 845fb86f578b2499e7a4bd8a12279b5d0aa7e8ab Mon Sep 17 00:00:00 2001 From: borja Date: Sun, 7 Sep 2025 19:25:15 +0200 Subject: [PATCH] fix: ajustar ver todos para mostrar sin responsable por grupo Co-authored-by: aider (openrouter/openai/gpt-5) --- src/services/command.ts | 52 ++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/services/command.ts b/src/services/command.ts index 0b103cf..9e8566f 100644 --- a/src/services/command.ts +++ b/src/services/command.ts @@ -275,16 +275,13 @@ export class CommandService { sections.push('No tienes tareas pendientes.'); } - // Añadir "sin responsable" de grupos donde el usuario es miembro activo y snapshot fresca - const memberGroups = GroupSyncService.getFreshMemberGroupsForUser(context.sender); - if (memberGroups.length > 0) { - const perGroup = TaskService.listUnassignedByGroups(memberGroups, LIMIT); - for (const gid of perGroup.keys()) { - const unassigned = perGroup.get(gid)!; - const groupName = - (gid && GroupSyncService.activeGroupsCache.get(gid)) || - gid; - + // En contexto de grupo: mantener compatibilidad mostrando solo "sin responsable" del grupo actual + if (isGroupId(context.groupId)) { + if (!GroupSyncService.isGroupActive(context.groupId)) { + sections.push('⚠️ Este grupo no está activo.'); + } else { + const groupName = GroupSyncService.activeGroupsCache.get(context.groupId) || context.groupId; + const unassigned = TaskService.listGroupUnassigned(context.groupId, LIMIT); if (unassigned.length > 0) { sections.push(`${groupName} — Sin responsable`); const renderedUnassigned = unassigned.map((t) => { @@ -294,15 +291,44 @@ export class CommandService { }); sections.push(...renderedUnassigned); - const totalUnassigned = TaskService.countGroupUnassigned(gid); + const totalUnassigned = TaskService.countGroupUnassigned(context.groupId); if (totalUnassigned > unassigned.length) { sections.push(`… y ${totalUnassigned - unassigned.length} más`); } + } else { + sections.push(`${groupName} — Sin responsable\n(no hay tareas sin responsable)`); } } } else { - // Si no hay snapshot fresca de membresía, mantenemos una nota instructiva mínima - sections.push('ℹ️ Para ver tareas sin responsable de un grupo, usa “/t ver sin” desde ese grupo.'); + // En DM: usar membresía real (snapshot fresca) para incluir "sin responsable" por grupo + const memberGroups = GroupSyncService.getFreshMemberGroupsForUser(context.sender); + if (memberGroups.length > 0) { + const perGroup = TaskService.listUnassignedByGroups(memberGroups, LIMIT); + for (const gid of perGroup.keys()) { + const unassigned = perGroup.get(gid)!; + const groupName = + (gid && GroupSyncService.activeGroupsCache.get(gid)) || + gid; + + if (unassigned.length > 0) { + sections.push(`${groupName} — Sin responsable`); + const renderedUnassigned = unassigned.map((t) => { + const isOverdue = t.due_date ? t.due_date < todayYMD : false; + const datePart = t.due_date ? ` — ${isOverdue ? `${ICONS.warn} ` : ''}${ICONS.date} ${formatDDMM(t.due_date)}` : ''; + return `- ${t.id}) _${t.description || '(sin descripción)'}_${datePart} — ${ICONS.unassigned} sin responsable`; + }); + sections.push(...renderedUnassigned); + + const totalUnassigned = TaskService.countGroupUnassigned(gid); + if (totalUnassigned > unassigned.length) { + sections.push(`… y ${totalUnassigned - unassigned.length} más`); + } + } + } + } else { + // Si no hay snapshot fresca de membresía, mantenemos una nota instructiva mínima + sections.push('ℹ️ Para ver tareas sin responsable de un grupo, usa “/t ver sin” desde ese grupo.'); + } } return [{