{ "version": 3, "sources": ["libs/conversation/core/src/lib/inbox-navigation.service.ts"], "sourcesContent": ["import { Injectable, inject } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { ConversationChannel, Participant } from '@vendasta/conversation';\nimport { ProductAnalyticsService } from '@vendasta/product-analytics';\nimport { Observable, catchError, firstValueFrom, switchMap, tap } from 'rxjs';\nimport { toFirestoreId } from './conversation-utils';\nimport { ConversationService } from './conversation.service';\nimport { InboxService } from './inbox.service';\nimport { ConversationDetail, SendMessage, SubjectParticipant } from './interface/conversation.interface';\nimport {\n ACCOUNT_GROUP_ID_TOKEN,\n CONVERSATION_HOST_APP_INTERFACE_TOKEN,\n CONVERSATION_ROUTES_TOKEN,\n PARTNER_ID_TOKEN,\n} from './tokens';\nimport { ViewModeService } from './view-mode.service';\nimport { ParticipantService } from './participant.service';\n\n@Injectable()\nexport class InboxNavigationService {\n private readonly conversationService = inject(ConversationService);\n private readonly inboxService = inject(InboxService);\n private readonly analyticsService = inject(ProductAnalyticsService);\n private readonly hostAppInterface = inject(CONVERSATION_HOST_APP_INTERFACE_TOKEN);\n private readonly routes = toSignal(inject(CONVERSATION_ROUTES_TOKEN));\n private readonly accountGroupId = toSignal(inject(ACCOUNT_GROUP_ID_TOKEN));\n private readonly partnerId = toSignal(inject(PARTNER_ID_TOKEN));\n private readonly viewModeService = inject(ViewModeService);\n private readonly participantService = inject(ParticipantService);\n\n private createOrGetConversation(\n subjectParticipants: SubjectParticipant[],\n currentParticipant: Participant,\n ): Observable {\n const channel = currentParticipant.channel;\n\n return this.hostAppInterface.buildSendMessageParams(currentParticipant, subjectParticipants).pipe(\n switchMap((sendMessage: SendMessage) =>\n this.conversationService.createConversation(\n sendMessage.participants ?? [],\n sendMessage.channel,\n sendMessage.location,\n ),\n ),\n tap((conversationResp) => {\n if (conversationResp?.conversation) {\n this.analyticsService.trackEvent('inbox', 'send-message', 'create-conversation-success', 0, {\n accountGroupId: this.accountGroupId(),\n partnerId: this.partnerId(),\n location: this.inboxService.platformLocation,\n channel,\n });\n }\n }),\n catchError((error) => {\n this.analyticsService.trackEvent('inbox', 'send-message', 'create-conversation-error', 0, {\n accountGroupId: this.accountGroupId(),\n partnerId: this.partnerId(),\n location: this.inboxService.platformLocation,\n channel,\n message: error?.error?.message,\n });\n\n throw new Error('Error creating a conversation');\n }),\n switchMap((conversationResp) =>\n this.conversationService.getConversationDetail(conversationResp.conversation.conversationId),\n ),\n );\n }\n\n /**\n * Go to or create a conversation between a current participant, and a list of Subject Participants\n * @param {SubjectParticipant[]} subjectParticipants - A list of subject participants\n * @param {Participant} currentParticipant - The current user that is going to the conversation\n * @param {string} prefilledMessage - A prefilled message in Inbox, this only works with the modal\n */\n gotoConversation(\n subjectParticipants: SubjectParticipant[],\n currentParticipant: Participant,\n prefilledMessage?: string,\n ): void {\n if (!this.routes()?.useModal) {\n this.hostAppInterface.redirectToInternalConversation(currentParticipant, subjectParticipants);\n return;\n }\n\n this.createOrGetConversation(subjectParticipants, currentParticipant).subscribe((conversationDetails) =>\n this.gotoConversationID(toFirestoreId(conversationDetails.conversation.conversationId), prefilledMessage),\n );\n }\n\n /**\n * Go to or create a conversation between a current participant, and a list of Subject Participants for a given\n * channel. This method will resolve the current IAM user for the caller.\n * @param {SubjectParticipant[]} subjectParticipants - A list of subject participants\n * @param {ConversationChannel} channel - The channel that the conversation exists in.\n * @param {string} prefilledMessage - A prefilled message in Inbox, this only works with the modal\n */\n async gotoConversationChannel(\n subjectParticipants: SubjectParticipant[],\n channel: ConversationChannel,\n prefilledMessage?: string,\n ): Promise {\n const currentParticipant = await firstValueFrom(this.participantService.buildIAMUserParticipant(channel));\n if (!this.routes()?.useModal) {\n // get first value from currentParticipant$ and redirect to internal conversation\n this.hostAppInterface.redirectToInternalConversation(currentParticipant, subjectParticipants);\n return;\n }\n\n const conversationDetails = await firstValueFrom(\n this.createOrGetConversation(subjectParticipants, currentParticipant),\n );\n if (!conversationDetails?.conversation) {\n // TODO(warped-tour): better handle if we fail to get the conversation\n console.error('error to get firestore conversation by conversation id; unable to go to conversation');\n return;\n }\n this.gotoConversationID(toFirestoreId(conversationDetails?.conversation?.conversationId), prefilledMessage);\n }\n\n /**\n * Go to a conversation via a conversation ID\n * @param {string} conversationId - A firestore conversation ID\n */\n gotoConversationID(conversationId: string, prefilledMessage?: string): void {\n this.viewModeService.open(conversationId, prefilledMessage);\n }\n}\n"], "mappings": "yWAmBA,IAAaA,GAAsB,IAAA,CAA7B,IAAOA,EAAP,MAAOA,CAAsB,CADnCC,aAAA,CAEmB,KAAAC,oBAAsBC,EAAOC,CAAmB,EAChD,KAAAC,aAAeF,EAAOG,CAAY,EAClC,KAAAC,iBAAmBJ,EAAOK,CAAuB,EACjD,KAAAC,iBAAmBN,EAAOO,CAAqC,EAC/D,KAAAC,OAASC,EAAST,EAAOU,CAAyB,CAAC,EACnD,KAAAC,eAAiBF,EAAST,EAAOY,CAAsB,CAAC,EACxD,KAAAC,UAAYJ,EAAST,EAAOc,CAAgB,CAAC,EAC7C,KAAAC,gBAAkBf,EAAOgB,CAAe,EACxC,KAAAC,mBAAqBjB,EAAOkB,CAAkB,EAEvDC,wBACNC,EACAC,EAA+B,CAE/B,IAAMC,EAAUD,EAAmBC,QAEnC,OAAO,KAAKhB,iBAAiBiB,uBAAuBF,EAAoBD,CAAmB,EAAEI,KAC3FC,EAAWC,GACT,KAAK3B,oBAAoB4B,mBACvBD,EAAYE,cAAgB,CAAA,EAC5BF,EAAYJ,QACZI,EAAYG,QAAQ,CACrB,EAEHC,EAAKC,GAAoB,CACnBA,GAAkBC,cACpB,KAAK5B,iBAAiB6B,WAAW,QAAS,eAAgB,8BAA+B,EAAG,CAC1FtB,eAAgB,KAAKA,eAAc,EACnCE,UAAW,KAAKA,UAAS,EACzBgB,SAAU,KAAK3B,aAAagC,iBAC5BZ,QAAAA,EACD,CAEL,CAAC,EACDa,EAAYC,GAAS,CACnB,WAAKhC,iBAAiB6B,WAAW,QAAS,eAAgB,4BAA6B,EAA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ationService", "constructor", "conversationService", "inject", "ConversationService", "inboxService", "InboxService", "analyticsService", "ProductAnalyticsService", "hostAppInterface", "CONVERSATION_HOST_APP_INTERFACE_TOKEN", "routes", "toSignal", "CONVERSATION_ROUTES_TOKEN", "accountGroupId", "ACCOUNT_GROUP_ID_TOKEN", "partnerId", "PARTNER_ID_TOKEN", "viewModeService", "ViewModeService", "participantService", "ParticipantService", "createOrGetConversation", "subjectParticipants", "currentParticipant", "channel", "buildSendMessageParams", "pipe", "switchMap", "sendMessage", "createConversation", "participants", "location", "tap", "conversationResp", "conversation", "trackEvent", "platformLocation", "catchError", "error", "message", "Error", "getConversationDetail", "conversationId", "gotoConversation", "prefilledMessage", "useModal", "redirectToInternalConversation", "subscribe", "conversationDetails", "gotoConversationID", "toFirestoreId", "gotoConversationChannel", "__async", "firstValueFrom", "buildIAMUserParticipant", "console", "open", "factory", "\u0275fac", "_InboxNavigationService"] }