import _ from 'lodash' ; import { SerializedMessage } from 'libs/Message' ; import { SerializedNotice } from 'libs/Notice' ; import { SerializedNotification } from 'libs/Notification' ; import { SerializedMarker } from 'store/ducks/logs' ; import { replaceImgTagByAlt } from 'utils/html' ; /**
 * HTMLDivElement used when converting messages to a string.
 */ const tmpConversionDiv = document . createElement ( 'div' ) ; param messages return export function convertMessagesToString ( messages ) { const messagesToConvert = _ . isArray ( messages ) ? messages : [ messages ] ; let convertedMessages = '' ; _ . forEach ( messagesToConvert , ( message , index ) => { tmpConversionDiv . innerHTML = replaceImgTagByAlt ( message . message ) ; const convertedMessage = tmpConversionDiv . textContent || tmpConversionDiv . innerText || '' ; const messageToConvert = `[${ message . time }] ${ message . user . displayName }: ${ convertedMessage }${ index < messagesToConvert . length - 1 ? '\n' : '' }` ; convertedMessages = convertedMessages . concat ( messageToConvert ) ; } ) ; return convertedMessages ; } param marker return export function convertMarkerToString ( marker ) { return `--[ ${ marker . time } ]---------------------------------------------------------------------` ; } param messages return export function convertNoticeToString ( notice ) { return `* ${ notice . message } *` ; } param messages return export function convertNotificationToString ( notification ) { return `~ ${ notification . title }${ _ . get ( notification , 'message' , '' ) } ~` ; } param messages return export function convertWhisperToString ( whisper ) { return `${ whisper . self ? '>' : '<' } ${ convertMessagesToString ( whisper ) }` ; }