@@ -71,7 +71,8 @@ export function useGetMessagesProvider() {
7171
7272 const currentToken = useGetToken ( )
7373 const contextThreadId = useGetThreadId ( )
74- const conversation = computed < Conversation | undefined > ( ( ) => store . getters . conversation ( currentToken . value ) )
74+ /** Conversation object by currentToken ref. If required in an async context, store getter should be used instead */
75+ const currentConversation = computed < Conversation | undefined > ( ( ) => store . getters . conversation ( currentToken . value ) )
7576 const isInLobby = computed < boolean > ( ( ) => store . getters . isInLobby )
7677
7778 const contextMessageId = ref < number > ( 0 )
@@ -84,11 +85,11 @@ export function useGetMessagesProvider() {
8485 * Returns whether the current participant is a participant of current conversation.
8586 */
8687 const isParticipant = computed < boolean > ( ( ) => {
87- if ( ! conversation . value ) {
88+ if ( ! currentConversation . value ) {
8889 return false
8990 }
9091
91- return ! ! store . getters . findParticipant ( currentToken . value , conversation . value ) ?. attendeeId
92+ return ! ! store . getters . findParticipant ( currentToken . value , currentConversation . value ) ?. attendeeId
9293 } )
9394
9495 const isChatBeginningReached = computed ( ( ) => {
@@ -120,17 +121,16 @@ export function useGetMessagesProvider() {
120121 }
121122 }
122123
123- if ( conversation . value ?. lastMessage && 'id' in conversation . value . lastMessage ) {
124- return conversation . value . lastMessage . id
124+ if ( currentConversation . value ?. lastMessage && 'id' in currentConversation . value . lastMessage ) {
125+ return currentConversation . value . lastMessage . id
125126 }
126127
127128 // Federated conversations do not provide lastMessage.id, fallback to last known message
128129 return chatStore . getLastKnownId ( currentToken . value , { threadId : contextThreadId . value } )
129130 } )
130131
131132 const isChatEndReached = computed ( ( ) => {
132- const conversation = store . getters . conversation ( currentToken . value ) as Conversation | undefined
133- if ( ! conversation || ! conversation . lastMessage ) {
133+ if ( ! currentConversation . value || ! currentConversation . value . lastMessage ) {
134134 // Do not block attempts to fetch new messages inside each block
135135 return false
136136 }
@@ -243,12 +243,13 @@ export function useGetMessagesProvider() {
243243 // the hash is non-empty, need to focus/highlight another message
244244 contextMessageId . value = focusMessageId
245245 } else {
246+ const conversation : Conversation | undefined = store . getters . conversation ( to . params . token )
246247 // try to focus last read message first, otherwise scroll to last known message in the most recent block store
247- const hasLastReadMessageInContextBelow = conversation . value ?. lastReadMessage && conversation . value . lastReadMessage > contextMessageId . value
248- && ( ! contextThreadId . value || chatStore . hasMessage ( to . params . token , { messageId : conversation . value . lastReadMessage , threadId : contextThreadId . value } ) )
248+ const hasLastReadMessageInContextBelow = conversation ?. lastReadMessage && conversation . lastReadMessage > contextMessageId . value
249+ && ( ! contextThreadId . value || chatStore . hasMessage ( to . params . token , { messageId : conversation . lastReadMessage , threadId : contextThreadId . value } ) )
249250
250251 contextMessageId . value = hasLastReadMessageInContextBelow
251- ? conversation . value . lastReadMessage
252+ ? conversation . lastReadMessage
252253 : conversationLastMessageId . value
253254 }
254255
@@ -314,9 +315,9 @@ export function useGetMessagesProvider() {
314315
315316 // Start from message hash or unread marker
316317 const focusMessageId = getMessageIdFromHash ( route . hash )
317- contextMessageId . value = focusMessageId !== null ? focusMessageId : conversation . value ! . lastReadMessage
318+ contextMessageId . value = focusMessageId !== null ? focusMessageId : currentConversation . value ! . lastReadMessage
318319
319- store . dispatch ( 'setVisualLastReadMessageId' , { token, id : conversation . value ! . lastReadMessage } )
320+ store . dispatch ( 'setVisualLastReadMessageId' , { token, id : currentConversation . value ! . lastReadMessage } )
320321
321322 if ( ! chatStore . chatBlocks [ token ] ) {
322323 try {
@@ -330,18 +331,20 @@ export function useGetMessagesProvider() {
330331 console . debug ( exception )
331332 }
332333
334+ // Checking after server response, compare to actual conversation in store
335+ const conversation : Conversation | undefined = store . getters . conversation ( token )
333336 // If last message is not present in the initial context,
334337 // add it as most recent chat block to start long polling from it
335- if ( conversation . value ?. lastMessage && 'id' in conversation . value . lastMessage
336- && ! chatStore . hasMessage ( token , { messageId : conversation . value . lastMessage . id } ) ) {
337- await store . dispatch ( 'processMessage' , { token, message : conversation . value . lastMessage } )
338- chatStore . processChatBlocks ( token , [ conversation . value . lastMessage ] )
338+ if ( conversation ?. lastMessage && 'id' in conversation . lastMessage
339+ && ! chatStore . hasMessage ( token , { messageId : conversation . lastMessage . id } ) ) {
340+ await store . dispatch ( 'processMessage' , { token, message : conversation . lastMessage } )
341+ chatStore . processChatBlocks ( token , [ conversation . lastMessage ] )
339342 }
340343
341344 // Fallback for sensitive and federated conversations: if there is still no chat block created,
342345 // ensure polling starts at least from the last read message by the user
343346 if ( ! chatStore . chatBlocks [ token ] ) {
344- chatStore . chatBlocks [ token ] = [ new Set ( [ conversation . value ! . lastReadMessage ] ) ]
347+ chatStore . chatBlocks [ token ] = [ new Set ( [ conversation ! . lastReadMessage ] ) ]
345348 }
346349 } else {
347350 await checkContextAndFocusMessage ( token , contextMessageId . value , contextThreadId . value , focusMessageId !== null )
@@ -630,7 +633,7 @@ export function useGetMessagesProvider() {
630633 }
631634
632635 // Patch for federated conversations: disable unsupported file shares
633- if ( conversation . value ?. remoteServer && Object . keys ( message . messageParameters ?? { } ) . some ( ( key ) => key . startsWith ( 'file' ) )
636+ if ( conversation ?. remoteServer && Object . keys ( message . messageParameters ?? { } ) . some ( ( key ) => key . startsWith ( 'file' ) )
634637 && [ MESSAGE . TYPE . COMMENT , MESSAGE . TYPE . VOICE_MESSAGE , MESSAGE . TYPE . RECORD_VIDEO , MESSAGE . TYPE . RECORD_AUDIO ] . includes ( message . messageType ) ) {
635638 message . message = '*' + t ( 'spreed' , 'File shares are currently not supported in federated conversations' ) + '*'
636639 delete message . messageParameters . file
0 commit comments