notificationmanager

package
v0.0.0-...-36085eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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 (m *Manager) ClearPersistedNotificationsSentByApplication(applicationID string)

func (*Manager) ClearPersistedNotificationsWithKeyPrefix

func (m *Manager) ClearPersistedNotificationsWithKeyPrefix(prefix string)

func (*Manager) CountRecipients

func (m *Manager) CountRecipients() int

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

func MakeEveryoneExceptSpecifiedRecipient(users []auth.User) Recipient

MakeEveryoneExceptSpecifiedRecipient creates a notification Recipient that corresponds to all users except the specified ones Do not specify anonymous/unknown users

func MakeUsersRecipient

func MakeUsersRecipient(users []auth.User) Recipient

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

type UserRecipient interface {
	Recipient
	ForUser() auth.User
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL