From 95b8e38dd47bc941cc4d8b3693da03961af3789f Mon Sep 17 00:00:00 2001 From: adb Date: Sat, 13 Mar 2021 00:42:24 +0100 Subject: [PATCH] list rooms --- src/lib/matrixHandler.js | 34 +++++++++++++++++++++++----------- src/views/chat.vue | 14 +++++++------- src/views/rooms.vue | 32 +++++++++++++++++++------------- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/lib/matrixHandler.js b/src/lib/matrixHandler.js index a435fe1..1f5ef7d 100644 --- a/src/lib/matrixHandler.js +++ b/src/lib/matrixHandler.js @@ -1,13 +1,13 @@ import matrix from 'matrix-js-sdk'; -export let client = undefined; - export class MatrixHandler { constructor(clientDisplayName = 'matrix-chat') { this.clientDisplayName = clientDisplayName; this.accessToken; this.client = undefined; - this.rooms = undefined; + this.rooms = []; + this.loading = undefined; + this.user = undefined; } login(user, password, baseUrl, onError, callback = ()=>{}){ if (this.client){ console.log('there is already an active session'); return; } @@ -26,8 +26,9 @@ export class MatrixHandler { } if (response.access_token){ console.log(`access token => ${response.access_token}`); - console.log(this.client.getRooms()); callback(response.access_token); + this.user = user; + this.startSync() } }).catch(error => { this.logout(); @@ -37,16 +38,27 @@ export class MatrixHandler { } tokenLogin(baseUrl, accessToken, userId){ if (this.client){ console.log('there is already an active session'); return; } - this.client = new matrix.createClient({baseUrl, accessToken, userId}).then(response => { - console.log(response); - }); - this.client.startClient(); - this.client.once('sync', (state) => { - console.log(state); - }); + this.client = new matrix.createClient({baseUrl, accessToken, userId}); + this.user = userId; + this.startSync(); } logout(){ this.client.stopClient(); this.client = undefined; } + startSync(callback = ()=>{}){ + this.loading = true; + this.client.startClient(); + this.client.once('sync', (state) => { + console.log(state); + this.rooms = this.client.getRooms(); + this.loading = false; + callback(); + }); + this.client.on('event', (event) => { + if (event.getType() === 'm.room.create') { + console.log(event) + } + }) + } } \ No newline at end of file diff --git a/src/views/chat.vue b/src/views/chat.vue index 248158a..2aa1a5d 100644 --- a/src/views/chat.vue +++ b/src/views/chat.vue @@ -2,7 +2,7 @@
-

this room is empty

+

this room is empty

-
+
{{group[0].sender}}
- +
-
+
+ loading... +
+

[chat]

-

{{session.rooms.length}} rooms:

-
+
{{room.name.substr(0,2)}}
{{room.name}}
- +
Please select a room to be displayed.

[c]

-
+
{{room.name.substr(0,2)}}
{{room.name}}
- +