import type { KanbanScope } from '../panel/kanbanScope' /** * issue opened 事件的看板 append 门禁:webhook 广播到所有开着看板的 * 机器,而 'mine' 范围的批量加载只拉"我创建/指派给我"的工单。若无条件 * append,别人建的单会在 'mine' 看板上凭空多出一张卡(刷新后又消失)。 * append 必须与批量加载遵循同一套可见性规则。 */ export function decideIssueAppend(opts: { /** 看板当前范围('mine' 只看我的 / 'all' 团队全部)。 */ scope: KanbanScope /** 本机面板发起的创建(nonce 匹配到 pending),用户正等这张卡上屏。 */ pendingCreatedLocally: boolean /** 工单创建者的 login;payload 缺失时为 undefined。 */ poster: string | undefined /** 工单 assignee 的 login 列表,空数组表示未指派。 */ assignees: string[] /** 本机 token 对应的 Gitea login;身份解析失败时为 undefined。 */ me: string | undefined }): boolean { // ① 本机发起的创建 → 恒显,范围和身份都不作数。 if (opts.pendingCreatedLocally) return true // ② 'all' 范围本来就展示团队全部 → 恒显。 if (opts.scope === 'all') return true // ③ 'mine' 范围:与批量加载(created_by=我 / assigned_by=我)同规则; // 身份未知时宁可少显示,下次刷新会兜底。 return opts.me !== undefined && (opts.poster === opts.me || opts.assignees.includes(opts.me)) }