2023-07-04 05:35:29 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2024-07-20 13:30:07 +00:00
|
|
|
const mixin = require("@cloudrac3r/mixin-deep")
|
2023-07-04 05:35:29 +00:00
|
|
|
const {channelToKState, _convertNameAndTopic} = require("./create-room")
|
2023-05-10 05:40:31 +00:00
|
|
|
const {kstateStripConditionals} = require("../../matrix/kstate")
|
2023-05-05 13:25:15 +00:00
|
|
|
const {test} = require("supertape")
|
|
|
|
const testData = require("../../test/data")
|
|
|
|
|
2023-10-12 11:51:38 +00:00
|
|
|
const passthrough = require("../../passthrough")
|
|
|
|
const {db} = passthrough
|
|
|
|
|
2024-08-31 04:18:33 +00:00
|
|
|
|
2023-10-12 11:51:38 +00:00
|
|
|
test("channel2room: discoverable privacy room", async t => {
|
2024-08-31 04:18:33 +00:00
|
|
|
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 {users: {"@example:matrix.org": 50}}
|
|
|
|
}
|
2023-10-12 11:51:38 +00:00
|
|
|
db.prepare("UPDATE guild_space SET privacy_level = 2").run()
|
|
|
|
t.deepEqual(
|
2024-08-31 04:18:33 +00:00
|
|
|
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
2023-10-12 11:51:38 +00:00
|
|
|
Object.assign({}, testData.room.general, {
|
|
|
|
"m.room.guest_access/": {guest_access: "forbidden"},
|
|
|
|
"m.room.join_rules/": {join_rule: "public"},
|
2024-08-31 04:18:33 +00:00
|
|
|
"m.room.history_visibility/": {history_visibility: "world_readable"},
|
|
|
|
"m.room.power_levels/": mixin({users: {"@example:matrix.org": 50}}, testData.room.general["m.room.power_levels/"])
|
2023-10-12 11:51:38 +00:00
|
|
|
})
|
|
|
|
)
|
2024-08-31 04:18:33 +00:00
|
|
|
t.equal(called, 1)
|
2023-10-12 11:51:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test("channel2room: linkable privacy room", async t => {
|
2024-08-31 04:18:33 +00:00
|
|
|
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 {users: {"@example:matrix.org": 50}}
|
|
|
|
}
|
2023-10-12 11:51:38 +00:00
|
|
|
db.prepare("UPDATE guild_space SET privacy_level = 1").run()
|
|
|
|
t.deepEqual(
|
2024-08-31 04:18:33 +00:00
|
|
|
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
2023-10-12 11:51:38 +00:00
|
|
|
Object.assign({}, testData.room.general, {
|
|
|
|
"m.room.guest_access/": {guest_access: "forbidden"},
|
2024-08-31 04:18:33 +00:00
|
|
|
"m.room.join_rules/": {join_rule: "public"},
|
|
|
|
"m.room.power_levels/": mixin({users: {"@example:matrix.org": 50}}, testData.room.general["m.room.power_levels/"])
|
2023-10-12 11:51:38 +00:00
|
|
|
})
|
|
|
|
)
|
2024-08-31 04:18:33 +00:00
|
|
|
t.equal(called, 1)
|
2023-10-12 11:51:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test("channel2room: invite-only privacy room", async t => {
|
2024-08-31 04:18:33 +00:00
|
|
|
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 {users: {"@example:matrix.org": 50}}
|
|
|
|
}
|
2023-10-12 11:51:38 +00:00
|
|
|
db.prepare("UPDATE guild_space SET privacy_level = 0").run()
|
2023-05-05 13:25:15 +00:00
|
|
|
t.deepEqual(
|
2024-08-31 04:18:33 +00:00
|
|
|
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
|
|
|
Object.assign({}, testData.room.general, {
|
|
|
|
"m.room.power_levels/": mixin({users: {"@example:matrix.org": 50}}, testData.room.general["m.room.power_levels/"])
|
|
|
|
})
|
2023-05-05 13:25:15 +00:00
|
|
|
)
|
2024-08-31 04:18:33 +00:00
|
|
|
t.equal(called, 1)
|
2023-05-05 13:25:15 +00:00
|
|
|
})
|
2023-07-04 05:35:29 +00:00
|
|
|
|
2024-03-06 21:17:39 +00:00
|
|
|
test("channel2room: room where limited people can mention everyone", async t => {
|
2024-08-31 04:18:33 +00:00
|
|
|
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 {users: {"@example:matrix.org": 50}}
|
|
|
|
}
|
2024-03-06 21:17:39 +00:00
|
|
|
const limitedGuild = mixin({}, testData.guild.general)
|
|
|
|
limitedGuild.roles[0].permissions = (BigInt(limitedGuild.roles[0].permissions) - 131072n).toString()
|
2024-08-31 04:18:33 +00:00
|
|
|
const limitedRoom = mixin({}, testData.room.general, {"m.room.power_levels/": {
|
|
|
|
notifications: {room: 20},
|
|
|
|
users: {"@example:matrix.org": 50}
|
|
|
|
}})
|
2024-03-06 21:17:39 +00:00
|
|
|
t.deepEqual(
|
2024-08-31 04:18:33 +00:00
|
|
|
kstateStripConditionals(await channelToKState(testData.channel.general, limitedGuild, {api: {getStateEvent}}).then(x => x.channelKState)),
|
2024-03-06 21:17:39 +00:00
|
|
|
limitedRoom
|
|
|
|
)
|
2024-08-31 04:18:33 +00:00
|
|
|
t.equal(called, 1)
|
2024-03-06 21:17:39 +00:00
|
|
|
})
|
|
|
|
|
2023-07-04 05:35:29 +00:00
|
|
|
test("convertNameAndTopic: custom name and topic", t => {
|
|
|
|
t.deepEqual(
|
2023-08-25 00:05:16 +00:00
|
|
|
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 0}, {id: "456"}, "hauntings"),
|
2023-07-04 05:35:29 +00:00
|
|
|
["hauntings", "#the-twilight-zone | Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test("convertNameAndTopic: custom name, no topic", t => {
|
|
|
|
t.deepEqual(
|
2023-08-25 00:05:16 +00:00
|
|
|
_convertNameAndTopic({id: "123", name: "the-twilight-zone", type: 0}, {id: "456"}, "hauntings"),
|
2023-07-04 05:35:29 +00:00
|
|
|
["hauntings", "#the-twilight-zone\n\nChannel ID: 123\nGuild ID: 456"]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test("convertNameAndTopic: original name and topic", t => {
|
|
|
|
t.deepEqual(
|
2023-08-25 00:05:16 +00:00
|
|
|
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 0}, {id: "456"}, null),
|
2023-07-04 05:35:29 +00:00
|
|
|
["the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test("convertNameAndTopic: original name, no topic", t => {
|
|
|
|
t.deepEqual(
|
2023-08-25 00:05:16 +00:00
|
|
|
_convertNameAndTopic({id: "123", name: "the-twilight-zone", type: 0}, {id: "456"}, null),
|
2023-07-04 05:35:29 +00:00
|
|
|
["the-twilight-zone", "Channel ID: 123\nGuild ID: 456"]
|
|
|
|
)
|
|
|
|
})
|
2023-08-25 00:05:16 +00:00
|
|
|
|
|
|
|
test("convertNameAndTopic: public thread icon", t => {
|
|
|
|
t.deepEqual(
|
|
|
|
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 11}, {id: "456"}, null),
|
|
|
|
["[⛓️] the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test("convertNameAndTopic: private thread icon", t => {
|
|
|
|
t.deepEqual(
|
|
|
|
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 12}, {id: "456"}, null),
|
|
|
|
["[🔒⛓️] the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test("convertNameAndTopic: voice channel icon", t => {
|
|
|
|
t.deepEqual(
|
|
|
|
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 2}, {id: "456"}, null),
|
|
|
|
["[🔊] the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
|
|
|
)
|
|
|
|
})
|