Allow Matrixers to @room if Discorders can too
This commit is contained in:
parent
0f1cf7a20c
commit
12d85c982e
4 changed files with 35 additions and 7 deletions
|
@ -12,6 +12,8 @@ const file = sync.require("../../matrix/file")
|
|||
const api = sync.require("../../matrix/api")
|
||||
/** @type {import("../../matrix/kstate")} */
|
||||
const ks = sync.require("../../matrix/kstate")
|
||||
/** @type {import("../../discord/utils")} */
|
||||
const utils = sync.require("../../discord/utils")
|
||||
/** @type {import("./create-space")}) */
|
||||
const createSpace = sync.require("./create-space") // watch out for the require loop
|
||||
|
||||
|
@ -119,6 +121,9 @@ async function channelToKState(channel, guild) {
|
|||
join_rules = {join_rule: PRIVACY_ENUMS.ROOM_JOIN_RULES[privacyLevel]}
|
||||
}
|
||||
|
||||
const everyonePermissions = utils.getPermissions([], guild.roles, undefined, channel.permission_overwrites)
|
||||
const everyoneCanMentionEveryone = utils.hasAllPermissions(everyonePermissions, ["MentionEveryone"])
|
||||
|
||||
const channelKState = {
|
||||
"m.room.name/": {name: convertedName},
|
||||
"m.room.topic/": {topic: convertedTopic},
|
||||
|
@ -136,7 +141,7 @@ async function channelToKState(channel, guild) {
|
|||
"m.room.avatar": 0
|
||||
},
|
||||
notifications: {
|
||||
room: 20 // TODO: Matrix users should have the same abilities as unprivileged Discord members. So make this automatically configured based on the guild or channel's default mention everyone permissions. That way if unprivileged Discord members can mention everyone, Matrix users can too.
|
||||
room: everyoneCanMentionEveryone ? 0 : 20
|
||||
},
|
||||
users: reg.ooye.invite.reduce((a, c) => (a[c] = 100, a), {})
|
||||
},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// @ts-check
|
||||
|
||||
const mixin = require("mixin-deep")
|
||||
const {channelToKState, _convertNameAndTopic} = require("./create-room")
|
||||
const {kstateStripConditionals} = require("../../matrix/kstate")
|
||||
const {test} = require("supertape")
|
||||
|
@ -39,6 +40,16 @@ test("channel2room: invite-only privacy room", async t => {
|
|||
)
|
||||
})
|
||||
|
||||
test("channel2room: room where limited people can mention everyone", async 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/": {notifications: {room: 20}}})
|
||||
t.deepEqual(
|
||||
kstateStripConditionals(await channelToKState(testData.channel.general, limitedGuild).then(x => x.channelKState)),
|
||||
limitedRoom
|
||||
)
|
||||
})
|
||||
|
||||
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"),
|
||||
|
|
|
@ -26,7 +26,7 @@ function getPermissions(userRoles, guildRoles, userID, channelOverwrites) {
|
|||
}
|
||||
|
||||
if (channelOverwrites) {
|
||||
/** @type {((overwrite: Required<DiscordTypes.APIGuildChannel>["permission_overwrites"][0]) => any)[]} */
|
||||
/** @type {((overwrite: Required<DiscordTypes.APIOverwrite>) => any)[]} */
|
||||
const actions = [
|
||||
// Channel @everyone deny
|
||||
overwrite => overwrite.id === everyoneID && (allowed &= ~BigInt(overwrite.deny)),
|
||||
|
|
22
test/data.js
22
test/data.js
|
@ -47,6 +47,9 @@ module.exports = {
|
|||
},
|
||||
users: {
|
||||
"@test_auto_invite:example.org": 100
|
||||
},
|
||||
notifications: {
|
||||
room: 0
|
||||
}
|
||||
},
|
||||
"chat.schildi.hide_ui/read_receipts": {hidden: true},
|
||||
|
@ -98,7 +101,6 @@ module.exports = {
|
|||
icon: "a_f83622e09ead74f0c5c527fe241f8f8c",
|
||||
emojis: [
|
||||
{
|
||||
version: 0,
|
||||
roles: [],
|
||||
require_colons: true,
|
||||
name: "hippo",
|
||||
|
@ -108,7 +110,6 @@ module.exports = {
|
|||
animated: false
|
||||
},
|
||||
{
|
||||
version: 0,
|
||||
roles: [],
|
||||
require_colons: true,
|
||||
name: "hipposcope",
|
||||
|
@ -121,7 +122,20 @@ module.exports = {
|
|||
premium_subscription_count: 14,
|
||||
roles: [
|
||||
{
|
||||
version: 1696964862461,
|
||||
unicode_emoji: null,
|
||||
tags: {},
|
||||
position: 0,
|
||||
permissions: '559623605575360',
|
||||
name: '@everyone',
|
||||
mentionable: false,
|
||||
managed: false,
|
||||
id: '112760669178241024',
|
||||
icon: null,
|
||||
hoist: false,
|
||||
flags: 0,
|
||||
color: 0
|
||||
},
|
||||
{
|
||||
unicode_emoji: null,
|
||||
tags: {},
|
||||
position: 22,
|
||||
|
@ -135,7 +149,6 @@ module.exports = {
|
|||
flags: 0,
|
||||
color: 0
|
||||
}, {
|
||||
version: 1696964862776,
|
||||
unicode_emoji: null,
|
||||
tags: {},
|
||||
position: 131,
|
||||
|
@ -149,7 +162,6 @@ module.exports = {
|
|||
flags: 0,
|
||||
color: 11076095
|
||||
}, {
|
||||
version: 1696964862698,
|
||||
unicode_emoji: '🍂',
|
||||
tags: {},
|
||||
position: 102,
|
||||
|
|
Loading…
Reference in a new issue