Documentation
¶
Overview ¶
Package notify tells the user about the items that newly need them, and keeps a log of everything it told.
After each refresh, the inbox reports its arrivals (see inbox.Arrival): pull requests that newly ask for the user's review, items newly assigned to them, and snoozes that new activity ended early. The Dispatcher records each one in the notifications table, then shows a native banner for each kind the user has not turned off, through the desktop shell's Poster. More than MaxBanners at once are shown as one banner that sums them up, so a morning's backlog does not bury the screen. The log is written whether or not a banner is shown, and whether or not the shell can show banners at all, so the window's notification history always has every one. Only the newest Keep entries are kept.
Service is what the window binds: the log, marking it read, clearing it, the state of the banners, and a test banner. Nothing here leaves the machine: banners are posted to the operating system, and the log is a local table.
Index ¶
- Constants
- Variables
- func DecodeBannersOff(stored map[string]string) []string
- func EncodeBannersOff(off []string) string
- func Kinds() []string
- func SetBanner(off []string, kind string, on bool) ([]string, error)
- func WakeDetail(r snooze.Reasons) string
- type Banner
- type Clock
- type Config
- type Dispatcher
- type Log
- type Notification
- type Notifier
- type Poster
- type Service
- type Store
Constants ¶
const ( // StatusOn means banners are shown. StatusOn = "on" // StatusOff means the user has not allowed the app's banners, or turned them off in // the system's settings. StatusOff = "off" // no app bundle to own them, or an OS the shell does not post to yet. StatusUnavailable = "unavailable" )
Banner states, as Poster.Status reports them.
const ( // KindReviewRequested is a pull request that newly asks for the user's review. KindReviewRequested = inbox.ArrivalReviewRequested // KindAssigned is an issue or pull request newly assigned to the user. KindAssigned = inbox.ArrivalAssigned // KindWoke is a snoozed item that new activity brought back early. KindWoke = inbox.ArrivalWoke )
Kinds of notification. They are the inbox's kinds of arrival.
const Keep = 200
Keep is how many notifications the log keeps; recording more drops the oldest.
const MaxBanners = 3
MaxBanners is how many banners one refresh shows one by one; more are summed up in one.
const PrefBannersOff = "notify.bannersOff"
PrefBannersOff is the prefs key listing, as a JSON array, the kinds of notification whose banners are off. Kinds are on unless listed, so a kind added later starts on.
Variables ¶
var ( ErrBannersUnavailable = errors.New("this build cannot show notifications; they need the packaged app") // ErrBannersOff is returned by SendTest when the user has not allowed banners. ErrBannersOff = errors.New("notifications are off for this app in System Settings") )
var ErrUnknownKind = errors.New("unknown kind of notification")
ErrUnknownKind is returned for a kind of notification that is not one of Kinds.
Functions ¶
func DecodeBannersOff ¶
DecodeBannersOff reads the kinds whose banners are off from the stored prefs. A value that cannot be read turns none off, and kinds that are not known are dropped.
func EncodeBannersOff ¶
EncodeBannersOff writes the kinds whose banners are off for the prefs table.
func Kinds ¶
func Kinds() []string
Kinds returns the kinds of notification in the order Settings lists them.
func SetBanner ¶
SetBanner turns a kind's banners on or off in off, the kinds whose banners are off, and returns the new list in the order of Kinds.
func WakeDetail ¶
WakeDetail says what ended a snooze early, most decisive first, as the inbox card does: "changes requested, 2 new commits, 3 new comments". It is "" when nothing did.
Types ¶
type Banner ¶
type Banner struct {
// ID identifies the banner to the system; posting the same ID again replaces it.
ID string
Title string
Subtitle string
Body string
// Thread groups the banners of one kind in the system's notification list.
Thread string
// ItemID is the item a click on the banner shows, or 0 for none. URL is the item on
// GitHub, for when it is no longer in the inbox.
ItemID int64
URL string
}
Banner is one native notification.
type Config ¶
Config holds the dependencies of a Dispatcher and a Service. Poster, Notifier, Clock, and Logger are optional: without a Poster no banner is shown, and the log is still kept.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher records the inbox's arrivals and shows their banners. It is the inbox's inbox.ArrivalSink, and is not bound to the window.
func (*Dispatcher) Arrived ¶
func (d *Dispatcher) Arrived(ctx context.Context, arrivals []inbox.Arrival)
Arrived records a notification for each arrival, tells the window, and shows banners for the kinds that are on, if the user allows banners. A failure is logged: the refresh that found the arrivals has already been stored, and nothing is gained by failing it.
type Log ¶
type Log struct {
Items []Notification `json:"items"`
Unread int `json:"unread"`
}
Log is the notification history: the newest first, and how many are unread.
type Notification ¶
type Notification struct {
ID int64 `json:"id"`
// Kind is KindReviewRequested, KindAssigned, or KindWoke.
Kind string `json:"kind"`
// CreatedAt is when it was recorded, as RFC 3339.
CreatedAt string `json:"createdAt"`
// Read reports whether the user has seen it in the history.
Read bool `json:"read"`
// ItemID is the item's id in the inbox snapshot, or 0 once the item is no longer
// stored.
ItemID int64 `json:"itemId"`
// ItemKind is "pr" or "issue".
ItemKind string `json:"itemKind"`
// Repo is "owner/name".
Repo string `json:"repo"`
Number int `json:"number"`
Title string `json:"title"`
URL string `json:"url"`
Author string `json:"author"`
// Detail is what ended a snooze early, in a few words ("approved, 2 new commits"), for
// KindWoke, and "" otherwise.
Detail string `json:"detail"`
}
Notification is one entry in the log, as the window shows it. Every field is a plain value.
type Notifier ¶
type Notifier interface {
NotificationsUpdated()
}
Notifier is told when the log changed, so the window reads it again.
type Poster ¶
type Poster interface {
// Post shows a banner. It never waits on the user: a banner the user has not allowed
// is not shown, and Post reports why.
Post(b Banner) error
// Status reports StatusOn, StatusOff, or StatusUnavailable.
Status() string
// Authorize asks the user to allow banners, if they have not been asked, and reports
// whether banners are allowed. It may wait for the user's answer.
Authorize() (bool, error)
}
Poster shows banners. The desktop shell implements it over the system's notification center.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the notification log as the window binds it.
func (*Service) BannerStatus ¶
BannerStatus reports whether banners are shown: StatusOn, StatusOff when the user has not allowed them, or StatusUnavailable when this build cannot show them.
func (*Service) List ¶
List returns the notification history, newest first, and how many are unread.
func (*Service) MarkAllRead ¶
MarkAllRead marks every notification read, as the history does once it is opened.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes the notification log.
func (*Store) MarkAllRead ¶
MarkAllRead marks every unread notification read at now.