Documentation ¶
Index ¶
- type Manager
- func (m *Manager) ClearPersistedNotification(key PersistencyKey)
- func (m *Manager) ClearPersistedNotificationsSentByApplication(applicationID string)
- func (m *Manager) ClearPersistedNotificationsWithKeyPrefix(prefix string)
- func (m *Manager) CountRecipients() int
- func (m *Manager) MarkAsRead(persistencyKey PersistencyKey, user auth.User)
- func (m *Manager) Notify(notification Notification) func()
- func (m *Manager) SubscribeToEventsForUser(user auth.User, callback func(NotificationEvent)) func()
- type Notification
- func MakeNotification(recipient Recipient, data proto.IsNotification_NotificationData) Notification
- func MakeNotificationWithSenderApplication(senderApplicationID string, recipient Recipient, ...) Notification
- func MakePersistentNotification(persistencyKey PersistencyKey, recipient Recipient, expiration time.Time, ...) Notification
- func MakePersistentNotificationWithSenderApplication(senderApplicationID string, persistencyKey PersistencyKey, recipient Recipient, ...) Notification
- type NotificationEvent
- type PersistencyKey
- type Recipient
- type RecipientID
- type UserRecipient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager takes care of notification dispatch and clearing
func NewManager ¶
func NewManager() *Manager
func (*Manager) ClearPersistedNotification ¶
func (m *Manager) ClearPersistedNotification(key PersistencyKey)
func (*Manager) ClearPersistedNotificationsSentByApplication ¶
func (*Manager) ClearPersistedNotificationsWithKeyPrefix ¶
func (*Manager) CountRecipients ¶
CountRecipients is exposed for testing
func (*Manager) MarkAsRead ¶
func (m *Manager) MarkAsRead(persistencyKey PersistencyKey, user auth.User)
func (*Manager) Notify ¶
func (m *Manager) Notify(notification Notification) func()
func (*Manager) SubscribeToEventsForUser ¶
func (m *Manager) SubscribeToEventsForUser(user auth.User, callback func(NotificationEvent)) func()
SubscribeToEventsForUser subscribes to notifications events (new notifications and reads) that are relevant to the specified user, returning a function that must be called to unsubscribe. The callback will be called for each event that is relevant and may be called concurrently. The callback may block without risk of losing events.
type Notification ¶
type Notification interface { SenderApplicationID() string Recipient() Recipient PersistencyKey() (PersistencyKey, bool) Expiration() time.Time SerializeDataForAPI() proto.IsNotification_NotificationData }
func MakeNotification ¶
func MakeNotification(recipient Recipient, data proto.IsNotification_NotificationData) Notification
func MakeNotificationWithSenderApplication ¶
func MakeNotificationWithSenderApplication(senderApplicationID string, recipient Recipient, data proto.IsNotification_NotificationData) Notification
func MakePersistentNotification ¶
func MakePersistentNotification(persistencyKey PersistencyKey, recipient Recipient, expiration time.Time, data proto.IsNotification_NotificationData) Notification
func MakePersistentNotificationWithSenderApplication ¶
func MakePersistentNotificationWithSenderApplication(senderApplicationID string, persistencyKey PersistencyKey, recipient Recipient, expiration time.Time, data proto.IsNotification_NotificationData) Notification
type NotificationEvent ¶
type NotificationEvent struct { IsClear bool NewNotifications []Notification ClearedKey PersistencyKey }
type PersistencyKey ¶
type PersistencyKey string
type Recipient ¶
type Recipient interface { // ID must return a value that can be used to compare recipients ID() RecipientID // ContainsUser returns true if the recipient set contains the specified user ContainsUser(user auth.User) bool // FullyContainedWithin returns true if the recipient is a subset of the specified users // The specified users are guaranteed not to be anonymous/unknown FullyContainedWithin(users map[string]struct{}) bool }
Recipient defines a set of users who should receive the notification
var RecipientEveryone Recipient = recipientEveryone{}
RecipientEveryone is used for notifications that should be sent to all users
func MakeEveryoneExceptSpecifiedRecipient ¶
MakeEveryoneExceptSpecifiedRecipient creates a notification Recipient that corresponds to all users except the specified ones Do not specify anonymous/unknown users
func MakeUsersRecipient ¶
MakeUsersRecipient creates a notification Recipient that corresponds to the specified users Do not specify anonymous/unknown users
type RecipientID ¶
type RecipientID any
RecipientID is any type that can be used to compare two recipients
type UserRecipient ¶
func MakeUserRecipient ¶
func MakeUserRecipient(user auth.User) UserRecipient
MakeUserRecipient creates a notification Recipient that corresponds to a specific user Do not specify an anonymous/unknown user