Allow "voice mode" to be set as default on room creation

Also, hide it behind a flag in config (experimental_voice_mode)
This commit is contained in:
N-Pex 2023-02-17 22:00:47 +01:00 committed by n8fr8
parent 3853f21f90
commit afa38275f0
7 changed files with 246 additions and 244 deletions

View file

@ -3,6 +3,8 @@ import * as ContentHelpers from "matrix-js-sdk/lib/content-helpers";
import dataUriToBuffer from "data-uri-to-buffer";
import ImageResize from "image-resize";
export const ROOM_TYPE_VOICE_MODE = "im.keanu.room_type_voice";
const sizeOf = require("image-size");
var dayjs = require('dayjs');
@ -424,6 +426,36 @@ class Util {
});
}
/**
* Return 'true' if we should use voice mode 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 not. The user can then override this default by flipping the "voice mode"
* swicth on room settings (it will be persisted as a user specific tag on the room)
*/
useVoiceMode(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"]) {
return tags["ui_options"]["voice_mode"] === 1;
}
// Was the room created with a voice mode type?
const createEvent = room.currentState.getStateEvents(
"m.room.create",
""
);
if (createEvent) {
return createEvent.getContent().type === ROOM_TYPE_VOICE_MODE;
}
}
return false;
}
/** Generate a random user name */
randomUser(prefix) {
var pfx = prefix ? prefix.replace(/[^0-9a-zA-Z\-_]/gi, '') : null;