[feature] open chat page via link from single chat window and open the used room after loading

This commit is contained in:
Markus 2023-07-19 15:54:31 +02:00
parent 332340ed07
commit 5bae7cbd94
2 changed files with 52 additions and 10 deletions

View File

@ -4,7 +4,7 @@
<vue-advanced-chat <vue-advanced-chat
:theme="theme" :theme="theme"
:current-user-id="currentUser.id" :current-user-id="currentUser.id"
:room-id="!singleRoom ? roomId : null" :room-id="computedRoomId"
:template-actions="JSON.stringify(templatesText)" :template-actions="JSON.stringify(templatesText)"
:menu-actions="JSON.stringify(menuActions)" :menu-actions="JSON.stringify(menuActions)"
:text-messages="JSON.stringify(textMessages)" :text-messages="JSON.stringify(textMessages)"
@ -27,10 +27,28 @@
show-reaction-emojis="false" show-reaction-emojis="false"
@show-demo-options="showDemoOptions = $event" @show-demo-options="showDemoOptions = $event"
> >
<div slot="menu-icon" @click.prevent.stop="$emit('close-single-room', true)"> <div
<div v-if="singleRoom"> v-if="selectedRoom && selectedRoom.roomId"
<ds-icon name="close"></ds-icon> slot="room-options"
class="chat-room-options"
>
<ds-flex v-if="singleRoom">
<ds-flex-item centered class="single-chat-bubble">
<nuxt-link :to="{ name: 'chat' }">
<base-icon name="chat-bubble" />
</nuxt-link>
</ds-flex-item>
<ds-flex-item centered>
<div
class="vac-svg-button vac-room-options"
@click="$emit('close-single-room', true)"
>
<slot name="menu-icon">
<ds-icon name="close" />
</slot>
</div> </div>
</ds-flex-item>
</ds-flex>
</div> </div>
<div slot="room-header-avatar"> <div slot="room-header-avatar">
@ -89,11 +107,6 @@ export default {
data() { data() {
return { return {
menuActions: [ menuActions: [
// NOTE: if menuActions is empty, the related slot is not shown
{
name: 'dummyItem',
title: 'Just a dummy item',
},
/* /*
{ {
name: 'inviteUser', name: 'inviteUser',
@ -197,10 +210,24 @@ export default {
computed: { computed: {
...mapGetters({ ...mapGetters({
currentUser: 'auth/user', currentUser: 'auth/user',
getStoreRoomId: 'chat/roomID',
}), }),
computedChatStyle() { computedChatStyle() {
return chatStyle.STYLE.light return chatStyle.STYLE.light
}, },
computedRoomId() {
let roomId = null
if (!this.singleRoom) {
roomId = this.roomId
if (this.getStoreRoomId.roomId) {
roomId = this.getStoreRoomId.roomId
}
}
return roomId
},
textMessages() { textMessages() {
return { return {
ROOMS_EMPTY: this.$t('chat.roomsEmpty'), ROOMS_EMPTY: this.$t('chat.roomsEmpty'),
@ -221,6 +248,7 @@ export default {
methods: { methods: {
...mapMutations({ ...mapMutations({
commitUnreadRoomCount: 'chat/UPDATE_ROOM_COUNT', commitUnreadRoomCount: 'chat/UPDATE_ROOM_COUNT',
commitRoomIdFromSingleRoom: 'chat/UPDATE_ROOM_ID',
}), }),
async fetchRooms({ room } = {}) { async fetchRooms({ room } = {}) {
this.roomsLoaded = false this.roomsLoaded = false
@ -253,6 +281,13 @@ export default {
this.roomsLoaded = true this.roomsLoaded = true
} }
this.roomPage += 1 this.roomPage += 1
if (this.singleRoom && this.rooms.length > 0) {
this.commitRoomIdFromSingleRoom(this.rooms[0].roomId)
} else if (this.getStoreRoomId.roomId) {
// reset store room id
this.commitRoomIdFromSingleRoom(null)
}
} catch (error) { } catch (error) {
this.rooms = [] this.rooms = []
this.$toast.error(error.message) this.$toast.error(error.message)
@ -389,4 +424,8 @@ body {
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
} }
.single-chat-bubble {
margin-right: 1em;
}
</style> </style>

View File

@ -14,6 +14,9 @@ export const mutations = {
UPDATE_ROOM_COUNT(state, count) { UPDATE_ROOM_COUNT(state, count) {
state.unreadRoomCount = count state.unreadRoomCount = count
}, },
UPDATE_ROOM_ID(state, roomid) {
state.roomId = roomid || null
},
} }
export const getters = { export const getters = {