Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export default {
},

scrollToBottom() {
this.$router.replace({ hash: '' })
// Reset the hash from focused message id (but keep the thread id)
this.$router.replace({ query: this.$route.query, hash: '' })
EventBus.emit('scroll-chat-to-bottom', { smooth: false, force: true })
},
},
Expand Down
11 changes: 3 additions & 8 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,9 @@ export default {
* @return {Array}
*/
messagesList() {
if (!this.threadId) {
return this.chatStore.getMessagesList(this.token)
}

return this.chatStore.getMessagesList(this.token)
.filter((message) => {
return message.threadId === this.threadId
})
return this.chatStore.getMessagesList(this.token, {
threadId: this.threadId,
})
},

isMessagesListPopulated() {
Expand Down
4 changes: 3 additions & 1 deletion src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,9 @@ export default {
}

// last message within 24 hours
const lastMessageByCurrentUser = this.chatStore.getMessagesList(this.token).findLast((message) => {
const lastMessageByCurrentUser = this.chatStore.getMessagesList(this.token, {
threadId: this.threadId,
}).findLast((message) => {
return this.actorStore.checkIfSelfIsActor(message)
&& !message.isTemporary && !message.systemMessage
&& (Date.now() - message.timestamp * 1000 < ONE_DAY_IN_MS)
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useDocumentTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function useDocumentTitle() {
} else {
// @ts-expect-error: Property 'id' does not exist on type ChatProxyMessage
const lastMessageId = lastMessage.id ?? 0
const lastKnownMessageId = Math.max(...chatStore.chatBlocks[token][0]) ?? 0
const lastKnownMessageId = chatStore.chatBlocks[token] ? Math.max(...chatStore.chatBlocks[token][0]) : 0
acc[token].lastMessageId = Math.max(lastMessageId, lastKnownMessageId)
}
acc[token].unreadMessages = unreadMessages
Expand Down
13 changes: 8 additions & 5 deletions src/composables/useGetMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export function useGetMessagesProvider() {
const hasMessageInStore = ('id' in (store.getters.message(to.params.token, focusMessageId) as ChatMessage | Record<string, never>))
if (!hasMessageInStore) {
// message not found in the list, need to fetch it first
await getMessageContext(to.params.token, focusMessageId)
await getMessageContext(to.params.token, focusMessageId, threadId.value)
}
// need some delay (next tick is too short) to be able to run
// after the browser's native "scroll to anchor" from the hash
Expand All @@ -191,7 +191,7 @@ export function useGetMessagesProvider() {
// FIXME temporary get thread messages from the start
const hasMessageInStore = ('id' in (store.getters.message(to.params.token, to.query.threadId) as ChatMessage | Record<string, never>))
if (!hasMessageInStore) {
await getMessageContext(to.params.token, +to.query.threadId)
await getMessageContext(to.params.token, +to.query.threadId, +to.query.threadId)
}
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ export function useGetMessagesProvider() {
throw new Error(`[DEBUG] spreed: context message ID is ${startingMessageId}`)
}

await getMessageContext(token, startingMessageId)
await getMessageContext(token, startingMessageId, threadId.value)
} catch (exception) {
console.debug(exception)
// Request was cancelled, stop getting preconditions and restore initial state
Expand All @@ -242,9 +242,10 @@ export function useGetMessagesProvider() {
* Fetches the messages of a conversation given the conversation token.
* Creates a long polling request for new messages.
* @param token token of conversation where a method was called
* @param messageId messageId
* @param messageId context messageId
* @param threadId context thread id
*/
async function getMessageContext(token: string, messageId: number) {
async function getMessageContext(token: string, messageId: number, threadId: number) {
loadingOldMessages.value = true
try {
debugTimer.start(`${token} | get context`)
Expand All @@ -258,6 +259,7 @@ export function useGetMessagesProvider() {
// using 0 as the API does not support negative values
// Get chat messages before last read message and after it
messageId: messageId !== MESSAGE.CHAT_BEGIN_ID ? messageId : 0,
threadId: threadId !== 0 ? threadId : undefined,
minimumVisible: CHAT.MINIMUM_VISIBLE,
})
debugTimer.end(`${token} | get context`, 'status 200')
Expand Down Expand Up @@ -301,6 +303,7 @@ export function useGetMessagesProvider() {
token,
lastKnownMessageId: store.getters.getFirstKnownMessageId(token),
includeLastKnown,
threadId: threadId.value !== 0 ? threadId.value : undefined,
minimumVisible: CHAT.MINIMUM_VISIBLE,
})
debugTimer.end(`${token} | fetch history`, 'status 200')
Expand Down
2 changes: 2 additions & 0 deletions src/services/messagesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type EditMessagePayload = { token: string, messageId: number, updatedMessage: ed
* @param data.token the conversation token;
* @param data.lastKnownMessageId last known message id;
* @param data.includeLastKnown whether to include the last known message in the response;
* @param data.threadId The thread id to retrieve data
* @param [data.lookIntoFuture=0] direction of message fetch
* @param [data.limit=100] Number of messages to load
* @param [options] Axios request options
Expand Down Expand Up @@ -110,6 +111,7 @@ async function pollNewMessages({
* @param data the wrapping object;
* @param data.token the conversation token;
* @param data.messageId last known message id;
* @param data.threadId The thread id to retrieve data
* @param [data.limit=50] Number of messages to load
* @param [options] Axios request options
*/
Expand Down
18 changes: 16 additions & 2 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ const actions = {
* @param {string} data.token the conversation token;
* @param {object} data.requestOptions request options;
* @param {string} data.lastKnownMessageId last known message id;
* @param {number} data.threadId Thread id to fetch messages for;
* @param {number} data.minimumVisible Minimum number of chat messages we want to load
* @param {boolean} data.includeLastKnown whether to include the last known message in the response;
* @param {number} [data.lookIntoFuture=0] direction of message fetch
Expand All @@ -944,6 +945,7 @@ const actions = {
token,
lastKnownMessageId,
includeLastKnown,
threadId,
requestOptions,
minimumVisible,
lookIntoFuture = CHAT.FETCH_OLD,
Expand All @@ -961,6 +963,7 @@ const actions = {
token,
lastKnownMessageId,
includeLastKnown,
threadId,
lookIntoFuture,
limit: CHAT.FETCH_LIMIT,
}, requestOptions)
Expand Down Expand Up @@ -1018,6 +1021,7 @@ const actions = {
const chatStore = useChatStore()
chatStore.processChatBlocks(token, response.data.ocs.data, {
mergeBy: +lastKnownMessageId,
threadId,
})

if (minimumVisible > 0) {
Expand All @@ -1031,6 +1035,7 @@ const actions = {
token,
lastKnownMessageId,
includeLastKnown,
threadId,
lookIntoFuture,
minimumVisible,
})
Expand All @@ -1047,10 +1052,17 @@ const actions = {
* @param {object} data the wrapping object;
* @param {string} data.token the conversation token;
* @param {number} data.messageId Message id to get the context for;
* @param {number} data.threadId Thread id to get the context for;
* @param {object} data.requestOptions request options;
* @param {number} data.minimumVisible Minimum number of chat messages we want to load
*/
async getMessageContext(context, { token, messageId, requestOptions, minimumVisible }) {
async getMessageContext(context, {
token,
messageId,
threadId,
requestOptions,
minimumVisible,
}) {
minimumVisible = (typeof minimumVisible === 'undefined') ? Math.floor(CHAT.MINIMUM_VISIBLE / 2) : minimumVisible

context.dispatch('cancelGetMessageContext')
Expand All @@ -1063,6 +1075,7 @@ const actions = {
const response = await request({
token,
messageId,
threadId,
limit: CHAT.FETCH_LIMIT / 2,
}, requestOptions)

Expand Down Expand Up @@ -1116,7 +1129,7 @@ const actions = {
context.commit('loadedMessagesOfConversation', { token })

const chatStore = useChatStore()
chatStore.processChatBlocks(token, response.data.ocs.data)
chatStore.processChatBlocks(token, response.data.ocs.data, { threadId })

if (minimumVisible > 0) {
debugTimer.tick(`${token} | get context`, 'first chunk')
Expand All @@ -1126,6 +1139,7 @@ const actions = {
token,
lastKnownMessageId: context.getters.getFirstKnownMessageId(token),
includeLastKnown: false,
threadId,
lookIntoFuture: CHAT.FETCH_OLD,
minimumVisible: minimumVisible * 2,
})
Expand Down
Loading