import { MessageHashService } from '../../cryptography' ; import { LegalHoldStatus , LinkPreviewUploadedContent , MentionContent , QuoteContent , TextContent } from '../content' ; import type { EditedTextMessage , TextMessage , QuotableMessage } from './OtrMessage' ; export class TextContentBuilder { private readonly content : TextContent ; private readonly payloadBundle : TextMessage | EditedTextMessage ; constructor ( payloadBundle ) { this . payloadBundle = payloadBundle ; this . content = this . payloadBundle . content as TextContent ; } build ( ) { this . payloadBundle . content = this . content ; return this . payloadBundle ; } withLinkPreviews ( linkPreviews ? ) { if ( linkPreviews ?. length ) { this . content . linkPreviews = linkPreviews ; } return this ; } withMentions ( mentions ? ) { if ( mentions ?. length ) { this . content . mentions = mentions ; } return this ; } withQuote ( quote ? ) { if ( quote ) { if ( ( quote as QuoteContent ) . quotedMessageId ) { this . content . quote = quote as QuoteContent ; } else { const messageHashService = new MessageHashService ( ( quote as QuotableMessage ) . content , ( quote as QuotableMessage ) . timestamp ) ; const messageHashBuffer = messageHashService . getHash ( ) ; this . content . quote = { quotedMessageId : ( quote as QuotableMessage ) . id , quotedMessageSha256 : new Uint8Array ( messageHashBuffer ) , } ; } } return this ; } withReadConfirmation ( expectsReadConfirmation = false ) { if ( typeof expectsReadConfirmation !== 'undefined' ) { this . content . expectsReadConfirmation = expectsReadConfirmation ; } return this ; } withLegalHoldStatus ( legalHoldStatus = LegalHoldStatus . UNKNOWN ) { if ( typeof legalHoldStatus !== 'undefined' ) { this . content . legalHoldStatus = legalHoldStatus ; } return this ; } }