configurable read_only_room_events_default_power

This commit is contained in:
bbedward 2025-09-08 22:21:13 -04:00
commit e19703ef03
4 changed files with 9 additions and 5 deletions

View file

@ -40,7 +40,9 @@ const PRIVACY_ENUMS = {
const DEFAULT_PRIVACY_LEVEL = 0 const DEFAULT_PRIVACY_LEVEL = 0
const READ_ONLY_ROOM_EVENTS_DEFAULT_POWER = 50 function getReadOnlyRoomEventsDefaultPower() {
return reg.ooye.read_only_room_events_default_power ?? 50
}
/** @type {Map<string, Promise<string>>} channel ID -> Promise<room ID> */ /** @type {Map<string, Promise<string>>} channel ID -> Promise<room ID> */
const inflightRoomCreate = new Map() const inflightRoomCreate = new Map()
@ -148,7 +150,7 @@ async function channelToKState(channel, guild, di) {
"m.room.join_rules/": join_rules, "m.room.join_rules/": join_rules,
/** @type {Ty.Event.M_Power_Levels} */ /** @type {Ty.Event.M_Power_Levels} */
"m.room.power_levels/": { "m.room.power_levels/": {
events_default: everyoneCanSend ? 0 : READ_ONLY_ROOM_EVENTS_DEFAULT_POWER, events_default: everyoneCanSend ? 0 : getReadOnlyRoomEventsDefaultPower(),
events: { events: {
"m.reaction": 0, "m.reaction": 0,
"m.room.redaction": 0 // only affects redactions of own events, required to be able to un-react "m.room.redaction": 0 // only affects redactions of own events, required to be able to un-react
@ -559,7 +561,7 @@ async function createAllForGuild(guildID) {
} }
module.exports.DEFAULT_PRIVACY_LEVEL = DEFAULT_PRIVACY_LEVEL module.exports.DEFAULT_PRIVACY_LEVEL = DEFAULT_PRIVACY_LEVEL
module.exports.READ_ONLY_ROOM_EVENTS_DEFAULT_POWER = READ_ONLY_ROOM_EVENTS_DEFAULT_POWER module.exports.getReadOnlyRoomEventsDefaultPower = getReadOnlyRoomEventsDefaultPower
module.exports.PRIVACY_ENUMS = PRIVACY_ENUMS module.exports.PRIVACY_ENUMS = PRIVACY_ENUMS
module.exports.createRoom = createRoom module.exports.createRoom = createRoom
module.exports.ensureRoom = ensureRoom module.exports.ensureRoom = ensureRoom

View file

@ -165,7 +165,7 @@ function memberToPowerLevel(user, member, guild, channel) {
/* PL 50 = if room is read-only but the user has been specially allowed to send messages */ /* PL 50 = if room is read-only but the user has been specially allowed to send messages */
const everyoneCanSend = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.SendMessages) const everyoneCanSend = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.SendMessages)
const userCanSend = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.SendMessages) const userCanSend = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.SendMessages)
if (!everyoneCanSend && userCanSend) return createRoom.READ_ONLY_ROOM_EVENTS_DEFAULT_POWER if (!everyoneCanSend && userCanSend) return createRoom.getReadOnlyRoomEventsDefaultPower()
/* PL 20 = Mention Everyone for technical reasons. */ /* PL 20 = Mention Everyone for technical reasons. */
const everyoneCanMentionEveryone = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.MentionEveryone) const everyoneCanMentionEveryone = utils.hasPermission(everyonePermissions, DiscordTypes.PermissionFlagsBits.MentionEveryone)
const userCanMentionEveryone = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.MentionEveryone) const userCanMentionEveryone = utils.hasPermission(permissions, DiscordTypes.PermissionFlagsBits.MentionEveryone)

View file

@ -57,7 +57,8 @@ function getTemplateRegistration(serverName) {
max_file_size: 5000000, max_file_size: 5000000,
content_length_workaround: false, content_length_workaround: false,
include_user_id_in_mxid: false, include_user_id_in_mxid: false,
invite: [] invite: [],
read_only_room_events_default_power: 50
} }
} }
} }

1
src/types.d.ts vendored
View file

@ -31,6 +31,7 @@ export type AppServiceRegistrationConfig = {
discord_origin?: string discord_origin?: string
discord_cdn_origin?: string, discord_cdn_origin?: string,
web_password: string web_password: string
read_only_room_events_default_power?: number
} }
old_bridge?: { old_bridge?: {
as_token: string as_token: string