Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Tweak read marker behavior
When no scrolling is possible, add delay before clearing.

Small related code cleanup.

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 committed Mar 8, 2021
commit b99adb66bc0af2c56fda909b8fc60d197905c509
11 changes: 8 additions & 3 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,11 @@ export default {

// if no scrollbars, clear read marker directly as scrolling is not possible for the user to clear it
// also clear in case lastReadMessage is zero which is due to an older bug
if (this.conversation.lastReadMessage === 0 || (this.isWindowVisible && document.hasFocus() && this.scroller.scrollHeight <= this.scroller.offsetHeight)) {
this.$store.dispatch('clearLastReadMessage', { token: this.token })
if (this.conversation.lastReadMessage === 0
|| (this.isWindowVisible && document.hasFocus() && this.scroller.scrollHeight <= this.scroller.offsetHeight)
) {
// clear after a delay, unless scrolling can resume in-between
this.debounceUpdateReadMarkerAfterScroll()
}
},

Expand Down Expand Up @@ -752,7 +755,9 @@ export default {
}

// if we're at bottom of the chat and focussed, then simply clear the marker
if (this.isSticky && this.isWindowVisible && document.hasFocus()) {
if (this.conversation.lastReadMessage === 0
|| (this.isSticky && this.isWindowVisible && document.hasFocus())
) {
this.$store.dispatch('clearLastReadMessage', { token: this.token })
return
}
Expand Down
11 changes: 3 additions & 8 deletions src/services/messagesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,9 @@ const postRichObjectToConversation = async function(token, { objectType, objectI
* @param {int} lastReadMessage id of the last read message to set
*/
const updateLastReadMessage = async function(token, lastReadMessage) {
try {
const response = await axios.post(generateOcsUrl('apps/spreed/api/v1', 2) + `chat/${token}/read`, {
lastReadMessage,
})
return response
} catch (error) {
console.error(`Error while updating the last read message to {lastReadMessage}`, error)
}
return axios.post(generateOcsUrl('apps/spreed/api/v1', 2) + `chat/${token}/read`, {
lastReadMessage,
})
}

export {
Expand Down
2 changes: 0 additions & 2 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ const actions = {
// optimistic early commit to avoid indicator flickering
context.commit('updateConversationLastReadMessage', { token, lastReadMessage: id })
await updateLastReadMessage(token, id)

// TODO: update unread counters if possible (otherwise user needs to wait for conversation list refresh)
},
}

Expand Down