2020-11-25 10:02:24 +01:00
|
|
|
<template>
|
2020-12-16 15:57:44 +01:00
|
|
|
<div class="join-root">
|
2021-01-08 11:07:02 +01:00
|
|
|
<div v-if="!waitingForInfo && !waitingForMembership" class="text-center">
|
2020-12-16 16:36:23 +01:00
|
|
|
<v-btn
|
|
|
|
|
class="btn-login"
|
|
|
|
|
text
|
|
|
|
|
small
|
|
|
|
|
@click.stop="handleLogin"
|
|
|
|
|
:loading="loading"
|
2021-01-11 17:42:58 +01:00
|
|
|
v-if="!currentUser"
|
2020-12-16 16:36:23 +01:00
|
|
|
>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">
|
2021-01-15 11:50:21 +01:00
|
|
|
<!-- Join the group chat in a web browser or with the Keanu app. -->
|
2020-12-16 16:36:23 +01:00
|
|
|
</div>
|
2021-01-20 09:42:13 +01:00
|
|
|
<v-container class="join-user-info">
|
|
|
|
|
<v-row>
|
|
|
|
|
<v-col class="flex-grow-0 flex-shrink-0">
|
|
|
|
|
<v-avatar @click="showAvatarPicker = true">
|
|
|
|
|
<v-img v-if="userAvatar" :src="userAvatar.image" />
|
|
|
|
|
</v-avatar>
|
|
|
|
|
</v-col>
|
|
|
|
|
<v-col class="flex-shrink-1 flex-grow-1">
|
|
|
|
|
<v-combobox
|
|
|
|
|
v-if="!currentUser || currentUser"
|
|
|
|
|
@update:search-input="updateDisplayName"
|
|
|
|
|
:items="defaultDisplayNames"
|
|
|
|
|
:value="displayName"
|
|
|
|
|
label="User name"
|
|
|
|
|
outlined
|
|
|
|
|
dense
|
|
|
|
|
></v-combobox>
|
|
|
|
|
</v-col>
|
|
|
|
|
</v-row>
|
|
|
|
|
</v-container>
|
2021-01-18 21:40:44 +01:00
|
|
|
|
2021-01-15 11:50:21 +01:00
|
|
|
<!--<v-btn
|
2020-12-16 16:36:23 +01:00
|
|
|
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
|
|
|
|
2021-01-15 11:50:21 +01:00
|
|
|
<div class="join-or-divider">OR</div> -->
|
2020-12-16 15:57:44 +01:00
|
|
|
|
2020-12-16 16:36:23 +01:00
|
|
|
<v-btn
|
|
|
|
|
class="btn-dark"
|
|
|
|
|
large
|
|
|
|
|
block
|
|
|
|
|
@click.stop="handleJoin"
|
|
|
|
|
:loading="loading"
|
2021-01-11 17:42:58 +01:00
|
|
|
v-if="!currentUser"
|
2020-11-25 10:02:24 +01:00
|
|
|
>Join as guest</v-btn
|
|
|
|
|
>
|
2021-01-11 17:42:58 +01:00
|
|
|
<v-btn
|
|
|
|
|
class="btn-dark"
|
|
|
|
|
large
|
|
|
|
|
block
|
|
|
|
|
@click.stop="handleJoin"
|
|
|
|
|
:loading="loading"
|
|
|
|
|
v-else
|
|
|
|
|
>Join room</v-btn
|
|
|
|
|
>
|
2020-11-25 10:02:24 +01:00
|
|
|
|
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>
|
2021-01-20 09:42:13 +01:00
|
|
|
|
|
|
|
|
<v-dialog
|
|
|
|
|
scrollable
|
|
|
|
|
:fullscreen="$vuetify.breakpoint.xs"
|
|
|
|
|
width="500"
|
|
|
|
|
transition="dialog-bottom-transition"
|
|
|
|
|
v-model="showAvatarPicker"
|
|
|
|
|
>
|
|
|
|
|
<v-card>
|
|
|
|
|
<v-toolbar dark flat color="primary">
|
|
|
|
|
<v-btn icon dark @click="showAvatarPicker = false">
|
|
|
|
|
<v-icon>close</v-icon>
|
|
|
|
|
</v-btn>
|
|
|
|
|
<v-toolbar-title>Select an Avatar</v-toolbar-title>
|
|
|
|
|
<v-spacer></v-spacer>
|
|
|
|
|
</v-toolbar>
|
|
|
|
|
<v-card-text>
|
|
|
|
|
<v-container row wrap>
|
|
|
|
|
<v-col
|
|
|
|
|
v-for="avatar in availableAvatars"
|
|
|
|
|
:key="avatar.id"
|
|
|
|
|
xs4
|
|
|
|
|
sm3
|
|
|
|
|
d-flex
|
|
|
|
|
>
|
|
|
|
|
<v-card tile flat class="d-flex">
|
|
|
|
|
<v-card-text class="d-flex">
|
|
|
|
|
<v-avatar
|
|
|
|
|
size="48"
|
|
|
|
|
@click="selectAvatar(avatar)"
|
|
|
|
|
class="avatar-picker-avatar"
|
|
|
|
|
:class="{ current: avatar === userAvatar }"
|
|
|
|
|
>
|
|
|
|
|
<img :src="avatar.image" />
|
|
|
|
|
</v-avatar>
|
|
|
|
|
</v-card-text>
|
|
|
|
|
</v-card>
|
|
|
|
|
</v-col>
|
|
|
|
|
</v-container>
|
|
|
|
|
</v-card-text>
|
|
|
|
|
</v-card>
|
|
|
|
|
</v-dialog>
|
2020-11-25 10:02:24 +01:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import User from "../models/user";
|
2021-01-12 11:26:01 +01:00
|
|
|
import util from "../plugins/utils";
|
2020-11-25 10:02:24 +01:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "Join",
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
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,
|
2021-01-08 11:07:02 +01:00
|
|
|
waitingForInfo: true,
|
|
|
|
|
waitingForMembership: false,
|
2021-01-20 09:42:13 +01:00
|
|
|
userAvatar: null,
|
2021-01-18 21:40:44 +01:00
|
|
|
displayName: null,
|
2021-01-20 09:42:13 +01:00
|
|
|
defaultDisplayNames: [],
|
|
|
|
|
availableAvatars: [],
|
|
|
|
|
showAvatarPicker: false,
|
2020-11-25 10:02:24 +01:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
2021-01-12 20:28:23 +01:00
|
|
|
this.$matrix.on("Room.myMembership", this.onMyMembership);
|
2021-01-20 09:42:13 +01:00
|
|
|
this.availableAvatars = util.getDefaultAvatars();
|
|
|
|
|
this.userAvatar = this.availableAvatars[0];
|
2021-01-18 21:40:44 +01:00
|
|
|
if (!this.currentUser || this.currentUser.is_guest) {
|
2021-01-20 09:42:13 +01:00
|
|
|
var values = require("!!raw-loader!../assets/usernames.txt")
|
|
|
|
|
.default.split("\n")
|
|
|
|
|
.filter((item) => {
|
|
|
|
|
return item.length > 0;
|
|
|
|
|
});
|
2021-01-18 21:40:44 +01:00
|
|
|
this.displayName = values[Math.floor(Math.random() * values.length)];
|
|
|
|
|
this.defaultDisplayNames = values;
|
2020-12-16 16:36:23 +01:00
|
|
|
}
|
2021-01-12 20:28:23 +01:00
|
|
|
},
|
|
|
|
|
destroyed() {
|
|
|
|
|
this.$matrix.off("Room.myMembership", this.onMyMembership);
|
2020-11-25 10:02:24 +01:00
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
currentUser() {
|
|
|
|
|
return this.$store.state.auth.user;
|
|
|
|
|
},
|
2021-01-28 22:13:08 +01:00
|
|
|
room() {
|
|
|
|
|
return this.$matrix.currentRoom;
|
|
|
|
|
},
|
|
|
|
|
roomId() {
|
|
|
|
|
if (this.room) {
|
|
|
|
|
return this.room.roomId;
|
|
|
|
|
}
|
|
|
|
|
return this.$matrix.currentRoomId;
|
|
|
|
|
},
|
|
|
|
|
roomAliasOrId() {
|
|
|
|
|
if (this.room) {
|
|
|
|
|
return this.room.getCanonicalAlias() || this.room.roomId;
|
|
|
|
|
}
|
|
|
|
|
return this.$matrix.currentRoomId;
|
|
|
|
|
},
|
2020-11-25 10:02:24 +01:00
|
|
|
},
|
2021-01-28 22:13:08 +01:00
|
|
|
watch: {
|
|
|
|
|
roomId: {
|
|
|
|
|
immediate: true,
|
|
|
|
|
handler(val, oldVal) {
|
|
|
|
|
if (val && val == oldVal) {
|
|
|
|
|
return; // No change.
|
|
|
|
|
}
|
|
|
|
|
console.log("Join: Current room changed");
|
|
|
|
|
this.roomName = this.roomId;
|
|
|
|
|
if (this.currentUser) {
|
|
|
|
|
this.waitingForMembership = true;
|
|
|
|
|
const self = this;
|
|
|
|
|
this.$matrix
|
|
|
|
|
.login(this.currentUser)
|
|
|
|
|
.then(() => {
|
|
|
|
|
self.$matrix.setCurrentRoomId(self.roomAliasOrId); // Go to this room, now or when joined.
|
|
|
|
|
const room = self.$matrix.getRoom(self.roomAliasOrId);
|
|
|
|
|
|
|
|
|
|
// Already joined?
|
|
|
|
|
if (
|
|
|
|
|
room &&
|
|
|
|
|
room.hasMembershipState(self.currentUser.user_id, "join")
|
|
|
|
|
) {
|
|
|
|
|
// Yes, go to room
|
|
|
|
|
self.$navigation.push(
|
|
|
|
|
{
|
|
|
|
|
name: "Chat",
|
|
|
|
|
params: { roomId: util.sanitizeRoomId(this.roomAliasOrId) },
|
|
|
|
|
},
|
|
|
|
|
-1
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.waitingForMembership = false;
|
|
|
|
|
})
|
|
|
|
|
.catch((ignoredErr) => {
|
|
|
|
|
this.waitingForMembership = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (this.roomId.startsWith("#")) {
|
|
|
|
|
this.$matrix
|
|
|
|
|
.getPublicRoomInfo(this.roomId)
|
|
|
|
|
.then((room) => {
|
|
|
|
|
console.log("Found room:", room);
|
|
|
|
|
this.roomName = room.name;
|
|
|
|
|
this.roomAvatar = room.avatar;
|
|
|
|
|
this.waitingForInfo = false;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log("Could not find room info", err);
|
|
|
|
|
this.waitingForInfo = false;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Private room, try to get name
|
|
|
|
|
const room = this.$matrix.getRoom(this.roomId);
|
|
|
|
|
if (room) {
|
|
|
|
|
this.roomName = room.name || this.roomName;
|
|
|
|
|
}
|
|
|
|
|
this.waitingForInfo = false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2020-11-25 10:02:24 +01:00
|
|
|
methods: {
|
2021-01-12 20:28:23 +01:00
|
|
|
onMyMembership(room, membership, ignoredprevMembership) {
|
|
|
|
|
if (room && room.roomId == this.roomId && membership == "join") {
|
2021-01-28 22:13:08 +01:00
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.$navigation.push(
|
|
|
|
|
{
|
|
|
|
|
name: "Chat",
|
|
|
|
|
params: { roomId: util.sanitizeRoomId(this.roomAliasOrId) },
|
|
|
|
|
},
|
|
|
|
|
-1
|
|
|
|
|
);
|
|
|
|
|
});
|
2021-01-12 20:28:23 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2020-12-16 15:57:44 +01:00
|
|
|
handleLogin() {
|
2021-01-11 17:42:58 +01:00
|
|
|
this.$navigation.push({ name: "Login" }, 1);
|
2020-12-16 15:57:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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) {
|
2021-01-27 12:57:23 +01:00
|
|
|
clientPromise = this.$matrix.login(this.currentUser);
|
2020-11-25 10:02:24 +01:00
|
|
|
} else {
|
2021-01-20 09:42:13 +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
|
2021-01-20 09:42:13 +01:00
|
|
|
.then(
|
|
|
|
|
function (user) {
|
|
|
|
|
if (
|
|
|
|
|
(this.currentUser && !this.currentUser.is_guest) ||
|
|
|
|
|
!this.displayName
|
|
|
|
|
) {
|
|
|
|
|
return Promise.resolve(user);
|
|
|
|
|
} else {
|
|
|
|
|
return this.$matrix.matrixClient.setDisplayName(
|
|
|
|
|
this.displayName,
|
|
|
|
|
undefined
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}.bind(this)
|
|
|
|
|
)
|
|
|
|
|
.then(
|
|
|
|
|
function () {
|
|
|
|
|
if (
|
|
|
|
|
(this.currentUser && !this.currentUser.is_guest) ||
|
|
|
|
|
!this.userAvatar
|
|
|
|
|
) {
|
|
|
|
|
return Promise.resolve("no avatar");
|
|
|
|
|
} else {
|
|
|
|
|
return util.setAvatar(
|
|
|
|
|
this.$matrix.matrixClient,
|
|
|
|
|
this.userAvatar.image,
|
|
|
|
|
function (progress) {
|
|
|
|
|
console.log("Progress: " + JSON.stringify(progress));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}.bind(this)
|
|
|
|
|
)
|
|
|
|
|
.then(
|
|
|
|
|
function (ignoreduser) {
|
|
|
|
|
this.loadingMessage = "Joining room...";
|
|
|
|
|
return this.$matrix.matrixClient.joinRoom(this.roomId);
|
|
|
|
|
}.bind(this)
|
|
|
|
|
)
|
2021-01-28 22:13:08 +01:00
|
|
|
.then((ignoredRoom) => {
|
2020-11-25 14:42:50 +01:00
|
|
|
this.loading = false;
|
|
|
|
|
this.loadingMessage = null;
|
2021-01-11 17:42:58 +01:00
|
|
|
this.$nextTick(() => {
|
2021-01-12 20:28:23 +01:00
|
|
|
this.$navigation.push(
|
2021-01-28 22:13:08 +01:00
|
|
|
{
|
|
|
|
|
name: "Chat",
|
|
|
|
|
params: { roomId: util.sanitizeRoomId(this.roomAliasOrId) },
|
|
|
|
|
},
|
2021-01-12 20:28:23 +01:00
|
|
|
-1
|
|
|
|
|
);
|
2021-01-11 17:42:58 +01:00
|
|
|
});
|
2020-11-25 14:42:50 +01:00
|
|
|
})
|
|
|
|
|
.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
|
|
|
},
|
2021-01-18 21:40:44 +01:00
|
|
|
|
|
|
|
|
updateDisplayName(value) {
|
|
|
|
|
this.displayName = value;
|
2021-01-20 09:42:13 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
selectAvatar(avatar) {
|
|
|
|
|
this.userAvatar = avatar;
|
|
|
|
|
this.showAvatarPicker = false;
|
|
|
|
|
},
|
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>
|