package channelbridge import ( "strings" "git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter" ) // This file holds the small package-level helpers shared across the bridge files: // platform/account naming, the sender label, and generic slice readers. // basePlatform returns the bare platform name of a (possibly multi-account) // adapter name like "telegram:conf0" → "telegram", so the credential gate and the // reply-routing fallback treat every account of a platform identically. func basePlatform(name string) string { if base, _, ok := strings.Cut(name, ":"); ok { return base } return name } // adapterName returns the account-adapter registration name (e.g. "kook:3bef...") // for the adapter that received a message, or "" when a is nil. The single-account // convenience path (process) and a platform with no registered adapter can pass a nil // adapter, so the persist hooks tolerate it and store an empty adapter_id rather than // dereferencing a nil adapter. func adapterName(a adapter.PlatformAdapter) string { if a == nil { return "" } return a.Name() } // senderDisplayName returns the human-readable sender name used to label a // third-party message. It prefers the resolved actor's display name (which the // channel layer derived from channel metadata + the raw SenderName), falling back // to the message's own SenderName, so an empty SenderName always means "the // owner/unlabeled" rather than a nickname that resolved to nothing. func senderDisplayName(msg adapter.UnifiedMessage, actor adapter.Actor) string { if actor.DisplayName != "" { return actor.DisplayName } return msg.SenderName } // sliceContains reports whether s is present in list. func sliceContains(list []string, s string) bool { for _, v := range list { if v == s { return true } } return false } // firstNonEmptyStr returns a when non-empty, otherwise b. func firstNonEmptyStr(a, b string) string { if a != "" { return a } return b }