keanu-weblite/src/components/Join.vue

156 lines
3.8 KiB
Vue
Raw Normal View History

2020-11-25 10:02:24 +01:00
<template>
2020-12-16 15:57:44 +01:00
<div class="join-root">
<div v-if="!waiting" class="text-center">
2020-12-16 16:36:23 +01:00
<v-btn
class="btn-login"
text
small
@click.stop="handleLogin"
:loading="loading"
>Login</v-btn
>
2020-11-25 10:02:24 +01:00
2020-12-16 15:57:44 +01:00
<v-avatar class="join-avatar">
<v-img v-if="roomAvatar" :src="roomAvatar" />
<span v-else class="white--text headline">{{
roomName.substring(0, 1).toUpperCase()
2020-12-16 16:36:23 +01:00
}}</span>
2020-12-16 15:57:44 +01:00
</v-avatar>
<div class="join-title">Welcome to {{ roomName }}</div>
2020-12-16 16:36:23 +01:00
<div class="join-message">
Join the group chat in a web browser or with the Keanu app.
</div>
<v-btn
class="btn-light"
large
block
@click.stop="handleOpenApp"
:loading="loading"
2020-12-16 15:57:44 +01:00
>Open Keanu app</v-btn
>
2020-12-16 16:36:23 +01:00
2020-12-16 15:57:44 +01:00
<div class="join-or-divider">OR</div>
2020-12-16 16:36:23 +01:00
<v-btn
class="btn-dark"
large
block
@click.stop="handleJoin"
:loading="loading"
2020-11-25 10:02:24 +01:00
>Join as guest</v-btn
>
2020-12-16 16:36:23 +01:00
<div class="join-privacy">
Enhance your physical privacy. <a href="#">Learn how</a>
</div>
2020-12-16 15:57:44 +01:00
2020-11-25 10:02:24 +01:00
<div v-if="loadingMessage">{{ loadingMessage }}</div>
</div>
</div>
</template>
<script>
import User from "../models/user";
export default {
name: "Join",
data() {
return {
roomId: null,
2020-12-16 15:57:44 +01:00
roomName: null,
roomAvatar: null,
2020-11-25 10:02:24 +01:00
guestUser: new User("https://neo.keanu.im", "", "", true),
loading: false,
loadingMessage: null,
2020-12-16 16:36:23 +01:00
waiting: true,
2020-11-25 10:02:24 +01:00
};
},
mounted() {
this.roomId = this.$route.hash;
2020-12-16 15:57:44 +01:00
this.roomName = this.roomId;
if (this.currentUser) {
2020-12-16 16:36:23 +01:00
this.waiting = true;
const self = this;
this.$matrix
.getMatrixClient(this.currentUser)
.then(() => {
// Already joined?
const room = self.$matrix.getRoom(self.roomId);
2020-12-16 16:36:23 +01:00
if (
room &&
room.hasMembershipState(self.currentUser.user_id, "join")
) {
// Yes, go to room
self.$matrix.setCurrentRoom(room);
self.$router.replace({ name: "Chat" });
return;
}
this.waiting = false;
})
2020-12-16 16:36:23 +01:00
.catch((ignoredErr) => {
this.waiting = false;
});
2020-12-16 16:36:23 +01:00
}
this.$matrix
.getPublicRoomInfo(this.roomId)
.then((room) => {
2020-12-16 15:57:44 +01:00
console.log("Found room:", room);
this.roomName = room.name;
this.roomAvatar = room.avatar;
2020-12-16 16:36:23 +01:00
this.waiting = false;
2020-12-16 15:57:44 +01:00
})
2020-12-16 16:36:23 +01:00
.catch((err) => {
2020-12-16 15:57:44 +01:00
console.log("Could not find room info", err);
2020-12-16 16:36:23 +01:00
this.waiting = false;
});
2020-11-25 10:02:24 +01:00
},
computed: {
currentUser() {
return this.$store.state.auth.user;
},
},
methods: {
2020-12-16 15:57:44 +01:00
handleLogin() {
this.$router.push("/login"); // TODO - replace?
},
handleOpenApp() {
console.log("Open app..."); //TODO
},
2020-11-25 10:02:24 +01:00
handleJoin() {
this.loading = true;
this.loadingMessage = "Logging in...";
2020-11-25 14:42:50 +01:00
var clientPromise;
2020-11-25 10:02:24 +01:00
if (this.currentUser) {
2020-11-25 14:42:50 +01:00
clientPromise = this.$matrix.getMatrixClient(this.currentUser);
2020-11-25 10:02:24 +01:00
} else {
2020-11-25 14:42:50 +01:00
clientPromise = this.$store.dispatch("auth/login", this.guestUser);
2020-11-25 10:02:24 +01:00
}
2020-11-25 14:42:50 +01:00
return clientPromise
.then((ignoreduser) => {
this.loadingMessage = "Joining room...";
return this.$matrix.matrixClient.joinRoom(this.roomId);
})
.then((room) => {
2020-11-25 15:07:51 +01:00
this.$matrix.setCurrentRoom(room);
2020-11-25 14:42:50 +01:00
this.loading = false;
this.loadingMessage = null;
this.$router.replace({ name: "Chat" });
})
.catch((err) => {
// TODO - handle error
console.log("Failed to join room", err);
this.loading = false;
this.loadingMessage = err.toString();
});
2020-11-25 10:02:24 +01:00
},
},
};
</script>
<style lang="scss">
2020-12-16 15:57:44 +01:00
@import "@/assets/css/join.scss";
2020-11-25 10:02:24 +01:00
</style>