Merge branch 'develop' of https://github.com/matrix-org/matrix-react-sdk into export-conversations
This commit is contained in:
commit
b04bfeda33
196 changed files with 5000 additions and 3423 deletions
54
src/utils/FileUtils.ts
Normal file
54
src/utils/FileUtils.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import filesize from 'filesize';
|
||||
import { IMediaEventContent } from '../customisations/models/IMediaEventContent';
|
||||
import { _t } from '../languageHandler';
|
||||
|
||||
/**
|
||||
* Extracts a human readable label for the file attachment to use as
|
||||
* link text.
|
||||
*
|
||||
* @param {IMediaEventContent} content The "content" key of the matrix event.
|
||||
* @param {string} fallbackText The fallback text
|
||||
* @param {boolean} withSize Whether to include size information. Default true.
|
||||
* @return {string} the human readable link text for the attachment.
|
||||
*/
|
||||
export function presentableTextForFile(
|
||||
content: IMediaEventContent,
|
||||
fallbackText = _t("Attachment"),
|
||||
withSize = true,
|
||||
): string {
|
||||
let text = fallbackText;
|
||||
if (content.body && content.body.length > 0) {
|
||||
// The content body should be the name of the file including a
|
||||
// file extension.
|
||||
text = content.body;
|
||||
}
|
||||
|
||||
if (content.info && content.info.size && withSize) {
|
||||
// If we know the size of the file then add it as human readable
|
||||
// string to the end of the link text so that the user knows how
|
||||
// big a file they are downloading.
|
||||
// The content.info also contains a MIME-type but we don't display
|
||||
// it since it is "ugly", users generally aren't aware what it
|
||||
// means and the type of the attachment can usually be inferrered
|
||||
// from the file extension.
|
||||
text += ' (' + filesize(content.info.size) + ')';
|
||||
}
|
||||
return text;
|
||||
}
|
|
@ -67,6 +67,7 @@ export class MediaEventHelper implements IDestroyable {
|
|||
private prepareThumbnailUrl = async () => {
|
||||
if (this.media.isEncrypted) {
|
||||
const blob = await this.thumbnailBlob.value;
|
||||
if (blob === null) return null;
|
||||
return URL.createObjectURL(blob);
|
||||
} else {
|
||||
return this.media.thumbnailHttp;
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import zxcvbn from 'zxcvbn';
|
||||
import zxcvbn, { ZXCVBNFeedbackWarning } from 'zxcvbn';
|
||||
|
||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||
import { _t, _td } from '../languageHandler';
|
||||
|
@ -84,7 +84,7 @@ export function scorePassword(password: string) {
|
|||
}
|
||||
// and warning, if any
|
||||
if (zxcvbnResult.feedback.warning) {
|
||||
zxcvbnResult.feedback.warning = _t(zxcvbnResult.feedback.warning);
|
||||
zxcvbnResult.feedback.warning = _t(zxcvbnResult.feedback.warning) as ZXCVBNFeedbackWarning;
|
||||
}
|
||||
|
||||
return zxcvbnResult;
|
||||
|
|
93
src/utils/RoomUpgrade.ts
Normal file
93
src/utils/RoomUpgrade.ts
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
|
||||
import { inviteUsersToRoom } from "../RoomInvite";
|
||||
import Modal from "../Modal";
|
||||
import { _t } from "../languageHandler";
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
import SpaceStore from "../stores/SpaceStore";
|
||||
|
||||
export async function upgradeRoom(
|
||||
room: Room,
|
||||
targetVersion: string,
|
||||
inviteUsers = false,
|
||||
handleError = true,
|
||||
updateSpaces = true,
|
||||
): Promise<string> {
|
||||
const cli = room.client;
|
||||
|
||||
let newRoomId: string;
|
||||
try {
|
||||
({ replacement_room: newRoomId } = await cli.upgradeRoom(room.roomId, targetVersion));
|
||||
} catch (e) {
|
||||
if (!handleError) throw e;
|
||||
console.error(e);
|
||||
|
||||
Modal.createTrackedDialog("Room Upgrade Error", "", ErrorDialog, {
|
||||
title: _t('Error upgrading room'),
|
||||
description: _t('Double check that your server supports the room version chosen and try again.'),
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
|
||||
// We have to wait for the js-sdk to give us the room back so
|
||||
// we can more effectively abuse the MultiInviter behaviour
|
||||
// which heavily relies on the Room object being available.
|
||||
if (inviteUsers) {
|
||||
const checkForUpgradeFn = async (newRoom: Room): Promise<void> => {
|
||||
// The upgradePromise should be done by the time we await it here.
|
||||
if (newRoom.roomId !== newRoomId) return;
|
||||
|
||||
const toInvite = [
|
||||
...room.getMembersWithMembership("join"),
|
||||
...room.getMembersWithMembership("invite"),
|
||||
].map(m => m.userId).filter(m => m !== cli.getUserId());
|
||||
|
||||
if (toInvite.length > 0) {
|
||||
// Errors are handled internally to this function
|
||||
await inviteUsersToRoom(newRoomId, toInvite);
|
||||
}
|
||||
|
||||
cli.removeListener('Room', checkForUpgradeFn);
|
||||
};
|
||||
cli.on('Room', checkForUpgradeFn);
|
||||
}
|
||||
|
||||
if (updateSpaces) {
|
||||
const parents = SpaceStore.instance.getKnownParents(room.roomId);
|
||||
try {
|
||||
for (const parentId of parents) {
|
||||
const parent = cli.getRoom(parentId);
|
||||
if (!parent?.currentState.maySendStateEvent(EventType.SpaceChild, cli.getUserId())) continue;
|
||||
|
||||
const currentEv = parent.currentState.getStateEvents(EventType.SpaceChild, room.roomId);
|
||||
await cli.sendStateEvent(parentId, EventType.SpaceChild, {
|
||||
...(currentEv?.getContent() || {}), // copy existing attributes like suggested
|
||||
via: [cli.getDomain()],
|
||||
}, newRoomId);
|
||||
await cli.sendStateEvent(parentId, EventType.SpaceChild, {}, room.roomId);
|
||||
}
|
||||
} catch (e) {
|
||||
// These errors are not critical to the room upgrade itself
|
||||
console.warn("Failed to update parent spaces during room upgrade", e);
|
||||
}
|
||||
}
|
||||
|
||||
return newRoomId;
|
||||
}
|
|
@ -16,10 +16,9 @@ limitations under the License.
|
|||
|
||||
import React from "react";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
|
||||
import { calculateRoomVia } from "../utils/permalinks/Permalinks";
|
||||
import { calculateRoomVia } from "./permalinks/Permalinks";
|
||||
import Modal from "../Modal";
|
||||
import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog";
|
||||
import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog";
|
||||
|
@ -30,8 +29,8 @@ import SpacePublicShare from "../components/views/spaces/SpacePublicShare";
|
|||
import InfoDialog from "../components/views/dialogs/InfoDialog";
|
||||
import { showRoomInviteDialog } from "../RoomInvite";
|
||||
|
||||
export const shouldShowSpaceSettings = (cli: MatrixClient, space: Room) => {
|
||||
const userId = cli.getUserId();
|
||||
export const shouldShowSpaceSettings = (space: Room) => {
|
||||
const userId = space.client.getUserId();
|
||||
return space.getMyMembership() === "join"
|
||||
&& (space.currentState.maySendStateEvent(EventType.RoomAvatar, userId)
|
||||
|| space.currentState.maySendStateEvent(EventType.RoomName, userId)
|
||||
|
@ -48,20 +47,20 @@ export const makeSpaceParentEvent = (room: Room, canonical = false) => ({
|
|||
state_key: room.roomId,
|
||||
});
|
||||
|
||||
export const showSpaceSettings = (cli: MatrixClient, space: Room) => {
|
||||
export const showSpaceSettings = (space: Room) => {
|
||||
Modal.createTrackedDialog("Space Settings", "", SpaceSettingsDialog, {
|
||||
matrixClient: cli,
|
||||
matrixClient: space.client,
|
||||
space,
|
||||
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
||||
};
|
||||
|
||||
export const showAddExistingRooms = async (cli: MatrixClient, space: Room) => {
|
||||
export const showAddExistingRooms = async (space: Room) => {
|
||||
return Modal.createTrackedDialog(
|
||||
"Space Landing",
|
||||
"Add Existing",
|
||||
AddExistingToSpaceDialog,
|
||||
{
|
||||
matrixClient: cli,
|
||||
matrixClient: space.client,
|
||||
onCreateRoomClick: showCreateNewRoom,
|
||||
space,
|
||||
},
|
||||
|
@ -69,7 +68,7 @@ export const showAddExistingRooms = async (cli: MatrixClient, space: Room) => {
|
|||
).finished;
|
||||
};
|
||||
|
||||
export const showCreateNewRoom = async (cli: MatrixClient, space: Room) => {
|
||||
export const showCreateNewRoom = async (space: Room) => {
|
||||
const modal = Modal.createTrackedDialog<[boolean, IOpts]>(
|
||||
"Space Landing",
|
||||
"Create Room",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue