Don't overwrite room custom topics
This commit is contained in:
parent
eec8b0f15b
commit
ad51079448
9 changed files with 57 additions and 19 deletions
15
package-lock.json
generated
15
package-lock.json
generated
|
@ -14,7 +14,7 @@
|
|||
"@cloudrac3r/giframe": "^0.4.3",
|
||||
"@cloudrac3r/html-template-tag": "^5.0.1",
|
||||
"@cloudrac3r/in-your-element": "^1.0.0",
|
||||
"@cloudrac3r/mixin-deep": "^3.0.0",
|
||||
"@cloudrac3r/mixin-deep": "^3.0.1",
|
||||
"@cloudrac3r/pngjs": "^7.0.3",
|
||||
"@cloudrac3r/pug": "^4.0.4",
|
||||
"@cloudrac3r/turndown": "^7.1.4",
|
||||
|
@ -281,9 +281,10 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@cloudrac3r/mixin-deep": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@cloudrac3r/mixin-deep/-/mixin-deep-3.0.0.tgz",
|
||||
"integrity": "sha512-yQz1wHSZbHfbKaGSjrV3wIG0e9MnElKlmekMKJPRdTn2jhF2Mt8wfMPX8U7v6rTyzR/7BTrX8CCUcrJMLgoQqw==",
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@cloudrac3r/mixin-deep/-/mixin-deep-3.0.1.tgz",
|
||||
"integrity": "sha512-awxfIraHjJ/URNlZ0ROc78Tdjtfk/fM/Gnj1embfrSN08h/HpRtLmPc3xlG3T2vFAy1AkONaebd52u7o6kDaYw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
|
@ -3217,9 +3218,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "6.19.8",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz",
|
||||
"integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==",
|
||||
"version": "6.21.1",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.21.1.tgz",
|
||||
"integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.17"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"@cloudrac3r/giframe": "^0.4.3",
|
||||
"@cloudrac3r/html-template-tag": "^5.0.1",
|
||||
"@cloudrac3r/in-your-element": "^1.0.0",
|
||||
"@cloudrac3r/mixin-deep": "^3.0.0",
|
||||
"@cloudrac3r/mixin-deep": "^3.0.1",
|
||||
"@cloudrac3r/pngjs": "^7.0.3",
|
||||
"@cloudrac3r/pug": "^4.0.4",
|
||||
"@cloudrac3r/turndown": "^7.1.4",
|
||||
|
|
|
@ -89,9 +89,10 @@ async function channelToKState(channel, guild, di) {
|
|||
assert(typeof parentSpaceID === "string")
|
||||
}
|
||||
|
||||
const channelRow = select("channel_room", ["nick", "custom_avatar"], {channel_id: channel.id}).get()
|
||||
const channelRow = select("channel_room", ["nick", "custom_avatar", "custom_topic"], {channel_id: channel.id}).get()
|
||||
const customName = channelRow?.nick
|
||||
const customAvatar = channelRow?.custom_avatar
|
||||
const hasCustomTopic = channelRow?.custom_topic
|
||||
const [convertedName, convertedTopic] = convertNameAndTopic(channel, guild, customName)
|
||||
|
||||
const avatarEventContent = {}
|
||||
|
@ -167,6 +168,8 @@ async function channelToKState(channel, guild, di) {
|
|||
}
|
||||
}
|
||||
|
||||
if (hasCustomTopic) delete channelKState["m.room.topic/"]
|
||||
|
||||
return {spaceID: parentSpaceID, privacyLevel, channelKState}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,26 @@ test("channel2room: room where limited people can mention everyone", async t =>
|
|||
t.equal(called, 1)
|
||||
})
|
||||
|
||||
test("channel2room: matrix room that already has a custom topic set", async t => {
|
||||
let called = 0
|
||||
async function getStateEvent(roomID, type, key) { // getting power levels from space to apply to room
|
||||
called++
|
||||
t.equal(roomID, "!jjWAGMeQdNrVZSSfvz:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {}
|
||||
}
|
||||
db.prepare("UPDATE channel_room SET custom_topic = 1 WHERE channel_id = ?").run(testData.channel.general.id)
|
||||
const expected = mixin({}, testData.room.general, {"m.room.power_levels/": {notifications: {room: 20}}})
|
||||
// @ts-ignore
|
||||
delete expected["m.room.topic/"]
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
||||
expected
|
||||
)
|
||||
t.equal(called, 1)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: custom name and topic", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 0}, {id: "456"}, "hauntings"),
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
BEGIN TRANSACTION;
|
||||
|
||||
ALTER TABLE channel_room ADD COLUMN custom_topic INTEGER DEFAULT 0;
|
||||
|
||||
COMMIT;
|
2
src/db/orm-defs.d.ts
vendored
2
src/db/orm-defs.d.ts
vendored
|
@ -10,6 +10,8 @@ export type Models = {
|
|||
speedbump_id: string | null
|
||||
speedbump_webhook_id: string | null
|
||||
speedbump_checked: number | null
|
||||
guild_id: string | null
|
||||
custom_topic: number
|
||||
}
|
||||
|
||||
event_message: {
|
||||
|
|
|
@ -164,6 +164,17 @@ async event => {
|
|||
db.prepare("UPDATE channel_room SET nick = ? WHERE room_id = ?").run(name, event.room_id)
|
||||
}))
|
||||
|
||||
sync.addTemporaryListener(as, "type:m.room.topic", guard("m.room.topic",
|
||||
/**
|
||||
* @param {Ty.Event.StateOuter<Ty.Event.M_Room_Topic>} event
|
||||
*/
|
||||
async event => {
|
||||
if (event.state_key !== "") return
|
||||
if (utils.eventSenderIsFromDiscord(event.sender)) return
|
||||
const customTopic = +!!event.content.topic
|
||||
db.prepare("UPDATE channel_room SET custom_topic = ? WHERE room_id = ?").run(customTopic, event.room_id)
|
||||
}))
|
||||
|
||||
sync.addTemporaryListener(as, "type:m.room.pinned_events", guard("m.room.pinned_events",
|
||||
/**
|
||||
* @param {Ty.Event.StateOuter<Ty.Event.M_Room_PinnedEvents>} event
|
||||
|
|
4
src/types.d.ts
vendored
4
src/types.d.ts
vendored
|
@ -243,6 +243,10 @@ export namespace Event {
|
|||
name?: string
|
||||
}
|
||||
|
||||
export type M_Room_Topic = {
|
||||
topic?: string
|
||||
}
|
||||
|
||||
export type M_Room_PinnedEvents = {
|
||||
pinned: string[]
|
||||
}
|
||||
|
|
|
@ -177,16 +177,12 @@ test("api invite: can invite to a moderated guild", async t => {
|
|||
async inviteToRoom(roomID, mxidToInvite, mxid) {
|
||||
t.equal(roomID, "!jjWAGMeQdNrVZSSfvz:cadence.moe")
|
||||
called++
|
||||
},
|
||||
async setUserPowerCascade(roomID, mxid, power) {
|
||||
t.equal(power, 0)
|
||||
called++
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
t.notOk(error)
|
||||
t.equal(called, 3)
|
||||
t.equal(called, 2)
|
||||
})
|
||||
|
||||
test("api invite: does not reinvite joined users", async t => {
|
||||
|
@ -205,14 +201,10 @@ test("api invite: does not reinvite joined users", async t => {
|
|||
async getStateEvent(roomID, type, key) {
|
||||
called++
|
||||
return {membership: "join"}
|
||||
},
|
||||
async setUserPowerCascade(roomID, mxid, power) {
|
||||
t.equal(power, 0)
|
||||
called++
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
t.notOk(error)
|
||||
t.equal(called, 2)
|
||||
t.equal(called, 1)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue