Room version 12 and room upgrades
This commit is contained in:
@@ -77,7 +77,7 @@ function convertNameAndTopic(channel, guild, customName) {
|
||||
* Async because it may create the guild and/or upload the guild icon to mxc.
|
||||
* @param {DiscordTypes.APIGuildTextChannel | DiscordTypes.APIThreadChannel} channel
|
||||
* @param {DiscordTypes.APIGuild} guild
|
||||
* @param {{api: {getStateEvent: typeof api.getStateEvent}}} di simple-as-nails dependency injection for the matrix API
|
||||
* @param {{api: {getStateEvent: typeof api.getStateEvent, getStateEventOuter: typeof api.getStateEventOuter}}} di simple-as-nails dependency injection for the matrix API
|
||||
*/
|
||||
async function channelToKState(channel, guild, di) {
|
||||
// @ts-ignore
|
||||
@@ -126,16 +126,17 @@ async function channelToKState(channel, guild, di) {
|
||||
const everyoneCanSend = dUtils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.SendMessages)
|
||||
const everyoneCanMentionEveryone = dUtils.hasAllPermissions(everyonePermissions, ["MentionEveryone"])
|
||||
|
||||
/** @type {Ty.Event.M_Power_Levels} */
|
||||
const spacePowerEvent = await di.api.getStateEvent(guildSpaceID, "m.room.power_levels", "")
|
||||
const spacePower = spacePowerEvent.users
|
||||
const spacePowerDetails = await mUtils.getEffectivePower(guildSpaceID, [], di.api)
|
||||
const spaceCreatorsAndFounders = spacePowerDetails.allCreators
|
||||
.concat(Object.entries(spacePowerDetails.powerLevels.users ?? {}).filter(([, power]) => power >= spacePowerDetails.tombstone).map(([mxid]) => mxid))
|
||||
|
||||
const globalAdmins = select("member_power", ["mxid", "power_level"], {room_id: "*"}).all()
|
||||
const globalAdminPower = globalAdmins.reduce((a, c) => (a[c.mxid] = c.power_level, a), {})
|
||||
const additionalCreators = select("member_power", "mxid", {room_id: "*"}, "AND power_level > 100").pluck().all()
|
||||
|
||||
const additionalCreators = select("member_power", "mxid", {room_id: "*"}, "AND power_level > 100").pluck().all().concat(spaceCreatorsAndFounders)
|
||||
const creationContent = {}
|
||||
creationContent.additional_creators = additionalCreators
|
||||
|
||||
if (channel.type === DiscordTypes.ChannelType.GuildForum) creationContent.type = "m.space"
|
||||
|
||||
/** @type {any} */
|
||||
@@ -162,10 +163,10 @@ async function channelToKState(channel, guild, di) {
|
||||
notifications: {
|
||||
room: everyoneCanMentionEveryone ? 0 : 20
|
||||
},
|
||||
users: {...spacePower, ...globalAdminPower}
|
||||
users: {...spacePowerDetails.powerLevels.users, ...globalAdminPower}
|
||||
},
|
||||
[`uk.half-shot.bridge/moe.cadence.ooye://discord/${guild.id}/${channel.id}`]: {
|
||||
bridgebot: `@${reg.sender_localpart}:${reg.ooye.server_name}`,
|
||||
bridgebot: mUtils.bot,
|
||||
protocol: {
|
||||
id: "discord",
|
||||
displayname: "Discord"
|
||||
|
||||
@@ -9,19 +9,44 @@ const testData = require("../../../test/data")
|
||||
const passthrough = require("../../passthrough")
|
||||
const {db} = passthrough
|
||||
|
||||
function mockAPI(t) {
|
||||
let called = 0
|
||||
return {
|
||||
getCalled() {
|
||||
return called
|
||||
},
|
||||
async getStateEvent(roomID, type, key) { // getting power levels from space to apply to room
|
||||
called++
|
||||
t.equal(roomID, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {users: {"@example:matrix.org": 50}, events: {"m.room.tombstone": 100}}
|
||||
},
|
||||
async getStateEventOuter(roomID, type, key) {
|
||||
called++
|
||||
t.equal(roomID, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.create")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
type: "m.room.create",
|
||||
state_key: "",
|
||||
content: {
|
||||
room_version: "11"
|
||||
},
|
||||
event_id: "$create",
|
||||
origin_server_ts: 0,
|
||||
room_id: "!jjmvBegULiLucuWEHU:cadence.moe",
|
||||
sender: "@_ooye_bot:cadence.moe"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("channel2room: discoverable privacy room", async t => {
|
||||
let called = 0
|
||||
async function getStateEvent(roomID, type, key) { // getting power levels from space to apply to room
|
||||
called++
|
||||
t.equal(roomID, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {users: {"@example:matrix.org": 50}}
|
||||
}
|
||||
const api = mockAPI(t)
|
||||
db.prepare("UPDATE guild_space SET privacy_level = 2").run()
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api}).then(x => x.channelKState)),
|
||||
Object.assign({}, testData.room.general, {
|
||||
"m.room.guest_access/": {guest_access: "forbidden"},
|
||||
"m.room.join_rules/": {join_rule: "public"},
|
||||
@@ -29,58 +54,37 @@ test("channel2room: discoverable privacy room", async t => {
|
||||
"m.room.power_levels/": mixin({users: {"@example:matrix.org": 50}}, testData.room.general["m.room.power_levels/"])
|
||||
})
|
||||
)
|
||||
t.equal(called, 1)
|
||||
t.equal(api.getCalled(), 2)
|
||||
})
|
||||
|
||||
test("channel2room: linkable privacy room", async t => {
|
||||
let called = 0
|
||||
async function getStateEvent(roomID, type, key) { // getting power levels from space to apply to room
|
||||
called++
|
||||
t.equal(roomID, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {users: {"@example:matrix.org": 50}}
|
||||
}
|
||||
const api = mockAPI(t)
|
||||
db.prepare("UPDATE guild_space SET privacy_level = 1").run()
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api}).then(x => x.channelKState)),
|
||||
Object.assign({}, testData.room.general, {
|
||||
"m.room.guest_access/": {guest_access: "forbidden"},
|
||||
"m.room.join_rules/": {join_rule: "public"},
|
||||
"m.room.power_levels/": mixin({users: {"@example:matrix.org": 50}}, testData.room.general["m.room.power_levels/"])
|
||||
})
|
||||
)
|
||||
t.equal(called, 1)
|
||||
t.equal(api.getCalled(), 2)
|
||||
})
|
||||
|
||||
test("channel2room: invite-only privacy room", async t => {
|
||||
let called = 0
|
||||
async function getStateEvent(roomID, type, key) { // getting power levels from space to apply to room
|
||||
called++
|
||||
t.equal(roomID, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {users: {"@example:matrix.org": 50}}
|
||||
}
|
||||
const api = mockAPI(t)
|
||||
db.prepare("UPDATE guild_space SET privacy_level = 0").run()
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api}).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/"])
|
||||
})
|
||||
)
|
||||
t.equal(called, 1)
|
||||
t.equal(api.getCalled(), 2)
|
||||
})
|
||||
|
||||
test("channel2room: room where limited people can mention everyone", async t => {
|
||||
let called = 0
|
||||
async function getStateEvent(roomID, type, key) { // getting power levels from space to apply to room
|
||||
called++
|
||||
t.equal(roomID, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {users: {"@example:matrix.org": 50}}
|
||||
}
|
||||
const api = mockAPI(t)
|
||||
const limitedGuild = mixin({}, testData.guild.general)
|
||||
limitedGuild.roles[0].permissions = (BigInt(limitedGuild.roles[0].permissions) - 131072n).toString()
|
||||
const limitedRoom = mixin({}, testData.room.general, {"m.room.power_levels/": {
|
||||
@@ -88,41 +92,27 @@ test("channel2room: room where limited people can mention everyone", async t =>
|
||||
users: {"@example:matrix.org": 50}
|
||||
}})
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, limitedGuild, {api: {getStateEvent}}).then(x => x.channelKState)),
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, limitedGuild, {api}).then(x => x.channelKState)),
|
||||
limitedRoom
|
||||
)
|
||||
t.equal(called, 1)
|
||||
t.equal(api.getCalled(), 2)
|
||||
})
|
||||
|
||||
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, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {}
|
||||
}
|
||||
const api = mockAPI(t)
|
||||
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}}})
|
||||
const expected = mixin({}, testData.room.general, {"m.room.power_levels/": {notifications: {room: 20}, users: {"@example:matrix.org": 50}}})
|
||||
// @ts-ignore
|
||||
delete expected["m.room.topic/"]
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, testData.guild.general, {api}).then(x => x.channelKState)),
|
||||
expected
|
||||
)
|
||||
t.equal(called, 1)
|
||||
t.equal(api.getCalled(), 2)
|
||||
})
|
||||
|
||||
test("channel2room: read-only discord channel", async t => {
|
||||
let called = 0
|
||||
async function getStateEvent(roomID, type, key) { // getting power levels from space to apply to room
|
||||
called++
|
||||
t.equal(roomID, "!jjmvBegULiLucuWEHU:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {}
|
||||
}
|
||||
const api = mockAPI(t)
|
||||
const expected = {
|
||||
"m.room.create/": {
|
||||
additional_creators: ["@test_auto_invite:example.org"],
|
||||
@@ -164,6 +154,7 @@ test("channel2room: read-only discord channel", async t => {
|
||||
},
|
||||
users: {
|
||||
"@test_auto_invite:example.org": 150,
|
||||
"@example:matrix.org": 50
|
||||
},
|
||||
},
|
||||
"m.space.parent/!jjmvBegULiLucuWEHU:cadence.moe": {
|
||||
@@ -193,10 +184,10 @@ test("channel2room: read-only discord channel", async t => {
|
||||
}
|
||||
}
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.updates, testData.guild.general, {api: {getStateEvent}}).then(x => x.channelKState)),
|
||||
kstateStripConditionals(await channelToKState(testData.channel.updates, testData.guild.general, {api}).then(x => x.channelKState)),
|
||||
expected
|
||||
)
|
||||
t.equal(called, 1)
|
||||
t.equal(api.getCalled(), 2)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: custom name and topic", t => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const {test} = require("supertape")
|
||||
const {messageToEvent} = require("./message-to-event")
|
||||
const data = require("../../../test/data")
|
||||
const {mockGetEffectivePower} = require("../../m2d/converters/utils.test")
|
||||
const {db} = require("../../passthrough")
|
||||
|
||||
test("message2event embeds: nothing but a field", async t => {
|
||||
@@ -86,17 +87,7 @@ test("message2event embeds: blockquote in embed", async t => {
|
||||
let called = 0
|
||||
const events = await messageToEvent(data.message_with_embeds.blockquote_in_embed, data.guild.general, {}, {
|
||||
api: {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
called++
|
||||
t.equal(roomID, "!qzDBLKlildpzrrOnFZ:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) {
|
||||
called++
|
||||
t.equal(roomID, "!qzDBLKlildpzrrOnFZ:cadence.moe")
|
||||
@@ -124,7 +115,7 @@ test("message2event embeds: blockquote in embed", async t => {
|
||||
formatted_body: "<blockquote><p><strong><a href=\"https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid\">⏺️ minimus</a></strong></p><p>reply draft<br><blockquote>The following is a message composed via consensus of the Stinker Council.<br><br>For those who are not currently aware of our existence, we represent the organization known as Wonderland. Our previous mission centered around the assortment and study of puzzling objects, entities and other assorted phenomena. This mission was the focus of our organization for more than 28 years.<br><br>Due to circumstances outside of our control, this directive has now changed. Our new mission will be the extermination of the stinker race.<br><br>There will be no further communication.</blockquote></p><p><a href=\"https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid\">Go to Message</a></p></blockquote>",
|
||||
"m.mentions": {}
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
t.equal(called, 1, "should call getJoinedMembers once")
|
||||
})
|
||||
|
||||
test("message2event embeds: crazy html is all escaped", async t => {
|
||||
@@ -343,16 +334,7 @@ test("message2event embeds: tenor gif should show a video link without a provide
|
||||
test("message2event embeds: if discord creates an embed preview for a discord channel link, don't copy that embed", async t => {
|
||||
const events = await messageToEvent(data.message_with_embeds.discord_server_included_punctuation_bad_discord, data.guild.general, {}, {
|
||||
api: {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
t.equal(roomID, "!TqlyQmifxGUggEmdBN:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) {
|
||||
t.equal(roomID, "!TqlyQmifxGUggEmdBN:cadence.moe")
|
||||
return {
|
||||
|
||||
@@ -2,6 +2,7 @@ const {test} = require("supertape")
|
||||
const {messageToEvent} = require("./message-to-event")
|
||||
const {MatrixServerError} = require("../../matrix/mreq")
|
||||
const data = require("../../../test/data")
|
||||
const {mockGetEffectivePower} = require("../../m2d/converters/utils.test")
|
||||
const Ty = require("../../types")
|
||||
|
||||
/**
|
||||
@@ -66,17 +67,7 @@ test("message2event: simple room mention", async t => {
|
||||
let called = 0
|
||||
const events = await messageToEvent(data.message.simple_room_mention, data.guild.general, {}, {
|
||||
api: {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
called++
|
||||
t.equal(roomID, "!BnKuBPCvyfOkhcUjEu:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) {
|
||||
called++
|
||||
t.equal(roomID, "!BnKuBPCvyfOkhcUjEu:cadence.moe")
|
||||
@@ -97,24 +88,14 @@ test("message2event: simple room mention", async t => {
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe?via=cadence.moe&via=matrix.org">#worm-farm</a>'
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
t.equal(called, 1, "should call getJoinedMembers")
|
||||
})
|
||||
|
||||
test("message2event: simple room link", async t => {
|
||||
let called = 0
|
||||
const events = await messageToEvent(data.message.simple_room_link, data.guild.general, {}, {
|
||||
api: {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
called++
|
||||
t.equal(roomID, "!BnKuBPCvyfOkhcUjEu:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) {
|
||||
called++
|
||||
t.equal(roomID, "!BnKuBPCvyfOkhcUjEu:cadence.moe")
|
||||
@@ -135,24 +116,14 @@ test("message2event: simple room link", async t => {
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe?via=cadence.moe&via=matrix.org">#worm-farm</a>'
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
t.equal(called, 1, "should call getJoinedMembers once")
|
||||
})
|
||||
|
||||
test("message2event: nicked room mention", async t => {
|
||||
let called = 0
|
||||
const events = await messageToEvent(data.message.nicked_room_mention, data.guild.general, {}, {
|
||||
api: {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) {
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
@@ -173,7 +144,7 @@ test("message2event: nicked room mention", async t => {
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org">#main</a>'
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
t.equal(called, 1, "should call getJoinedMembers once")
|
||||
})
|
||||
|
||||
test("message2event: unknown room mention", async t => {
|
||||
@@ -224,17 +195,7 @@ test("message2event: simple message link", async t => {
|
||||
let called = 0
|
||||
const events = await messageToEvent(data.message.simple_message_link, data.guild.general, {}, {
|
||||
api: {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) {
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
@@ -255,13 +216,14 @@ test("message2event: simple message link", async t => {
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid</a>'
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
t.equal(called, 1, "should call getJoinedMembers once")
|
||||
})
|
||||
|
||||
test("message2event: message link that OOYE doesn't know about", async t => {
|
||||
let called = 0
|
||||
const events = await messageToEvent(data.message.message_link_to_before_ooye, data.guild.general, {}, {
|
||||
api: {
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getEventForTimestamp(roomID, ts) {
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
@@ -270,17 +232,6 @@ test("message2event: message link that OOYE doesn't know about", async t => {
|
||||
origin_server_ts: 1613287812754
|
||||
}
|
||||
},
|
||||
async getStateEvent(roomID, type, key) { // for ?via calculation
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
async getJoinedMembers(roomID) { // for ?via calculation
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
@@ -303,7 +254,7 @@ test("message2event: message link that OOYE doesn't know about", async t => {
|
||||
formatted_body: "Me: I'll scroll up to find a certain message I'll send<br><em>scrolls up and clicks message links for god knows how long</em><br><em>completely forgets what they were looking for and simply begins scrolling up to find some fun moments</em><br><em>stumbles upon:</em> "
|
||||
+ '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org</a>'
|
||||
}])
|
||||
t.equal(called, 3, "getEventForTimestamp, getStateEvent, and getJoinedMembers should be called once each")
|
||||
t.equal(called, 2, "getEventForTimestamp and getJoinedMembers should be called once each")
|
||||
})
|
||||
|
||||
test("message2event: message timestamp failed to fetch", async t => {
|
||||
@@ -318,17 +269,7 @@ test("message2event: message timestamp failed to fetch", async t => {
|
||||
error: "Unable to find event from 1726762095974 in direction Direction.FORWARDS"
|
||||
}, {})
|
||||
},
|
||||
async getStateEvent(roomID, type, key) { // for ?via calculation
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) { // for ?via calculation
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
@@ -351,7 +292,7 @@ test("message2event: message timestamp failed to fetch", async t => {
|
||||
formatted_body: "Me: I'll scroll up to find a certain message I'll send<br><em>scrolls up and clicks message links for god knows how long</em><br><em>completely forgets what they were looking for and simply begins scrolling up to find some fun moments</em><br><em>stumbles upon:</em> "
|
||||
+ '[unknown event, timestamp resolution failed, in room: <a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org</a>]'
|
||||
}])
|
||||
t.equal(called, 3, "getEventForTimestamp, getStateEvent, and getJoinedMembers should be called once each")
|
||||
t.equal(called, 2, "getEventForTimestamp and getJoinedMembers should be called once each")
|
||||
})
|
||||
|
||||
test("message2event: message link from another server", async t => {
|
||||
@@ -1136,6 +1077,7 @@ test("message2event: forwarded image", async t => {
|
||||
test("message2event: constructed forwarded message", async t => {
|
||||
const events = await messageToEvent(data.message.constructed_forwarded_message, {}, {}, {
|
||||
api: {
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers() {
|
||||
return {
|
||||
joined: {
|
||||
@@ -1194,6 +1136,7 @@ test("message2event: constructed forwarded message", async t => {
|
||||
test("message2event: constructed forwarded text", async t => {
|
||||
const events = await messageToEvent(data.message.constructed_forwarded_text, {}, {}, {
|
||||
api: {
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers() {
|
||||
return {
|
||||
joined: {
|
||||
@@ -1331,6 +1274,7 @@ test("message2event: vc invite event renders embed", async t => {
|
||||
test("message2event: vc invite event renders embed with room link", async t => {
|
||||
const events = await messageToEvent({content: "https://discord.gg/placeholder?event=1381174024801095751"}, {}, {}, {
|
||||
api: {
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
getJoinedMembers: async () => ({
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
@@ -1380,6 +1324,7 @@ test("message2event: channel links are converted even inside lists (parser post-
|
||||
+ "\nThis list will probably change in the future"
|
||||
}, data.guild.general, {}, {
|
||||
api: {
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
getJoinedMembers(roomID) {
|
||||
called++
|
||||
t.equal(roomID, "!qzDBLKlildpzrrOnFZ:cadence.moe")
|
||||
|
||||
@@ -2,6 +2,7 @@ const {test} = require("supertape")
|
||||
const {threadToAnnouncement} = require("./thread-to-announcement")
|
||||
const data = require("../../../test/data")
|
||||
const Ty = require("../../types")
|
||||
const {mockGetEffectivePower} = require("../../m2d/converters/utils.test")
|
||||
|
||||
/**
|
||||
* @param {string} roomID
|
||||
@@ -30,13 +31,7 @@ function mockGetEvent(t, roomID_in, eventID_in, outer) {
|
||||
}
|
||||
|
||||
const viaApi = {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
getEffectivePower: mockGetEffectivePower(),
|
||||
async getJoinedMembers(roomID) {
|
||||
return {
|
||||
joined: {
|
||||
|
||||
Reference in New Issue
Block a user