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 [{