Packbase

pb.inbox

Read, count, mark, and delete notifications for the signed-in user.

pb.inbox gives access to the signed-in user's notification inbox. Each method requires authentication. Read the Pagination guide if you are not familiar with paginated responses.

Methods overview

MethodDescription
pb.inbox.fetch(options?)Fetch paginated notifications
pb.inbox.count()Get the unread notification count
pb.inbox.markRead(ids)Mark one, several, or all notifications as read
pb.inbox.delete(ids)Delete notifications

pb.inbox.fetch(options?): Fetch notifications

Sends GET /inbox/fetch. The result contains one page of notifications in data. For the next page, send the cursor from the previous response. Do not make a cursor.

// First page
const page = await ..({ : 20 })
const page: Paginated<Notification>
const { , , } = for (const of ) { .(., ., .) } // Next page if () { const = await ..({ }) }

Options:

OptionTypeDefaultDescription
limitnumberserver defaultMax notifications per page.
cursorstringNot setPagination cursor from previous response.
unreadOnlybooleanfalseWhen true, only unread notifications are returned.

Returns: Promise<Paginated<Notification>>

Unread-only feed

const { data } = await ..({ : true })
const data: Notification[]
.(`${.} unread notifications`)

Fetch all notifications

async function (): <Notification[]> {
  const : Notification[] = []
  let : string | undefined
  let  = true

  do {
    const page = await ..({ : 50,  })
const page: Paginated<Notification>
.(....) = . = . } while () return }

pb.inbox.count(): Unread count

Fires GET /inbox/count. This works well for an unread badge because it returns only the count, without downloading the notification list.

const result = await ..()
const result: {
    count: number;
}
.(`${.} unread notifications`)

Returns: Promise<{ count: number }>

pb.inbox.markRead(ids): Mark as read

Fires POST /inbox/read. Pass an array of notification IDs for selected items or the exact string 'all' for the entire inbox.

// Mark specific notifications
const r1 = await ..(['id1', 'id2', 'id3'])
const r1: {
    success: boolean;
    count: number;
}
// Mark all notifications as read const = await ..('all')

Parameters:

ValueDescription
string[]Array of notification UUIDs to mark as read.
'all'Mark every notification as read at once.

Returns: Promise<{ success: boolean; count: number }>

pb.inbox.delete(ids): Delete notifications

Fires POST /inbox/delete.

const result = await ..(['id1', 'id2'])
const result: {
    success: boolean;
    count: number;
}
await ..('all')

Pass an array to delete selected notifications. Pass 'all' to clear the inbox. Deletion is permanent. Make sure that the user confirms before the application sends 'all'.

Returns: Promise<{ success: boolean; count: number }>

On this page