Only allow admins to change room mode

This commit is contained in:
N Pex 2023-08-07 14:13:35 +00:00
parent 31b7c4ed26
commit cfc14f05a0
6 changed files with 90 additions and 48 deletions

View file

@ -7,6 +7,8 @@ export const ROOM_TYPE_DEFAULT = "im.keanu.room_type_default";
export const ROOM_TYPE_VOICE_MODE = "im.keanu.room_type_voice";
export const ROOM_TYPE_FILE_MODE = "im.keanu.room_type_file";
export const STATE_EVENT_ROOM_TYPE = "im.keanu.room_type";
const sizeOf = require("image-size");
var dayjs = require('dayjs');
@ -482,19 +484,19 @@ class Util {
/**
* Return what "mode" to use for the given room.
*
* The default value is given by the room itself. If the "type" of the
* room is set to 'im.keanu.room_type_voice' then we default to voice mode,
* else if set to 'im.keanu.room_type_file' we default to file mode.
* The user can then override this default by changing the "room type"
* in room settings (it will be persisted as a user specific tag on the room)
* The default value is given by the room itself (as state events, see roomTypeMixin).
* This method just returns if the user has overridden this in room settings (this
* fact will be persisted as a user specific tag on the room). Note: currently override
* is disabled in the UI...
*/
roomDisplayType(roomOrNull) {
roomDisplayTypeOverride(roomOrNull) {
if (roomOrNull) {
const room = roomOrNull;
// Have we changed our local view mode of this room?
const tags = room.tags;
if (tags && tags["ui_options"]) {
console.error("We have a tag!");
if (tags["ui_options"]["voice_mode"] === 1) {
return ROOM_TYPE_VOICE_MODE;
} else if (tags["ui_options"]["file_mode"] === 1) {
@ -504,30 +506,16 @@ class Util {
return ROOM_TYPE_DEFAULT;
}
}
// Was the room created with a voice mode type?
const createEvent = room.currentState.getStateEvents(
"m.room.create",
""
);
if (createEvent) {
const roomType = createEvent.getContent().type;
// Validate value, or return default
if ([ROOM_TYPE_FILE_MODE, ROOM_TYPE_VOICE_MODE].includes(roomType)) {
return roomType;
}
}
}
return ROOM_TYPE_DEFAULT;
return null;
}
/**
* Return the room type for the current room
* @param {*} roomOrNull
*/
roomDisplayTypeToQueryParam(roomOrNull) {
const roomType = this.roomDisplayType(roomOrNull);
roomDisplayTypeToQueryParam(roomOrNull, roomDisplayType) {
const roomType = this.roomDisplayTypeOverride(roomOrNull) || roomDisplayType;
if (roomType === ROOM_TYPE_FILE_MODE) {
// Send "file" here, so the receiver of the invite link knows to display the "file drop" join page
// instead of the standard one.