diff --git a/pkg/internal/grpc/notifier.go b/pkg/internal/grpc/notifier.go index d13daf9..e155e23 100644 --- a/pkg/internal/grpc/notifier.go +++ b/pkg/internal/grpc/notifier.go @@ -116,6 +116,7 @@ func (v *Server) NotifyAllUser(_ context.Context, in *proto.NotifyRequest) (*pro Picture: in.Picture, IsRealtime: in.GetIsRealtime(), IsForcePush: in.GetIsForcePush(), + Account: user, AccountID: user.ID, } diff --git a/pkg/internal/services/notifications.go b/pkg/internal/services/notifications.go index 158d5dc..670a127 100644 --- a/pkg/internal/services/notifications.go +++ b/pkg/internal/services/notifications.go @@ -67,6 +67,26 @@ func NewNotification(notification models.Notification) error { } func NewNotificationBatch(notifications []models.Notification) error { + if len(notifications) == 0 { + return nil + } + + notifiable := CheckNotificationNotifiableBatch(lo.Map(notifications, func(item models.Notification, index int) models.Account { + return item.Account + }), notifications[0].Topic) + accountIdx := lo.Map( + lo.Filter(notifications, func(item models.Notification, index int) bool { + return notifiable[index] + }), + func(item models.Notification, index int) uint { + return item.AccountID + }, + ) + + if len(accountIdx) == 0 { + return nil + } + if err := database.C.CreateInBatches(notifications, 1000).Error; err != nil { return err } diff --git a/pkg/internal/services/preferences.go b/pkg/internal/services/preferences.go index cfb84c5..0b56505 100644 --- a/pkg/internal/services/preferences.go +++ b/pkg/internal/services/preferences.go @@ -47,10 +47,8 @@ func CheckNotificationNotifiable(account models.Account, topic string) bool { return false } if val, ok := notification.Config[topic]; ok { - if status, ok := val.(bool); !ok || status { - return true - } else if !status { - return false + if status, ok := val.(bool); ok { + return status } } return true @@ -67,11 +65,8 @@ func CheckNotificationNotifiableBatch(accounts []models.Account, topic string) [ var notifiable []bool for _, notification := range notifications { if val, ok := notification.Config[topic]; ok { - if status, ok := val.(bool); !ok || status { - notifiable = append(notifiable, true) - continue - } else if !status { - notifiable = append(notifiable, false) + if status, ok := val.(bool); ok { + notifiable = append(notifiable, status) continue } }