Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] feat: handle callUser links in Talk without page reload #12047

Merged
merged 1 commit into from
Apr 10, 2024
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
4 changes: 4 additions & 0 deletions src/store/conversationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ const getters = {
&& !getters.isModerator
&& (conversation.permissions & PARTICIPANT.PERMISSIONS.LOBBY_IGNORE) === 0
},
getConversationForUser: (state, getters) => {
return (userId) => getters.conversationsList
.find((conversation) => conversation.type === CONVERSATION.TYPE.ONE_TO_ONE && conversation.name === userId)
},
}

const mutations = {
Expand Down
87 changes: 83 additions & 4 deletions src/views/WelcomeView.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<template>
<EmptyView :name="t('spreed', 'Join a conversation or start a new one')"
:description="t('spreed', 'Say hi to your friends and colleagues!')">
<EmptyView :name="text.name"
:description="text.description">
<template #icon>
<NcIconSvgWrapper :svg="IconTalk" />
<NcLoadingIcon v-if="callUser" />
<NcIconSvgWrapper v-else :svg="IconTalk" />
</template>
</EmptyView>
</template>

<script>
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'

import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'

import EmptyView from '../components/EmptyView.vue'

Expand All @@ -19,12 +24,86 @@ export default {

components: {
EmptyView,
NcIconSvgWrapper
NcIconSvgWrapper,
NcLoadingIcon,
},

setup() {
return {
IconTalk,
}
},

data() {
return {
isCreatingConversationForCallUser: false,
}
},

computed: {
callUser() {
return this.$route.query.callUser
},

text() {
if (this.isCreatingConversationForCallUser) {
return {
name: t('spreed', 'Creating and joining a conversation with "{userid}"', { userid: this.callUser }),
description: '',
}
}

if (this.callUser) {
return {
name: t('spreed', 'Joining a conversation with "{userid}"', { userid: this.callUser }),
description: '',
}
}

return {
name: t('spreed', 'Join a conversation or start a new one'),
description: t('spreed', 'Say hi to your friends and colleagues!'),
}
}
},

watch: {
callUser: {
immediate: true,
handler() {
if (this.callUser) {
this.createAndJoinConversationForCallUser()
}
}
}
},

methods: {
async createAndJoinConversationForCallUser() {
// Try to find an existing conversation
const conversation = this.$store.getters.getConversationForUser(this.callUser)
if (conversation) {
this.$router.push({
name: 'conversation',
params: { token: conversation.token },
})
return
}

// Create a new one-to-one conversation
this.isCreatingConversationForCallUser = true
try {
const newConversation = await this.$store.dispatch('createOneToOneConversation', this.callUser)
this.$router.push({
name: 'conversation',
params: { token: newConversation.token },
})
} catch (error) {
showError(t('spreed', 'Error while joining the conversation'))
console.error(error)
this.$router.push({ name: 'notfound' })
}
},
}
}
</script>
Loading