Skip to content

Commit

Permalink
Switch+scroll to joined listed conversation
Browse files Browse the repository at this point in the history
When joining a listed conversation, the left sidebar now switches back
to the full list and displays a temporary entry while the joining
process is running.

When joining a conversation, the conversation list now automatically
scrolls to the item. It often happens that listable conversation entries
appear lower in the list, so they need to be made visible.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
  • Loading branch information
PVince81 committed Dec 3, 2020
1 parent 9058292 commit 2fc5379
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
15 changes: 13 additions & 2 deletions src/components/LeftSidebar/ConversationsList/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
<AppContentListItem
:title="item.displayName"
:anchor-id="`conversation_${item.token}`"
:to="{ name: 'conversation', params: { token: item.token }}"
:class="{ 'has-unread-messages': item.unreadMessages }">
:to="!isSearchResult ? { name: 'conversation', params: { token: item.token }} : ''"
:class="{ 'has-unread-messages': item.unreadMessages }"
@click="onClick">
<template v-slot:icon>
<ConversationIcon
:item="item"
Expand Down Expand Up @@ -196,6 +197,11 @@ export default {
},

conversationInformation() {
// temporary item while joining
if (!this.isSearchResult && !this.item.actorId) {
return t('spreed', 'Joining conversation...')
}

if (!Object.keys(this.lastChatMessage).length) {
return ''
}
Expand Down Expand Up @@ -361,6 +367,11 @@ export default {
await setNotificationLevel(this.item.token, level)
this.item.notificationLevel = level
},

// forward click event
onClick(event) {
this.$emit('click', event)
},
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,21 @@ export default {
mounted() {
EventBus.$on('routeChange', this.onRouteChange)
EventBus.$on('newMessagePosted', this.onMessagePosted)
EventBus.$on('joinedConversation', this.onJoinedConversation)
},

beforeDestroy() {
EventBus.$off('routeChange', this.onRouteChange)
EventBus.$off('newMessagePosted', this.onMessagePosted)
EventBus.$off('joinedConversation', this.onJoinedConversation)
},

methods: {
onMessagePosted({ token }) {
scrollToConversation(token) {
const conversation = document.getElementById(`conversation_${token}`)
if (!conversation) {
return
}
this.$nextTick(() => {
conversation.scrollIntoView({
behavior: 'smooth',
Expand All @@ -94,6 +99,12 @@ export default {
})
})
},
onJoinedConversation({ token }) {
this.scrollToConversation(token)
},
onMessagePosted({ token }) {
this.scrollToConversation(token)
},
onRouteChange({ from, to }) {
if (from.name === 'conversation'
&& to.name === 'conversation'
Expand Down
24 changes: 8 additions & 16 deletions src/components/LeftSidebar/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
:key="item.id"
:item="item"
:is-search-result="true"
@click="joinListedConversation" />
@click="joinListedConversation(item)" />
</template>
<template v-if="searchResultsUsers.length !== 0">
<Caption
Expand Down Expand Up @@ -299,13 +299,6 @@ export default {
this.focusInitialise()
},

async joinListedConversation(item) {
// there's already an event handler in Component.vue that will take care
// of switching the route,
// so all we need to do today is reset the UI
EventBus.$emit('resetSearchFilter')
},

/**
* Create a new conversation with the selected group/user/circle
* @param {Object} item The autocomplete suggestion to start a conversation with
Expand All @@ -325,6 +318,13 @@ export default {
EventBus.$emit('resetSearchFilter')
},

async joinListedConversation(conversation) {
// add as temporary item that will refresh after the joining process is complete
this.$store.dispatch('addConversation', conversation)
this.$router.push({ name: 'conversation', params: { token: conversation.token } }).catch(err => console.debug(`Error while pushing the new conversation's route: ${err}`))
EventBus.$emit('resetSearchFilter')
},

hasOneToOneConversationWith(userId) {
return !!this.conversationsList.find(conversation => conversation.type === CONVERSATION.TYPE.ONE_TO_ONE && conversation.name === userId)
},
Expand All @@ -341,14 +341,6 @@ export default {
handleClickSearchResult(selectedConversationToken) {
// End the search operation
this.abortSearch()
const selectedConversation = document.getElementById(`conversation_${selectedConversationToken}`)
this.$nextTick(() => {
selectedConversation.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'nearest',
})
})
},

sortConversations(conversation1, conversation2) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/participantsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const joinConversation = async(token) => {
// FIXME Signaling should not be synchronous
await signalingJoinConversation(token, response.data.ocs.data.sessionId)
SessionStorage.setItem('joined_conversation', token)
EventBus.$emit('joinedConversation')
EventBus.$emit('joinedConversation', { token })
return response
} catch (error) {
if (error.response.status === 409) {
Expand Down

0 comments on commit 2fc5379

Please sign in to comment.