Merge branch 'develop' into sort-imports
Signed-off-by: Aaron Raimist <aaron@raim.ist>
This commit is contained in:
commit
7b94e13a84
642 changed files with 30052 additions and 8035 deletions
|
@ -14,16 +14,17 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { MatrixEvent, EventStatus } from 'matrix-js-sdk/src/models/event';
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||
import { Thread } from 'matrix-js-sdk/src/models/thread';
|
||||
import { logger } from 'matrix-js-sdk/src/logger';
|
||||
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
||||
|
||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||
import shouldHideEvent from "../shouldHideEvent";
|
||||
import { getHandlerTile, haveTileForEvent } from "../components/views/rooms/EventTile";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||
import { Thread } from 'matrix-js-sdk/src/models/thread';
|
||||
import { logger } from 'matrix-js-sdk/src/logger';
|
||||
import { POLL_START_EVENT_TYPE } from '../polls/consts';
|
||||
|
||||
/**
|
||||
* Returns whether an event should allow actions like reply, reactions, edit, etc.
|
||||
|
@ -54,14 +55,17 @@ export function isContentActionable(mxEvent: MatrixEvent): boolean {
|
|||
}
|
||||
|
||||
export function canEditContent(mxEvent: MatrixEvent): boolean {
|
||||
if (mxEvent.status === EventStatus.CANCELLED || mxEvent.getType() !== "m.room.message" || mxEvent.isRedacted()) {
|
||||
if (mxEvent.status === EventStatus.CANCELLED ||
|
||||
mxEvent.getType() !== EventType.RoomMessage ||
|
||||
mxEvent.isRedacted() ||
|
||||
mxEvent.isRelation(RelationType.Replace) ||
|
||||
mxEvent.getSender() !== MatrixClientPeg.get().getUserId()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const content = mxEvent.getOriginalContent();
|
||||
const { msgtype } = content;
|
||||
return (msgtype === "m.text" || msgtype === "m.emote") &&
|
||||
content.body && typeof content.body === 'string' &&
|
||||
mxEvent.getSender() === MatrixClientPeg.get().getUserId();
|
||||
|
||||
const { msgtype, body } = mxEvent.getOriginalContent();
|
||||
return (msgtype === MsgType.Text || msgtype === MsgType.Emote) && body && typeof body === 'string';
|
||||
}
|
||||
|
||||
export function canEditOwnEvent(mxEvent: MatrixEvent): boolean {
|
||||
|
@ -136,7 +140,8 @@ export function getEventDisplayInfo(mxEvent: MatrixEvent): {
|
|||
!isLeftAlignedBubbleMessage &&
|
||||
eventType !== EventType.RoomMessage &&
|
||||
eventType !== EventType.Sticker &&
|
||||
eventType !== EventType.RoomCreate
|
||||
eventType !== EventType.RoomCreate &&
|
||||
eventType !== POLL_START_EVENT_TYPE.name
|
||||
);
|
||||
|
||||
// If we're showing hidden events in the timeline, we should use the
|
||||
|
|
|
@ -23,7 +23,7 @@ import { inviteUsersToRoom } from "../RoomInvite";
|
|||
import Modal, { IHandle } from "../Modal";
|
||||
import { _t } from "../languageHandler";
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
import SpaceStore from "../stores/SpaceStore";
|
||||
import SpaceStore from "../stores/spaces/SpaceStore";
|
||||
import Spinner from "../components/views/elements/Spinner";
|
||||
|
||||
interface IProgress {
|
||||
|
|
|
@ -77,7 +77,8 @@ export default abstract class Exporter {
|
|||
|
||||
protected async downloadZIP(): Promise<string | void> {
|
||||
const brand = SdkConfig.get().brand;
|
||||
const filename = `${brand} - Chat Export - ${formatFullDateNoDay(new Date())}.zip`;
|
||||
const filenameWithoutExt = `${brand} - Chat Export - ${formatFullDateNoDay(new Date())}`;
|
||||
const filename = `${filenameWithoutExt}.zip`;
|
||||
const { default: JSZip } = await import('jszip');
|
||||
|
||||
const zip = new JSZip();
|
||||
|
@ -85,7 +86,7 @@ export default abstract class Exporter {
|
|||
if (!this.cancelled) this.updateProgress("Generating a ZIP");
|
||||
else return this.cleanUp();
|
||||
|
||||
for (const file of this.files) zip.file(file.name, file.blob);
|
||||
for (const file of this.files) zip.file(filenameWithoutExt + "/" + file.name, file.blob);
|
||||
|
||||
const content = await zip.generateAsync({ type: "blob" });
|
||||
|
||||
|
|
|
@ -16,29 +16,29 @@ limitations under the License.
|
|||
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import Exporter from "./Exporter";
|
||||
import { mediaFromMxc } from "../../customisations/Media";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import Exporter from "./Exporter";
|
||||
import { mediaFromMxc } from "../../customisations/Media";
|
||||
import { Layout } from "../../settings/Layout";
|
||||
import { Layout } from "../../settings/enums/Layout";
|
||||
import { shouldFormContinuation } from "../../components/structures/MessagePanel";
|
||||
import { formatFullDateNoDayNoTime, wantsDateSeparator } from "../../DateUtils";
|
||||
import { RoomPermalinkCreator } from "../permalinks/Permalinks";
|
||||
import { _t } from "../../languageHandler";
|
||||
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
|
||||
import * as Avatar from "../../Avatar";
|
||||
import EventTile, { haveTileForEvent } from "../../components/views/rooms/EventTile";
|
||||
import DateSeparator from "../../components/views/messages/DateSeparator";
|
||||
import BaseAvatar from "../../components/views/avatars/BaseAvatar";
|
||||
import { ExportType, IExportOptions } from "./exportUtils";
|
||||
import exportJS from "!!raw-loader!./exportJS";
|
||||
import { ExportType } from "./exportUtils";
|
||||
import { IExportOptions } from "./exportUtils";
|
||||
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
||||
import getExportCSS from "./exportCSS";
|
||||
import { textForEvent } from "../../TextForEvent";
|
||||
|
||||
import exportJS from "!!raw-loader!./exportJS";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
export default class HTMLExporter extends Exporter {
|
||||
protected avatars: Map<string, boolean>;
|
||||
|
|
|
@ -16,14 +16,16 @@ limitations under the License.
|
|||
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
import React from "react";
|
||||
import { EventStatus } from "matrix-js-sdk/src/models/event";
|
||||
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import { _t } from "../languageHandler";
|
||||
import Modal from "../Modal";
|
||||
import Modal, { IHandle } from "../Modal";
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
import React from "react";
|
||||
import dis from "../dispatcher/dispatcher";
|
||||
import RoomViewStore from "../stores/RoomViewStore";
|
||||
import Spinner from "../components/views/elements/Spinner";
|
||||
|
||||
/**
|
||||
* Approximation of a membership status for a given room.
|
||||
|
@ -85,7 +87,12 @@ export function isJoinedOrNearlyJoined(membership: string): boolean {
|
|||
return effective === EffectiveMembership.Join || effective === EffectiveMembership.Invite;
|
||||
}
|
||||
|
||||
export async function leaveRoomBehaviour(roomId: string, retry = true) {
|
||||
export async function leaveRoomBehaviour(roomId: string, retry = true, spinner = true) {
|
||||
let spinnerModal: IHandle<any>;
|
||||
if (spinner) {
|
||||
spinnerModal = Modal.createDialog(Spinner, null, 'mx_Dialog_spinner');
|
||||
}
|
||||
|
||||
const cli = MatrixClientPeg.get();
|
||||
let leavingAllVersions = true;
|
||||
const history = cli.getRoomUpgradeHistory(roomId);
|
||||
|
@ -98,6 +105,26 @@ export async function leaveRoomBehaviour(roomId: string, retry = true) {
|
|||
}
|
||||
}
|
||||
|
||||
const room = cli.getRoom(roomId);
|
||||
// await any queued messages being sent so that they do not fail
|
||||
await Promise.all(room.getPendingEvents().filter(ev => {
|
||||
return [EventStatus.QUEUED, EventStatus.ENCRYPTING, EventStatus.SENDING].includes(ev.status);
|
||||
}).map(ev => new Promise<void>((resolve, reject) => {
|
||||
const handler = () => {
|
||||
if (ev.status === EventStatus.NOT_SENT) {
|
||||
spinnerModal?.close();
|
||||
reject(ev.error);
|
||||
}
|
||||
|
||||
if (!ev.status || ev.status === EventStatus.SENT) {
|
||||
ev.off("Event.status", handler);
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
ev.on("Event.status", handler);
|
||||
})));
|
||||
|
||||
let results: { [roomId: string]: Error & { errcode?: string, message: string, data?: Record<string, any> } } = {};
|
||||
if (!leavingAllVersions) {
|
||||
try {
|
||||
|
@ -118,10 +145,12 @@ export async function leaveRoomBehaviour(roomId: string, retry = true) {
|
|||
const limitExceededError = Object.values(results).find(e => e?.errcode === "M_LIMIT_EXCEEDED");
|
||||
if (limitExceededError) {
|
||||
await sleep(limitExceededError.data.retry_after_ms ?? 100);
|
||||
return leaveRoomBehaviour(roomId, false);
|
||||
return leaveRoomBehaviour(roomId, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
spinnerModal?.close();
|
||||
|
||||
const errors = Object.entries(results).filter(r => !!r[1]);
|
||||
if (errors.length > 0) {
|
||||
const messages = [];
|
||||
|
|
|
@ -20,15 +20,16 @@ import { Room } from "matrix-js-sdk/src/models/room";
|
|||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
import SpecPermalinkConstructor, { baseUrl as matrixtoBaseUrl } from "./SpecPermalinkConstructor";
|
||||
import PermalinkConstructor, { PermalinkParts } from "./PermalinkConstructor";
|
||||
import ElementPermalinkConstructor from "./ElementPermalinkConstructor";
|
||||
import matrixLinkify from "../../linkify-matrix";
|
||||
import SdkConfig from "../../SdkConfig";
|
||||
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ELEMENT_URL_PATTERN } from "../../linkify-matrix";
|
||||
|
||||
// The maximum number of servers to pick when working out which servers
|
||||
// to add to permalinks. The servers are appended as ?via=example.org
|
||||
const MAX_SERVER_CANDIDATES = 3;
|
||||
|
@ -347,7 +348,7 @@ export function tryTransformPermalinkToLocalHref(permalink: string): string {
|
|||
}
|
||||
|
||||
try {
|
||||
const m = decodeURIComponent(permalink).match(matrixLinkify.ELEMENT_URL_PATTERN);
|
||||
const m = decodeURIComponent(permalink).match(ELEMENT_URL_PATTERN);
|
||||
if (m) {
|
||||
return m[1];
|
||||
}
|
||||
|
@ -385,7 +386,7 @@ export function getPrimaryPermalinkEntity(permalink: string): string {
|
|||
|
||||
// If not a permalink, try the vector patterns.
|
||||
if (!permalinkParts) {
|
||||
const m = permalink.match(matrixLinkify.ELEMENT_URL_PATTERN);
|
||||
const m = permalink.match(ELEMENT_URL_PATTERN);
|
||||
if (m) {
|
||||
// A bit of a hack, but it gets the job done
|
||||
const handler = new ElementPermalinkConstructor("http://localhost");
|
||||
|
|
|
@ -18,6 +18,7 @@ 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 { JoinRule } from "matrix-js-sdk/src/@types/partials";
|
||||
|
||||
import { calculateRoomVia } from "./permalinks/Permalinks";
|
||||
import Modal from "../Modal";
|
||||
|
@ -101,6 +102,10 @@ export const showCreateNewRoom = async (space: Room): Promise<boolean> => {
|
|||
return shouldCreate;
|
||||
};
|
||||
|
||||
export const shouldShowSpaceInvite = (space: Room) =>
|
||||
(space?.getMyMembership() === "join" && space.canInvite(space.client.getUserId())) ||
|
||||
space.getJoinRule() === JoinRule.Public;
|
||||
|
||||
export const showSpaceInvite = (space: Room, initialText = ""): void => {
|
||||
if (space.getJoinRule() === "public") {
|
||||
const modal = Modal.createTrackedDialog("Space Invite", "User Menu", InfoDialog, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue