keanu-weblite/src/components/RoomInfo.vue

194 lines
5 KiB
Vue
Raw Normal View History

2020-12-04 17:15:18 +01:00
<template>
<div v-if="room" class="room-info">
2021-01-20 09:42:13 +01:00
<div class="chat-header">
<v-container fluid>
<div class="room-name" v-if="room">
{{ room.summary.info.title }}
</div>
<v-btn
text
class="back"
v-show="$navigation && $navigation.canPop()"
@click.stop="$navigation.pop"
>
<v-icon>arrow_back</v-icon>
<span>BACK</span>
</v-btn>
2021-01-20 09:42:13 +01:00
</v-container>
</div>
2020-12-04 17:15:18 +01:00
<v-card class="members ma-3" flat>
2021-01-20 09:42:13 +01:00
<v-card-title
>Members<v-spacer></v-spacer>
<div>{{ room.getJoinedMemberCount() }}</div></v-card-title
>
2020-12-10 20:10:22 +01:00
<v-card-text>
2021-01-20 09:42:13 +01:00
<div
class="member ma-2"
v-for="(member, index) in joinedMembers"
2021-01-20 09:42:13 +01:00
:key="member.userId"
v-show="showAllMembers || index < 5"
2021-01-20 09:42:13 +01:00
>
<v-avatar class="avatar" size="40" color="grey">
<img v-if="memberAvatar(member)" :src="memberAvatar(member)" />
<span v-else class="white--text headline">{{
member.name.substring(0, 1).toUpperCase()
}}</span>
</v-avatar>
{{ member.user ? member.user.displayName : member.name
}}{{ member.userId == $matrix.currentUserId ? " (you)" : "" }}
</div>
<div class="show-all" @click="showAllMembers = !showAllMembers">
{{ showAllMembers ? "Hide" : "Show all" }}
2020-12-04 17:15:18 +01:00
</div>
2020-12-10 20:10:22 +01:00
</v-card-text>
</v-card>
<v-card class="account ma-3" flat>
<v-card-title>My Profile</v-card-title>
2020-12-14 16:11:45 +01:00
<v-card-text>
<div v-if="$matrix.currentUser.is_guest">
<div>
Your identity <b>{{ displayName }}</b> is temporary. You can change
your name or set a password to keep it.
</div>
<v-btn block class="outlined-button" @click.stop="viewProfile"
>View</v-btn
>
2020-12-14 16:11:45 +01:00
</div>
</v-card-text>
</v-card>
<v-card class="account ma-3" flat>
<v-card-text>
<v-btn color="red" block class="filled-button" @click.stop="showLeaveConfirmation = true"
>Leave group</v-btn
2021-01-20 09:42:13 +01:00
>
<div>
Note: This step cannot be undone. Make sure you want to logout and delete the chat forever.
</div>
</v-card-text>
</v-card>
<LeaveRoomDialog :show="showLeaveConfirmation" :room="room" @close="showLeaveConfirmation = false" />
2020-12-04 17:15:18 +01:00
</div>
</template>
<script>
import LeaveRoomDialog from '../components/LeaveRoomDialog';
2020-12-04 17:15:18 +01:00
export default {
name: "RoomInfo",
components: {
LeaveRoomDialog
},
2020-12-04 17:15:18 +01:00
data() {
return {
2020-12-10 20:10:22 +01:00
memberCount: null,
user: null,
displayName: "",
showAllMembers: false,
showLeaveConfirmation: false
2021-01-20 09:42:13 +01:00
};
2020-12-04 17:15:18 +01:00
},
mounted() {
this.$matrix.on("Room.timeline", this.onEvent);
this.updateMemberCount();
2020-12-10 20:10:22 +01:00
this.user = this.$matrix.matrixClient.getUser(this.$matrix.currentUserId);
this.displayName = this.user.displayName;
2020-12-04 17:15:18 +01:00
},
destroyed() {
this.$matrix.off("Room.timeline", this.onEvent);
},
computed: {
room() {
return this.$matrix.currentRoom;
},
joinedMembers() {
if (!this.room) {
return [];
}
const myUserId = this.$matrix.currentUserId;
return this.room.getJoinedMembers().sort((a, b) => {
if (a.userId == myUserId) {
return -1;
} else if (b.userId == myUserId) {
return 1;
}
const aName = a.user ? a.user.displayName : a.name;
const bName = b.user ? b.user.displayName : b.name;
return aName.localeCompare(bName);
});
},
2020-12-04 17:15:18 +01:00
},
watch: {
room: {
handler(newVal, ignoredOldVal) {
console.log("RoomInfo: Current room changed");
this.memberCount = newVal.getJoinedMemberCount();
2021-01-20 09:42:13 +01:00
},
},
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() {
this.memberCount = this.room.getJoinedMemberCount();
},
memberAvatar(member) {
if (member) {
return member.getAvatarUrl(
this.$matrix.matrixClient.getHomeserverUrl(),
40,
40,
"scale",
true
);
}
return null;
},
2020-12-14 16:11:45 +01:00
viewProfile() {
this.$navigation.push({ name: "Profile" }, 1);
},
leaveRoom() {
console.log("Leave");
},
2020-12-14 16:11:45 +01:00
upgradeAccount() {
2021-01-20 09:42:13 +01:00
this.$matrix
.upgradeGuestAccount()
.then((user) => {
2021-01-20 09:42:13 +01:00
// Done, login with the "new" account to get a real token instead of our guest token.
this.user = user;
return this.$store.dispatch("auth/login", this.user);
})
.then(() => {
console.log("Upgrade done!");
})
.catch((err) => {
console.log("ERROR", err);
});
},
2020-12-04 17:15:18 +01:00
},
};
</script>
<style lang="scss">
@import "@/assets/css/chat.scss";
</style>