import { MeetingAdapter } from './MeetingAdapter' ; import { ChatAdapter , ChatAdapterState } from '../../ChatComposite' ; import { ErrorBarStrings } from '@internal/react-components' ; import { ChatThreadClientState } from '@internal/chat-stateful-client' ; import { MeetingAdapterState , MeetingState } from '..' ; function chatThreadStateFromMeetingState ( meetingState ) { return { chatMessages : meetingState . chatMessages , participants : meetingState . participants , threadId : meetingState . threadId , properties : meetingState . properties , readReceipts : meetingState . readReceipts , typingIndicators : meetingState . typingIndicators , latestReadTime : meetingState . latestReadTime } ; } function ChatAdapterStateFromMeetingAdapterState ( meetingState ) { if ( ! meetingState . meeting ) { throw 'Cannot get chat adapter state. Meeting state is undefined.' ; } return { userId : meetingState . userId , displayName : meetingState . displayName || '' , thread : chatThreadStateFromMeetingState ( meetingState . meeting ) , latestErrors : { } } ; } private export class MeetingBackedChatAdapter implements ChatAdapter { private meetingAdapter : MeetingAdapter ; private eventStore : Map < ( state : ChatAdapterState ) => void , ( state : MeetingAdapterState ) => void > = new Map ( ) ; constructor ( meetingAdapter ) { this . meetingAdapter = meetingAdapter ; } public fetchInitialData = async ( ) : Promise < void > => await this . meetingAdapter . fetchInitialData ( ) ; public sendMessage = async ( content ) : Promise < void > => await this . meetingAdapter . sendMessage ( content ) ; public sendReadReceipt = async ( chatMessageId ) : Promise < void > => await this . meetingAdapter . sendReadReceipt ( chatMessageId ) ; public sendTypingIndicator = async ( ) : Promise < void > => await this . meetingAdapter . sendTypingIndicator ( ) ; public removeParticipant = async ( userId ) : Promise < void > => await this . meetingAdapter . removeParticipant ( userId ) ; public loadPreviousChatMessages = async ( messagesToLoad ) : Promise < boolean > => await this . meetingAdapter . loadPreviousChatMessages ( messagesToLoad ) ; public dispose = ( ) : void => this . meetingAdapter . dispose ( ) ; public onStateChange = ( handler ) : void => { const convertedHandler = ( state ) : void => { handler ( ChatAdapterStateFromMeetingAdapterState ( state ) ) ; } ; this . meetingAdapter . onStateChange ( convertedHandler ) ; this . eventStore . set ( handler , convertedHandler ) ; } ; public offStateChange = ( handler ) : void => { const convertedHandler = this . eventStore . get ( handler ) ; convertedHandler && this . meetingAdapter . offStateChange ( convertedHandler ) ; } ; public getState = ( ) : ChatAdapterState => ChatAdapterStateFromMeetingAdapterState ( this . meetingAdapter . getState ( ) ) ; public on = ( event , listener ) : void => this . meetingAdapter . on ( event , listener ) ; public off = ( event , listener ) : void => this . meetingAdapter . off ( event , listener ) ; public updateMessage = async ( messageId , content ) : Promise < void > => await this . meetingAdapter . updateMessage ( messageId , content ) ; public deleteMessage = async ( messageId ) : Promise < void > => await this . meetingAdapter . deleteMessage ( messageId ) ; public clearErrors = ( errorTypes ) : void => { throw `Method not supported in meetings.` ; } ; public setTopic = async ( topicName ) : Promise < void > => { throw `Chat Topics are not supported in meetings.` ; } ; }