notifications

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertSent added in v0.18.0

func AssertSent(t *testing.T, n Notification)

AssertSent asserts a notification has been sent

func CanMarkNotificationAsRead

func CanMarkNotificationAsRead(s *xorm.Session, notification *DatabaseNotification, notifiableID int64) (can bool, err error)

CanMarkNotificationAsRead checks if a user can mark a notification as read.

func Fake added in v0.18.0

func Fake()

func GetTables

func GetTables() []interface{}

GetTables returns all structs which are also a table.

func MarkAllNotificationsAsRead added in v0.22.0

func MarkAllNotificationsAsRead(s *xorm.Session, userID int64) (err error)

func MarkNotificationAsRead

func MarkNotificationAsRead(s *xorm.Session, notification *DatabaseNotification, read bool) (err error)

MarkNotificationAsRead marks a notification as read. It should be called only after CanMarkNotificationAsRead has been called.

func Notify

func Notify(notifiable Notifiable, notification Notification) (err error)

Notify notifies a notifiable of a notification

func RenderMail

func RenderMail(m *Mail) (mailOpts *mail.Opts, err error)

RenderMail takes a precomposed mail message and renders it into a ready to send mail.Opts object

func SendMail

func SendMail(m *Mail) error

SendMail passes the notification to the mailing queue for sending

Types

type DatabaseNotification

type DatabaseNotification struct {
	// The unique, numeric id of this notification.
	ID int64 `xorm:"bigint autoincr not null unique pk" json:"id" param:"notificationid"`

	// The ID of the notifiable this notification is associated with.
	NotifiableID int64 `xorm:"bigint not null" json:"-"`
	// The actual content of the notification.
	Notification interface{} `xorm:"json not null" json:"notification"`
	// The name of the notification
	Name string `xorm:"varchar(250) index not null" json:"name"`
	// The thing the notification is about. Used to check if a notification for this thing already happened or not.
	SubjectID int64 `xorm:"bigint null" json:"-"`

	// When this notification is marked as read, this will be updated with the current timestamp.
	ReadAt time.Time `xorm:"datetime null" json:"read_at"`

	// A timestamp when this notification was created. You cannot change this value.
	Created time.Time `xorm:"created not null" json:"created"`
}

DatabaseNotification represents a notification that was saved to the database

func GetNotificationsForNameAndUser added in v0.18.0

func GetNotificationsForNameAndUser(s *xorm.Session, notifiableID int64, event string, subjectID int64) (notifications []*DatabaseNotification, err error)

func GetNotificationsForUser

func GetNotificationsForUser(s *xorm.Session, notifiableID int64, limit, start int) (notifications []*DatabaseNotification, resultCount int, total int64, err error)

GetNotificationsForUser returns all notifications for a user. It is possible to limit the amount of notifications to return with the limit and start parameters. We're not passing a user object in directly because every other package imports this one so we'd get import cycles.

func (*DatabaseNotification) TableName

func (d *DatabaseNotification) TableName() string

TableName resolves to a better table name for notifications

type Mail

type Mail struct {
	// contains filtered or unexported fields
}

Mail is a mail message

func NewMail

func NewMail() *Mail

NewMail creates a new mail object with a default greeting

func (*Mail) Action

func (m *Mail) Action(text, url string) *Mail

Action sets any action a mail might have

func (*Mail) From

func (m *Mail) From(from string) *Mail

From sets the from name and email address

func (*Mail) Greeting

func (m *Mail) Greeting(greeting string) *Mail

Greeting sets the greeting of the mail message

func (*Mail) Line

func (m *Mail) Line(line string) *Mail

Line adds a line of text to the mail

func (*Mail) Subject

func (m *Mail) Subject(subject string) *Mail

Subject sets the subject of the mail message

func (*Mail) To

func (m *Mail) To(to string) *Mail

To sets the recipient of the mail message

type Notifiable

type Notifiable interface {
	// RouteForMail should return the email address this notifiable has.
	RouteForMail() (string, error)
	// RouteForDB should return the id of the notifiable entity to save it in the database.
	RouteForDB() int64
	// ShouldNotify provides a last-minute way to cancel a notification. It will be called immediately before
	// sending a notification.
	ShouldNotify() (should bool, err error)
}

Notifiable is an entity which can be notified. Usually a user.

type Notification

type Notification interface {
	ToMail() *Mail
	ToDB() interface{}
	Name() string
}

Notification is a notification which can be sent via mail or db.

type NotificationWithSubject added in v0.18.0

type NotificationWithSubject interface {
	Notification
	SubjectID
}

type SubjectID added in v0.18.0

type SubjectID interface {
	SubjectID() int64
}

Jump to

Keyboard shortcuts

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