parent
4f7b1fc4d2
commit
3dc1fa3567
3 changed files with 68 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="d-flex justify-center login-root">
|
<div class="d-flex justify-center login-root">
|
||||||
<div color="rgba(255,255,255,0.1)">
|
<div v-if="!waiting">
|
||||||
<h4>Join room</h4>
|
<h4>Join room</h4>
|
||||||
<div>You have been invited to the room {{ roomId }}</div>
|
<div>You have been invited to the room {{ roomId }}</div>
|
||||||
|
|
||||||
|
|
@ -24,10 +24,31 @@ export default {
|
||||||
guestUser: new User("https://neo.keanu.im", "", "", true),
|
guestUser: new User("https://neo.keanu.im", "", "", true),
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingMessage: null,
|
loadingMessage: null,
|
||||||
|
waiting: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.roomId = this.$route.hash;
|
this.roomId = this.$route.hash;
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
currentUser() {
|
currentUser() {
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ class Util {
|
||||||
|
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
reject("No url found!");
|
reject("No url found!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
axios.get(url, { responseType: 'arraybuffer' })
|
axios.get(url, { responseType: 'arraybuffer' })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
@ -288,6 +289,16 @@ class Util {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate random 12 char password
|
||||||
|
*/
|
||||||
|
randomPass() {
|
||||||
|
return this.randomString(
|
||||||
|
12,
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#_-*+"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// From here: https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
|
// From here: https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
|
||||||
randomString(length, characters) {
|
randomString(length, characters) {
|
||||||
var result = "";
|
var result = "";
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
global.Olm = require("olm");
|
global.Olm = require("olm");
|
||||||
import sdk from "matrix-js-sdk";
|
import sdk from "matrix-js-sdk";
|
||||||
//import util from "../plugins/utils";
|
import util from "../plugins/utils";
|
||||||
|
|
||||||
const LocalStorageCryptoStore = require("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store")
|
const LocalStorageCryptoStore = require("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store")
|
||||||
.LocalStorageCryptoStore;
|
.LocalStorageCryptoStore;
|
||||||
|
|
@ -60,7 +60,6 @@ export default {
|
||||||
var promiseLogin;
|
var promiseLogin;
|
||||||
|
|
||||||
if (user.is_guest) {
|
if (user.is_guest) {
|
||||||
//const randomUsername = util.randomUser();
|
|
||||||
promiseLogin = tempMatrixClient
|
promiseLogin = tempMatrixClient
|
||||||
.registerGuest({}, undefined)
|
.registerGuest({}, undefined)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
@ -95,6 +94,29 @@ export default {
|
||||||
this.$store.commit("setCurrentRoomId", null);
|
this.$store.commit("setCurrentRoomId", null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade a guest account into a "normal" account. For now, use random user and pass...
|
||||||
|
*/
|
||||||
|
upgradeGuestAccount() {
|
||||||
|
if (!this.matrixClient || !this.currentUser || !this.currentUser.is_guest) {
|
||||||
|
return Promise.reject("Invalid params");
|
||||||
|
}
|
||||||
|
const randomUsername = util.randomUser();
|
||||||
|
const randomPassword = util.randomPass();
|
||||||
|
const data = {
|
||||||
|
username:randomUsername,
|
||||||
|
password:randomPassword,
|
||||||
|
guest_access_token:this.currentUser.access_token
|
||||||
|
};
|
||||||
|
return this.matrixClient.registerRequest(data, undefined, undefined)
|
||||||
|
.then((response) => {
|
||||||
|
console.log("Response", response);
|
||||||
|
response.is_guest = false;
|
||||||
|
localStorage.setItem('user', JSON.stringify(response));
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
initClient() {
|
initClient() {
|
||||||
this.reloadRooms();
|
this.reloadRooms();
|
||||||
this.matrixClientReady = true;
|
this.matrixClientReady = true;
|
||||||
|
|
@ -102,6 +124,9 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
async getMatrixClient(user) {
|
async getMatrixClient(user) {
|
||||||
|
if (user === undefined) {
|
||||||
|
user = this.$store.state.auth.user;
|
||||||
|
}
|
||||||
if (this.matrixClientReady) {
|
if (this.matrixClientReady) {
|
||||||
return new Promise((resolve, ignoredreject) => {
|
return new Promise((resolve, ignoredreject) => {
|
||||||
resolve(user);
|
resolve(user);
|
||||||
|
|
@ -234,7 +259,12 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
getRoom(roomId) {
|
getRoom(roomId) {
|
||||||
var room = this.rooms.find(room => room.roomId == roomId);
|
var room = this.rooms.find(room => {
|
||||||
|
if (roomId.startsWith("#")) {
|
||||||
|
return room.getCanonicalAlias() == roomId;
|
||||||
|
}
|
||||||
|
return room.roomId == roomId;
|
||||||
|
});
|
||||||
if (!room && this.matrixClient) {
|
if (!room && this.matrixClient) {
|
||||||
room = this.matrixClient.getRoom(roomId);
|
room = this.matrixClient.getRoom(roomId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue