Store invite in database and sync power on startup

This commit is contained in:
Cadence Ember 2024-08-26 01:34:46 +12:00
commit df1296e579
8 changed files with 119 additions and 4 deletions

View file

@ -0,0 +1,14 @@
BEGIN TRANSACTION;
-- the power we want them to have
CREATE TABLE IF NOT EXISTS member_power (
mxid TEXT NOT NULL,
room_id TEXT NOT NULL,
power_level INTEGER NOT NULL,
PRIMARY KEY(mxid, room_id)
) WITHOUT ROWID;
-- the power they have
ALTER TABLE member_cache ADD COLUMN power_level INTEGER NOT NULL DEFAULT 0;
COMMIT;

9
db/orm-defs.d.ts vendored
View file

@ -42,7 +42,14 @@ export type Models = {
room_id: string
mxid: string
displayname: string | null
avatar_url: string | null
avatar_url: string | null,
power_level: number
}
member_power: {
mxid: string
room_id: string
power_level: number
}
message_channel: {

View file

@ -44,6 +44,8 @@ class From {
/** @private */
this.cols = []
/** @private */
this.makeColsSafe = true
/** @private */
this.using = []
/** @private */
this.isPluck = false
@ -78,6 +80,12 @@ class From {
return r
}
selectUnsafe(...cols) {
this.cols = cols
this.makeColsSafe = false
return this
}
/**
* @template {Col} Select
* @param {Select} col
@ -112,7 +120,8 @@ class From {
}
prepare() {
let sql = `SELECT ${this.cols.map(k => `"${k}"`).join(", ")} FROM ${this.tables[0]} `
if (this.makeColsSafe) this.cols = this.cols.map(k => `"${k}"`)
let sql = `SELECT ${this.cols.join(", ")} FROM ${this.tables[0]} `
for (let i = 1; i < this.tables.length; i++) {
const table = this.tables[i]
const col = this.using[i-1]