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
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package livestore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"cloud.google.com/go/firestore"
|
|
)
|
|
|
|
//go:generate go tool mockgen -source ./membershippublisher.go -destination ./mocks/membershippublisher.go
|
|
|
|
// MembershipPublisher fans network membership changes out to Firestore.
|
|
// Postgres is the source of truth; the reconciler heals drift, so publish
|
|
// failures are safe to log and ignore.
|
|
type MembershipPublisher interface {
|
|
Add(ctx context.Context, humanId, networkID string) error
|
|
Remove(ctx context.Context, humanId, networkID string) error
|
|
}
|
|
|
|
func NewMembershipPublisher(fs *firestore.Client) MembershipPublisher {
|
|
return &firestoreMembershipPublisher{fs: fs}
|
|
}
|
|
|
|
type firestoreMembershipPublisher struct {
|
|
fs *firestore.Client
|
|
}
|
|
|
|
func (p *firestoreMembershipPublisher) Add(ctx context.Context, humanId, networkID string) error {
|
|
_, err := p.fs.Collection("humans").Doc(humanId).Set(ctx, map[string]any{
|
|
"networks": firestore.ArrayUnion(networkID),
|
|
"updated_at": firestore.ServerTimestamp,
|
|
}, firestore.MergeAll)
|
|
return err
|
|
}
|
|
|
|
func (p *firestoreMembershipPublisher) Remove(ctx context.Context, humanId, networkID string) error {
|
|
_, err := p.fs.Collection("humans").Doc(humanId).Set(ctx, map[string]any{
|
|
"networks": firestore.ArrayRemove(networkID),
|
|
"updated_at": firestore.ServerTimestamp,
|
|
}, firestore.MergeAll)
|
|
return err
|
|
}
|