Experimental "file drop" mode
This commit is contained in:
parent
791fa5936a
commit
ebadd509e9
19 changed files with 1038 additions and 85 deletions
|
|
@ -3,7 +3,9 @@ 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_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";
|
||||
|
||||
const sizeOf = require("image-size");
|
||||
|
||||
|
|
@ -283,7 +285,7 @@ class Util {
|
|||
matrixClient.sendEvent(roomId, eventType, content, undefined, undefined)
|
||||
.then((result) => {
|
||||
console.log("Message sent: ", result);
|
||||
resolve(true);
|
||||
resolve(result.event_id);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Send error: ", err);
|
||||
|
|
@ -322,7 +324,7 @@ class Util {
|
|||
matrixClient.resendEvent(event, matrixClient.getRoom(event.getRoomId()))
|
||||
.then((result) => {
|
||||
console.log("Message sent: ", result);
|
||||
resolve(true);
|
||||
resolve(result.event_id);
|
||||
})
|
||||
.catch((err) => {
|
||||
// Still error, abort
|
||||
|
|
@ -337,7 +339,7 @@ class Util {
|
|||
});
|
||||
}
|
||||
|
||||
sendImage(matrixClient, roomId, file, onUploadProgress) {
|
||||
sendImage(matrixClient, roomId, file, onUploadProgress, threadRoot) {
|
||||
return new UploadPromise((resolve, reject, aborter) => {
|
||||
const abortionController = aborter;
|
||||
var reader = new FileReader();
|
||||
|
|
@ -382,6 +384,14 @@ class Util {
|
|||
msgtype: msgtype
|
||||
}
|
||||
|
||||
// If thread root (an eventId) is set, add that here
|
||||
if (threadRoot) {
|
||||
messageContent["m.relates_to"] = {
|
||||
"rel_type": "m.thread",
|
||||
"event_id": threadRoot
|
||||
};
|
||||
}
|
||||
|
||||
// Set filename for files
|
||||
if (msgtype == 'm.file') {
|
||||
messageContent.filename = file.name;
|
||||
|
|
@ -462,21 +472,29 @@ class Util {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return 'true' if we should use voice mode for the given room.
|
||||
*
|
||||
* 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 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)
|
||||
* 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)
|
||||
*/
|
||||
useVoiceMode(roomOrNull) {
|
||||
roomDisplayType(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;
|
||||
if (tags["ui_options"]["voice_mode"] === 1) {
|
||||
return ROOM_TYPE_VOICE_MODE;
|
||||
} else if (tags["ui_options"]["file_mode"] === 1) {
|
||||
return ROOM_TYPE_FILE_MODE;
|
||||
} else if (tags["ui_options"]["file_mode"] === 0 && tags["ui_options"]["file_mode"] === 0) {
|
||||
// Explicitly set to "default"
|
||||
return ROOM_TYPE_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
// Was the room created with a voice mode type?
|
||||
|
|
@ -485,10 +503,34 @@ class Util {
|
|||
""
|
||||
);
|
||||
if (createEvent) {
|
||||
return createEvent.getContent().type === ROOM_TYPE_VOICE_MODE;
|
||||
const roomType = createEvent.getContent().type;
|
||||
|
||||
// Validate value, or return default
|
||||
if ([ROOM_TYPE_FILE_MODE, ROOM_TYPE_VOICE_MODE].includes(roomType)) {
|
||||
return roomType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return ROOM_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the room type for the current room
|
||||
* @param {*} roomOrNull
|
||||
*/
|
||||
roomDisplayTypeToQueryParam(roomOrNull) {
|
||||
const roomType = this.roomDisplayType(roomOrNull);
|
||||
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.
|
||||
return "file";
|
||||
} else if (roomType === ROOM_TYPE_VOICE_MODE) {
|
||||
// No need to return "voice" here. The invite page looks the same for default and voice mode,
|
||||
// so currently no point in cluttering the invite link with it. The corrent mode will be picked up from
|
||||
// room creation flags once the user joins.
|
||||
return undefined;
|
||||
}
|
||||
return undefined; // Default, just return undefined
|
||||
}
|
||||
|
||||
/** Generate a random user name */
|
||||
|
|
@ -592,7 +634,7 @@ class Util {
|
|||
|
||||
findOneVisibleElement(parentNode) {
|
||||
let start = 0;
|
||||
let end = parentNode.children.length - 1;
|
||||
let end = (parentNode && parentNode.children) ? parentNode.children.length - 1 : -1;
|
||||
while (start <= end) {
|
||||
let middle = Math.floor((start + end) / 2);
|
||||
let childNode = parentNode.children[middle];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue