this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: test notification was not sent to any subscription

+42 -24
+2 -9
messages.go
··· 14 14 } 15 15 16 16 func (msg Message) Run() error { 17 - users, err := Receivers(msg) 17 + subs, users, err := msg.ShouldSendTo() 18 18 if err != nil { 19 - return fmt.Errorf("could not determine who to send the notification to: %w", err) 20 - } 21 - 22 - ll.Debug("Sending notification for %s on %s to %d users: %v", msg.Event, msg.ChurrosObjectId, len(users), users) 23 - 24 - subs, err := subscriptionsOfUsers(users) 25 - if err != nil { 26 - return fmt.Errorf("could not determine which subscriptions to send the notification to: %w", err) 19 + return fmt.Errorf("could not determine what subscriptions to send the notification to: %w", err) 27 20 } 28 21 29 22 if len(subs) == 0 {
+40 -15
subscriptions.go
··· 21 21 Owner SubscriptionOwner `json:"owner"` 22 22 } 23 23 24 + func (msg Message) ShouldSendTo() (subs []Subscription, userIds []string, err error) { 25 + if msg.Event == EventTest { 26 + sub, err := prisma.NotificationSubscription.FindUnique(db.NotificationSubscription.ID.Equals(msg.ChurrosObjectId)).With(db.NotificationSubscription.Owner.Fetch()).Exec(context.Background()) 27 + return []Subscription{SubscriptionFromDatabase(*sub)}, []string{}, err 28 + } 29 + 30 + users, err := Receivers(msg) 31 + if err != nil { 32 + return []Subscription{}, users, fmt.Errorf("could not determine who to send the notification to: %w", err) 33 + } 34 + 35 + ll.Debug("Sending notification for %s on %s to %d users: %v", msg.Event, msg.ChurrosObjectId, len(users), users) 36 + 37 + subs, err = subscriptionsOfUsers(users) 38 + if err != nil { 39 + return []Subscription{}, users, fmt.Errorf("could not determine which subscriptions to send the notification to: %w", err) 40 + } 41 + 42 + return subs, []string{}, nil 43 + } 44 + 24 45 func subscriptionsOfUsers(ids []string) (subscriptions []Subscription, err error) { 25 46 if err := prisma.Prisma.Connect(); err != nil { 26 47 return nil, fmt.Errorf("could not connect to prisma: %w", err) ··· 34 55 } 35 56 36 57 for _, sub := range subs { 37 - subscriptions = append(subscriptions, Subscription{ 38 - Webpush: webpush.Subscription{ 39 - Endpoint: sub.Endpoint, 40 - Keys: webpush.Keys{ 41 - Auth: sub.AuthKey, 42 - P256dh: sub.P256DhKey, 43 - }, 44 - }, 45 - Owner: SubscriptionOwner{ 46 - Id: sub.OwnerID, 47 - Uid: sub.Owner().UID, 48 - FirstName: sub.Owner().FirstName, 49 - LastName: sub.Owner().LastName, 50 - }, 51 - }) 58 + subscriptions = append(subscriptions, SubscriptionFromDatabase(sub)) 52 59 } 53 60 54 61 ll.Debug("Found %d subscriptions for %d users %v", len(subscriptions), len(ids), ids) 55 62 56 63 return subscriptions, nil 64 + } 65 + 66 + func SubscriptionFromDatabase(sub db.NotificationSubscriptionModel) Subscription { 67 + return Subscription{ 68 + Webpush: webpush.Subscription{ 69 + Endpoint: sub.Endpoint, 70 + Keys: webpush.Keys{ 71 + Auth: sub.AuthKey, 72 + P256dh: sub.P256DhKey, 73 + }, 74 + }, 75 + Owner: SubscriptionOwner{ 76 + Id: sub.OwnerID, 77 + Uid: sub.Owner().UID, 78 + FirstName: sub.Owner().FirstName, 79 + LastName: sub.Owner().LastName, 80 + }, 81 + } 57 82 } 58 83 59 84 func (sub Subscription) Destroy() error {