Commit 6e5af38a authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Correct notification identifier handling for persistent notifications sent to all users.

parent d07bcee4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Improve JS runtime authoritative match filtered broadcasts to large sets of users.
- Correctly align optional parameters in JS runtime bindings.
- Fix JS registered match handlers not being available within the InitModule function.
- Correct notification identifier handling for persistent notifications sent to all users.

## [3.11.0] - 2022-03-21
### Added
+26 −10
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ func NotificationSend(ctx context.Context, logger *zap.Logger, db *sql.DB, messa
}

func NotificationSendAll(ctx context.Context, logger *zap.Logger, db *sql.DB, tracker Tracker, messageRouter MessageRouter, notification *api.Notification) error {
	// Non-persistent notifications don't need to work through all database users, just use currently connected notification streams.
	if !notification.Persistent {
		env := &rtapi.Envelope{
			Message: &rtapi.Envelope_Notifications{
				Notifications: &rtapi.Notifications{
@@ -93,8 +95,6 @@ func NotificationSendAll(ctx context.Context, logger *zap.Logger, db *sql.DB, tr
			},
		}

	// Non-persistent notifications don't need to work through all database users, just use currently connected notification streams.
	if !notification.Persistent {
		notificationStreamMode := StreamModeNotifications
		streams := tracker.CountByStreamModeFilter(map[uint8]*uint8{StreamModeNotifications: &notificationStreamMode})
		for streamPtr, count := range streams {
@@ -144,7 +144,15 @@ func NotificationSendAll(ctx context.Context, logger *zap.Logger, db *sql.DB, tr
					notificationLogger.Error("Failed to parse scanned user id data to send notification", zap.String("id", userIDStr), zap.Error(err))
					return
				}
				sends[userID] = []*api.Notification{notification}
				sends[userID] = []*api.Notification{{
					Id:         uuid.Must(uuid.NewV4()).String(),
					Subject:    notification.Subject,
					Content:    notification.Content,
					Code:       notification.Code,
					SenderId:   notification.SenderId,
					CreateTime: notification.CreateTime,
					Persistent: notification.Persistent,
				}}
			}
			_ = rows.Close()

@@ -159,7 +167,15 @@ func NotificationSendAll(ctx context.Context, logger *zap.Logger, db *sql.DB, tr
			}

			// Deliver live notifications to connected users.
			for userID, _ := range sends {
			for userID, notifications := range sends {
				env := &rtapi.Envelope{
					Message: &rtapi.Envelope_Notifications{
						Notifications: &rtapi.Notifications{
							Notifications: []*api.Notification{notifications[0]},
						},
					},
				}

				messageRouter.SendToStream(logger, PresenceStream{Mode: StreamModeNotifications, Subject: userID}, env, true)
			}