-
Notifications
You must be signed in to change notification settings - Fork 12
/
notifications.go
802 lines (591 loc) · 31.7 KB
/
notifications.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
package client
import (
"fmt"
"sync"
"time"
"github.com/companyzero/bisonrelay/client/clientdb"
"github.com/companyzero/bisonrelay/client/clientintf"
"github.com/companyzero/bisonrelay/rpc"
"github.com/companyzero/bisonrelay/zkidentity"
)
// Following are the notification types. Add new types at the bottom of this
// list, then add a notifyX() to NotificationManager and initialize a new
// container in NewNotificationManager().
const onPMNtfnType = "onPM"
// OnPMNtfn is the handler for received private messages.
type OnPMNtfn func(*RemoteUser, rpc.RMPrivateMessage, time.Time)
func (_ OnPMNtfn) typ() string { return onPMNtfnType }
const onGCMNtfnType = "onGCM"
// OnGCMNtfn is the handler for received gc messages.
type OnGCMNtfn func(*RemoteUser, rpc.RMGroupMessage, time.Time)
func (_ OnGCMNtfn) typ() string { return onGCMNtfnType }
const onPostRcvdNtfnType = "onPostRcvd"
// OnPostRcvdNtfn is the handler for received posts.
type OnPostRcvdNtfn func(*RemoteUser, clientdb.PostSummary, rpc.PostMetadata)
func (_ OnPostRcvdNtfn) typ() string { return onPostRcvdNtfnType }
const onPostStatusRcvdNtfnType = "onPostStatusRcvd"
// OnPostStatusRcvdNtfn is the handler for received post status updates.
type OnPostStatusRcvdNtfn func(*RemoteUser, clientintf.PostID, UserID,
rpc.PostMetadataStatus)
func (_ OnPostStatusRcvdNtfn) typ() string { return onPostStatusRcvdNtfnType }
const onRemoteSubscriptionChangedType = "onSubChanged"
// OnRemoteSubscriptionChanged is the handler for a remote user subscription
// changed event.
type OnRemoteSubscriptionChangedNtfn func(*RemoteUser, bool)
func (_ OnRemoteSubscriptionChangedNtfn) typ() string { return onRemoteSubscriptionChangedType }
const onRemoteSubscriptionErrorNtfnType = "onSubChangedErr"
// OnRemoteSubscriptionErrorNtfn is the handler for a remote user subscription
// change attempt that errored.
type OnRemoteSubscriptionErrorNtfn func(user *RemoteUser, wasSubscribing bool, errMsg string)
func (_ OnRemoteSubscriptionErrorNtfn) typ() string { return onRemoteSubscriptionErrorNtfnType }
const onLocalClientOfflineTooLong = "onLocalClientOfflineTooLong"
// OnLocalClientOfflineTooLong is called after the local client connects to the
// server, if it determines it has been offline for too long given the server's
// message retention policy.
type OnLocalClientOfflineTooLong func(time.Time)
func (_ OnLocalClientOfflineTooLong) typ() string { return onLocalClientOfflineTooLong }
const onKXCompleted = "onKXCompleted"
// OnKXCompleted is called after KX is completed with a remote user (either a
// new user or a reset KX).
type OnKXCompleted func(*clientintf.RawRVID, *RemoteUser, bool)
func (_ OnKXCompleted) typ() string { return onKXCompleted }
const onKXSuggested = "onKXSuggested"
// OnKXSuggested is called after a remote user suggests that this user should KX
// with another remote user.
type OnKXSuggested func(*RemoteUser, zkidentity.PublicIdentity)
func (_ OnKXSuggested) typ() string { return onKXSuggested }
const onInvoiceGenFailedNtfnType = "onInvoiceGenFailed"
type OnInvoiceGenFailedNtfn func(user *RemoteUser, dcrAmount float64, err error)
func (_ OnInvoiceGenFailedNtfn) typ() string { return onInvoiceGenFailedNtfnType }
const onGCVersionWarningType = "onGCVersionWarn"
// OnGCVersionWarning is a handler for warnings about a GC that has an
// unsupported version.
type OnGCVersionWarning func(user *RemoteUser, gc rpc.RMGroupList, minVersion, maxVersion uint8)
func (_ OnGCVersionWarning) typ() string { return onGCVersionWarningType }
const onJoinedGCNtfnType = "onJoinedGC"
// OnJoinedGCNtfn is a handler for when the local client joins a GC.
type OnJoinedGCNtfn func(gc rpc.RMGroupList)
func (_ OnJoinedGCNtfn) typ() string { return onJoinedGCNtfnType }
const onAddedGCMembersNtfnType = "onAddedGCMembers"
// OnAddedGCMembersNtfn is a handler for new members added to a GC.
type OnAddedGCMembersNtfn func(gc rpc.RMGroupList, uids []clientintf.UserID)
func (_ OnAddedGCMembersNtfn) typ() string { return onAddedGCMembersNtfnType }
const onRemovedGCMembersNtfnType = "onRemovedGCMembers"
// OnRemovedGCMembersNtfn is a handler for members removed from a GC.
type OnRemovedGCMembersNtfn func(gc rpc.RMGroupList, uids []clientintf.UserID)
func (_ OnRemovedGCMembersNtfn) typ() string { return onRemovedGCMembersNtfnType }
const onGCUpgradedNtfnType = "onGCUpgraded"
// OnGCUpgradedNtfn is a handler for a GC that had its version upgraded.
type OnGCUpgradedNtfn func(gc rpc.RMGroupList, oldVersion uint8)
func (_ OnGCUpgradedNtfn) typ() string { return onGCUpgradedNtfnType }
const onInvitedToGCNtfnType = "onInvitedToGC"
// OnInvitedToGCNtfn is a handler for invites received to join GCs.
type OnInvitedToGCNtfn func(user *RemoteUser, iid uint64, invite rpc.RMGroupInvite)
func (_ OnInvitedToGCNtfn) typ() string { return onInvitedToGCNtfnType }
const onGCInviteAcceptedNtfnType = "onGCInviteAccepted"
// OnGCInviteAcceptedNtfn is a handler for invites accepted by remote users to
// join a GC we invited them to.
type OnGCInviteAcceptedNtfn func(user *RemoteUser, gc rpc.RMGroupList)
func (_ OnGCInviteAcceptedNtfn) typ() string { return onGCInviteAcceptedNtfnType }
const onGCUserPartedNtfnType = "onGCUserParted"
// OnGCUserPartedNtfn is a handler when a user parted from a GC or an admin
// kicked a user.
type OnGCUserPartedNtfn func(gcid GCID, uid UserID, reason string, kicked bool)
func (_ OnGCUserPartedNtfn) typ() string { return onGCUserPartedNtfnType }
const onGCKilledNtfnType = "onGCKilled"
// OnGCKilledNtfn is a handler for a GC dissolved by its admin.
type OnGCKilledNtfn func(gcid GCID, reason string)
func (_ OnGCKilledNtfn) typ() string { return onGCKilledNtfnType }
const onGCAdminsChangedNtfnType = "onGCAdminsChanged"
type OnGCAdminsChangedNtfn func(ru *RemoteUser, gc rpc.RMGroupList, added, removed []zkidentity.ShortID)
func (_ OnGCAdminsChangedNtfn) typ() string { return onGCAdminsChangedNtfnType }
const onKXSearchCompletedNtfnType = "kxSearchCompleted"
// OnKXSearchCompleted is a handler for completed KX search procedures.
type OnKXSearchCompleted func(user *RemoteUser)
func (_ OnKXSearchCompleted) typ() string { return onKXSearchCompletedNtfnType }
const onTipAttemptProgressNtfnType = "onTipAttemptProgress"
type OnTipAttemptProgressNtfn func(ru *RemoteUser, amtMAtoms int64, completed bool, attempt int, attemptErr error, willRetry bool)
func (_ OnTipAttemptProgressNtfn) typ() string { return onTipAttemptProgressNtfnType }
const onBlockNtfnType = "onBlock"
// OnBlockNtfn is called when we blocked the specified user due to their
// request. Note that the passed user cannot be used for messaging anymore.
type OnBlockNtfn func(user *RemoteUser)
func (_ OnBlockNtfn) typ() string { return onBlockNtfnType }
const onServerSessionChangedNtfnType = "onServerSessionChanged"
// OnServerSessionChangedNtfn is called indicating that the connection to the
// server changed to the specified state (either connected or not).
//
// The push and subscription rates are specified in milliatoms/byte.
type OnServerSessionChangedNtfn func(connected bool, policy clientintf.ServerPolicy)
func (_ OnServerSessionChangedNtfn) typ() string { return onServerSessionChangedNtfnType }
const onOnboardStateChangedNtfnType = "onOnboardStateChanged"
type OnOnboardStateChangedNtfn func(state clientintf.OnboardState, err error)
func (_ OnOnboardStateChangedNtfn) typ() string { return onOnboardStateChangedNtfnType }
const onResourceFetchedNtfnType = "onResourceFetched"
// OnResourceFetchedNtfn is called when a reply to a fetched resource is
// received.
//
// Note that the user may be nil if the resource was fetched locally, such as
// through the FetchLocalResource call.
type OnResourceFetchedNtfn func(ru *RemoteUser, fr clientdb.FetchedResource, sess clientdb.PageSessionOverview)
func (_ OnResourceFetchedNtfn) typ() string { return onResourceFetchedNtfnType }
const onTipUserInvoiceGeneratedNtfnType = "onTipUserInvoiceGenerated"
// OnTipUserInvoiceGeneratedNtfn is called when the local client generates an
// invoice to send to a remote user, for tipping purposes.
type OnTipUserInvoiceGeneratedNtfn func(ru *RemoteUser, tag uint32, invoice string)
func (_ OnTipUserInvoiceGeneratedNtfn) typ() string { return onTipUserInvoiceGeneratedNtfnType }
const onHandshakeStageNtfnType = "onHandshakeStage"
// OnHandshakeStageNtfn is called during a 3-way handshake with a remote client.
// mstype may be SYN, SYNACK or ACK. The SYNACK and ACK types allow the
// respective clients to infer that the ratchet operations are working.
type OnHandshakeStageNtfn func(ru *RemoteUser, msgtype string)
func (_ OnHandshakeStageNtfn) typ() string { return onHandshakeStageNtfnType }
const onGCWithUnkxdMemberNtfnType = "onGCWithUnkxdMember"
// OnGCWithUnkxdMemberNtfn is called when attempting to send a message to a
// GC in which there are members that the local client hasn't KX'd with.
type OnGCWithUnkxdMemberNtfn func(gc zkidentity.ShortID, uid clientintf.UserID,
hasKX, hasMI bool, miCount uint32, startedMIMediator *clientintf.UserID)
func (_ OnGCWithUnkxdMemberNtfn) typ() string { return onGCWithUnkxdMemberNtfnType }
const onTipReceivedNtfnType = "onTipReceived"
// OnTipReceivedNtfn is called when a tip is received from a remote user.
type OnTipReceivedNtfn func(ru *RemoteUser, amountMAtoms int64)
func (_ OnTipReceivedNtfn) typ() string { return onTipReceivedNtfnType }
const onMessageContentFilteredNtfType = "onMsgContentFiltered"
// MsgContentFilteredEvent is the data for a message content filter event.
type MsgContentFilteredEvent struct {
UID UserID
GC *zkidentity.ShortID
PID *clientintf.PostID
PostFrom *clientintf.UserID
IsPostComment bool
Msg string
Rule clientdb.ContentFilter
}
// OnMsgContentFilteredNtfn is called when a message was filtered due to its
// contents.
type OnMsgContentFilteredNtfn func(MsgContentFilteredEvent)
func (_ OnMsgContentFilteredNtfn) typ() string { return onMessageContentFilteredNtfType }
const onPostSubscriberUpdated = "onPostSubscriberUpdated"
// OnPostSubscriberUpdated is called when a remote user changes its subscription
// status to the local client's posts (i.e. the remote user subscribed or
// unsubscribed to the local client's posts).
type OnPostSubscriberUpdated func(user *RemoteUser, subscribed bool)
func (_ OnPostSubscriberUpdated) typ() string { return onPostSubscriberUpdated }
const onPostsListReceived = "onPostsListReceived"
// PostsListReceived is called when the local client receives the list of posts
// from a remote user.
type OnPostsListReceived func(user *RemoteUser, postList rpc.RMListPostsReply)
func (_ OnPostsListReceived) typ() string { return onPostsListReceived }
const onUnsubscribingIdleRemoteClient = "onUnsubscribingIdleRemoteClient"
// OnUnsubscribingIdleRemoteClient is a notification sent when a remote client
// is detected as idle and being unsubscribed from GCs and posts.
type OnUnsubscribingIdleRemoteClient func(user *RemoteUser, lastDecTime time.Time)
func (_ OnUnsubscribingIdleRemoteClient) typ() string { return onUnsubscribingIdleRemoteClient }
const onReceiveReceipt = "onReceiveReceipt"
// OnReceiveReceipt is a notification sent when a remote client sends a
// receive receipt.
type OnReceiveReceipt func(user *RemoteUser, rr rpc.RMReceiveReceipt, serverTime time.Time)
func (_ OnReceiveReceipt) typ() string { return onReceiveReceipt }
const onContentListReceived = "onContentListReceived"
// ContentListReceived is called when the list of content of the user is
// received.
type OnContentListReceived func(user *RemoteUser, files []clientdb.RemoteFile, listErr error)
func (_ OnContentListReceived) typ() string { return onContentListReceived }
const onFileDownloadCompleted = "onFileDownloadCompleted"
// FileDownloadCompleted is called whenever a download of a file has
// completed.
type OnFileDownloadCompleted func(user *RemoteUser, fm rpc.FileMetadata, diskPath string)
func (_ OnFileDownloadCompleted) typ() string { return onFileDownloadCompleted }
const onFileDownloadProgress = "onFileDownloadProgress"
// FileDownloadProgress is called reporting the progress of a file
// download process.
type OnFileDownloadProgress func(user *RemoteUser, fm rpc.FileMetadata, nbMissingChunks int)
func (_ OnFileDownloadProgress) typ() string { return onFileDownloadProgress }
const onRMReceived = "onRMReceived"
// OnRMReceived is a notification sent whenever a remote user receives an RM.
// Note: this is called _before_ the RM has been processed, therefore care must
// be taken when hooking and handling this notification.
type OnRMReceived func(ru *RemoteUser, h *rpc.RMHeader, p interface{}, ts time.Time)
func (_ OnRMReceived) typ() string { return onRMReceived }
const onRMSent = "onRMSent"
// OnRMSent is a notification sent whenever a message has been delivered to
// the server directed to a remote user. Note: this is called _after_ the RM
// has been acknowledged by the server.
type OnRMSent func(ru *RemoteUser, p interface{})
func (_ OnRMSent) typ() string { return onRMSent }
const onServerUnwelcomeError = "onServerUnwelcomeError"
// OnServerUnwelcomeError is a notification sent, when attempting to connect
// to a server, the client receives an error that hints that it should
// upgrade.
type OnServerUnwelcomeError func(err error)
func (_ OnServerUnwelcomeError) typ() string { return onServerUnwelcomeError }
// ProfileUpdateField tracks profile fields which may be updated.
type ProfileUpdateField string
const (
// ProfileUpdateAvatar is the profile field that corresponds to the
// user's avatar.
ProfileUpdateAvatar ProfileUpdateField = "avatar"
)
const onProfileUpdatedType = "onProfileChanged"
// OnProfileChanged is a notification sent whenever a remote client has updated
// its profile.
type OnProfileUpdated func(ru *RemoteUser, ab *clientdb.AddressBookEntry, fields []ProfileUpdateField)
func (_ OnProfileUpdated) typ() string { return onProfileUpdatedType }
const onTransitiveEventType = "onTransitiveEvent"
// OnTransitiveEvent is called whenever a request is made by source for the
// local client to forward a message to dst.
type OnTransitiveEvent func(src, dst UserID, event TransitiveEvent)
func (_ OnTransitiveEvent) typ() string { return onTransitiveEventType }
const onRequestingMediateIDType = "onReqMediateID"
// OnRequestingMediateID is called whenever an autokx attempt is requesting a
// mediator to mediate id between the local client and a target.
type OnRequestingMediateID func(mediator, target UserID)
func (_ OnRequestingMediateID) typ() string { return onRequestingMediateIDType }
// The following is used only in tests.
const onTestNtfnType = "testNtfnType"
type onTestNtfn func()
func (_ onTestNtfn) typ() string { return onTestNtfnType }
// Following is the generic notification code.
type NotificationRegistration struct {
unreg func() bool
}
func (reg NotificationRegistration) Unregister() bool {
return reg.unreg()
}
type NotificationHandler interface {
typ() string
}
type handler[T any] struct {
handler T
async bool
}
type handlersFor[T any] struct {
mtx sync.Mutex
next uint
handlers map[uint]handler[T]
}
func (hn *handlersFor[T]) register(h T, async bool) NotificationRegistration {
var id uint
hn.mtx.Lock()
id, hn.next = hn.next, hn.next+1
if hn.handlers == nil {
hn.handlers = make(map[uint]handler[T])
}
hn.handlers[id] = handler[T]{handler: h, async: async}
registered := true
hn.mtx.Unlock()
return NotificationRegistration{
unreg: func() bool {
hn.mtx.Lock()
res := registered
if registered {
delete(hn.handlers, id)
registered = false
}
hn.mtx.Unlock()
return res
},
}
}
func (hn *handlersFor[T]) visit(f func(T)) {
hn.mtx.Lock()
for _, h := range hn.handlers {
if h.async {
go f(h.handler)
} else {
f(h.handler)
}
}
hn.mtx.Unlock()
}
func (hn *handlersFor[T]) Register(v interface{}, async bool) NotificationRegistration {
if h, ok := v.(T); !ok {
panic("wrong type")
} else {
return hn.register(h, async)
}
}
func (hn *handlersFor[T]) AnyRegistered() bool {
hn.mtx.Lock()
res := len(hn.handlers) > 0
hn.mtx.Unlock()
return res
}
type handlersRegistry interface {
Register(v interface{}, async bool) NotificationRegistration
AnyRegistered() bool
}
type NotificationManager struct {
handlers map[string]handlersRegistry
}
func (nmgr *NotificationManager) register(handler NotificationHandler, async bool) NotificationRegistration {
handlers := nmgr.handlers[handler.typ()]
if handlers == nil {
panic(fmt.Sprintf("forgot to init the handler type %T "+
"in NewNotificationManager", handler))
}
return handlers.Register(handler, async)
}
// Register registers a callback notification function that is called
// asynchronously to the event (i.e. in a separate goroutine).
func (nmgr *NotificationManager) Register(handler NotificationHandler) NotificationRegistration {
return nmgr.register(handler, true)
}
// RegisterSync registers a callback notification function that is called
// synchronously to the event. This callback SHOULD return as soon as possible,
// otherwise the client might hang.
//
// Synchronous callbacks are mostly intended for tests and when external
// callers need to ensure proper order of multiple sequential events. In
// general it is preferable to use callbacks registered with the Register call,
// to ensure the client will not deadlock or hang.
func (nmgr *NotificationManager) RegisterSync(handler NotificationHandler) NotificationRegistration {
return nmgr.register(handler, false)
}
// AnyRegistered returns true if there are any handlers registered for the given
// handler type.
func (ngmr *NotificationManager) AnyRegistered(handler NotificationHandler) bool {
return ngmr.handlers[handler.typ()].AnyRegistered()
}
// Following are the notifyX() calls (one for each type of notification).
func (nmgr *NotificationManager) notifyTest() {
nmgr.handlers[onTestNtfnType].(*handlersFor[onTestNtfn]).
visit(func(h onTestNtfn) { h() })
}
func (nmgr *NotificationManager) notifyOnPM(user *RemoteUser, pm rpc.RMPrivateMessage, ts time.Time) {
nmgr.handlers[onPMNtfnType].(*handlersFor[OnPMNtfn]).
visit(func(h OnPMNtfn) { h(user, pm, ts) })
}
func (nmgr *NotificationManager) notifyOnGCM(user *RemoteUser, gcm rpc.RMGroupMessage, ts time.Time) {
nmgr.handlers[onGCMNtfnType].(*handlersFor[OnGCMNtfn]).
visit(func(h OnGCMNtfn) { h(user, gcm, ts) })
}
func (nmgr *NotificationManager) notifyOnPostRcvd(user *RemoteUser, summary clientdb.PostSummary, post rpc.PostMetadata) {
nmgr.handlers[onPostRcvdNtfnType].(*handlersFor[OnPostRcvdNtfn]).
visit(func(h OnPostRcvdNtfn) { h(user, summary, post) })
}
func (nmgr *NotificationManager) notifyOnPostStatusRcvd(user *RemoteUser, pid clientintf.PostID,
statusFrom UserID, status rpc.PostMetadataStatus) {
nmgr.handlers[onPostStatusRcvdNtfnType].(*handlersFor[OnPostStatusRcvdNtfn]).
visit(func(h OnPostStatusRcvdNtfn) { h(user, pid, statusFrom, status) })
}
func (nmgr *NotificationManager) notifyOnRemoteSubChanged(user *RemoteUser, subscribed bool) {
nmgr.handlers[onRemoteSubscriptionChangedType].(*handlersFor[OnRemoteSubscriptionChangedNtfn]).
visit(func(h OnRemoteSubscriptionChangedNtfn) { h(user, subscribed) })
}
func (nmgr *NotificationManager) notifyOnRemoteSubErrored(user *RemoteUser, wasSubscribing bool, errMsg string) {
nmgr.handlers[onRemoteSubscriptionErrorNtfnType].(*handlersFor[OnRemoteSubscriptionErrorNtfn]).
visit(func(h OnRemoteSubscriptionErrorNtfn) { h(user, wasSubscribing, errMsg) })
}
func (nmgr *NotificationManager) notifyOnLocalClientOfflineTooLong(date time.Time) {
nmgr.handlers[onLocalClientOfflineTooLong].(*handlersFor[OnLocalClientOfflineTooLong]).
visit(func(h OnLocalClientOfflineTooLong) { h(date) })
}
func (nmgr *NotificationManager) notifyOnGCVersionWarning(user *RemoteUser, gc rpc.RMGroupList, minVersion, maxVersion uint8) {
nmgr.handlers[onGCVersionWarningType].(*handlersFor[OnGCVersionWarning]).
visit(func(h OnGCVersionWarning) { h(user, gc, minVersion, maxVersion) })
}
func (nmgr *NotificationManager) notifyOnKXCompleted(ir *clientintf.RawRVID, user *RemoteUser, isNew bool) {
nmgr.handlers[onKXCompleted].(*handlersFor[OnKXCompleted]).
visit(func(h OnKXCompleted) { h(ir, user, isNew) })
}
func (nmgr *NotificationManager) notifyOnKXSearchCompleted(user *RemoteUser) {
nmgr.handlers[onKXSearchCompletedNtfnType].(*handlersFor[OnKXSearchCompleted]).
visit(func(h OnKXSearchCompleted) { h(user) })
}
func (nmgr *NotificationManager) notifyOnKXSuggested(invitee *RemoteUser, target zkidentity.PublicIdentity) {
nmgr.handlers[onKXSuggested].(*handlersFor[OnKXSuggested]).
visit(func(h OnKXSuggested) { h(invitee, target) })
}
func (nmgr *NotificationManager) notifyInvoiceGenFailed(user *RemoteUser, dcrAmount float64, err error) {
nmgr.handlers[onInvoiceGenFailedNtfnType].(*handlersFor[OnInvoiceGenFailedNtfn]).
visit(func(h OnInvoiceGenFailedNtfn) { h(user, dcrAmount, err) })
}
func (nmgr *NotificationManager) notifyOnJoinedGC(gc rpc.RMGroupList) {
nmgr.handlers[onJoinedGCNtfnType].(*handlersFor[OnJoinedGCNtfn]).
visit(func(h OnJoinedGCNtfn) { h(gc) })
}
func (nmgr *NotificationManager) notifyOnAddedGCMembers(gc rpc.RMGroupList, uids []clientintf.UserID) {
nmgr.handlers[onAddedGCMembersNtfnType].(*handlersFor[OnAddedGCMembersNtfn]).
visit(func(h OnAddedGCMembersNtfn) { h(gc, uids) })
}
func (nmgr *NotificationManager) notifyOnRemovedGCMembers(gc rpc.RMGroupList, uids []clientintf.UserID) {
nmgr.handlers[onRemovedGCMembersNtfnType].(*handlersFor[OnRemovedGCMembersNtfn]).
visit(func(h OnRemovedGCMembersNtfn) { h(gc, uids) })
}
func (nmgr *NotificationManager) notifyOnGCUpgraded(gc rpc.RMGroupList, oldVersion uint8) {
nmgr.handlers[onGCUpgradedNtfnType].(*handlersFor[OnGCUpgradedNtfn]).
visit(func(h OnGCUpgradedNtfn) { h(gc, oldVersion) })
}
func (nmgr *NotificationManager) notifyInvitedToGC(user *RemoteUser, iid uint64, invite rpc.RMGroupInvite) {
nmgr.handlers[onInvitedToGCNtfnType].(*handlersFor[OnInvitedToGCNtfn]).
visit(func(h OnInvitedToGCNtfn) { h(user, iid, invite) })
}
func (nmgr *NotificationManager) notifyGCInviteAccepted(user *RemoteUser, gc rpc.RMGroupList) {
nmgr.handlers[onGCInviteAcceptedNtfnType].(*handlersFor[OnGCInviteAcceptedNtfn]).
visit(func(h OnGCInviteAcceptedNtfn) { h(user, gc) })
}
func (nmgr *NotificationManager) notifyGCUserParted(gcid GCID, uid UserID, reason string, kicked bool) {
nmgr.handlers[onGCUserPartedNtfnType].(*handlersFor[OnGCUserPartedNtfn]).
visit(func(h OnGCUserPartedNtfn) { h(gcid, uid, reason, kicked) })
}
func (nmgr *NotificationManager) notifyOnGCKilled(gcid GCID, reason string) {
nmgr.handlers[onGCKilledNtfnType].(*handlersFor[OnGCKilledNtfn]).
visit(func(h OnGCKilledNtfn) { h(gcid, reason) })
}
func (nmgr *NotificationManager) notifyGCAdminsChanged(ru *RemoteUser, gc rpc.RMGroupList,
added, removed []zkidentity.ShortID) {
nmgr.handlers[onGCAdminsChangedNtfnType].(*handlersFor[OnGCAdminsChangedNtfn]).
visit(func(h OnGCAdminsChangedNtfn) { h(ru, gc, added, removed) })
}
func (nmgr *NotificationManager) notifyTipAttemptProgress(ru *RemoteUser, amtMAtoms int64, completed bool, attempt int, attemptErr error, willRetry bool) {
nmgr.handlers[onTipAttemptProgressNtfnType].(*handlersFor[OnTipAttemptProgressNtfn]).
visit(func(h OnTipAttemptProgressNtfn) { h(ru, amtMAtoms, completed, attempt, attemptErr, willRetry) })
}
func (nmgr *NotificationManager) notifyTipUserInvoiceGenerated(ru *RemoteUser, tag uint32, invoice string) {
nmgr.handlers[onTipUserInvoiceGeneratedNtfnType].(*handlersFor[OnTipUserInvoiceGeneratedNtfn]).
visit(func(h OnTipUserInvoiceGeneratedNtfn) { h(ru, tag, invoice) })
}
func (nmgr *NotificationManager) notifyOnBlock(ru *RemoteUser) {
nmgr.handlers[onBlockNtfnType].(*handlersFor[OnBlockNtfn]).
visit(func(h OnBlockNtfn) { h(ru) })
}
func (nmgr *NotificationManager) notifyServerSessionChanged(connected bool, policy clientintf.ServerPolicy) {
nmgr.handlers[onServerSessionChangedNtfnType].(*handlersFor[OnServerSessionChangedNtfn]).
visit(func(h OnServerSessionChangedNtfn) { h(connected, policy) })
}
func (nmgr *NotificationManager) notifyOnOnboardStateChanged(state clientintf.OnboardState, err error) {
nmgr.handlers[onOnboardStateChangedNtfnType].(*handlersFor[OnOnboardStateChangedNtfn]).
visit(func(h OnOnboardStateChangedNtfn) { h(state, err) })
}
func (nmgr *NotificationManager) notifyResourceFetched(ru *RemoteUser,
fr clientdb.FetchedResource, sess clientdb.PageSessionOverview) {
nmgr.handlers[onResourceFetchedNtfnType].(*handlersFor[OnResourceFetchedNtfn]).
visit(func(h OnResourceFetchedNtfn) { h(ru, fr, sess) })
}
func (nmgr *NotificationManager) notifyHandshakeStage(ru *RemoteUser, msgtype string) {
nmgr.handlers[onHandshakeStageNtfnType].(*handlersFor[OnHandshakeStageNtfn]).
visit(func(h OnHandshakeStageNtfn) { h(ru, msgtype) })
}
func (nmgr *NotificationManager) notifyGCWithUnxkdMember(gc zkidentity.ShortID, uid clientintf.UserID,
hasKX, hasMI bool, miCount uint32, startedMIMediator *clientintf.UserID) {
nmgr.handlers[onGCWithUnkxdMemberNtfnType].(*handlersFor[OnGCWithUnkxdMemberNtfn]).
visit(func(h OnGCWithUnkxdMemberNtfn) {
h(gc, uid, hasKX, hasMI, miCount, startedMIMediator)
})
}
func (nmgr *NotificationManager) notifyTipReceived(ru *RemoteUser, amountMAtoms int64) {
nmgr.handlers[onTipReceivedNtfnType].(*handlersFor[OnTipReceivedNtfn]).
visit(func(h OnTipReceivedNtfn) { h(ru, amountMAtoms) })
}
func (nmgr *NotificationManager) notifyMsgContentFiltered(e MsgContentFilteredEvent) {
nmgr.handlers[onMessageContentFilteredNtfType].(*handlersFor[OnMsgContentFilteredNtfn]).
visit(func(h OnMsgContentFilteredNtfn) {
h(e)
})
}
func (nmgr *NotificationManager) notifyPostsSubscriberUpdated(ru *RemoteUser, subscribed bool) {
nmgr.handlers[onPostSubscriberUpdated].(*handlersFor[OnPostSubscriberUpdated]).
visit(func(h OnPostSubscriberUpdated) { h(ru, subscribed) })
}
func (nmgr *NotificationManager) notifyPostsListReceived(ru *RemoteUser, postList rpc.RMListPostsReply) {
nmgr.handlers[onPostsListReceived].(*handlersFor[OnPostsListReceived]).
visit(func(h OnPostsListReceived) { h(ru, postList) })
}
func (nmgr *NotificationManager) notifyUnsubscribingIdleRemote(ru *RemoteUser, lastDecTime time.Time) {
nmgr.handlers[onUnsubscribingIdleRemoteClient].(*handlersFor[OnUnsubscribingIdleRemoteClient]).
visit(func(h OnUnsubscribingIdleRemoteClient) { h(ru, lastDecTime) })
}
func (nmgr *NotificationManager) notifyReceiveReceipt(ru *RemoteUser, rr rpc.RMReceiveReceipt, serverTime time.Time) {
nmgr.handlers[onReceiveReceipt].(*handlersFor[OnReceiveReceipt]).
visit(func(h OnReceiveReceipt) { h(ru, rr, serverTime) })
}
func (nmgr *NotificationManager) notifyContentListReceived(user *RemoteUser, files []clientdb.RemoteFile, listErr error) {
nmgr.handlers[onContentListReceived].(*handlersFor[OnContentListReceived]).
visit(func(h OnContentListReceived) { h(user, files, listErr) })
}
func (nmgr *NotificationManager) notifyFileDownloadCompleted(user *RemoteUser, fm rpc.FileMetadata, diskPath string) {
nmgr.handlers[onFileDownloadCompleted].(*handlersFor[OnFileDownloadCompleted]).
visit(func(h OnFileDownloadCompleted) { h(user, fm, diskPath) })
}
func (nmgr *NotificationManager) notifyFileDownloadProgress(user *RemoteUser, fm rpc.FileMetadata, nbMissingChunks int) {
nmgr.handlers[onFileDownloadProgress].(*handlersFor[OnFileDownloadProgress]).
visit(func(h OnFileDownloadProgress) { h(user, fm, nbMissingChunks) })
}
func (nmgr *NotificationManager) notifyRMReceived(ru *RemoteUser, rmh *rpc.RMHeader, p interface{}, ts time.Time) {
nmgr.handlers[onRMReceived].(*handlersFor[OnRMReceived]).
visit(func(h OnRMReceived) { h(ru, rmh, p, ts) })
}
func (nmgr *NotificationManager) notifyRMSent(ru *RemoteUser, p interface{}) {
nmgr.handlers[onRMSent].(*handlersFor[OnRMSent]).
visit(func(h OnRMSent) { h(ru, p) })
}
func (nmgr *NotificationManager) notifyServerUnwelcomeError(err error) {
nmgr.handlers[onServerUnwelcomeError].(*handlersFor[OnServerUnwelcomeError]).
visit(func(h OnServerUnwelcomeError) { h(err) })
}
func (nmgr *NotificationManager) notifyProfileUpdated(ru *RemoteUser, ab *clientdb.AddressBookEntry,
fields []ProfileUpdateField) {
nmgr.handlers[onProfileUpdatedType].(*handlersFor[OnProfileUpdated]).
visit(func(h OnProfileUpdated) { h(ru, ab, fields) })
}
func (nmgr *NotificationManager) notifyTransitiveEvent(src, tgt clientintf.UserID,
event TransitiveEvent) {
nmgr.handlers[onTransitiveEventType].(*handlersFor[OnTransitiveEvent]).
visit(func(h OnTransitiveEvent) { h(src, tgt, event) })
}
func (nmgr *NotificationManager) notifyRequestingMediateID(mediator, target clientintf.UserID) {
nmgr.handlers[onRequestingMediateIDType].(*handlersFor[OnRequestingMediateID]).
visit(func(h OnRequestingMediateID) { h(mediator, target) })
}
func NewNotificationManager() *NotificationManager {
return &NotificationManager{
handlers: map[string]handlersRegistry{
onTestNtfnType: &handlersFor[onTestNtfn]{},
onPMNtfnType: &handlersFor[OnPMNtfn]{},
onGCMNtfnType: &handlersFor[OnGCMNtfn]{},
onKXCompleted: &handlersFor[OnKXCompleted]{},
onKXSuggested: &handlersFor[OnKXSuggested]{},
onBlockNtfnType: &handlersFor[OnBlockNtfn]{},
onPostRcvdNtfnType: &handlersFor[OnPostRcvdNtfn]{},
onPostStatusRcvdNtfnType: &handlersFor[OnPostStatusRcvdNtfn]{},
onHandshakeStageNtfnType: &handlersFor[OnHandshakeStageNtfn]{},
onTipReceivedNtfnType: &handlersFor[OnTipReceivedNtfn]{},
onReceiveReceipt: &handlersFor[OnReceiveReceipt]{},
onRMReceived: &handlersFor[OnRMReceived]{},
onRMSent: &handlersFor[OnRMSent]{},
onProfileUpdatedType: &handlersFor[OnProfileUpdated]{},
onTransitiveEventType: &handlersFor[OnTransitiveEvent]{},
onPostSubscriberUpdated: &handlersFor[OnPostSubscriberUpdated]{},
onPostsListReceived: &handlersFor[OnPostsListReceived]{},
onGCVersionWarningType: &handlersFor[OnGCVersionWarning]{},
onJoinedGCNtfnType: &handlersFor[OnJoinedGCNtfn]{},
onAddedGCMembersNtfnType: &handlersFor[OnAddedGCMembersNtfn]{},
onRemovedGCMembersNtfnType: &handlersFor[OnRemovedGCMembersNtfn]{},
onGCUpgradedNtfnType: &handlersFor[OnGCUpgradedNtfn]{},
onInvitedToGCNtfnType: &handlersFor[OnInvitedToGCNtfn]{},
onGCInviteAcceptedNtfnType: &handlersFor[OnGCInviteAcceptedNtfn]{},
onGCUserPartedNtfnType: &handlersFor[OnGCUserPartedNtfn]{},
onGCKilledNtfnType: &handlersFor[OnGCKilledNtfn]{},
onGCAdminsChangedNtfnType: &handlersFor[OnGCAdminsChangedNtfn]{},
onContentListReceived: &handlersFor[OnContentListReceived]{},
onFileDownloadCompleted: &handlersFor[OnFileDownloadCompleted]{},
onFileDownloadProgress: &handlersFor[OnFileDownloadProgress]{},
onServerUnwelcomeError: &handlersFor[OnServerUnwelcomeError]{},
onRequestingMediateIDType: &handlersFor[OnRequestingMediateID]{},
onKXSearchCompletedNtfnType: &handlersFor[OnKXSearchCompleted]{},
onInvoiceGenFailedNtfnType: &handlersFor[OnInvoiceGenFailedNtfn]{},
onRemoteSubscriptionChangedType: &handlersFor[OnRemoteSubscriptionChangedNtfn]{},
onRemoteSubscriptionErrorNtfnType: &handlersFor[OnRemoteSubscriptionErrorNtfn]{},
onLocalClientOfflineTooLong: &handlersFor[OnLocalClientOfflineTooLong]{},
onTipAttemptProgressNtfnType: &handlersFor[OnTipAttemptProgressNtfn]{},
onTipUserInvoiceGeneratedNtfnType: &handlersFor[OnTipUserInvoiceGeneratedNtfn]{},
onServerSessionChangedNtfnType: &handlersFor[OnServerSessionChangedNtfn]{},
onOnboardStateChangedNtfnType: &handlersFor[OnOnboardStateChangedNtfn]{},
onResourceFetchedNtfnType: &handlersFor[OnResourceFetchedNtfn]{},
onGCWithUnkxdMemberNtfnType: &handlersFor[OnGCWithUnkxdMemberNtfn]{},
onMessageContentFilteredNtfType: &handlersFor[OnMsgContentFilteredNtfn]{},
onUnsubscribingIdleRemoteClient: &handlersFor[OnUnsubscribingIdleRemoteClient]{},
},
}
}