keanu-weblite/src/components/ChatHeader.vue

110 lines
2.7 KiB
Vue
Raw Normal View History

2020-12-04 17:15:18 +01:00
<template>
2020-12-09 15:20:50 +01:00
<v-container fluid v-if="room">
2020-12-04 17:15:18 +01:00
<v-row class="chat-header-row">
<v-col
class="chat-header-members text-center flex-grow-0 flex-shrink-1 ma-0 pa-0"
>
<v-avatar size="40">
2020-12-09 15:20:50 +01:00
<v-img :src="room.avatar" />
</v-avatar>
2020-12-04 17:15:18 +01:00
</v-col>
<v-col class="flex-grow-1 flex-shrink-1 ma-0 pa-0">
<div class="room-name" @click.stop="showRoomList = true">{{ room.summary.info.title }} <v-icon>expand_more</v-icon></div>
<RoomList v-if="showRoomList" v-click-outside="hideRoomList" @close="hideRoomList" />
2020-12-09 15:20:50 +01:00
<div class="num-members">{{ memberCount }}{{ memberCount > 1 ? " members" : " member" }}</div>
2020-12-04 17:15:18 +01:00
</v-col>
<v-col class="text-center flex-grow-0 flex-shrink-1 ma-0 pa-0">
<v-btn text class="info-button" @click.stop="showRoomInfo"><v-icon color="black">info</v-icon></v-btn>
</v-col>
2020-12-04 17:15:18 +01:00
<v-col class="text-center flex-grow-0 flex-shrink-1 ma-0 pa-0">
2020-12-09 15:20:50 +01:00
<v-btn text class="leave-button" @click.stop="leaveRoom">Leave</v-btn>
2020-12-04 17:15:18 +01:00
</v-col>
</v-row>
<!-- "REALLY LEAVE?" dialog -->
<LeaveRoomDialog :show="showLeaveConfirmation" :room="room" @close="showLeaveConfirmation = false" />
2020-12-04 17:15:18 +01:00
</v-container>
</template>
<script>
import LeaveRoomDialog from '../components/LeaveRoomDialog';
import RoomList from "../components/RoomList";
2020-12-04 17:15:18 +01:00
export default {
name: "ChatHeader",
components: {
LeaveRoomDialog,
RoomList
},
2020-12-04 17:15:18 +01:00
data() {
return {
memberCount: null,
showRoomList: false,
showLeaveConfirmation: false
2020-12-04 17:15:18 +01:00
};
},
mounted() {
this.$matrix.on("Room.timeline", this.onEvent);
this.updateMemberCount();
},
destroyed() {
this.$matrix.off("Room.timeline", this.onEvent);
},
computed: {
room() {
return this.$matrix.currentRoom;
},
},
watch: {
room: {
handler(newVal, ignoredOldVal) {
2020-12-09 15:20:50 +01:00
if (newVal) {
this.memberCount = newVal.getJoinedMemberCount();
} else {
this.memberCount = null;
}
2020-12-04 17:15:18 +01:00
},
},
},
methods: {
onEvent(event) {
if (event.getRoomId() !== this.roomId) {
return; // Not for this room
}
if (event.getType() == "m.room.member") {
this.updateMemberCount();
}
},
updateMemberCount() {
2021-01-11 17:42:58 +01:00
if (!this.room) {
this.memberCount = 0;
} else {
this.memberCount = this.room.getJoinedMemberCount();
}
2020-12-04 17:15:18 +01:00
},
showRoomInfo() {
2021-01-12 11:32:24 +01:00
this.$navigation.push({ name: "RoomInfo" });
2020-12-04 17:15:18 +01:00
},
2020-12-09 15:20:50 +01:00
leaveRoom() {
this.showLeaveConfirmation = true;
},
hideRoomList() {
this.showRoomList = false;
}
2020-12-04 17:15:18 +01:00
},
};
</script>
<style lang="scss">
@import "@/assets/css/chat.scss";
</style>