Reminders and notifications
Your app can reach a user in two ways while it isn't open. Your client sets reminders for the user, for example a nudge to write each evening. Your rules notify one member of a room, for example when someone joins their game. Your app can't notify anyone else.
To remind the user, call tinylib.reminders.set with a name you choose:
At its time, the reminder shows on each of the user's devices that receive notifications, with your app's name and icon above your title and text.
Setting the same name again replaces that reminder. A user can have 32 of your app's reminders at once. Past that, set with a new name rejects with limit.
A reminder has exactly one of at and repeat. For a one-off, give at a time on the device's clock as 'YYYY-MM-DDTHH:MM'. Or give it a timestamp in milliseconds from tinylib.now(), which follows Tinylib's clock rather than the device's:
repeat takes a schedule from daily, weekly, or monthly. The reminder starts at the next time the schedule matches:
A reminder set for a clock time keeps the time zone of the device that set it. One set for 6pm in Atlanta goes off at 6pm Atlanta time, wherever the user is and across clock changes. To move a reminder to the user's current time zone, set it again. list() gives each reminder's time zone as timeZone.
set, list, and cancel work offline. A reminder set offline still goes off on that device at its time: in Tinylib's Android app even while Tinylib is closed, and on the web while Tinylib is open in a tab. Once the device reconnects, the reminder reaches the user's other devices too. A guest has no other devices, so their reminder goes off only on the device that set it.
A device that can't show a reminder on time, for example because it was switched off, shows it up to 1 hour late, and otherwise skips it.
Each reminder in the list has what it was set with, plus next, when it next goes off. The user can also cancel reminders on your app's page in Tinylib, so call list() again each time a screen shows them.
For a daily reminder the user turns on and off in your app, followDailyReminder in tinylib-sdk/kits keeps your switch in step.
To tell a member something needs them while they're away, call ctx.notify in a handler with their id. Tinylib sends nothing while the member has the room open on any device, and never notifies a guest, who has no Tinylib account. Tapping the notification opens your app at the kind's address, so give the kind one:
Notify sparingly, when something waits on the member: it's their turn, or a list they shared is finished. Tell the member it waits on, not every member about every change; the others see it in the room's status and its view when they open it:
A member has one notification from a room at a time. A newer one replaces it and alerts again, so a member who missed three moves sees only the last. Opening or leaving the room clears it on that device and on the member's Android phones at once, and in another browser once the room opens there.
A title longer than 80 characters or a text longer than 300 characters isn't sent, and the error shows on the developer page. A room sends at most 60 per hour to one member and 300 per hour in all, and Tinylib drops the rest.
Tapping a reminder or a room's notification opens your app at its address, or at your start screen when a reminder has none. If your app is already open, it keeps running and moves to that address, and tinylib.places.onChange calls your function.
Your app learns only the address, not what the user tapped, so route on it as Places and links shows. To tell a reminder's arrival from any other, put something in its address, for example today?from=evening.
Your app never asks for permission to notify. Tinylib asks, the first time your app sets a reminder or creates or joins a room on a device that hasn't been asked yet.
tinylib.user.settings holds your app's switches, not the device's permission. Platforms says which devices get notifications.
Your client reads the switches as tinylib.user.settings.reminders and tinylib.user.settings.notifications, the field for Rooms. Both start on. Only the user changes them, on your app's page in Tinylib or in the sheet that tinylib.user.manageSettings() opens over your app. To offer the switch where the user expects reminders:
While Reminders is off, none of your app's reminders goes off, though they stay set and set still works. A time that passes meanwhile is skipped: a repeating reminder moves on to its next time, and a one-off is gone.
While Rooms is off, or the user has muted a room, your rules' notifications don't reach them. tinylib.rooms.list() gives a room the user muted muted: true.
In npx tinylib-sdk dev, each user's pane has a Notifications list of what would reach them, including what a switch or a muted room held back. Tapping one opens the app at its address. The clock's buttons skip ahead, so a reminder comes due without waiting.