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
// set up directs
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))
})
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
Object.entries(root.rooms.join).forEach(([id, data]) => {
if (!store.rooms.has(id)) {
store.rooms.askAdd(id, data)
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.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
Promise.all(
Object.keys(root.groups.join).map(id => {
if (!store.groups.has(id)) {
return Promise.all(["profile", "rooms"].map(path => {
const url = new URL(`${lsm.get("domain")}/_matrix/client/r0/groups/${id}/${path}`)
url.searchParams.append("access_token", lsm.get("access_token"))
return fetch(url.toString()).then(res => res.json())
})).then(([profile, rooms]) => {
rooms = rooms.chunk
let order = 999
let orderEvent = root.account_data.events.find(e => e.type === "im.vector.web.tag_ordering")
if (orderEvent) {
if (orderEvent.content.tags.includes(id)) {
order = orderEvent.content.tags.indexOf(id)
if (root.groups) {
Promise.all(
Object.keys(root.groups.join).map(id => {
if (!store.groups.has(id)) {
return Promise.all(["profile", "rooms"].map(path => {
const url = new URL(`${lsm.get("domain")}/_matrix/client/r0/groups/${id}/${path}`)
url.searchParams.append("access_token", lsm.get("access_token"))
return fetch(url.toString()).then(res => res.json())
})).then(([profile, rooms]) => {
rooms = rooms.chunk
let order = 999
let orderEvent = root.account_data.events.find(e => e.type === "im.vector.web.tag_ordering")
if (orderEvent) {
if (orderEvent.content.tags.includes(id)) {
order = orderEvent.content.tags.indexOf(id)
}
}
}
const data = {
name: profile.name,
icon: resolveMxc(profile.avatar_url, 96, "crop"),
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)
const data = {
name: profile.name,
icon: resolveMxc(profile.avatar_url, 96, "crop"),
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.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")
} catch (e) {
console.error(root)

View file

@ -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()
}