Support Construct homeserver
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Cadence Ember 2020-11-12 17:29:46 +13:00
parent 9f6c955b63
commit c0c7278279
Signed by: cadence
GPG key ID: BC1C2C61CF521B17
2 changed files with 62 additions and 48 deletions

View file

@ -39,28 +39,39 @@ function manageSync(root) {
let newEvents = false let newEvents = false
// set up directs // set up directs
if (root.account_data) {
const directs = root.account_data.events.find(e => e.type === "m.direct") const directs = root.account_data.events.find(e => e.type === "m.direct")
if (directs) { if (directs) {
Object.values(directs.content).forEach(ids => { Object.values(directs.content).forEach(ids => {
ids.forEach(id => store.directs.add(id)) ids.forEach(id => store.directs.add(id))
}) })
} }
}
// set up rooms // set up rooms
if (root.rooms) {
if (root.rooms.join) {
Object.entries(root.rooms.join).forEach(([id, data]) => { Object.entries(root.rooms.join).forEach(([id, data]) => {
if (!store.rooms.has(id)) { if (!store.rooms.has(id)) {
store.rooms.askAdd(id, data) store.rooms.askAdd(id, data)
} }
const room = store.rooms.get(id).value() const room = store.rooms.get(id).value()
const timeline = room.timeline const timeline = room.timeline
if (data.state) timeline.updateStateEvents(data.state.events)
if (data.timeline) {
if (!timeline.from) timeline.from = data.timeline.prev_batch if (!timeline.from) timeline.from = data.timeline.prev_batch
if (data.timeline.events.length) newEvents = true if (data.timeline.events.length) {
timeline.updateStateEvents(data.state.events) newEvents = true
timeline.updateEvents(data.timeline.events) timeline.updateEvents(data.timeline.events)
timeline.updateEphemeral(data.ephemeral.events) }
}
if (data.ephemeral) timeline.updateEphemeral(data.ephemeral.events)
}) })
}
}
// set up groups // set up groups
if (root.groups) {
Promise.all( Promise.all(
Object.keys(root.groups.join).map(id => { Object.keys(root.groups.join).map(id => {
if (!store.groups.has(id)) { if (!store.groups.has(id)) {
@ -95,6 +106,8 @@ function manageSync(root) {
).then(() => { ).then(() => {
store.rooms.sort() store.rooms.sort()
}) })
}
if (newEvents) store.newEvents.broadcast("changeSelf") if (newEvents) store.newEvents.broadcast("changeSelf")
} catch (e) { } catch (e) {
console.error(root) console.error(root)

View file

@ -295,7 +295,7 @@ class Timeline extends Subscribable {
async loadScrollback() { async loadScrollback() {
debug = true debug = true
if (!this.from) throw new Error("Can't load scrollback, no from token") if (!this.from) return // no more scrollback for this timeline
const url = new URL(`${lsm.get("domain")}/_matrix/client/r0/rooms/${this.id}/messages`) const url = new URL(`${lsm.get("domain")}/_matrix/client/r0/rooms/${this.id}/messages`)
url.searchParams.set("access_token", lsm.get("access_token")) url.searchParams.set("access_token", lsm.get("access_token"))
url.searchParams.set("from", this.from) url.searchParams.set("from", this.from)
@ -316,7 +316,8 @@ class Timeline extends Subscribable {
if (root.chunk.length) { if (root.chunk.length) {
// there are events to display // there are events to display
this.updateEvents(root.chunk) this.updateEvents(root.chunk)
} else { }
if (!root.chunk.length || !root.end) {
// we reached the top of the scrollback // we reached the top of the scrollback
this.reactiveTimeline.loadMore.remove() this.reactiveTimeline.loadMore.remove()
} }