2020-11-25 10:02:24 +01:00
|
|
|
<template>
|
|
|
|
|
<div class="d-flex justify-center login-root">
|
2020-12-14 16:11:38 +01:00
|
|
|
<div v-if="!waiting">
|
2020-11-25 10:02:24 +01:00
|
|
|
<h4>Join room</h4>
|
|
|
|
|
<div>You have been invited to the room {{ roomId }}</div>
|
|
|
|
|
|
|
|
|
|
<v-btn primary large block @click.stop="handleJoin" :loading="loading"
|
|
|
|
|
>Join as guest</v-btn
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
<div v-if="loadingMessage">{{ loadingMessage }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import User from "../models/user";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "Join",
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
roomId: null,
|
|
|
|
|
guestUser: new User("https://neo.keanu.im", "", "", true),
|
|
|
|
|
loading: false,
|
|
|
|
|
loadingMessage: null,
|
2020-12-14 16:11:38 +01:00
|
|
|
waiting: false
|
2020-11-25 10:02:24 +01:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.roomId = this.$route.hash;
|
2020-12-14 16:11:38 +01:00
|
|
|
if (this.currentUser) {
|
|
|
|
|
this.waiting = true;
|
|
|
|
|
const self = this;
|
|
|
|
|
this.$matrix.getMatrixClient(this.currentUser)
|
|
|
|
|
.then(() => {
|
|
|
|
|
// Already joined?
|
|
|
|
|
const room = self.$matrix.getRoom(self.roomId);
|
|
|
|
|
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;
|
|
|
|
|
})
|
|
|
|
|
.catch(ignoredErr => {
|
|
|
|
|
this.waiting = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-11-25 10:02:24 +01:00
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
currentUser() {
|
|
|
|
|
return this.$store.state.auth.user;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
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">
|
|
|
|
|
@import "@/assets/css/login.scss";
|
|
|
|
|
</style>
|