Merge branch 'develop' into export-conversations
This commit is contained in:
commit
e88edba650
87 changed files with 4403 additions and 1194 deletions
|
@ -17,18 +17,22 @@ limitations under the License.
|
|||
// Pull in the encryption lib so that we can decrypt attachments.
|
||||
import encrypt from 'browser-encrypt-attachment';
|
||||
import { mediaFromContent } from "../customisations/Media";
|
||||
import { IEncryptedFile } from "../customisations/models/IMediaEventContent";
|
||||
import { IEncryptedFile, IMediaEventInfo } from "../customisations/models/IMediaEventContent";
|
||||
import { getBlobSafeMimeType } from "./blobs";
|
||||
|
||||
/**
|
||||
* Decrypt a file attached to a matrix event.
|
||||
* @param {IEncryptedFile} file The json taken from the matrix event.
|
||||
* @param {IEncryptedFile} file The encrypted file information taken from the matrix event.
|
||||
* This passed to [link]{@link https://github.com/matrix-org/browser-encrypt-attachments}
|
||||
* as the encryption info object, so will also have the those keys in addition to
|
||||
* the keys below.
|
||||
* @param {IMediaEventInfo} info The info parameter taken from the matrix event.
|
||||
* @returns {Promise<Blob>} Resolves to a Blob of the file.
|
||||
*/
|
||||
export function decryptFile(file: IEncryptedFile): Promise<Blob> {
|
||||
export function decryptFile(
|
||||
file: IEncryptedFile,
|
||||
info?: IMediaEventInfo,
|
||||
): Promise<Blob> {
|
||||
const media = mediaFromContent({ file });
|
||||
// Download the encrypted file as an array buffer.
|
||||
return media.downloadSource().then((response) => {
|
||||
|
@ -44,7 +48,7 @@ export function decryptFile(file: IEncryptedFile): Promise<Blob> {
|
|||
// they introduce XSS attacks if the Blob URI is viewed directly in the
|
||||
// browser (e.g. by copying the URI into a new tab or window.)
|
||||
// See warning at top of file.
|
||||
let mimetype = file.mimetype ? file.mimetype.split(";")[0].trim() : '';
|
||||
let mimetype = info?.mimetype ? info.mimetype.split(";")[0].trim() : '';
|
||||
mimetype = getBlobSafeMimeType(mimetype);
|
||||
|
||||
return new Blob([dataArray], { type: mimetype });
|
||||
|
|
|
@ -76,7 +76,8 @@ export class MediaEventHelper implements IDestroyable {
|
|||
|
||||
private fetchSource = () => {
|
||||
if (this.media.isEncrypted) {
|
||||
return decryptFile(this.event.getContent<IMediaEventContent>().file);
|
||||
const content = this.event.getContent<IMediaEventContent>();
|
||||
return decryptFile(content.file, content.info);
|
||||
}
|
||||
return this.media.downloadSource().then(r => r.blob());
|
||||
};
|
||||
|
@ -87,7 +88,7 @@ export class MediaEventHelper implements IDestroyable {
|
|||
if (this.media.isEncrypted) {
|
||||
const content = this.event.getContent<IMediaEventContent>();
|
||||
if (content.info?.thumbnail_file) {
|
||||
return decryptFile(content.info.thumbnail_file);
|
||||
return decryptFile(content.info.thumbnail_file, content.info.thumbnail_info);
|
||||
} else {
|
||||
// "Should never happen"
|
||||
console.warn("Media claims to have thumbnail and is encrypted, but no thumbnail_file found");
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
|
||||
import { calculateRoomVia } from "./permalinks/Permalinks";
|
||||
import Modal from "../Modal";
|
||||
|
@ -37,6 +38,7 @@ import { leaveRoomBehaviour } from "./membership";
|
|||
import Spinner from "../components/views/elements/Spinner";
|
||||
import dis from "../dispatcher/dispatcher";
|
||||
import LeaveSpaceDialog from "../components/views/dialogs/LeaveSpaceDialog";
|
||||
import CreateSpaceFromCommunityDialog from "../components/views/dialogs/CreateSpaceFromCommunityDialog";
|
||||
|
||||
export const shouldShowSpaceSettings = (space: Room) => {
|
||||
const userId = space.client.getUserId();
|
||||
|
@ -173,3 +175,10 @@ export const leaveSpace = (space: Room) => {
|
|||
},
|
||||
}, "mx_LeaveSpaceDialog_wrapper");
|
||||
};
|
||||
|
||||
export const createSpaceFromCommunity = (cli: MatrixClient, groupId: string): Promise<[string?]> => {
|
||||
return Modal.createTrackedDialog('Create Space', 'from community', CreateSpaceFromCommunityDialog, {
|
||||
matrixClient: cli,
|
||||
groupId,
|
||||
}, "mx_CreateSpaceFromCommunityDialog_wrapper").finished as Promise<[string?]>;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue