Get account notifications

Get account notifications in Bitsocial React Hooks. Usage, options, and examples.

useNotifications returns the account’s notifications (newest first) along with read/unread and local removal actions. Call markAsRead() with no argument to mark every unread notification as read, or pass a notification object (or its cid) to markAsRead, markAsUnread, or deleteNotification to act on one notification. deleteNotification and deleteAllNotifications only remove notifications locally from the account’s inbox and persist durable per-account deletion markers outside the bounded reply cache so deleted notifications stay hidden across reloads, LRU rotations, and comment refreshes; they never delete protocol comments.

const {
  notifications,
  markAsRead,
  markAsUnread,
  deleteNotification,
  deleteAllNotifications,
} = useNotifications();
for (const notification of notifications) {
  console.log(notification);
}

// mark one notification as read or unread, or delete it locally (accepts a notification object or its cid)
if (notifications[0]) {
  await markAsRead(notifications[0]);
  await markAsUnread(notifications[0].cid);
  await deleteNotification(notifications[0]);
}

// mark all unread notifications as read or clear all notifications locally from the inbox
await markAsRead();
await deleteAllNotifications();

const johnsNotifications = useNotifications({ accountName: "John" });
for (const notification of johnsNotifications.notifications) {
  console.log(notification);
}
await johnsNotifications.markAsRead();

// get the unread notification counts for all accounts
const { accounts } = useAccounts();
const accountsUnreadNotificationsCounts = accounts?.map(
  (account) => account.unreadNotificationCount,
);