d262f734f0
* mobile: wire notification registration and listener
* implement backend components for push notifications
* refactor: agentic comment cleanup
* docs: use proper module name for particle processor
* set required env variables for push notifications
* bump version
* fix: always upsert push token on mobile start
* Revert "fix: always upsert push token on mobile start"
This reverts commit 90ff18a788.
* send push notifications regardless of online status
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package pusher
|
|
|
|
// Channel tracks the local connections subscribed on this pod.
|
|
// State is only mutated by the Hub goroutine, so no locks are needed.
|
|
type Channel struct {
|
|
id string
|
|
members map[*Conn]string // conn → humanID
|
|
}
|
|
|
|
func newChannel(id string) *Channel {
|
|
return &Channel{
|
|
id: id,
|
|
members: make(map[*Conn]string),
|
|
}
|
|
}
|
|
|
|
func (ch *Channel) addMember(conn *Conn, humanID string) {
|
|
ch.members[conn] = humanID
|
|
}
|
|
|
|
func (ch *Channel) removeMember(conn *Conn) {
|
|
delete(ch.members, conn)
|
|
}
|
|
|
|
func (ch *Channel) isEmpty() bool {
|
|
return len(ch.members) == 0
|
|
}
|
|
|
|
// Deduplicated set; the same human may have multiple connections.
|
|
func (ch *Channel) localHumanIDs() []string {
|
|
seen := make(map[string]bool, len(ch.members))
|
|
ids := make([]string, 0, len(ch.members))
|
|
for _, hid := range ch.members {
|
|
if !seen[hid] {
|
|
seen[hid] = true
|
|
ids = append(ids, hid)
|
|
}
|
|
}
|
|
return ids
|
|
}
|
|
|
|
func (ch *Channel) hasHumanID(humanID string) bool {
|
|
for _, hid := range ch.members {
|
|
if hid == humanID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (ch *Channel) broadcast(msg ServerMessage, exclude *Conn) {
|
|
for conn := range ch.members {
|
|
if conn != exclude {
|
|
conn.Send(msg)
|
|
}
|
|
}
|
|
}
|