Lime Web Components API Documentation - v7.4.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
    • Associated LimeObject (the object being notified about)
    • 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>>;
        markAsRead<T = unknown>(
            notification: Notification<T>,
            read?: boolean,
        ): Promise<Notification<T>>;
    }
    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

      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'}`);
      }
      import { PlatformServiceName } from '@limetech/lime-web-components';

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

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

      for (const notification of response.items) {
      await repository.markAsRead(notification, true);
      }

      console.log(`Marked ${response.items.length} notifications as read`);