package gateway // 管理渠道列表里的**每账号**连接状态(AdminChannelAccount.Connected)。 // // 为什么要有它:平台级 `connected` 只反映该平台第一条已注册适配器(ChannelSummary // 由聚合行上的那个适配器决定),多账号平台上它无法回答「我点连接的那条现在活着吗」。 // 面板因此只能盲目渲染每行的连接/断开按钮 —— 主人有两条 qq-obv11 时,「断开」到底 // 断的是哪一条、断完有没有生效,看板上都无从判断。这里按账号把它补上。 import ( capreg "git.yeij.top/AskaEth/Cyrene_v2/internal/capability/registry" "git.yeij.top/AskaEth/Cyrene_v2/pkg/plugins/sdk" ) // liveAccountConnections 收集每个平台各账号的实时连接状态,键与 liveBotIdentity // 相同(裸适配器名 ⇒ 空账号 id)。注册表里**没有**该账号的适配器时它直接缺席, // 而不是报 false:缺席 = 状态未知(面板画「状态未知」),false = 确知未连接。 func (s *Server) liveAccountConnections() map[string]map[string]bool { out := make(map[string]map[string]bool) if s.caps == nil { return out } for _, cap := range s.caps.List(capreg.KindChannel) { ch, ok := cap.Value.(sdk.Channel) if !ok { continue } platform, acct := splitAdapterName(ch.Name()) if out[platform] == nil { out[platform] = make(map[string]bool) } out[platform][acct] = ch.IsConnected() } return out } // enrichAccountsWithConnection 把实时连接状态合并进平台中匹配的账号(按账号 id // 配对,与适配器注册名一致)。没有实时适配器的账号保持 Connected == nil(未知), // 因此面板能在「没连上」与「读不到」之间如实区分。入参切片不被修改。 func enrichAccountsWithConnection(accts []AdminChannelAccount, by map[string]bool) []AdminChannelAccount { if len(by) == 0 { return accts } out := make([]AdminChannelAccount, 0, len(accts)) for _, a := range accts { if connected, ok := by[a.ID]; ok { value := connected a.Connected = &value } out = append(out, a) } return out }