Support Construct homeserver
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9f6c955b63
commit
c0c7278279
2 changed files with 62 additions and 48 deletions
|
@ -39,28 +39,39 @@ function manageSync(root) {
|
|||
let newEvents = false
|
||||
|
||||
// set up directs
|
||||
if (root.account_data) {
|
||||
const directs = root.account_data.events.find(e => e.type === "m.direct")
|
||||
if (directs) {
|
||||
Object.values(directs.content).forEach(ids => {
|
||||
ids.forEach(id => store.directs.add(id))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// set up rooms
|
||||
if (root.rooms) {
|
||||
if (root.rooms.join) {
|
||||
Object.entries(root.rooms.join).forEach(([id, data]) => {
|
||||
if (!store.rooms.has(id)) {
|
||||
store.rooms.askAdd(id, data)
|
||||
}
|
||||
const room = store.rooms.get(id).value()
|
||||
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 (data.timeline.events.length) newEvents = true
|
||||
timeline.updateStateEvents(data.state.events)
|
||||
if (data.timeline.events.length) {
|
||||
newEvents = true
|
||||
timeline.updateEvents(data.timeline.events)
|
||||
timeline.updateEphemeral(data.ephemeral.events)
|
||||
}
|
||||
}
|
||||
if (data.ephemeral) timeline.updateEphemeral(data.ephemeral.events)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// set up groups
|
||||
if (root.groups) {
|
||||
Promise.all(
|
||||
Object.keys(root.groups.join).map(id => {
|
||||
if (!store.groups.has(id)) {
|
||||
|
@ -95,6 +106,8 @@ function manageSync(root) {
|
|||
).then(() => {
|
||||
store.rooms.sort()
|
||||
})
|
||||
}
|
||||
|
||||
if (newEvents) store.newEvents.broadcast("changeSelf")
|
||||
} catch (e) {
|
||||
console.error(root)
|
||||
|
|
|
@ -295,7 +295,7 @@ class Timeline extends Subscribable {
|
|||
|
||||
async loadScrollback() {
|
||||
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`)
|
||||
url.searchParams.set("access_token", lsm.get("access_token"))
|
||||
url.searchParams.set("from", this.from)
|
||||
|
@ -316,7 +316,8 @@ class Timeline extends Subscribable {
|
|||
if (root.chunk.length) {
|
||||
// there are events to display
|
||||
this.updateEvents(root.chunk)
|
||||
} else {
|
||||
}
|
||||
if (!root.chunk.length || !root.end) {
|
||||
// we reached the top of the scrollback
|
||||
this.reactiveTimeline.loadMore.remove()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue