Skip to content
Snippets Groups Projects

Update firebase error handling for more info & better handling

5 files
+ 33
39
Compare changes
  • Side-by-side
  • Inline

Files

+ 9
6
@@ -9,7 +9,6 @@
@@ -9,7 +9,6 @@
package notifications
package notifications
import (
import (
"bytes"
"encoding/base64"
"encoding/base64"
"gitlab.com/elixxir/notifications-bot/notifications/apns"
"gitlab.com/elixxir/notifications-bot/notifications/apns"
"sync"
"sync"
@@ -42,7 +41,7 @@ import (
@@ -42,7 +41,7 @@ import (
const notificationsTag = "notificationData"
const notificationsTag = "notificationData"
// Function type definitions for the main operations (poll and notify)
// Function type definitions for the main operations (poll and notify)
type NotifyFunc func(int64, *bytes.Buffer, *apns.ApnsComm, *firebase.FirebaseComm, *storage.Storage) error
type NotifyFunc func(int64, []*pb.NotificationData, *apns.ApnsComm, *firebase.FirebaseComm, *storage.Storage) error
// Params struct holds info passed in for configuration
// Params struct holds info passed in for configuration
type Params struct {
type Params struct {
@@ -185,7 +184,7 @@ func NewImplementation(instance *Impl) *notificationBot.Implementation {
@@ -185,7 +184,7 @@ func NewImplementation(instance *Impl) *notificationBot.Implementation {
// NotifyUser accepts a UID and service key file path.
// NotifyUser accepts a UID and service key file path.
// It handles the logic involved in retrieving a user's token and sending the notification
// It handles the logic involved in retrieving a user's token and sending the notification
func notifyUser(ephID int64, data *bytes.Buffer, apnsClient *apns.ApnsComm, fc *firebase.FirebaseComm, db *storage.Storage) error {
func notifyUser(ephID int64, data []*pb.NotificationData, apnsClient *apns.ApnsComm, fc *firebase.FirebaseComm, db *storage.Storage) error {
elist, err := db.GetEphemeral(ephID)
elist, err := db.GetEphemeral(ephID)
if err != nil {
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -201,7 +200,11 @@ func notifyUser(ephID int64, data *bytes.Buffer, apnsClient *apns.ApnsComm, fc *
@@ -201,7 +200,11 @@ func notifyUser(ephID int64, data *bytes.Buffer, apnsClient *apns.ApnsComm, fc *
return errors.WithMessagef(err, "Failed to lookup user with tRSA hash %+v", e.TransmissionRSAHash)
return errors.WithMessagef(err, "Failed to lookup user with tRSA hash %+v", e.TransmissionRSAHash)
}
}
notificationsCSV := string(data.Bytes())
notifs, rest := pb.BuildNotificationCSV(data, 4096-len([]byte(notificationsTag)))
 
for _, nd := range rest {
 
db.GetNotificationBuffer().Add(nd)
 
}
 
notificationsCSV := string(notifs)
isAPNS := !strings.Contains(u.Token, ":")
isAPNS := !strings.Contains(u.Token, ":")
// mutableContent := 1
// mutableContent := 1
@@ -398,12 +401,12 @@ func (nb *Impl) Sender(sendFreq int) {
@@ -398,12 +401,12 @@ func (nb *Impl) Sender(sendFreq int) {
select {
select {
case <-sendTicker.C:
case <-sendTicker.C:
notifBuf := nb.Storage.GetNotificationBuffer()
notifBuf := nb.Storage.GetNotificationBuffer()
notifMap := notifBuf.Swap(uint(nb.maxNotifications), 4096)
notifMap := notifBuf.Swap(uint(nb.maxNotifications))
for ephID := range notifMap {
for ephID := range notifMap {
localEphID := ephID
localEphID := ephID
notifList := notifMap[localEphID]
notifList := notifMap[localEphID]
go func() {
go func() {
err := nb.notifyFunc(localEphID, notifList.Csv, nb.apnsClient, nb.fcm, nb.Storage)
err := nb.notifyFunc(localEphID, notifList, nb.apnsClient, nb.fcm, nb.Storage)
if err != nil {
if err != nil {
jww.ERROR.Printf("Failed to notify %d: %+v", localEphID, err)
jww.ERROR.Printf("Failed to notify %d: %+v", localEphID, err)
}
}
Loading