@@ -97,7 +97,7 @@ const getters = {
9797 return conversation . objectType !== 'room'
9898 } ) ,
9999 /**
100- * Get a conversation providing it's token
100+ * Get a conversation providing its token
101101 *
102102 * @param {object } state state object
103103 * @return {Function } The callback function returning the conversation object
@@ -146,13 +146,16 @@ const mutations = {
146146 Vue . set ( state . conversations [ token ] , 'lastMessage' , lastMessage )
147147 } ,
148148
149- updateUnreadMessages ( state , { token, unreadMessages, unreadMention } ) {
149+ updateUnreadMessages ( state , { token, unreadMessages, unreadMention, unreadMentionDirect } ) {
150150 if ( unreadMessages !== undefined ) {
151151 Vue . set ( state . conversations [ token ] , 'unreadMessages' , unreadMessages )
152152 }
153153 if ( unreadMention !== undefined ) {
154154 Vue . set ( state . conversations [ token ] , 'unreadMention' , unreadMention )
155155 }
156+ if ( unreadMentionDirect !== undefined ) {
157+ Vue . set ( state . conversations [ token ] , 'unreadMentionDirect' , unreadMentionDirect )
158+ }
156159 } ,
157160
158161 overwriteHasCallByChat ( state , { token, hasCall } ) {
@@ -477,6 +480,107 @@ const actions = {
477480 }
478481 } ,
479482
483+ async updateConversationLastMessageFromNotification ( { getters, commit } , { notification } ) {
484+ const [ token , messageId ] = notification . objectId . split ( '/' )
485+ const conversation = { ...getters . conversation ( token ) }
486+
487+ if ( ! conversation ) {
488+ // Conversation not loaded yet, skipping
489+ return
490+ }
491+
492+ const actor = notification . subjectRichParameters . user || notification . subjectRichParameters . guest || {
493+ type : 'guest' ,
494+ id : 'unknown' ,
495+ name : t ( 'spreed' , 'Guest' ) ,
496+ }
497+
498+ const lastMessage = {
499+ token,
500+ id : parseInt ( messageId , 10 ) ,
501+ actorType : actor . type + 's' ,
502+ actorId : actor . id ,
503+ actorDisplayName : actor . name ,
504+ message : notification . messageRich ,
505+ messageParameters : notification . messageRichParameters ,
506+ timestamp : ( new Date ( notification . datetime ) ) . getTime ( ) / 1000 ,
507+
508+ // Inaccurate but best effort from here on:
509+ expirationTimestamp : 0 ,
510+ isReplyable : true ,
511+ messageType : 'comment' ,
512+ reactions : { } ,
513+ referenceId : '' ,
514+ systemMessage : '' ,
515+ }
516+
517+ const unreadCounterUpdate = {
518+ token,
519+ unreadMessages : conversation . unreadMessages ,
520+ unreadMention : conversation . unreadMention ,
521+ unreadMentionDirect : conversation . unreadMentionDirect ,
522+ }
523+
524+ if ( conversation . type === CONVERSATION . TYPE . ONE_TO_ONE ) {
525+ unreadCounterUpdate . unreadMessages ++
526+ unreadCounterUpdate . unreadMention ++
527+ unreadCounterUpdate . unreadMentionDirect = true
528+ } else {
529+ unreadCounterUpdate . unreadMessages ++
530+ Object . keys ( notification . messageRichParameters ) . forEach ( function ( p ) {
531+ const parameter = notification . messageRichParameters [ p ]
532+ if ( parameter . type === 'user' && parameter . id === notification . user ) {
533+ unreadCounterUpdate . unreadMention ++
534+ unreadCounterUpdate . unreadMentionDirect = true
535+ } else if ( parameter . type === 'call' && parameter . id === token ) {
536+ unreadCounterUpdate . unreadMention ++
537+ }
538+ } )
539+ }
540+ conversation . lastActivity = lastMessage . timestamp
541+
542+ commit ( 'addConversation' , conversation )
543+ commit ( 'updateConversationLastMessage' , { token, lastMessage } )
544+ commit ( 'updateUnreadMessages' , unreadCounterUpdate )
545+ } ,
546+
547+ async updateCallStateFromNotification ( { getters, commit } , { notification } ) {
548+ const token = notification . objectId
549+ const conversation = { ...getters . conversation ( token ) }
550+
551+ if ( ! conversation ) {
552+ // Conversation not loaded yet, skipping
553+ return
554+ }
555+
556+ conversation . hasCall = true
557+ conversation . callFlag = PARTICIPANT . CALL_FLAG . WITH_VIDEO
558+ conversation . activeSince = ( new Date ( notification . datetime ) ) . getTime ( ) / 1000
559+ conversation . lastActivity = conversation . activeSince
560+ conversation . callStartTime = conversation . activeSince
561+
562+ // Inaccurate but best effort from here on:
563+ const lastMessage = {
564+ token,
565+ id : 'temp' + conversation . activeSince ,
566+ actorType : 'guests' ,
567+ actorId : 'unknown' ,
568+ actorDisplayName : t ( 'spreed' , 'Guest' ) ,
569+ message : notification . subjectRich ,
570+ messageParameters : notification . subjectRichParameters ,
571+ timestamp : conversation . activeSince ,
572+ messageType : 'system' ,
573+ systemMessage : 'call_started' ,
574+ expirationTimestamp : 0 ,
575+ isReplyable : false ,
576+ reactions : { } ,
577+ referenceId : '' ,
578+ }
579+
580+ commit ( 'updateConversationLastMessage' , { token, lastMessage } )
581+ commit ( 'addConversation' , conversation )
582+ } ,
583+
480584 async updateConversationLastReadMessage ( { commit } , { token, lastReadMessage } ) {
481585 commit ( 'updateConversationLastReadMessage' , { token, lastReadMessage } )
482586 } ,
0 commit comments