parser.ts 989 B

1234567891011121314151617181920212223242526
  1. import { FolderNotification } from "../../../../services/backend";
  2. import { NotificationParser, OnNotificationError } from "../../../../services/backend/notifications/parser";
  3. declare type FolderNotificationCallback = (ty: FolderNotification, payload: Uint8Array) => void;
  4. export class FolderNotificationParser extends NotificationParser<FolderNotification> {
  5. constructor(params: { id?: String; callback: FolderNotificationCallback; onError?: OnNotificationError }) {
  6. super(
  7. params.callback,
  8. (ty) => {
  9. let notification = FolderNotification[ty];
  10. if (isFolderNotification(notification)) {
  11. return FolderNotification[notification];
  12. } else {
  13. return FolderNotification.Unknown;
  14. }
  15. },
  16. params.id,
  17. params.onError
  18. );
  19. }
  20. }
  21. const isFolderNotification = (notification: string): notification is keyof typeof FolderNotification => {
  22. return Object.values(FolderNotification).indexOf(notification) !== -1;
  23. };