Compare commits
No commits in common. "0237d45c60e2a325892c00fed17fc1175374c107" and "33dd73f80972028b310136248a38084a1180cc94" have entirely different histories.
0237d45c60
...
33dd73f809
5 changed files with 7 additions and 46 deletions
|
@ -110,23 +110,6 @@ async function channelToKState(channel, guild) {
|
||||||
},
|
},
|
||||||
"chat.schildi.hide_ui/read_receipts": {
|
"chat.schildi.hide_ui/read_receipts": {
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
|
||||||
[`uk.half-shot.bridge/moe.cadence.ooye://discord/${guild.id}/${channel.id}`]: {
|
|
||||||
bridgebot: `@${reg.sender_localpart}:${reg.ooye.server_name}`,
|
|
||||||
protocol: {
|
|
||||||
id: "discord",
|
|
||||||
displayname: "Discord"
|
|
||||||
},
|
|
||||||
network: {
|
|
||||||
id: guild.id,
|
|
||||||
displayname: guild.name,
|
|
||||||
avatar_url: file.DISCORD_IMAGES_BASE + file.guildIcon(guild)
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
id: channel.id,
|
|
||||||
displayname: channel.name,
|
|
||||||
external_url: `https://discord.com/channels/${guild.id}/${channel.id}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,9 +295,6 @@ async function _unbridgeRoom(channelID) {
|
||||||
await api.sendState(roomID, "m.space.parent", spaceID, {})
|
await api.sendState(roomID, "m.space.parent", spaceID, {})
|
||||||
await api.sendState(spaceID, "m.space.child", roomID, {})
|
await api.sendState(spaceID, "m.space.child", roomID, {})
|
||||||
|
|
||||||
// remove declaration that the room is bridged
|
|
||||||
await api.sendState(roomID, "uk.half-shot.bridge", `moe.cadence.ooye://discord/${channel.guild_id}/${channel.id}`, {})
|
|
||||||
|
|
||||||
// send a notification in the room
|
// send a notification in the room
|
||||||
await api.sendEvent(roomID, "m.room.message", {
|
await api.sendEvent(roomID, "m.room.message", {
|
||||||
msgtype: "m.notice",
|
msgtype: "m.notice",
|
||||||
|
|
|
@ -121,8 +121,7 @@ async function sendState(roomID, type, stateKey, content, mxid) {
|
||||||
assert.ok(type)
|
assert.ok(type)
|
||||||
assert.ok(typeof stateKey === "string")
|
assert.ok(typeof stateKey === "string")
|
||||||
/** @type {Ty.R.EventSent} */
|
/** @type {Ty.R.EventSent} */
|
||||||
// encodeURIComponent is necessary because state key can contain some special characters like / but you must encode them so they fit in a single component of the URI
|
const root = await mreq.mreq("PUT", path(`/client/v3/rooms/${roomID}/state/${type}/${stateKey}`, mxid), content)
|
||||||
const root = await mreq.mreq("PUT", path(`/client/v3/rooms/${roomID}/state/${type}/${encodeURIComponent(stateKey)}`, mxid), content)
|
|
||||||
return root.event_id
|
return root.event_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,6 @@ function sticker(sticker) {
|
||||||
return `/stickers/${sticker.id}.${ext}`
|
return `/stickers/${sticker.id}.${ext}`
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.DISCORD_IMAGES_BASE = DISCORD_IMAGES_BASE
|
|
||||||
module.exports.guildIcon = guildIcon
|
module.exports.guildIcon = guildIcon
|
||||||
module.exports.userAvatar = userAvatar
|
module.exports.userAvatar = userAvatar
|
||||||
module.exports.memberAvatar = memberAvatar
|
module.exports.memberAvatar = memberAvatar
|
||||||
|
|
|
@ -19,10 +19,9 @@ function kstateToState(kstate) {
|
||||||
const events = []
|
const events = []
|
||||||
kstateStripConditionals(kstate)
|
kstateStripConditionals(kstate)
|
||||||
for (const [k, content] of Object.entries(kstate)) {
|
for (const [k, content] of Object.entries(kstate)) {
|
||||||
const slashIndex = k.indexOf("/")
|
const [type, state_key] = k.split("/")
|
||||||
assert(slashIndex > 0)
|
assert.ok(typeof type === "string")
|
||||||
const type = k.slice(0, slashIndex)
|
assert.ok(typeof state_key === "string")
|
||||||
const state_key = k.slice(slashIndex + 1)
|
|
||||||
events.push({type, state_key, content})
|
events.push({type, state_key, content})
|
||||||
}
|
}
|
||||||
return events
|
return events
|
||||||
|
@ -44,7 +43,7 @@ function diffKState(actual, target) {
|
||||||
const diff = {}
|
const diff = {}
|
||||||
// go through each key that it should have
|
// go through each key that it should have
|
||||||
for (const key of Object.keys(target)) {
|
for (const key of Object.keys(target)) {
|
||||||
if (!key.includes("/")) throw new Error(`target kstate's key "${key}" does not contain a slash separator; if a blank state_key was intended, add a trailing slash to the kstate key.\ncontext: ${JSON.stringify(target)}`)
|
if (!key.includes("/")) throw new Error(`target kstate's key "${key}" does not contain a slash separator; if a blank state_key was intended, add a trailing slash to the kstate key.`)
|
||||||
|
|
||||||
if (key === "m.room.power_levels/") {
|
if (key === "m.room.power_levels/") {
|
||||||
// Special handling for power levels, we want to deep merge the actual and target into the final state.
|
// Special handling for power levels, we want to deep merge the actual and target into the final state.
|
||||||
|
|
|
@ -23,8 +23,7 @@ test("kstate strip: keeps true conditions while removing $if", t => {
|
||||||
test("kstate2state: general", t => {
|
test("kstate2state: general", t => {
|
||||||
t.deepEqual(kstateToState({
|
t.deepEqual(kstateToState({
|
||||||
"m.room.name/": {name: "test name"},
|
"m.room.name/": {name: "test name"},
|
||||||
"m.room.member/@cadence:cadence.moe": {membership: "join"},
|
"m.room.member/@cadence:cadence.moe": {membership: "join"}
|
||||||
"uk.half-shot.bridge/org.matrix.appservice-irc://irc/epicord.net/#general": {creator: "@cadence:cadence.moe"}
|
|
||||||
}), [
|
}), [
|
||||||
{
|
{
|
||||||
type: "m.room.name",
|
type: "m.room.name",
|
||||||
|
@ -39,13 +38,6 @@ test("kstate2state: general", t => {
|
||||||
content: {
|
content: {
|
||||||
membership: "join"
|
membership: "join"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "uk.half-shot.bridge",
|
|
||||||
state_key: "org.matrix.appservice-irc://irc/epicord.net/#general",
|
|
||||||
content: {
|
|
||||||
creator: "@cadence:cadence.moe"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
@ -65,18 +57,10 @@ test("state2kstate: general", t => {
|
||||||
content: {
|
content: {
|
||||||
membership: "join"
|
membership: "join"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "uk.half-shot.bridge",
|
|
||||||
state_key: "org.matrix.appservice-irc://irc/epicord.net/#general",
|
|
||||||
content: {
|
|
||||||
creator: "@cadence:cadence.moe"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]), {
|
]), {
|
||||||
"m.room.name/": {name: "test name"},
|
"m.room.name/": {name: "test name"},
|
||||||
"m.room.member/@cadence:cadence.moe": {membership: "join"},
|
"m.room.member/@cadence:cadence.moe": {membership: "join"}
|
||||||
"uk.half-shot.bridge/org.matrix.appservice-irc://irc/epicord.net/#general": {creator: "@cadence:cadence.moe"}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue