Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458import { Result, ok, err } from '../../../../shared/core/Result';import { DomainService } from '../../../../shared/domain/DomainService';import { Notification } from '../Notification';import { INotificationRepository } from '../INotificationRepository';import { CuratorId } from '../../../cards/domain/value-objects/CuratorId';import { CardId } from '../../../cards/domain/value-objects/CardId';import { CollectionId } from '../../../cards/domain/value-objects/CollectionId';import { ConnectionId } from '../../../cards/domain/value-objects/ConnectionId';
export class NotificationServiceError extends Error { constructor(message: string) { super(message); this.name = 'NotificationServiceError'; }}
export class NotificationService implements DomainService { constructor(private notificationRepository: INotificationRepository) {}
async createUserAddedYourCardNotification( recipientUserId: CuratorId, actorUserId: CuratorId, cardId: CardId, collectionIds?: CollectionId[], ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is adding their own card if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserAddedYourCard( recipientUserId, actorUserId, cardId, collectionIds, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserAddedToYourCollectionNotification( recipientUserId: CuratorId, actorUserId: CuratorId, cardId: CardId, collectionId: CollectionId, ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is adding to their own collection if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserAddedToYourCollection( recipientUserId, actorUserId, cardId, collectionId, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserFollowedYouNotification( recipientUserId: CuratorId, actorUserId: CuratorId, ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is following themselves (shouldn't happen) if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserFollowedYou( recipientUserId, actorUserId, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserFollowedYourCollectionNotification( recipientUserId: CuratorId, actorUserId: CuratorId, collectionId: CollectionId, ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is following their own collection if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserFollowedYourCollection( recipientUserId, actorUserId, collectionId, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserAddedYourBskyPostNotification( recipientUserId: CuratorId, actorUserId: CuratorId, cardId: CardId, collectionIds?: CollectionId[], ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is adding their own post if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserAddedYourBskyPost( recipientUserId, actorUserId, cardId, collectionIds, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserAddedYourCollectionNotification( recipientUserId: CuratorId, actorUserId: CuratorId, cardId: CardId, collectionIds?: CollectionId[], ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is adding their own collection if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserAddedYourCollection( recipientUserId, actorUserId, cardId, collectionIds, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserConnectedYourUrlNotification( recipientUserId: CuratorId, actorUserId: CuratorId, connectionId: ConnectionId, ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is connecting their own URLs if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserConnectedYourUrl( recipientUserId, actorUserId, connectionId, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserConnectedYourPostNotification( recipientUserId: CuratorId, actorUserId: CuratorId, connectionId: ConnectionId, ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is connecting their own post if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserConnectedYourPost( recipientUserId, actorUserId, connectionId, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }
async createUserConnectedYourCollectionNotification( recipientUserId: CuratorId, actorUserId: CuratorId, connectionId: ConnectionId, ): Promise<Result<Notification, NotificationServiceError>> { try { // Don't create notification if user is connecting their own collection if (recipientUserId.equals(actorUserId)) { return err( new NotificationServiceError( 'Cannot notify user about their own action', ), ); }
const notificationResult = Notification.createUserConnectedYourCollection( recipientUserId, actorUserId, connectionId, );
if (notificationResult.isErr()) { return err( new NotificationServiceError(notificationResult.error.message), ); }
const notification = notificationResult.value; const saveResult = await this.notificationRepository.save(notification);
if (saveResult.isErr()) { return err( new NotificationServiceError( `Failed to save notification: ${saveResult.error.message}`, ), ); }
return ok(notification); } catch (error) { return err( new NotificationServiceError( `Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}`, ), ); } }}