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,62 +39,75 @@ function manageSync(root) {
let newEvents = false let newEvents = false
// set up directs // set up directs
const directs = root.account_data.events.find(e => e.type === "m.direct") if (root.account_data) {
if (directs) { const directs = root.account_data.events.find(e => e.type === "m.direct")
Object.values(directs.content).forEach(ids => { if (directs) {
ids.forEach(id => store.directs.add(id)) Object.values(directs.content).forEach(ids => {
}) ids.forEach(id => store.directs.add(id))
})
}
} }
// set up rooms // set up rooms
Object.entries(root.rooms.join).forEach(([id, data]) => { if (root.rooms) {
if (!store.rooms.has(id)) { if (root.rooms.join) {
store.rooms.askAdd(id, data) 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.updateEvents(data.timeline.events)
}
}
if (data.ephemeral) timeline.updateEphemeral(data.ephemeral.events)
})
} }
const room = store.rooms.get(id).value() }
const timeline = room.timeline
if (!timeline.from) timeline.from = data.timeline.prev_batch
if (data.timeline.events.length) newEvents = true
timeline.updateStateEvents(data.state.events)
timeline.updateEvents(data.timeline.events)
timeline.updateEphemeral(data.ephemeral.events)
})
// set up groups // set up groups
Promise.all( if (root.groups) {
Object.keys(root.groups.join).map(id => { Promise.all(
if (!store.groups.has(id)) { Object.keys(root.groups.join).map(id => {
return Promise.all(["profile", "rooms"].map(path => { if (!store.groups.has(id)) {
const url = new URL(`${lsm.get("domain")}/_matrix/client/r0/groups/${id}/${path}`) return Promise.all(["profile", "rooms"].map(path => {
url.searchParams.append("access_token", lsm.get("access_token")) const url = new URL(`${lsm.get("domain")}/_matrix/client/r0/groups/${id}/${path}`)
return fetch(url.toString()).then(res => res.json()) url.searchParams.append("access_token", lsm.get("access_token"))
})).then(([profile, rooms]) => { return fetch(url.toString()).then(res => res.json())
rooms = rooms.chunk })).then(([profile, rooms]) => {
let order = 999 rooms = rooms.chunk
let orderEvent = root.account_data.events.find(e => e.type === "im.vector.web.tag_ordering") let order = 999
if (orderEvent) { let orderEvent = root.account_data.events.find(e => e.type === "im.vector.web.tag_ordering")
if (orderEvent.content.tags.includes(id)) { if (orderEvent) {
order = orderEvent.content.tags.indexOf(id) if (orderEvent.content.tags.includes(id)) {
order = orderEvent.content.tags.indexOf(id)
}
} }
} const data = {
const data = { name: profile.name,
name: profile.name, icon: resolveMxc(profile.avatar_url, 96, "crop"),
icon: resolveMxc(profile.avatar_url, 96, "crop"), order
order
}
store.groups.askAdd(id, data)
rooms.forEach(groupRoom => {
if (store.rooms.has(groupRoom.room_id)) {
store.rooms.get(groupRoom.room_id).value().setGroup(id)
} }
store.groups.askAdd(id, data)
rooms.forEach(groupRoom => {
if (store.rooms.has(groupRoom.room_id)) {
store.rooms.get(groupRoom.room_id).value().setGroup(id)
}
})
store.newEvents.broadcast("changeSelf") // trigger a room list update
}) })
store.newEvents.broadcast("changeSelf") // trigger a room list update }
}) })
} ).then(() => {
store.rooms.sort()
}) })
).then(() => { }
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()
} }