tinylib.invitations
While your app is open, Tinylib shows its own sheet for each invitation
to it, except those you take with handle. Outside your app, Tinylib notifies the user of every invitation.
Lists the user's invitations to your app's rooms, including those a
handle shows.JavaScript
const invitations = await tinylib.invitations.list()
Returns
- Promise<Invitation[]>
- The invitations, newest first. Always empty for a guest.
Rejects with
- offline
tinylib.invitations.handle(pick: (invitation: Invitation) => boolean, fn: (invitations: Invitation[]) => void): () => void
Hands the invitations
pick selects to your app to show, in place of Tinylib's sheet. Calls fn with them at once and again each time the user's invitations to your app change. Offer block and report for each sender.JavaScript
const rematch = document.querySelector('#rematch')
const stop = tinylib.invitations.handle(
(invitation) => invitation.rematchOf === gameId,
(invitations) => {
rematch.hidden = invitations.length === 0
},
)
Parameters
- pick(invitation: Invitation) => boolean
- Called with each invitation. Returns true for one your app shows.
- fn(invitations: Invitation[]) => void
- Called with every invitation
pickreturned true for, possibly none.
Returns
- () => void
- A function that stops the calls and gives the invitations back to Tinylib's sheet.
Throws
- TypeError
- When
pickorfnisn't a function.
interface Invitation
An invitation to one of your app's rooms.
Properties
- idstringread-only
- The invitation's id.
- kindstringread-only
- The room's kind.
- namestring | nullread-only
- The room's name, or null when the rules haven't set one.
- atnumberread-only
- When the invitation was sent, in milliseconds on Tinylib's clock.
- rematchOfstring | nullread-only
- The id of the room this one is a rematch of, or null.
invitation.accept(): Promise<{ id: string }>
Joins the room and removes the invitation. It doesn't open the room.
JavaScript
const { id } = await invitation.accept()
tinylib.places.go(`game/${id}`)
Returns
- Promise<{ id: string }>
- The room's id, as
{ id }.
Rejects with
- not_found
- When the invitation is gone, or its sender has left the room or may no longer invite.
- refused
- When the user or a member has blocked the other, or the user is a guest.
- limit
- When the user is already in 50 rooms of your app, or the room already has 64 members.
- offline
invitation.dismiss(): Promise<void>
Declines the invitation and removes it.
JavaScript
await invitation.dismiss()
Rejects with
- refused
- When the user is a guest.
- offline