@@ -28,14 +28,12 @@ func (f PushNotificationHandlerFunc) HandlePushNotification(ctx context.Context,
28
28
type PushNotificationRegistry struct {
29
29
mu sync.RWMutex
30
30
handlers map [string ]PushNotificationHandler // command -> single handler
31
- global []PushNotificationHandler // global handlers for all notifications
32
31
}
33
32
34
33
// NewPushNotificationRegistry creates a new push notification registry.
35
34
func NewPushNotificationRegistry () * PushNotificationRegistry {
36
35
return & PushNotificationRegistry {
37
36
handlers : make (map [string ]PushNotificationHandler ),
38
- global : make ([]PushNotificationHandler , 0 ),
39
37
}
40
38
}
41
39
@@ -52,14 +50,6 @@ func (r *PushNotificationRegistry) RegisterHandler(command string, handler PushN
52
50
return nil
53
51
}
54
52
55
- // RegisterGlobalHandler registers a handler that will receive all push notifications.
56
- func (r * PushNotificationRegistry ) RegisterGlobalHandler (handler PushNotificationHandler ) {
57
- r .mu .Lock ()
58
- defer r .mu .Unlock ()
59
-
60
- r .global = append (r .global , handler )
61
- }
62
-
63
53
// UnregisterHandler removes the handler for a specific push notification command.
64
54
func (r * PushNotificationRegistry ) UnregisterHandler (command string ) {
65
55
r .mu .Lock ()
@@ -68,7 +58,7 @@ func (r *PushNotificationRegistry) UnregisterHandler(command string) {
68
58
delete (r .handlers , command )
69
59
}
70
60
71
- // HandleNotification processes a push notification by calling all registered handlers .
61
+ // HandleNotification processes a push notification by calling the registered handler .
72
62
func (r * PushNotificationRegistry ) HandleNotification (ctx context.Context , notification []interface {}) bool {
73
63
if len (notification ) == 0 {
74
64
return false
@@ -83,23 +73,12 @@ func (r *PushNotificationRegistry) HandleNotification(ctx context.Context, notif
83
73
r .mu .RLock ()
84
74
defer r .mu .RUnlock ()
85
75
86
- handled := false
87
-
88
- // Call global handlers first
89
- for _ , handler := range r .global {
90
- if handler .HandlePushNotification (ctx , notification ) {
91
- handled = true
92
- }
93
- }
94
-
95
76
// Call specific handler
96
77
if handler , exists := r .handlers [command ]; exists {
97
- if handler .HandlePushNotification (ctx , notification ) {
98
- handled = true
99
- }
78
+ return handler .HandlePushNotification (ctx , notification )
100
79
}
101
80
102
- return handled
81
+ return false
103
82
}
104
83
105
84
// GetRegisteredCommands returns a list of commands that have registered handlers.
@@ -114,12 +93,12 @@ func (r *PushNotificationRegistry) GetRegisteredCommands() []string {
114
93
return commands
115
94
}
116
95
117
- // HasHandlers returns true if there are any handlers registered (global or specific) .
96
+ // HasHandlers returns true if there are any handlers registered.
118
97
func (r * PushNotificationRegistry ) HasHandlers () bool {
119
98
r .mu .RLock ()
120
99
defer r .mu .RUnlock ()
121
100
122
- return len (r .global ) > 0 || len ( r . handlers ) > 0
101
+ return len (r .handlers ) > 0
123
102
}
124
103
125
104
// PushNotificationProcessor handles the processing of push notifications from Redis.
@@ -206,22 +185,12 @@ func (p *PushNotificationProcessor) RegisterHandler(command string, handler Push
206
185
return p .registry .RegisterHandler (command , handler )
207
186
}
208
187
209
- // RegisterGlobalHandler is a convenience method to register a global handler.
210
- func (p * PushNotificationProcessor ) RegisterGlobalHandler (handler PushNotificationHandler ) {
211
- p .registry .RegisterGlobalHandler (handler )
212
- }
213
-
214
188
// RegisterHandlerFunc is a convenience method to register a function as a handler.
215
189
// Returns an error if a handler is already registered for this command.
216
190
func (p * PushNotificationProcessor ) RegisterHandlerFunc (command string , handlerFunc func (ctx context.Context , notification []interface {}) bool ) error {
217
191
return p .registry .RegisterHandler (command , PushNotificationHandlerFunc (handlerFunc ))
218
192
}
219
193
220
- // RegisterGlobalHandlerFunc is a convenience method to register a function as a global handler.
221
- func (p * PushNotificationProcessor ) RegisterGlobalHandlerFunc (handlerFunc func (ctx context.Context , notification []interface {}) bool ) {
222
- p .registry .RegisterGlobalHandler (PushNotificationHandlerFunc (handlerFunc ))
223
- }
224
-
225
194
// Common push notification commands
226
195
const (
227
196
// Redis Cluster notifications
0 commit comments