Lime Web Components API Documentation - v7.11.0
    Preparing search index...

    Interface NotificationRepositoryBeta

    Repository for managing user notifications.

    NotificationRepository provides methods to load, manage, and interact with notifications for the current user. Notifications inform users about:

    • Task assignments (NotificationType.assignment)
    • Object follows (NotificationType.follow)
    • Mentions in comments (NotificationType.mention)

    Each Notification contains:

    • A unique ID
    • Type indicating what triggered the notification
    • Timestamp of creation
    • The LimeObject it is about, or its bundle's object when loaded through loadBundles (see Notification.limeobject)
    • Creator information (who triggered the notification)
    • Optional custom data
    • Read status
    import { PlatformServiceName } from '@limetech/lime-web-components';

    const repository = platform.get(PlatformServiceName.NotificationRepository);

    const response = await repository.loadAll({
    filter: { read: false },
    limit: 20,
    });

    const notifications = response.items;
    const unreadCount = response.count.unread;

    The repository methods are generic in T so callers can supply the expected shape of Notification.data on a per-call basis. The default is unknown — narrow it at the call site when you know what payload to expect, e.g. repo.get<MentionData>(id).

    interface NotificationRepository {
        delete<T = unknown>(notification: Notification<T>): Promise<void>;
        get<T = unknown>(notificationId: number): Notification<T> | undefined;
        loadAll<T = unknown>(
            options?: NotificationLoadOptions,
        ): Promise<NotificationResponse<T>>;
        loadBundles<T = unknown>(
            options?: NotificationBundleLoadOptions,
        ): Promise<NotificationBundleResponse<T>>;
        markAllAsRead(): Promise<number>;
        markAsRead<T = unknown>(
            notification: Notification<T>,
            read?: boolean,
        ): Promise<Notification<T>>;
        markBundleAsRead(bundle: NotificationBundle): Promise<number>;
    }
    Index

    Methods

    • Beta

      Delete a notification.

      Permanently removes the notification for the current user. This operation cannot be undone. The notification will be removed from:

      • The database
      • The repository cache
      • Any notification lists in the UI

      Type Parameters

      • T = unknown

      Parameters

      Returns Promise<void>

      Promise that resolves when deletion is complete

      Error if deletion fails

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const response = await repository.loadAll({ limit: 1 });
      const [notification] = response.items;

      if (notification) {
      try {
      await repository.delete(notification);
      } catch (error) {
      console.error('Failed to delete:', error);
      }
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const response = await repository.loadAll({ filter: { read: true } });

      for (const notification of response.items) {
      await repository.delete(notification);
      }

      console.log(`Cleared ${response.items.length} read notifications`);
    • Beta

      Get a cached notification by ID.

      Retrieves a notification from the repository cache without making a network request. Returns undefined if the notification has not been loaded or doesn't exist.

      Use this to access notifications that were previously loaded via loadAll.

      Type Parameters

      • T = unknown

      Parameters

      • notificationId: number

        ID of the notification to retrieve

      Returns Notification<T> | undefined

      The cached Notification, or undefined if not found

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);
      const notificationId = 1001;

      const notification = repository.get(notificationId);

      if (notification) {
      console.log('Type:', notification.type);
      console.log('Read:', notification.read !== undefined);
      } else {
      console.log('Notification not in cache');
      }
    • Beta

      Load notifications for the current user.

      Fetches notifications from the server with optional filtering and pagination. Returns both the notification items and count information (total and unread).

      Use NotificationLoadOptions to:

      • Filter by read/unread status
      • Paginate with limit and offset
      • Load only recent notifications (newerThan, olderThan)

      Type Parameters

      • T = unknown

      Parameters

      Returns Promise<NotificationResponse<T>>

      Promise resolving to NotificationResponse with items and counts

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);
      const pageSize = 20;
      const pageNumber = 2;

      const response = await repository.loadAll({
      limit: pageSize,
      offset: pageNumber * pageSize,
      });

      const totalPages = Math.ceil(response.count.total / pageSize);
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const seen = await repository.loadAll({ limit: 1 });
      const lastNotificationId = seen.items[0]?.id;

      const response = await repository.loadAll({
      newerThan: lastNotificationId,
      limit: 100,
      });

      if (response.items.length > 0) {
      console.log(`${response.items.length} new notifications`);
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const firstPage = await repository.loadAll({ limit: 25 });
      let notifications = firstPage.items;
      const oldestId = notifications.at(-1)?.id;

      const response = await repository.loadAll({
      olderThan: oldestId,
      limit: 25,
      });

      notifications = [...notifications, ...response.items];
    • Beta

      Load the current user's notifications grouped into bundles, one per object they are about.

      Notifications are filtered before they are grouped, so with filter: { read: false } a bundle holds only unread notifications. Read notifications are included for a limited time after they were read, and a bundle holds only its newest notifications. Older ones are in the object's activity feed.

      Bundles are ordered by their newest notification. To page, pass the id of the newest notification in the last bundle as olderThan, or in the first bundle as newerThan.

      Loaded notifications are cached, so NotificationRepository.get finds them.

      The response sends each object once; the repository returns them resolved.

      Type Parameters

      • T = unknown

      Parameters

      Returns Promise<NotificationBundleResponse<T>>

      the bundles, and counts of all the user's notifications

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const response = await repository.loadBundles({
      limit: 10,
      notificationsPerBundle: 5,
      });

      for (const bundle of response.items) {
      const onlyInFeed = bundle.count.total - bundle.notifications.length;
      console.log(bundle.id, bundle.count.unread, onlyInFeed);
      }
    • Beta

      Mark all of the current user's unread notifications as read.

      Returns Promise<number>

      the number of notifications that were marked as read

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const count = await repository.markAllAsRead();

      console.log(`Marked ${count} notifications as read`);
    • Beta

      Mark a notification as read or unread.

      Updates the read status of a notification. When marked as read, the notification's read property is set to the current timestamp. When marked as unread, the read property is cleared.

      Marking as read is typically done when:

      • User clicks on the notification
      • User views the related object
      • Notification panel is opened

      Type Parameters

      • T = unknown

      Parameters

      • notification: Notification<T>

        The Notification to update

      • Optionalread: boolean

        Whether to mark as read (true) or unread (false). Defaults to true

      Returns Promise<Notification<T>>

      Promise resolving to the updated Notification

      Error if update fails

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);
      const navigatorService = platform.get(PlatformServiceName.Navigator);

      const response = await repository.loadAll({ limit: 1 });
      const [notification] = response.items;

      if (notification && !notification.read) {
      try {
      await repository.markAsRead(notification);

      const limeobject = notification.limeobject;
      if (limeobject) {
      navigatorService.navigate(
      `/object/${limeobject.getLimetype().name}/${limeobject.id}`
      );
      }
      } catch (error) {
      console.error('Failed to mark as read:', error);
      }
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const response = await repository.loadAll({ limit: 1 });
      const [notification] = response.items;

      if (notification) {
      const shouldBeRead = !notification.read;

      await repository.markAsRead(notification, shouldBeRead);
      console.log(`Marked as ${shouldBeRead ? 'read' : 'unread'}`);
      }
    • Beta

      Mark the current user's unread notifications in a bundle as read, including those that were not loaded with it.

      Parameters

      Returns Promise<number>

      the number of notifications that were marked as read

      import { PlatformServiceName } from '@limetech/lime-web-components';

      const repository = platform.get(PlatformServiceName.NotificationRepository);

      const { items } = await repository.loadBundles();
      const [bundle] = items;

      if (bundle) {
      const count = await repository.markBundleAsRead(bundle);
      console.log(`Marked ${count} notifications in ${bundle.id} as read`);
      }