diff --git a/src/assets/avatars/avatar-0.png b/src/assets/avatars/avatar-0.png new file mode 100644 index 0000000..20aa5de Binary files /dev/null and b/src/assets/avatars/avatar-0.png differ diff --git a/src/assets/avatars/avatar-1.png b/src/assets/avatars/avatar-1.png new file mode 100644 index 0000000..dc81ee7 Binary files /dev/null and b/src/assets/avatars/avatar-1.png differ diff --git a/src/assets/avatars/avatar-10.png b/src/assets/avatars/avatar-10.png new file mode 100644 index 0000000..91bd3ef Binary files /dev/null and b/src/assets/avatars/avatar-10.png differ diff --git a/src/assets/avatars/avatar-11.png b/src/assets/avatars/avatar-11.png new file mode 100644 index 0000000..ef3eebf Binary files /dev/null and b/src/assets/avatars/avatar-11.png differ diff --git a/src/assets/avatars/avatar-2.png b/src/assets/avatars/avatar-2.png new file mode 100644 index 0000000..dd6378a Binary files /dev/null and b/src/assets/avatars/avatar-2.png differ diff --git a/src/assets/avatars/avatar-3.png b/src/assets/avatars/avatar-3.png new file mode 100644 index 0000000..87dd5b9 Binary files /dev/null and b/src/assets/avatars/avatar-3.png differ diff --git a/src/assets/avatars/avatar-4.png b/src/assets/avatars/avatar-4.png new file mode 100644 index 0000000..814337a Binary files /dev/null and b/src/assets/avatars/avatar-4.png differ diff --git a/src/assets/avatars/avatar-5.png b/src/assets/avatars/avatar-5.png new file mode 100644 index 0000000..540f6d8 Binary files /dev/null and b/src/assets/avatars/avatar-5.png differ diff --git a/src/assets/avatars/avatar-6.png b/src/assets/avatars/avatar-6.png new file mode 100644 index 0000000..e0d9b1a Binary files /dev/null and b/src/assets/avatars/avatar-6.png differ diff --git a/src/assets/avatars/avatar-7.png b/src/assets/avatars/avatar-7.png new file mode 100644 index 0000000..7b8bae7 Binary files /dev/null and b/src/assets/avatars/avatar-7.png differ diff --git a/src/assets/avatars/avatar-8.png b/src/assets/avatars/avatar-8.png new file mode 100644 index 0000000..a27ae11 Binary files /dev/null and b/src/assets/avatars/avatar-8.png differ diff --git a/src/assets/avatars/avatar-9.png b/src/assets/avatars/avatar-9.png new file mode 100644 index 0000000..80ffdc3 Binary files /dev/null and b/src/assets/avatars/avatar-9.png differ diff --git a/src/assets/css/join.scss b/src/assets/css/join.scss index c30da01..bf7302c 100644 --- a/src/assets/css/join.scss +++ b/src/assets/css/join.scss @@ -38,6 +38,12 @@ right: 0; margin: 20px; } + + .join-user-info { + display: flex; + flex-wrap: nowrap; + max-width: 40%; + } } .join-avatar { diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 7d65e4c..5b856d3 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -650,10 +650,10 @@ export default { showAttachmentPicker() { // Guests not currently allowed to send attachments (=actually upload them) // See https://matrix.org/docs/spec/client_server/r0.2.0#guest-access - if (this.$matrix.currentUser && this.$matrix.currentUser.is_guest) { - this.showNotAllowedForGuests = true; - return; - } + // if (this.$matrix.currentUser && this.$matrix.currentUser.is_guest) { + // this.showNotAllowedForGuests = true; + // return; + // } this.$refs.attachment.click() }, diff --git a/src/components/Join.vue b/src/components/Join.vue index 30c0d35..6a2ce49 100644 --- a/src/components/Join.vue +++ b/src/components/Join.vue @@ -21,15 +21,26 @@
- + + + + + + + + + + + + - -
{{ room.summary.info.title }}
-
- - - + + + - Members
{{ room.getJoinedMemberCount() }}
+ Members +
{{ room.getJoinedMemberCount() }}
-
- - - {{ - member.name.substring(0, 1).toUpperCase() - }} - - {{ member.user ? member.user.displayName : member.name }}{{ (member.userId == $matrix.currentUserId) ? " (you)" : "" }} - edit +
+ + + {{ + member.name.substring(0, 1).toUpperCase() + }} + + {{ member.user ? member.user.displayName : member.name + }}{{ member.userId == $matrix.currentUserId ? " (you)" : "" }} + edit
@@ -54,22 +74,29 @@ - - - - Display name - - - - - - - Cancel - Ok - - - - + + + + Display name + + + + + + + Cancel + Ok + + +
@@ -82,7 +109,7 @@ export default { showEditDialog: false, user: null, displayName: "", - } + }; }, mounted() { this.$matrix.on("Room.timeline", this.onEvent); @@ -106,8 +133,8 @@ export default { handler(newVal, ignoredOldVal) { console.log("RoomInfo: Current room changed"); this.memberCount = newVal.getJoinedMemberCount(); - } - } + }, + }, }, methods: { @@ -124,9 +151,7 @@ export default { this.memberCount = this.room.getJoinedMemberCount(); }, - showRoomInfo() { - - }, + showRoomInfo() {}, memberAvatar(member) { if (member) { @@ -142,14 +167,20 @@ export default { }, upgradeAccount() { - this.$matrix.upgradeGuestAccount() - .then(() => { - console.log("Done"); - }) - .catch(err => { - console.log("ERROR", err); - }) - } + this.$matrix + .upgradeGuestAccount() + .then(user => { + // 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); + }); + }, }, }; diff --git a/src/plugins/utils.js b/src/plugins/utils.js index d27d98f..bbc8b44 100644 --- a/src/plugins/utils.js +++ b/src/plugins/utils.js @@ -365,6 +365,56 @@ class Util { // key wasn't found return null; } + + _importAll(r) { + var images = []; + r.keys().forEach(res => { + console.log("Avatar", res); + // // Remove"./" + // const parts = res.split("/"); + // const pack = parts[1]; + // const sticker = parts[2].split(".")[0]; + const image = r(res); + images.push({ id: res, image: image }); + // if (stickerPacks[pack] !== undefined) { + // stickerPacks[pack].push({ image: image, name: sticker }); + // } + }); + return images; + } + + getDefaultAvatars() { + return this._importAll(require.context('../assets/avatars/', true, /\.(jpeg|jpg|png)$/)); + } + + setAvatar(matrixClient, file, onUploadProgress) { + return new Promise((resolve, reject) => { + axios.get(file, { responseType: 'arraybuffer' }) + .then(response => { + const opts = { + type: response.headers['content-type'].split(';')[0], + name: "Avatar", + progressHandler: onUploadProgress, + onlyContentUri: false + }; + matrixClient.uploadContent(response.data, opts) + .then((response) => { + const uri = response.content_uri; + return matrixClient.setProfileInfo('avatar_url', { avatar_url: uri }); + }) + .then(result => { + resolve(result); + }) + .catch(err => { + reject(err); + }); + }) + .catch(err => { + reject(err); + }); + + }) + } } export default new Util(); diff --git a/src/services/matrix.service.js b/src/services/matrix.service.js index 85a221e..0c090cf 100644 --- a/src/services/matrix.service.js +++ b/src/services/matrix.service.js @@ -65,10 +65,20 @@ export default { var promiseLogin; if (user.is_guest) { + // Generate random username and password. We don't user REAL matrix + // guest accounts because 1. They are not allowed to post media, 2. They + // can not use avatars and 3. They can not seamlessly be upgraded to real accounts. + // + // Instead, we use an ILAG approach, Improved Landing as Guest. + const user = util.randomUser(); + const pass = util.randomPass(); promiseLogin = tempMatrixClient - .registerGuest({}, undefined) + .register(user, pass, null, { + type: "m.login.dummy", + }) .then((response) => { console.log("Response", response); + response.password = pass; response.is_guest = true; localStorage.setItem('user', JSON.stringify(response)); return response; @@ -106,19 +116,19 @@ export default { 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) + const self = this; + return this.matrixClient.register(this.matrixClient.getUserIdLocalpart(), randomPassword, null, { + type: "m.login.dummy", + }, undefined, this.currentUser.access_token) .then((response) => { console.log("Response", response); response.is_guest = false; - localStorage.setItem('user', JSON.stringify(response)); - return response; + response.password = randomPassword; + self.currentUser = response; + localStorage.setItem('user', JSON.stringify(response)); // Update local storage as well. + self.logout(); + return self.currentUser; }); }, @@ -163,12 +173,13 @@ export default { deviceId: user.device_id, accessToken: user.access_token, timelineSupport: true, - unstableClientRelationAggregation: true + unstableClientRelationAggregation: true, + //useAuthorizationHeader: true } this.matrixClient = sdk.createClient(opts); - if (user.is_guest) { - this.matrixClient.setGuest(true); - } + // if (user.is_guest) { + // this.matrixClient.setGuest(true); + // } return this.matrixClient .initCrypto() .then(() => { @@ -210,6 +221,7 @@ export default { if (client) { client.on("event", this.onEvent); client.on("Room", this.onRoom); + client.on("Session.logged_out", this.onSessionLoggedOut); } }, @@ -217,6 +229,7 @@ export default { if (client) { client.off("event", this.onEvent); client.off("Room", this.onRoom); + client.off("Session.logged_out", this.onSessionLoggedOut); } }, @@ -244,6 +257,11 @@ export default { this.reloadRooms(); }, + onSessionLoggedOut() { + console.log("Logged out!"); + this.logout(); + }, + reloadRooms() { this.rooms = this.matrixClient.getVisibleRooms(); this.rooms.forEach(room => {