From f8020318489f45d58f593de105c3ac1b16b12542 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 15 Dec 2020 01:05:00 +1300 Subject: [PATCH] Sync with Dendrite --- src/js/room-picker.js | 13 +++++++++++-- src/js/sync/sync.js | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/js/room-picker.js b/src/js/room-picker.js index d0bc0b9..9192ae9 100644 --- a/src/js/room-picker.js +++ b/src/js/room-picker.js @@ -193,6 +193,15 @@ class Room extends ElemJS { } } + getHeroes() { + if (this.data.summary) { + return this.data.summary["m.heroes"] + } else { + const me = lsm.get("mx_user_id") + return this.data.state.events.filter(e => e.type === "m.room.member" && e.content.membership === "join" && e.state_key !== me).map(e => e.state_key) + } + } + getName() { // if the room has a name let name = this.data.state.events.find(e => e.type === "m.room.name") @@ -205,7 +214,7 @@ class Room extends ElemJS { return canonicalAlias.content.alias } // if the room has no alias, use the names of its members ("heroes") - const users = this.data.summary["m.heroes"] + const users = this.getHeroes() if (users && users.length) { const usernames = users.map(mxid => this.getMemberName(mxid)) return usernames.join(", ") @@ -224,7 +233,7 @@ class Room extends ElemJS { } } // if the room has no avatar set, use a member's avatar - const users = this.data.summary["m.heroes"] + const users = this.getHeroes() if (users && users[0] && this.members.has(users[0])) { // console.log(users[0], this.members.get(users[0])) const userAvatar = this.members.get(users[0]).value().content.avatar_url diff --git a/src/js/sync/sync.js b/src/js/sync/sync.js index b445253..f8bfc52 100644 --- a/src/js/sync/sync.js +++ b/src/js/sync/sync.js @@ -58,15 +58,15 @@ function manageSync(root) { } const room = store.rooms.get(id).value() const timeline = room.timeline - if (data.state) timeline.updateStateEvents(data.state.events) - if (data.timeline) { + if (data.state && data.state.events) timeline.updateStateEvents(data.state.events) + if (data.timeline && data.timeline.events) { if (!timeline.from) timeline.from = data.timeline.prev_batch if (data.timeline.events.length) { newEvents = true timeline.updateEvents(data.timeline.events) } } - if (data.ephemeral) timeline.updateEphemeral(data.ephemeral.events) + if (data.ephemeral && data.ephemeral.events) timeline.updateEphemeral(data.ephemeral.events) if (data.unread_notifications) { timeline.updateNotificationCount(data.unread_notifications.notification_count) notificationsChange = true