keanu-weblite/src/components/RoomInfo.vue

343 lines
8.8 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>
2021-01-21 12:12:55 +01:00
<div class="room-name">Info</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
2021-01-21 12:12:55 +01:00
<v-card class="members ma-3 pa-3" flat>
<div class="text-center">
2021-01-20 16:39:28 +01:00
<v-avatar class="room-avatar">
<v-img v-if="roomAvatar" :src="roomAvatar" />
<span v-else class="white--text headline">{{
roomName.substring(0, 1).toUpperCase()
}}</span>
</v-avatar>
2021-01-21 12:12:55 +01:00
<div class="h1">{{ roomName }}</div>
2021-02-17 10:49:54 +01:00
<div class="h3">{{ roomTopic }}</div>
2021-01-21 12:12:55 +01:00
<div class="small">Created by {{ creator }}</div>
<canvas class="qr" id="room-qr"></canvas>
</div>
2021-01-20 16:39:28 +01:00
</v-card>
<v-card class="account ma-3" flat>
<v-card-title class="h2">Permissions</v-card-title>
<v-card-text>
<div v-if="anyoneCanJoin">
<div>
Anyone with a link can join.
</div>
<v-text-field
:value="roomLink"
readonly
append-icon="content_copy"
filled
type="text"
@click:append="copyRoomLink"
></v-text-field>
</div>
</v-card-text>
</v-card>
<v-card class="members ma-3" flat>
2021-01-21 12:12:55 +01:00
<v-card-title class="h2"
2021-01-20 09:42:13 +01:00
>Members<v-spacer></v-spacer>
<div>{{ memberCount }}</div></v-card-title
2021-01-20 09:42:13 +01:00
>
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-02-01 15:51:14 +01:00
@click="toggleMemberExpanded(member)"
2021-01-20 09:42:13 +01:00
>
2021-01-21 12:12:55 +01:00
<v-avatar class="avatar" size="32" color="grey">
2021-01-20 09:42:13 +01:00
<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)" : "" }}
2021-02-01 15:51:14 +01:00
<DeviceList v-if="expandedMembers.includes(member)" :member="member" />
</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>
2021-01-21 12:12:55 +01:00
<v-card-title class="h2">My Profile</v-card-title>
2020-12-14 16:11:45 +01:00
<v-card-text>
<div>
<div v-if="$matrix.currentUser.is_guest">
Your identity <b>{{ displayName }}</b> is temporary. You can change
your name or set a password to keep it.
</div>
<div v-else>
Your are logged in as <b>{{ displayName }}</b>.
</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>
2021-01-20 16:39:28 +01:00
<v-btn
color="red"
block
class="filled-button"
@click.stop="showLeaveConfirmation = true"
>Leave group</v-btn
>
<div>
Note: This step cannot be undone. Make sure you want to logout and
delete the chat forever.
</div>
</v-card-text>
</v-card>
2021-01-29 21:53:22 +01:00
<div class="build-version">Powered by Guardian Project. Version: {{ buildVersion }}</div>
2021-01-20 16:39:28 +01:00
<LeaveRoomDialog
:show="showLeaveConfirmation"
:room="room"
@close="showLeaveConfirmation = false"
/>
2020-12-04 17:15:18 +01:00
</div>
</template>
<script>
2021-01-20 16:39:28 +01:00
import LeaveRoomDialog from "../components/LeaveRoomDialog";
2021-02-01 15:51:14 +01:00
import DeviceList from "../components/DeviceList";
2021-01-21 12:12:55 +01:00
import QRCode from "qrcode";
2020-12-04 17:15:18 +01:00
export default {
name: "RoomInfo",
components: {
2021-01-20 16:39:28 +01:00
LeaveRoomDialog,
2021-02-01 15:51:14 +01:00
DeviceList
},
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,
2021-01-20 16:39:28 +01:00
showLeaveConfirmation: false,
2021-02-01 15:51:14 +01:00
expandedMembers: [],
2021-01-29 21:53:22 +01:00
buildVersion: "",
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;
2021-01-21 12:12:55 +01:00
// Set QR code
this.updateQRCode();
2021-01-29 21:53:22 +01:00
// Display build version
const version = require("!!raw-loader!../assets/version.txt").default;
console.log("Version", version);
this.buildVersion = version;
2020-12-04 17:15:18 +01:00
},
destroyed() {
this.$matrix.off("Room.timeline", this.onEvent);
},
computed: {
room() {
return this.$matrix.currentRoom;
},
2021-01-21 12:12:55 +01:00
creator() {
if (this.room) {
const createEvent = this.room.currentState.getStateEvents("m.room.create", "");
if (!createEvent) {
console.warn("Room " + this.roomId + " does not have an m.room.create event");
return '';
}
const creatorId = createEvent.getContent().creator;
const member = this.room.getMember(creatorId);
if (!member) {
return creatorId;
}
return member.user ? member.user.displayName : member.name;
}
return "";
},
2021-01-20 16:39:28 +01:00
roomName() {
if (this.room) {
return this.room.name;
}
return "";
},
2021-02-17 10:49:54 +01:00
roomTopic() {
if (this.room) {
return this.room.topic;
}
return "";
},
anyoneCanJoin() {
// TODO: fix this! For now, just return true of we have a canonical alias.
if (this.room && this.room.getCanonicalAlias() && this.room.getCanonicalAlias().startsWith('#')) {
return true;
}
return false;
},
roomLink() {
if (this.room) {
return this.$router.getRoomLink(this.room.getCanonicalAlias() || this.room.roomId);
}
return null;
},
2021-01-20 16:39:28 +01:00
roomAvatar() {
if (this.room) {
return this.room.avatar;
}
return "";
},
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(ignoredNewVal, ignoredOldVal) {
2020-12-04 17:15:18 +01:00
console.log("RoomInfo: Current room changed");
this.updateMemberCount();
2021-01-21 12:12:55 +01:00
this.updateQRCode();
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() {
if (this.room) {
this.memberCount = this.room.getJoinedMemberCount();
} else {
this.memberCount = null;
}
2020-12-04 17:15:18 +01:00
},
2021-01-21 12:12:55 +01:00
updateQRCode() {
var fullUrl = this.roomLink;
2021-01-21 12:12:55 +01:00
var canvas = document.getElementById("room-qr");
QRCode.toCanvas(
canvas,
fullUrl,
{
type: "image/png",
margin: 1,
width: canvas.clientWidth,
},
function (error) {
if (error) console.error(error);
else console.log("success!");
}
);
},
2020-12-04 17:15:18 +01:00
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);
},
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);
});
},
copyRoomLink() {
this.$copyText(this.roomLink).then(function (e) {
console.log(e)
}, function (e) {
console.log(e)
});
2021-02-01 15:51:14 +01:00
},
toggleMemberExpanded(member) {
const index = this.expandedMembers.indexOf(member);
if (index > -1) {
this.expandedMembers.splice(index, 1);
} else {
this.expandedMembers.push(member);
}
}
2020-12-04 17:15:18 +01:00
},
};
</script>
<style lang="scss">
@import "@/assets/css/chat.scss";
</style>