@@ -346,7 +346,15 @@ const onIncomingMessage = (
346346
347347 const { containsLatestMessageMap} = state . chat2
348348 const shouldAddMessage = containsLatestMessageMap . get ( conversationIDKey ) || false
349- const message = Constants . uiMessageToMessage ( state , conversationIDKey , cMsg )
349+
350+ const { username, getLastOrdinal, devicename} = Constants . getMessageStateExtras ( state , conversationIDKey )
351+ const message = Constants . uiMessageToMessage (
352+ conversationIDKey ,
353+ cMsg ,
354+ username ,
355+ getLastOrdinal ,
356+ devicename
357+ )
350358 if ( message ) {
351359 // The attachmentuploaded call is like an 'edit' of an attachment. We get the placeholder, then its replaced by the actual image
352360 if (
@@ -374,7 +382,13 @@ const onIncomingMessage = (
374382 switch ( body . messageType ) {
375383 case RPCChatTypes . MessageType . edit :
376384 if ( modifiedMessage ) {
377- const modMessage = Constants . uiMessageToMessage ( state , conversationIDKey , modifiedMessage )
385+ const modMessage = Constants . uiMessageToMessage (
386+ conversationIDKey ,
387+ modifiedMessage ,
388+ username ,
389+ getLastOrdinal ,
390+ devicename
391+ )
378392 if ( modMessage ) {
379393 actions . push ( Chat2Gen . createMessagesAdd ( { context : { type : 'incoming' } , messages : [ modMessage ] } ) )
380394 }
@@ -537,6 +551,8 @@ const ephemeralPurgeToActions = (info: RPCChatTypes.EphemeralPurgeNotifInfo) =>
537551
538552const messagesUpdatedToActions = ( state : Container . TypedState , info : RPCChatTypes . MessagesUpdated ) => {
539553 const conversationIDKey = Types . conversationIDToKey ( info . convID )
554+
555+ const { username, getLastOrdinal, devicename} = Constants . getMessageStateExtras ( state , conversationIDKey )
540556 const messages = ( info . updates ?? [ ] ) . reduce <
541557 Array < {
542558 message : Types . Message
@@ -547,7 +563,7 @@ const messagesUpdatedToActions = (state: Container.TypedState, info: RPCChatType
547563 if ( ! messageID ) {
548564 return l
549565 }
550- const uiMsg = Constants . uiMessageToMessage ( state , conversationIDKey , msg )
566+ const uiMsg = Constants . uiMessageToMessage ( conversationIDKey , msg , username , getLastOrdinal , devicename )
551567 if ( ! uiMsg ) {
552568 return l
553569 }
@@ -1115,32 +1131,35 @@ function* loadMoreMessages(
11151131
11161132 const loadingKey = Constants . waitingKeyThreadLoad ( conversationIDKey )
11171133 let calledClear = false
1118- const onGotThread = ( thread : string ) => {
1119- if ( ! thread ) {
1120- return
1121- }
1134+ const onGotThread = ( thread : string ) =>
1135+ Saga . callUntyped ( function * ( ) {
1136+ if ( ! thread ) {
1137+ return
1138+ }
11221139
1123- const uiMessages : RPCChatTypes . UIMessages = JSON . parse ( thread )
1124- const actions : Array < Saga . PutEffect > = [ ]
1125- let shouldClearOthers = false
1126- if ( ( forceClear || sd === 'none' ) && ! calledClear ) {
1127- shouldClearOthers = true
1128- calledClear = true
1129- }
1130- const messages = ( uiMessages . messages ?? [ ] ) . reduce < Array < Types . Message > > ( ( arr , m ) => {
1131- const message = conversationIDKey ? Constants . uiMessageToMessage ( state , conversationIDKey , m ) : null
1132- if ( message ) {
1133- arr . push ( message )
1140+ const state = yield * Saga . selectState ( )
1141+ const { username, getLastOrdinal, devicename} = Constants . getMessageStateExtras ( state , conversationIDKey )
1142+ const uiMessages : RPCChatTypes . UIMessages = JSON . parse ( thread )
1143+ let shouldClearOthers = false
1144+ if ( ( forceClear || sd === 'none' ) && ! calledClear ) {
1145+ shouldClearOthers = true
1146+ calledClear = true
11341147 }
1135- return arr
1136- } , [ ] )
1148+ const messages = ( uiMessages . messages ?? [ ] ) . reduce < Array < Types . Message > > ( ( arr , m ) => {
1149+ const message = conversationIDKey
1150+ ? Constants . uiMessageToMessage ( conversationIDKey , m , username , getLastOrdinal , devicename )
1151+ : null
1152+ if ( message ) {
1153+ arr . push ( message )
1154+ }
1155+ return arr
1156+ } , [ ] )
11371157
1138- const moreToLoad = uiMessages . pagination ? ! uiMessages . pagination . last : true
1139- actions . push ( Saga . put ( Chat2Gen . createUpdateMoreToLoad ( { conversationIDKey, moreToLoad} ) ) )
1158+ const moreToLoad = uiMessages . pagination ? ! uiMessages . pagination . last : true
1159+ yield Saga . put ( Chat2Gen . createUpdateMoreToLoad ( { conversationIDKey, moreToLoad} ) )
11401160
1141- if ( messages . length ) {
1142- actions . push (
1143- Saga . put (
1161+ if ( messages . length ) {
1162+ yield Saga . put (
11441163 Chat2Gen . createMessagesAdd ( {
11451164 centeredMessageIDs,
11461165 context : { conversationIDKey, type : 'threadLoad' } ,
@@ -1149,11 +1168,8 @@ function* loadMoreMessages(
11491168 shouldClearOthers,
11501169 } )
11511170 )
1152- )
1153- }
1154-
1155- return actions
1156- }
1171+ }
1172+ } )
11571173
11581174 const onGotThreadLoadStatus = ( status : RPCChatTypes . UIChatThreadStatus ) => [
11591175 Saga . put ( Chat2Gen . createSetThreadLoadStatus ( { conversationIDKey, status} ) ) ,
@@ -1425,18 +1441,29 @@ const messageRetry = (action: Chat2Gen.MessageRetryPayload) => {
14251441}
14261442
14271443function * loadAttachmentView (
1428- state : Container . TypedState ,
1444+ _ : Container . TypedState ,
14291445 action : Chat2Gen . LoadAttachmentViewPayload ,
14301446 logger : Saga . SagaLogger
14311447) {
14321448 const { conversationIDKey, viewType, fromMsgID} = action . payload
14331449
1434- const onHit = ( hit : RPCChatTypes . MessageTypes [ 'chat.1.chatUi.chatLoadGalleryHit' ] [ 'inParam' ] ) => {
1435- const message = Constants . uiMessageToMessage ( state , conversationIDKey , hit . message )
1436- return message
1437- ? Saga . put ( Chat2Gen . createAddAttachmentViewMessage ( { conversationIDKey, message, viewType} ) )
1438- : [ ]
1439- }
1450+ const onHit = ( hit : RPCChatTypes . MessageTypes [ 'chat.1.chatUi.chatLoadGalleryHit' ] [ 'inParam' ] ) =>
1451+ Saga . callUntyped ( function * ( ) {
1452+ const state = yield * Saga . selectState ( )
1453+ const { username, getLastOrdinal, devicename} = Constants . getMessageStateExtras ( state , conversationIDKey )
1454+
1455+ const message = Constants . uiMessageToMessage (
1456+ conversationIDKey ,
1457+ hit . message ,
1458+ username ,
1459+ getLastOrdinal ,
1460+ devicename
1461+ )
1462+ if ( message ) {
1463+ yield Saga . put ( Chat2Gen . createAddAttachmentViewMessage ( { conversationIDKey, message, viewType} ) )
1464+ }
1465+ } )
1466+
14401467 try {
14411468 const res = yield RPCChatTypes . localLoadGalleryRpcSaga ( {
14421469 incomingCallMap : { 'chat.1.chatUi.chatLoadGalleryHit' : onHit } ,
@@ -1467,15 +1494,29 @@ function* threadSearch(
14671494 logger : Saga . SagaLogger
14681495) {
14691496 const { conversationIDKey, query} = action . payload
1497+
1498+ const { username, getLastOrdinal, devicename} = Constants . getMessageStateExtras ( state , conversationIDKey )
14701499 const onHit = ( hit : RPCChatTypes . MessageTypes [ 'chat.1.chatUi.chatSearchHit' ] [ 'inParam' ] ) => {
1471- const message = Constants . uiMessageToMessage ( state , conversationIDKey , hit . searchHit . hitMessage )
1500+ const message = Constants . uiMessageToMessage (
1501+ conversationIDKey ,
1502+ hit . searchHit . hitMessage ,
1503+ username ,
1504+ getLastOrdinal ,
1505+ devicename
1506+ )
14721507 return message
14731508 ? Saga . put ( Chat2Gen . createThreadSearchResults ( { clear : false , conversationIDKey, messages : [ message ] } ) )
14741509 : false
14751510 }
14761511 const onInboxHit = ( resp : RPCChatTypes . MessageTypes [ 'chat.1.chatUi.chatSearchInboxHit' ] [ 'inParam' ] ) => {
14771512 const messages = ( resp . searchHit . hits || [ ] ) . reduce < Array < Types . Message > > ( ( l , h ) => {
1478- const uiMsg = Constants . uiMessageToMessage ( state , conversationIDKey , h . hitMessage )
1513+ const uiMsg = Constants . uiMessageToMessage (
1514+ conversationIDKey ,
1515+ h . hitMessage ,
1516+ username ,
1517+ getLastOrdinal ,
1518+ devicename
1519+ )
14791520 if ( uiMsg ) {
14801521 l . push ( uiMsg )
14811522 }
0 commit comments