2016-03-05 05:30:18 +03:00
|
|
|
/*
|
2022-01-13 20:03:37 +03:00
|
|
|
Copyright 2015 - 2022 The Matrix.org Foundation C.I.C.
|
2016-03-05 05:30:18 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2021-10-26 17:28:22 +03:00
|
|
|
|
2021-06-24 11:40:30 +03:00
|
|
|
import React from "react";
|
2023-08-08 13:12:12 +03:00
|
|
|
import {
|
|
|
|
MatrixEvent,
|
|
|
|
MatrixClient,
|
|
|
|
GuestAccess,
|
|
|
|
HistoryVisibility,
|
|
|
|
JoinRule,
|
|
|
|
EventType,
|
|
|
|
MsgType,
|
2023-08-23 12:04:25 +03:00
|
|
|
M_POLL_START,
|
|
|
|
M_POLL_END,
|
2024-03-12 17:52:54 +03:00
|
|
|
KnownMembership,
|
2023-08-08 13:12:12 +03:00
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2021-10-23 01:23:32 +03:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
import { removeDirectionOverrideChars } from "matrix-js-sdk/src/utils";
|
2023-01-13 20:02:33 +03:00
|
|
|
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
|
2021-10-23 01:23:32 +03:00
|
|
|
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from "./languageHandler";
|
2017-04-10 12:09:26 +03:00
|
|
|
import * as Roles from "./Roles";
|
2021-06-22 09:42:37 +03:00
|
|
|
import { isValid3pidInvite } from "./RoomInvite";
|
2019-06-26 22:22:01 +03:00
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { ALL_RULE_TYPES, ROOM_RULE_TYPES, SERVER_RULE_TYPES, USER_RULE_TYPES } from "./mjolnir/BanList";
|
|
|
|
import { WIDGET_LAYOUT_EVENT_TYPE } from "./stores/widgets/WidgetLayoutStore";
|
2022-01-05 18:14:44 +03:00
|
|
|
import { RightPanelPhases } from "./stores/right-panel/RightPanelStorePhases";
|
2021-06-24 11:40:30 +03:00
|
|
|
import defaultDispatcher from "./dispatcher/dispatcher";
|
2023-04-27 14:55:29 +03:00
|
|
|
import { RoomSettingsTab } from "./components/views/dialogs/RoomSettingsDialog";
|
2023-02-13 14:39:16 +03:00
|
|
|
import AccessibleButton, { ButtonEvent } from "./components/views/elements/AccessibleButton";
|
2022-01-05 18:14:44 +03:00
|
|
|
import RightPanelStore from "./stores/right-panel/RightPanelStore";
|
2022-12-12 18:09:11 +03:00
|
|
|
import { highlightEvent, isLocationEvent } from "./utils/EventUtils";
|
2022-10-06 17:27:12 +03:00
|
|
|
import { ElementCall } from "./models/Call";
|
2022-12-12 18:09:11 +03:00
|
|
|
import { textForVoiceBroadcastStoppedEvent, VoiceBroadcastInfoEventType } from "./voice-broadcast";
|
2022-12-16 14:01:16 +03:00
|
|
|
import { getSenderName } from "./utils/event/getSenderName";
|
2022-01-19 03:58:31 +03:00
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function getRoomMemberDisplayname(client: MatrixClient, event: MatrixEvent, userId = event.getSender()): string {
|
2022-02-11 12:25:14 +03:00
|
|
|
const roomId = event.getRoomId();
|
2023-02-15 16:36:22 +03:00
|
|
|
const member = client.getRoom(roomId)?.getMember(userId!);
|
2023-09-01 10:26:48 +03:00
|
|
|
return member?.name || member?.rawDisplayName || userId || _t("common|someone");
|
2022-02-11 12:25:14 +03:00
|
|
|
}
|
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForCallEvent(event: MatrixEvent, client: MatrixClient): () => string {
|
|
|
|
const roomName = client.getRoom(event.getRoomId()!)?.name;
|
|
|
|
const isSupported = client.supportsVoip();
|
2022-10-06 17:27:12 +03:00
|
|
|
|
|
|
|
return isSupported
|
2023-09-04 21:41:39 +03:00
|
|
|
? () => _t("timeline|m.call|video_call_started", { roomName })
|
|
|
|
: () => _t("timeline|m.call|video_call_started_unsupported", { roomName });
|
2022-10-06 17:27:12 +03:00
|
|
|
}
|
|
|
|
|
2021-06-07 06:06:56 +03:00
|
|
|
// These functions are frequently used just to check whether an event has
|
|
|
|
// any text to display at all. For this reason they return deferred values
|
|
|
|
// to avoid the expense of looking up translations when they're not needed.
|
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForCallInviteEvent(event: MatrixEvent, client: MatrixClient): (() => string) | null {
|
2022-01-19 03:58:31 +03:00
|
|
|
const senderName = getSenderName(event);
|
2021-08-02 15:34:18 +03:00
|
|
|
// FIXME: Find a better way to determine this from the event?
|
2022-02-09 12:09:28 +03:00
|
|
|
const isVoice = !event.getContent().offer?.sdp?.includes("m=video");
|
2023-06-05 20:12:23 +03:00
|
|
|
const isSupported = client.supportsVoip();
|
2021-08-02 15:34:18 +03:00
|
|
|
|
|
|
|
// This ladder could be reduced down to a couple string variables, however other languages
|
|
|
|
// can have a hard time translating those strings. In an effort to make translations easier
|
|
|
|
// and more accurate, we break out the string-based variables to a couple booleans.
|
|
|
|
if (isVoice && isSupported) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.call.invite|voice_call", { senderName });
|
2021-08-02 15:34:18 +03:00
|
|
|
} else if (isVoice && !isSupported) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.call.invite|voice_call_unsupported", { senderName });
|
2021-08-02 15:34:18 +03:00
|
|
|
} else if (!isVoice && isSupported) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.call.invite|video_call", { senderName });
|
2021-08-02 15:34:18 +03:00
|
|
|
} else if (!isVoice && !isSupported) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.call.invite|video_call_unsupported", { senderName });
|
2021-08-02 15:34:18 +03:00
|
|
|
}
|
2023-02-15 16:36:22 +03:00
|
|
|
|
|
|
|
return null;
|
2021-08-02 15:34:18 +03:00
|
|
|
}
|
|
|
|
|
2023-05-12 14:54:24 +03:00
|
|
|
enum Modification {
|
|
|
|
None,
|
|
|
|
Unset,
|
|
|
|
Set,
|
|
|
|
Changed,
|
|
|
|
}
|
|
|
|
|
|
|
|
function getModification(prev?: string, value?: string): Modification {
|
|
|
|
if (prev && value && prev !== value) {
|
|
|
|
return Modification.Changed;
|
|
|
|
}
|
|
|
|
if (prev && !value) {
|
|
|
|
return Modification.Unset;
|
|
|
|
}
|
|
|
|
if (!prev && value) {
|
|
|
|
return Modification.Set;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Modification.None;
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForMemberEvent(
|
|
|
|
ev: MatrixEvent,
|
|
|
|
client: MatrixClient,
|
|
|
|
allowJSX: boolean,
|
|
|
|
showHiddenEvents?: boolean,
|
|
|
|
): (() => string) | null {
|
2015-10-30 05:07:04 +03:00
|
|
|
// XXX: SYJS-16 "sender is sometimes null for join messages"
|
2023-06-05 20:12:23 +03:00
|
|
|
const senderName = ev.sender?.name || getRoomMemberDisplayname(client, ev);
|
|
|
|
const targetName = ev.target?.name || getRoomMemberDisplayname(client, ev, ev.getStateKey());
|
2017-09-25 11:48:00 +03:00
|
|
|
const prevContent = ev.getPrevContent();
|
|
|
|
const content = ev.getContent();
|
2021-06-23 19:31:08 +03:00
|
|
|
const reason = content.reason;
|
2017-09-25 11:48:00 +03:00
|
|
|
|
|
|
|
switch (content.membership) {
|
2024-03-12 17:52:54 +03:00
|
|
|
case KnownMembership.Invite: {
|
2017-09-25 11:48:00 +03:00
|
|
|
const threePidContent = content.third_party_invite;
|
2015-12-17 18:48:14 +03:00
|
|
|
if (threePidContent) {
|
2016-03-02 19:04:24 +03:00
|
|
|
if (threePidContent.display_name) {
|
2021-06-24 04:42:47 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.member|accepted_3pid_invite", {
|
2018-07-03 12:30:08 +03:00
|
|
|
targetName,
|
2017-09-25 11:48:00 +03:00
|
|
|
displayName: threePidContent.display_name,
|
|
|
|
});
|
2016-03-02 19:04:24 +03:00
|
|
|
} else {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|accepted_invite", { targetName });
|
2016-03-02 19:04:24 +03:00
|
|
|
}
|
2017-09-25 11:48:00 +03:00
|
|
|
} else {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|invite", { senderName, targetName });
|
2015-12-17 18:48:14 +03:00
|
|
|
}
|
2017-09-25 11:48:00 +03:00
|
|
|
}
|
2024-03-12 17:52:54 +03:00
|
|
|
case KnownMembership.Ban:
|
2021-06-23 19:31:08 +03:00
|
|
|
return () =>
|
|
|
|
reason
|
2023-09-04 21:41:39 +03:00
|
|
|
? _t("timeline|m.room.member|ban_reason", { senderName, targetName, reason })
|
|
|
|
: _t("timeline|m.room.member|ban", { senderName, targetName });
|
2024-03-12 17:52:54 +03:00
|
|
|
case KnownMembership.Join:
|
|
|
|
if (prevContent && prevContent.membership === KnownMembership.Join) {
|
2023-05-12 14:54:24 +03:00
|
|
|
const modDisplayname = getModification(prevContent.displayname, content.displayname);
|
|
|
|
const modAvatarUrl = getModification(prevContent.avatar_url, content.avatar_url);
|
|
|
|
|
|
|
|
if (modDisplayname !== Modification.None && modAvatarUrl !== Modification.None) {
|
|
|
|
// Compromise to provide the user with more context without needing 16 translations
|
2021-06-24 04:42:47 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.member|change_name_avatar", {
|
2021-10-20 19:14:11 +03:00
|
|
|
// We're taking the display namke directly from the event content here so we need
|
|
|
|
// to strip direction override chars which the js-sdk would normally do when
|
|
|
|
// calculating the display name
|
2023-02-16 20:21:44 +03:00
|
|
|
oldDisplayName: removeDirectionOverrideChars(prevContent.displayname!),
|
2023-05-12 14:54:24 +03:00
|
|
|
});
|
|
|
|
} else if (modDisplayname === Modification.Changed) {
|
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.member|change_name", {
|
2023-05-12 14:54:24 +03:00
|
|
|
// We're taking the display name directly from the event content here so we need
|
|
|
|
// to strip direction override chars which the js-sdk would normally do when
|
|
|
|
// calculating the display name
|
|
|
|
oldDisplayName: removeDirectionOverrideChars(prevContent.displayname!),
|
2023-02-16 20:21:44 +03:00
|
|
|
displayName: removeDirectionOverrideChars(content.displayname!),
|
2017-09-25 11:48:00 +03:00
|
|
|
});
|
2023-05-12 14:54:24 +03:00
|
|
|
} else if (modDisplayname === Modification.Set) {
|
2021-06-24 04:42:47 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.member|set_name", {
|
2018-07-03 12:30:08 +03:00
|
|
|
senderName: ev.getSender(),
|
2023-02-16 20:21:44 +03:00
|
|
|
displayName: removeDirectionOverrideChars(content.displayname!),
|
2017-09-25 11:48:00 +03:00
|
|
|
});
|
2023-05-12 14:54:24 +03:00
|
|
|
} else if (modDisplayname === Modification.Unset) {
|
2021-06-24 04:42:47 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.member|remove_name", {
|
2018-07-03 12:30:08 +03:00
|
|
|
senderName,
|
2023-02-16 20:21:44 +03:00
|
|
|
oldDisplayName: removeDirectionOverrideChars(prevContent.displayname!),
|
2017-09-25 11:48:00 +03:00
|
|
|
});
|
2023-05-12 14:54:24 +03:00
|
|
|
} else if (modAvatarUrl === Modification.Unset) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|remove_avatar", { senderName });
|
2023-05-12 14:54:24 +03:00
|
|
|
} else if (modAvatarUrl === Modification.Changed) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|change_avatar", { senderName });
|
2023-05-12 14:54:24 +03:00
|
|
|
} else if (modAvatarUrl === Modification.Set) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|set_avatar", { senderName });
|
2021-06-16 01:59:42 +03:00
|
|
|
} else if (showHiddenEvents ?? SettingsStore.getValue("showHiddenEventsInTimeline")) {
|
2021-06-24 04:42:47 +03:00
|
|
|
// This is a null rejoin, it will only be visible if using 'show hidden events' (labs)
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|no_change", { senderName });
|
2019-06-26 22:22:01 +03:00
|
|
|
} else {
|
2021-06-07 06:06:56 +03:00
|
|
|
return null;
|
2015-09-16 16:48:49 +03:00
|
|
|
}
|
|
|
|
} else {
|
2021-10-15 17:31:29 +03:00
|
|
|
if (!ev.target) logger.warn("Join message has no target! -- " + ev.getContent().state_key);
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|join", { targetName });
|
2015-09-16 16:48:49 +03:00
|
|
|
}
|
2024-03-12 17:52:54 +03:00
|
|
|
case KnownMembership.Leave:
|
2015-09-16 16:48:49 +03:00
|
|
|
if (ev.getSender() === ev.getStateKey()) {
|
2024-03-12 17:52:54 +03:00
|
|
|
if (prevContent.membership === KnownMembership.Invite) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|reject_invite", { targetName });
|
2017-09-25 11:48:00 +03:00
|
|
|
} else {
|
2021-06-23 19:31:08 +03:00
|
|
|
return () =>
|
|
|
|
reason
|
2023-09-04 21:41:39 +03:00
|
|
|
? _t("timeline|m.room.member|left_reason", { targetName, reason })
|
|
|
|
: _t("timeline|m.room.member|left", { targetName });
|
2016-03-05 05:30:18 +03:00
|
|
|
}
|
2024-03-12 17:52:54 +03:00
|
|
|
} else if (prevContent.membership === KnownMembership.Ban) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.member|unban", { senderName, targetName });
|
2024-03-12 17:52:54 +03:00
|
|
|
} else if (prevContent.membership === KnownMembership.Invite) {
|
2021-06-23 19:31:08 +03:00
|
|
|
return () =>
|
|
|
|
reason
|
2023-09-04 21:41:39 +03:00
|
|
|
? _t("timeline|m.room.member|withdrew_invite_reason", {
|
2021-06-23 19:31:08 +03:00
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
reason,
|
|
|
|
})
|
2023-09-04 21:41:39 +03:00
|
|
|
: _t("timeline|m.room.member|withdrew_invite", { senderName, targetName });
|
2024-03-12 17:52:54 +03:00
|
|
|
} else if (prevContent.membership === KnownMembership.Join) {
|
2021-06-23 19:31:08 +03:00
|
|
|
return () =>
|
|
|
|
reason
|
2023-09-04 21:41:39 +03:00
|
|
|
? _t("timeline|m.room.member|kick_reason", {
|
2021-06-23 19:31:08 +03:00
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
reason,
|
|
|
|
})
|
2023-09-04 21:41:39 +03:00
|
|
|
: _t("timeline|m.room.member|kick", { senderName, targetName });
|
2021-04-12 14:13:28 +03:00
|
|
|
} else {
|
2021-06-07 06:06:56 +03:00
|
|
|
return null;
|
2015-09-16 16:48:49 +03:00
|
|
|
}
|
|
|
|
}
|
2023-02-15 16:36:22 +03:00
|
|
|
|
|
|
|
return null;
|
2016-09-15 19:01:02 +03:00
|
|
|
}
|
2015-09-16 16:48:49 +03:00
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForTopicEvent(ev: MatrixEvent): (() => string) | null {
|
2017-09-25 11:48:00 +03:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.topic", {
|
2018-07-03 12:30:08 +03:00
|
|
|
senderDisplayName,
|
2017-09-25 11:48:00 +03:00
|
|
|
topic: ev.getContent().topic,
|
|
|
|
});
|
2016-09-15 19:01:02 +03:00
|
|
|
}
|
2015-09-16 16:48:49 +03:00
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForRoomAvatarEvent(ev: MatrixEvent): (() => string) | null {
|
2021-08-13 06:29:28 +03:00
|
|
|
const senderDisplayName = ev?.sender?.name || ev.getSender();
|
2023-09-19 19:16:38 +03:00
|
|
|
return () => _t("timeline|m.room.avatar|changed", { senderDisplayName });
|
2021-06-22 10:20:15 +03:00
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForRoomNameEvent(ev: MatrixEvent): (() => string) | null {
|
2017-09-25 11:48:00 +03:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2017-06-10 16:26:27 +03:00
|
|
|
|
2017-05-30 08:21:14 +03:00
|
|
|
if (!ev.getContent().name || ev.getContent().name.trim().length === 0) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.name|remove", { senderDisplayName });
|
2017-05-30 08:21:14 +03:00
|
|
|
}
|
2020-03-07 21:36:24 +03:00
|
|
|
if (ev.getPrevContent().name) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.name|change", {
|
2018-07-03 12:30:08 +03:00
|
|
|
senderDisplayName,
|
2020-03-07 21:36:24 +03:00
|
|
|
oldRoomName: ev.getPrevContent().name,
|
|
|
|
newRoomName: ev.getContent().name,
|
2022-12-12 14:24:14 +03:00
|
|
|
});
|
|
|
|
}
|
2021-06-29 15:11:58 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.name|set", {
|
2020-03-07 21:36:24 +03:00
|
|
|
senderDisplayName,
|
|
|
|
roomName: ev.getContent().name,
|
|
|
|
});
|
2016-09-15 19:01:02 +03:00
|
|
|
}
|
2015-10-30 05:07:04 +03:00
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForTombstoneEvent(ev: MatrixEvent): (() => string) | null {
|
2019-01-11 01:15:45 +03:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.tombstone", { senderDisplayName });
|
2019-01-11 01:15:45 +03:00
|
|
|
}
|
|
|
|
|
2023-01-12 16:25:14 +03:00
|
|
|
const onViewJoinRuleSettingsClick = (): void => {
|
2021-10-26 17:28:22 +03:00
|
|
|
defaultDispatcher.dispatch({
|
|
|
|
action: "open_room_settings",
|
2023-04-27 14:55:29 +03:00
|
|
|
initial_tab_id: RoomSettingsTab.Security,
|
2021-10-26 17:28:22 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForJoinRulesEvent(ev: MatrixEvent, client: MatrixClient, allowJSX: boolean): () => Renderable {
|
2019-02-07 22:14:58 +03:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().join_rule) {
|
2021-10-26 17:28:22 +03:00
|
|
|
case JoinRule.Public:
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.join_rules|public", {
|
2021-06-07 06:06:56 +03:00
|
|
|
senderDisplayName,
|
|
|
|
});
|
2021-10-26 17:28:22 +03:00
|
|
|
case JoinRule.Invite:
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.join_rules|invite", {
|
2021-06-07 06:06:56 +03:00
|
|
|
senderDisplayName,
|
|
|
|
});
|
2023-07-10 11:01:03 +03:00
|
|
|
case JoinRule.Knock:
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.join_rules|knock", { senderDisplayName });
|
2021-10-26 17:28:22 +03:00
|
|
|
case JoinRule.Restricted:
|
|
|
|
if (allowJSX) {
|
|
|
|
return () => (
|
|
|
|
<span>
|
|
|
|
{_t(
|
2023-09-04 21:41:39 +03:00
|
|
|
"timeline|m.room.join_rules|restricted_settings",
|
2021-10-26 17:28:22 +03:00
|
|
|
{
|
|
|
|
senderDisplayName,
|
|
|
|
},
|
|
|
|
{
|
2022-01-07 12:40:53 +03:00
|
|
|
a: (sub) => (
|
|
|
|
<AccessibleButton kind="link_inline" onClick={onViewJoinRuleSettingsClick}>
|
2021-10-26 17:28:22 +03:00
|
|
|
{sub}
|
2022-01-07 12:40:53 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-10-26 17:28:22 +03:00
|
|
|
},
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.join_rules|restricted", { senderDisplayName });
|
2019-02-07 22:14:58 +03:00
|
|
|
default:
|
|
|
|
// The spec supports "knock" and "private", however nothing implements these.
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.join_rules|unknown", {
|
2019-02-07 22:14:58 +03:00
|
|
|
senderDisplayName,
|
|
|
|
rule: ev.getContent().join_rule,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForGuestAccessEvent(ev: MatrixEvent): (() => string) | null {
|
2019-02-07 22:14:58 +03:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().guest_access) {
|
2021-10-26 17:28:22 +03:00
|
|
|
case GuestAccess.CanJoin:
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.guest_access|can_join", { senderDisplayName });
|
2021-10-26 17:28:22 +03:00
|
|
|
case GuestAccess.Forbidden:
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => _t("timeline|m.room.guest_access|forbidden", { senderDisplayName });
|
2019-02-07 22:14:58 +03:00
|
|
|
default:
|
|
|
|
// There's no other options we can expect, however just for safety's sake we'll do this.
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.guest_access|unknown", {
|
2019-02-07 22:14:58 +03:00
|
|
|
senderDisplayName,
|
|
|
|
rule: ev.getContent().guest_access,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForServerACLEvent(ev: MatrixEvent): (() => string) | null {
|
2018-07-06 18:36:26 +03:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2018-07-06 18:54:28 +03:00
|
|
|
const prevContent = ev.getPrevContent();
|
|
|
|
const current = ev.getContent();
|
|
|
|
const prev = {
|
|
|
|
deny: Array.isArray(prevContent.deny) ? prevContent.deny : [],
|
|
|
|
allow: Array.isArray(prevContent.allow) ? prevContent.allow : [],
|
2022-05-04 00:04:37 +03:00
|
|
|
allow_ip_literals: prevContent.allow_ip_literals !== false,
|
2018-07-06 18:54:28 +03:00
|
|
|
};
|
2020-10-14 00:08:04 +03:00
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
let getText: () => string;
|
2018-07-06 17:31:21 +03:00
|
|
|
if (prev.deny.length === 0 && prev.allow.length === 0) {
|
2023-09-04 21:41:39 +03:00
|
|
|
getText = () => _t("timeline|m.room.server_acl|set", { senderDisplayName });
|
2018-07-06 12:18:31 +03:00
|
|
|
} else {
|
2023-09-04 21:41:39 +03:00
|
|
|
getText = () => _t("timeline|m.room.server_acl|changed", { senderDisplayName });
|
2018-07-06 12:18:31 +03:00
|
|
|
}
|
|
|
|
|
2018-07-06 22:22:37 +03:00
|
|
|
if (!Array.isArray(current.allow)) {
|
|
|
|
current.allow = [];
|
|
|
|
}
|
2020-10-14 00:08:04 +03:00
|
|
|
|
|
|
|
// If we know for sure everyone is banned, mark the room as obliterated
|
2018-07-06 18:54:28 +03:00
|
|
|
if (current.allow.length === 0) {
|
2023-09-04 21:41:39 +03:00
|
|
|
return () => getText() + " " + _t("timeline|m.room.server_acl|all_servers_banned");
|
2018-07-06 18:36:44 +03:00
|
|
|
}
|
|
|
|
|
2021-06-07 06:06:56 +03:00
|
|
|
return getText;
|
2016-09-15 19:01:02 +03:00
|
|
|
}
|
2015-10-30 05:07:04 +03:00
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForMessageEvent(ev: MatrixEvent, client: MatrixClient): (() => string) | null {
|
2022-05-10 18:39:28 +03:00
|
|
|
if (isLocationEvent(ev)) {
|
2022-01-19 03:58:31 +03:00
|
|
|
return textForLocationEvent(ev);
|
|
|
|
}
|
|
|
|
|
2021-06-07 06:06:56 +03:00
|
|
|
return () => {
|
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2021-06-17 08:16:08 +03:00
|
|
|
let message = ev.getContent().body;
|
2021-06-22 12:23:48 +03:00
|
|
|
if (ev.isRedacted()) {
|
2023-06-05 20:12:23 +03:00
|
|
|
message = textForRedactedPollAndMessageEvent(ev, client);
|
2021-06-22 12:23:48 +03:00
|
|
|
}
|
2022-01-13 20:03:37 +03:00
|
|
|
|
2021-10-26 17:28:22 +03:00
|
|
|
if (ev.getContent().msgtype === MsgType.Emote) {
|
2021-06-07 06:06:56 +03:00
|
|
|
message = "* " + senderDisplayName + " " + message;
|
2021-10-26 17:28:22 +03:00
|
|
|
} else if (ev.getContent().msgtype === MsgType.Image) {
|
2023-10-02 15:52:27 +03:00
|
|
|
message = _t("timeline|m.image|sent", { senderDisplayName });
|
2021-10-26 17:28:22 +03:00
|
|
|
} else if (ev.getType() == EventType.Sticker) {
|
2023-09-04 21:41:39 +03:00
|
|
|
message = _t("timeline|m.sticker", { senderDisplayName });
|
2021-08-13 21:14:07 +03:00
|
|
|
} else {
|
|
|
|
// in this case, parse it as a plain text message
|
|
|
|
message = senderDisplayName + ": " + message;
|
|
|
|
}
|
2021-06-07 06:06:56 +03:00
|
|
|
return message;
|
|
|
|
};
|
2016-09-15 19:01:02 +03:00
|
|
|
}
|
2015-09-16 16:48:49 +03:00
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForCanonicalAliasEvent(ev: MatrixEvent): (() => string) | null {
|
2022-02-09 12:09:28 +03:00
|
|
|
const senderName = getSenderName(ev);
|
2018-09-20 03:07:01 +03:00
|
|
|
const oldAlias = ev.getPrevContent().alias;
|
2020-03-09 20:24:48 +03:00
|
|
|
const oldAltAliases = ev.getPrevContent().alt_aliases || [];
|
2018-09-20 03:07:01 +03:00
|
|
|
const newAlias = ev.getContent().alias;
|
2020-03-09 20:24:48 +03:00
|
|
|
const newAltAliases = ev.getContent().alt_aliases || [];
|
2023-02-13 14:39:16 +03:00
|
|
|
const removedAltAliases = oldAltAliases.filter((alias: string) => !newAltAliases.includes(alias));
|
|
|
|
const addedAltAliases = newAltAliases.filter((alias: string) => !oldAltAliases.includes(alias));
|
2018-09-20 03:07:01 +03:00
|
|
|
|
2020-03-09 20:24:48 +03:00
|
|
|
if (!removedAltAliases.length && !addedAltAliases.length) {
|
|
|
|
if (newAlias) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.canonical_alias|set", {
|
2022-02-09 12:09:28 +03:00
|
|
|
senderName,
|
2020-03-09 20:24:48 +03:00
|
|
|
address: ev.getContent().alias,
|
|
|
|
});
|
|
|
|
} else if (oldAlias) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-04 21:41:39 +03:00
|
|
|
_t("timeline|m.room.canonical_alias|removed", {
|
2022-02-09 12:09:28 +03:00
|
|
|
senderName,
|
2020-03-09 20:24:48 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (newAlias === oldAlias) {
|
|
|
|
if (addedAltAliases.length && !removedAltAliases.length) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|m.room.canonical_alias|alt_added", {
|
2022-02-09 12:09:28 +03:00
|
|
|
senderName,
|
2020-03-09 20:24:48 +03:00
|
|
|
addresses: addedAltAliases.join(", "),
|
|
|
|
count: addedAltAliases.length,
|
|
|
|
});
|
2022-05-04 00:04:37 +03:00
|
|
|
}
|
|
|
|
if (removedAltAliases.length && !addedAltAliases.length) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|m.room.canonical_alias|alt_removed", {
|
2022-02-09 12:09:28 +03:00
|
|
|
senderName,
|
2020-03-09 20:24:48 +03:00
|
|
|
addresses: removedAltAliases.join(", "),
|
|
|
|
count: removedAltAliases.length,
|
|
|
|
});
|
2022-05-04 00:04:37 +03:00
|
|
|
}
|
|
|
|
if (removedAltAliases.length && addedAltAliases.length) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.room.canonical_alias|changed_alternative", {
|
2022-02-09 12:09:28 +03:00
|
|
|
senderName,
|
2020-03-09 20:24:48 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-10 20:45:51 +03:00
|
|
|
// both alias and alt_aliases where modified
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.room.canonical_alias|changed_main_and_alternative", {
|
2022-02-09 12:09:28 +03:00
|
|
|
senderName,
|
2018-09-20 03:07:01 +03:00
|
|
|
});
|
|
|
|
}
|
2020-03-10 20:45:51 +03:00
|
|
|
// in case there is no difference between the two events,
|
|
|
|
// say something as we can't simply hide the tile from here
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.room.canonical_alias|changed", {
|
2022-02-09 12:09:28 +03:00
|
|
|
senderName,
|
2020-03-10 20:45:51 +03:00
|
|
|
});
|
2018-09-20 03:07:01 +03:00
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForThreePidInviteEvent(event: MatrixEvent): (() => string) | null {
|
2022-01-19 03:58:31 +03:00
|
|
|
const senderName = getSenderName(event);
|
2019-03-29 05:38:15 +03:00
|
|
|
|
2019-03-29 20:45:07 +03:00
|
|
|
if (!isValid3pidInvite(event)) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.room.third_party_invite|revoked", {
|
2019-03-29 05:38:15 +03:00
|
|
|
senderName,
|
2023-09-01 10:26:48 +03:00
|
|
|
targetDisplayName: event.getPrevContent().display_name || _t("common|someone"),
|
2019-03-29 05:38:15 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.room.third_party_invite|sent", {
|
2018-07-03 12:30:08 +03:00
|
|
|
senderName,
|
2017-09-25 11:48:00 +03:00
|
|
|
targetDisplayName: event.getContent().display_name,
|
|
|
|
});
|
2016-09-15 19:01:02 +03:00
|
|
|
}
|
2015-12-17 18:48:14 +03:00
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForHistoryVisibilityEvent(event: MatrixEvent): (() => string) | null {
|
2022-01-19 03:58:31 +03:00
|
|
|
const senderName = getSenderName(event);
|
2017-09-17 15:28:17 +03:00
|
|
|
switch (event.getContent().history_visibility) {
|
2021-10-26 17:28:22 +03:00
|
|
|
case HistoryVisibility.Invited:
|
2023-09-05 12:44:41 +03:00
|
|
|
return () => _t("timeline|m.room.history_visibility|invited", { senderName });
|
2021-10-26 17:28:22 +03:00
|
|
|
case HistoryVisibility.Joined:
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.room.history_visibility|joined", {
|
2023-08-22 18:32:05 +03:00
|
|
|
senderName,
|
|
|
|
});
|
2021-10-26 17:28:22 +03:00
|
|
|
case HistoryVisibility.Shared:
|
2023-09-05 12:44:41 +03:00
|
|
|
return () => _t("timeline|m.room.history_visibility|shared", { senderName });
|
2021-10-26 17:28:22 +03:00
|
|
|
case HistoryVisibility.WorldReadable:
|
2023-09-05 12:44:41 +03:00
|
|
|
return () => _t("timeline|m.room.history_visibility|world_readable", { senderName });
|
2017-09-17 15:28:17 +03:00
|
|
|
default:
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.room.history_visibility|unknown", {
|
2018-07-03 12:30:08 +03:00
|
|
|
senderName,
|
2017-09-17 15:28:17 +03:00
|
|
|
visibility: event.getContent().history_visibility,
|
|
|
|
});
|
2016-03-16 02:47:40 +03:00
|
|
|
}
|
2016-09-15 19:01:02 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:02:35 +03:00
|
|
|
// Currently will only display a change if a user's power level is changed
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForPowerEvent(event: MatrixEvent, client: MatrixClient): (() => string) | null {
|
2022-01-19 03:58:31 +03:00
|
|
|
const senderName = getSenderName(event);
|
2022-08-10 16:33:13 +03:00
|
|
|
if (!event.getPrevContent()?.users || !event.getContent()?.users) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return null;
|
2017-04-06 19:02:35 +03:00
|
|
|
}
|
2022-08-10 16:33:13 +03:00
|
|
|
const previousUserDefault: number = event.getPrevContent().users_default || 0;
|
|
|
|
const currentUserDefault: number = event.getContent().users_default || 0;
|
2017-04-06 19:02:35 +03:00
|
|
|
// Construct set of userIds
|
2022-08-10 16:33:13 +03:00
|
|
|
const users: string[] = [];
|
|
|
|
Object.keys(event.getContent().users).forEach((userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
|
|
|
});
|
|
|
|
Object.keys(event.getPrevContent().users).forEach((userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
|
|
|
});
|
|
|
|
|
|
|
|
const diffs: {
|
|
|
|
userId: string;
|
|
|
|
name: string;
|
|
|
|
from: number;
|
|
|
|
to: number;
|
|
|
|
}[] = [];
|
2017-04-06 19:02:35 +03:00
|
|
|
users.forEach((userId) => {
|
|
|
|
// Previous power level
|
2022-08-10 16:33:13 +03:00
|
|
|
let from: number = event.getPrevContent().users[userId];
|
2021-06-23 06:35:47 +03:00
|
|
|
if (!Number.isInteger(from)) {
|
|
|
|
from = previousUserDefault;
|
|
|
|
}
|
2017-04-06 19:02:35 +03:00
|
|
|
// Current power level
|
2021-06-23 06:48:01 +03:00
|
|
|
let to = event.getContent().users[userId];
|
2021-06-23 06:35:47 +03:00
|
|
|
if (!Number.isInteger(to)) {
|
|
|
|
to = currentUserDefault;
|
|
|
|
}
|
|
|
|
if (from === previousUserDefault && to === currentUserDefault) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-06 19:02:35 +03:00
|
|
|
if (to !== from) {
|
2023-06-05 20:12:23 +03:00
|
|
|
const name = getRoomMemberDisplayname(client, event, userId);
|
2022-01-25 12:40:02 +03:00
|
|
|
diffs.push({ userId, name, from, to });
|
2017-04-06 19:02:35 +03:00
|
|
|
}
|
|
|
|
});
|
2021-06-07 06:06:56 +03:00
|
|
|
if (!diffs.length) {
|
|
|
|
return null;
|
2017-04-06 19:02:35 +03:00
|
|
|
}
|
2022-01-25 12:40:02 +03:00
|
|
|
|
2021-06-07 06:06:56 +03:00
|
|
|
// XXX: This is also surely broken for i18n
|
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|m.room.power_levels|changed", {
|
2018-07-03 12:30:08 +03:00
|
|
|
senderName,
|
2021-06-07 06:06:56 +03:00
|
|
|
powerLevelDiffText: diffs
|
|
|
|
.map((diff) =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|m.room.power_levels|user_from_to", {
|
2022-01-25 12:40:02 +03:00
|
|
|
userId: diff.name,
|
2021-06-23 06:35:47 +03:00
|
|
|
fromPowerLevel: Roles.textualPowerLevel(diff.from, previousUserDefault),
|
|
|
|
toPowerLevel: Roles.textualPowerLevel(diff.to, currentUserDefault),
|
2021-06-07 06:06:56 +03:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
.join(", "),
|
2017-05-27 17:52:24 +03:00
|
|
|
});
|
2017-04-06 19:02:35 +03:00
|
|
|
}
|
|
|
|
|
2021-06-24 17:58:56 +03:00
|
|
|
const onPinnedMessagesClick = (): void => {
|
2022-01-05 18:14:44 +03:00
|
|
|
RightPanelStore.instance.setCard({ phase: RightPanelPhases.PinnedMessages }, false);
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2021-06-24 17:58:56 +03:00
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForPinnedEvent(event: MatrixEvent, client: MatrixClient, allowJSX: boolean): (() => Renderable) | null {
|
2021-06-24 11:40:30 +03:00
|
|
|
if (!SettingsStore.getValue("feature_pinning")) return null;
|
2022-01-19 03:58:31 +03:00
|
|
|
const senderName = getSenderName(event);
|
2023-02-15 16:36:22 +03:00
|
|
|
const roomId = event.getRoomId()!;
|
2021-06-24 11:40:30 +03:00
|
|
|
|
2023-02-13 14:39:16 +03:00
|
|
|
const pinned = event.getContent<{ pinned: string[] }>().pinned ?? [];
|
|
|
|
const previouslyPinned: string[] = event.getPrevContent().pinned ?? [];
|
2021-07-27 17:37:05 +03:00
|
|
|
const newlyPinned = pinned.filter((item) => previouslyPinned.indexOf(item) < 0);
|
2021-07-27 18:58:53 +03:00
|
|
|
const newlyUnpinned = previouslyPinned.filter((item) => pinned.indexOf(item) < 0);
|
2021-07-27 17:37:05 +03:00
|
|
|
|
2021-08-11 16:56:59 +03:00
|
|
|
if (newlyPinned.length === 1 && newlyUnpinned.length === 0) {
|
2021-07-27 17:37:05 +03:00
|
|
|
// A single message was pinned, include a link to that message.
|
|
|
|
if (allowJSX) {
|
2023-02-16 20:21:44 +03:00
|
|
|
const messageId = newlyPinned.pop()!;
|
2021-07-27 17:37:05 +03:00
|
|
|
|
|
|
|
return () => (
|
|
|
|
<span>
|
2021-08-10 17:50:23 +03:00
|
|
|
{_t(
|
2023-09-05 12:44:41 +03:00
|
|
|
"timeline|m.room.pinned_events|pinned_link",
|
2021-08-10 17:50:23 +03:00
|
|
|
{ senderName },
|
|
|
|
{
|
|
|
|
a: (sub) => (
|
2023-02-13 14:39:16 +03:00
|
|
|
<AccessibleButton
|
|
|
|
kind="link_inline"
|
|
|
|
onClick={(e: ButtonEvent) => highlightEvent(roomId, messageId)}
|
|
|
|
>
|
2021-08-10 17:50:23 +03:00
|
|
|
{sub}
|
2022-01-07 12:40:53 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 17:50:23 +03:00
|
|
|
b: (sub) => (
|
2022-01-07 12:40:53 +03:00
|
|
|
<AccessibleButton kind="link_inline" onClick={onPinnedMessagesClick}>
|
2021-08-10 17:50:23 +03:00
|
|
|
{sub}
|
2022-01-07 12:40:53 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 17:50:23 +03:00
|
|
|
},
|
|
|
|
)}
|
2021-07-27 17:37:05 +03:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-05 12:44:41 +03:00
|
|
|
return () => _t("timeline|m.room.pinned_events|pinned", { senderName });
|
2021-07-27 17:37:05 +03:00
|
|
|
}
|
|
|
|
|
2021-08-11 16:56:59 +03:00
|
|
|
if (newlyUnpinned.length === 1 && newlyPinned.length === 0) {
|
2021-07-27 18:58:53 +03:00
|
|
|
// A single message was unpinned, include a link to that message.
|
|
|
|
if (allowJSX) {
|
2023-02-16 20:21:44 +03:00
|
|
|
const messageId = newlyUnpinned.pop()!;
|
2021-07-27 18:58:53 +03:00
|
|
|
|
|
|
|
return () => (
|
|
|
|
<span>
|
2021-08-10 17:50:23 +03:00
|
|
|
{_t(
|
2023-09-05 12:44:41 +03:00
|
|
|
"timeline|m.room.pinned_events|unpinned_link",
|
2021-08-10 17:50:23 +03:00
|
|
|
{ senderName },
|
|
|
|
{
|
|
|
|
a: (sub) => (
|
2023-02-13 14:39:16 +03:00
|
|
|
<AccessibleButton
|
|
|
|
kind="link_inline"
|
|
|
|
onClick={(e: ButtonEvent) => highlightEvent(roomId, messageId)}
|
|
|
|
>
|
2021-08-10 17:50:23 +03:00
|
|
|
{sub}
|
2022-01-07 12:40:53 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 17:50:23 +03:00
|
|
|
b: (sub) => (
|
2022-01-07 12:40:53 +03:00
|
|
|
<AccessibleButton kind="link_inline" onClick={onPinnedMessagesClick}>
|
2021-08-10 17:50:23 +03:00
|
|
|
{sub}
|
2022-01-07 12:40:53 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 17:50:23 +03:00
|
|
|
},
|
|
|
|
)}
|
2021-07-27 18:58:53 +03:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-05 12:44:41 +03:00
|
|
|
return () => _t("timeline|m.room.pinned_events|unpinned", { senderName });
|
2021-07-27 18:58:53 +03:00
|
|
|
}
|
2021-06-24 11:40:30 +03:00
|
|
|
|
2021-06-24 15:02:06 +03:00
|
|
|
if (allowJSX) {
|
|
|
|
return () => (
|
|
|
|
<span>
|
2021-08-10 17:50:23 +03:00
|
|
|
{_t(
|
2023-09-05 12:44:41 +03:00
|
|
|
"timeline|m.room.pinned_events|changed_link",
|
2021-08-10 17:50:23 +03:00
|
|
|
{ senderName },
|
2022-01-07 12:40:53 +03:00
|
|
|
{
|
|
|
|
a: (sub) => (
|
|
|
|
<AccessibleButton kind="link_inline" onClick={onPinnedMessagesClick}>
|
|
|
|
{sub}
|
|
|
|
</AccessibleButton>
|
|
|
|
),
|
|
|
|
},
|
2021-08-10 17:50:23 +03:00
|
|
|
)}
|
2021-06-24 15:02:06 +03:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
2021-06-24 18:27:53 +03:00
|
|
|
|
2023-09-05 12:44:41 +03:00
|
|
|
return () => _t("timeline|m.room.pinned_events|changed", { senderName });
|
2017-09-28 20:03:13 +03:00
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForWidgetEvent(event: MatrixEvent): (() => string) | null {
|
2022-02-09 12:09:28 +03:00
|
|
|
const senderName = getSenderName(event);
|
2021-06-29 15:11:58 +03:00
|
|
|
const { name: prevName, type: prevType, url: prevUrl } = event.getPrevContent();
|
|
|
|
const { name, type, url } = event.getContent() || {};
|
2017-08-28 10:19:39 +03:00
|
|
|
|
|
|
|
let widgetName = name || prevName || type || prevType || "";
|
2017-08-18 20:02:50 +03:00
|
|
|
// Apply sentence case to widget name
|
|
|
|
if (widgetName && widgetName.length > 0) {
|
2020-11-24 14:27:02 +03:00
|
|
|
widgetName = widgetName[0].toUpperCase() + widgetName.slice(1);
|
2017-08-18 20:02:50 +03:00
|
|
|
}
|
2017-08-16 19:46:20 +03:00
|
|
|
|
2017-08-18 14:04:34 +03:00
|
|
|
// If the widget was removed, its content should be {}, but this is sufficiently
|
|
|
|
// equivalent to that condition.
|
2017-08-18 12:45:43 +03:00
|
|
|
if (url) {
|
2017-08-28 10:19:39 +03:00
|
|
|
if (prevUrl) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.widget|modified", {
|
2017-08-28 10:19:39 +03:00
|
|
|
widgetName,
|
|
|
|
senderName,
|
|
|
|
});
|
|
|
|
} else {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.widget|added", {
|
2017-08-28 10:19:39 +03:00
|
|
|
widgetName,
|
|
|
|
senderName,
|
|
|
|
});
|
|
|
|
}
|
2017-08-16 19:46:20 +03:00
|
|
|
} else {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-05 12:44:41 +03:00
|
|
|
_t("timeline|m.widget|removed", {
|
2017-08-18 20:02:50 +03:00
|
|
|
widgetName,
|
|
|
|
senderName,
|
2017-08-16 19:46:20 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForWidgetLayoutEvent(event: MatrixEvent): (() => string) | null {
|
2022-02-09 12:09:28 +03:00
|
|
|
const senderName = getSenderName(event);
|
2023-09-05 12:44:41 +03:00
|
|
|
return () => _t("timeline|io.element.widgets.layout", { senderName });
|
2021-01-19 05:31:11 +03:00
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForMjolnirEvent(event: MatrixEvent): (() => string) | null {
|
2022-02-09 12:09:28 +03:00
|
|
|
const senderName = getSenderName(event);
|
2021-06-29 15:11:58 +03:00
|
|
|
const { entity: prevEntity } = event.getPrevContent();
|
|
|
|
const { entity, recommendation, reason } = event.getContent();
|
2019-12-10 06:36:00 +03:00
|
|
|
|
|
|
|
// Rule removed
|
|
|
|
if (!entity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2023-09-08 11:58:31 +03:00
|
|
|
return () => _t("timeline|mjolnir|removed_rule_users", { senderName, glob: prevEntity });
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2023-09-08 11:58:31 +03:00
|
|
|
return () => _t("timeline|mjolnir|removed_rule_rooms", { senderName, glob: prevEntity });
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|removed_rule_servers", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: prevEntity,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something, but we shouldn't end up here.
|
2023-09-08 11:58:31 +03:00
|
|
|
return () => _t("timeline|mjolnir|removed_rule", { senderName, glob: prevEntity });
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid rule
|
2023-09-08 11:58:31 +03:00
|
|
|
if (!recommendation || !reason) return () => _t("timeline|mjolnir|updated_invalid_rule", { senderName });
|
2019-12-10 06:36:00 +03:00
|
|
|
|
|
|
|
// Rule updated
|
|
|
|
if (entity === prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|updated_rule_users", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|updated_rule_rooms", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|updated_rule_servers", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|updated_rule", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// New rule
|
|
|
|
if (!prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|created_rule_users", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|created_rule_rooms", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|created_rule_servers", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|created_rule", {
|
2021-06-29 15:11:58 +03:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// else the entity !== prevEntity - count as a removal & add
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|changed_rule_users", { senderName, oldGlob: prevEntity, newGlob: entity, reason });
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|changed_rule_rooms", { senderName, oldGlob: prevEntity, newGlob: entity, reason });
|
2019-12-10 06:36:00 +03:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|changed_rule_servers", { senderName, oldGlob: prevEntity, newGlob: entity, reason });
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 06:06:56 +03:00
|
|
|
return () =>
|
2023-09-08 11:58:31 +03:00
|
|
|
_t("timeline|mjolnir|changed_rule_glob", {
|
2023-08-22 18:32:05 +03:00
|
|
|
senderName,
|
|
|
|
oldGlob: prevEntity,
|
|
|
|
newGlob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 06:36:00 +03:00
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
export function textForLocationEvent(event: MatrixEvent): () => string {
|
2022-01-19 03:58:31 +03:00
|
|
|
return () =>
|
2023-09-19 19:16:38 +03:00
|
|
|
_t("timeline|m.location|full", {
|
2022-01-19 03:58:31 +03:00
|
|
|
senderName: getSenderName(event),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForRedactedPollAndMessageEvent(ev: MatrixEvent, client: MatrixClient): string {
|
2023-09-05 12:44:41 +03:00
|
|
|
let message = _t("timeline|self_redaction");
|
2022-04-11 12:10:16 +03:00
|
|
|
const unsigned = ev.getUnsigned();
|
|
|
|
const redactedBecauseUserId = unsigned?.redacted_because?.sender;
|
|
|
|
if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) {
|
2023-06-05 20:12:23 +03:00
|
|
|
const room = client.getRoom(ev.getRoomId());
|
2022-04-11 12:10:16 +03:00
|
|
|
const sender = room?.getMember(redactedBecauseUserId);
|
2023-09-05 12:44:41 +03:00
|
|
|
message = _t("timeline|redaction", {
|
2022-04-11 12:10:16 +03:00
|
|
|
name: sender?.name || redactedBecauseUserId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:12:23 +03:00
|
|
|
function textForPollStartEvent(event: MatrixEvent, client: MatrixClient): (() => string) | null {
|
2022-04-11 12:10:16 +03:00
|
|
|
return () => {
|
|
|
|
let message = "";
|
|
|
|
|
|
|
|
if (event.isRedacted()) {
|
2023-06-05 20:12:23 +03:00
|
|
|
message = textForRedactedPollAndMessageEvent(event, client);
|
2022-04-11 12:10:16 +03:00
|
|
|
const senderDisplayName = event.sender?.name ?? event.getSender();
|
|
|
|
message = senderDisplayName + ": " + message;
|
|
|
|
} else {
|
2023-09-05 12:44:41 +03:00
|
|
|
message = _t("timeline|m.poll.start", {
|
2022-04-11 12:10:16 +03:00
|
|
|
senderName: getSenderName(event),
|
|
|
|
pollQuestion: (event.unstableExtensibleEvent as PollStartEvent)?.question?.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
};
|
2022-01-19 03:58:31 +03:00
|
|
|
}
|
|
|
|
|
2023-02-15 16:36:22 +03:00
|
|
|
function textForPollEndEvent(event: MatrixEvent): (() => string) | null {
|
2022-01-19 03:58:31 +03:00
|
|
|
return () =>
|
2023-10-02 15:52:27 +03:00
|
|
|
_t("timeline|m.poll.end|sender_ended", {
|
2022-01-19 03:58:31 +03:00
|
|
|
senderName: getSenderName(event),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:03:56 +03:00
|
|
|
type Renderable = string | React.ReactNode | null;
|
2022-05-04 00:04:37 +03:00
|
|
|
|
2021-06-09 04:58:48 +03:00
|
|
|
interface IHandlers {
|
2023-06-05 20:12:23 +03:00
|
|
|
[type: string]: (
|
|
|
|
ev: MatrixEvent,
|
|
|
|
client: MatrixClient,
|
|
|
|
allowJSX: boolean,
|
|
|
|
showHiddenEvents?: boolean,
|
|
|
|
) => (() => Renderable) | null;
|
2021-06-09 04:58:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const handlers: IHandlers = {
|
2021-10-26 17:28:22 +03:00
|
|
|
[EventType.RoomMessage]: textForMessageEvent,
|
|
|
|
[EventType.Sticker]: textForMessageEvent,
|
|
|
|
[EventType.CallInvite]: textForCallInviteEvent,
|
2022-01-19 03:58:31 +03:00
|
|
|
[M_POLL_START.name]: textForPollStartEvent,
|
|
|
|
[M_POLL_END.name]: textForPollEndEvent,
|
|
|
|
[M_POLL_START.altName]: textForPollStartEvent,
|
|
|
|
[M_POLL_END.altName]: textForPollEndEvent,
|
2017-10-06 14:07:38 +03:00
|
|
|
};
|
|
|
|
|
2021-06-09 04:58:48 +03:00
|
|
|
const stateHandlers: IHandlers = {
|
2021-10-26 17:28:22 +03:00
|
|
|
[EventType.RoomCanonicalAlias]: textForCanonicalAliasEvent,
|
|
|
|
[EventType.RoomName]: textForRoomNameEvent,
|
|
|
|
[EventType.RoomTopic]: textForTopicEvent,
|
|
|
|
[EventType.RoomMember]: textForMemberEvent,
|
|
|
|
[EventType.RoomAvatar]: textForRoomAvatarEvent,
|
|
|
|
[EventType.RoomThirdPartyInvite]: textForThreePidInviteEvent,
|
|
|
|
[EventType.RoomHistoryVisibility]: textForHistoryVisibilityEvent,
|
|
|
|
[EventType.RoomPowerLevels]: textForPowerEvent,
|
|
|
|
[EventType.RoomPinnedEvents]: textForPinnedEvent,
|
|
|
|
[EventType.RoomServerAcl]: textForServerACLEvent,
|
|
|
|
[EventType.RoomTombstone]: textForTombstoneEvent,
|
|
|
|
[EventType.RoomJoinRules]: textForJoinRulesEvent,
|
|
|
|
[EventType.RoomGuestAccess]: textForGuestAccessEvent,
|
2017-08-16 19:46:20 +03:00
|
|
|
|
2020-08-03 18:02:26 +03:00
|
|
|
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
|
2017-08-16 19:46:20 +03:00
|
|
|
"im.vector.modular.widgets": textForWidgetEvent,
|
2021-01-19 05:31:11 +03:00
|
|
|
[WIDGET_LAYOUT_EVENT_TYPE]: textForWidgetLayoutEvent,
|
2022-12-12 18:03:56 +03:00
|
|
|
[VoiceBroadcastInfoEventType]: textForVoiceBroadcastStoppedEvent,
|
2015-09-16 16:48:49 +03:00
|
|
|
};
|
|
|
|
|
2019-12-10 06:36:00 +03:00
|
|
|
// Add all the Mjolnir stuff to the renderer
|
|
|
|
for (const evType of ALL_RULE_TYPES) {
|
|
|
|
stateHandlers[evType] = textForMjolnirEvent;
|
|
|
|
}
|
|
|
|
|
2022-10-06 17:27:12 +03:00
|
|
|
// Add both stable and unstable m.call events
|
|
|
|
for (const evType of ElementCall.CALL_EVENT_TYPE.names) {
|
|
|
|
stateHandlers[evType] = textForCallEvent;
|
|
|
|
}
|
|
|
|
|
2021-06-16 01:59:42 +03:00
|
|
|
/**
|
|
|
|
* Determines whether the given event has text to display.
|
2023-06-05 20:12:23 +03:00
|
|
|
*
|
|
|
|
* @param client The Matrix Client instance for the logged-in user
|
2021-06-16 01:59:42 +03:00
|
|
|
* @param ev The event
|
|
|
|
* @param showHiddenEvents An optional cached setting value for showHiddenEventsInTimeline
|
|
|
|
* to avoid hitting the settings store
|
|
|
|
*/
|
2023-06-05 20:12:23 +03:00
|
|
|
export function hasText(ev: MatrixEvent, client: MatrixClient, showHiddenEvents?: boolean): boolean {
|
2021-06-07 06:06:56 +03:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2023-06-05 20:12:23 +03:00
|
|
|
return Boolean(handler?.(ev, client, false, showHiddenEvents));
|
2021-06-07 06:06:56 +03:00
|
|
|
}
|
|
|
|
|
2021-06-16 01:59:42 +03:00
|
|
|
/**
|
|
|
|
* Gets the textual content of the given event.
|
2023-06-05 20:12:23 +03:00
|
|
|
*
|
2021-06-16 01:59:42 +03:00
|
|
|
* @param ev The event
|
2023-06-05 20:12:23 +03:00
|
|
|
* @param client The Matrix Client instance for the logged-in user
|
2021-06-30 05:13:18 +03:00
|
|
|
* @param allowJSX Whether to output rich JSX content
|
2021-06-16 01:59:42 +03:00
|
|
|
* @param showHiddenEvents An optional cached setting value for showHiddenEventsInTimeline
|
|
|
|
* to avoid hitting the settings store
|
|
|
|
*/
|
2023-06-05 20:12:23 +03:00
|
|
|
export function textForEvent(ev: MatrixEvent, client: MatrixClient): string;
|
|
|
|
export function textForEvent(
|
|
|
|
ev: MatrixEvent,
|
|
|
|
client: MatrixClient,
|
|
|
|
allowJSX: true,
|
|
|
|
showHiddenEvents?: boolean,
|
|
|
|
): string | React.ReactNode;
|
|
|
|
export function textForEvent(
|
|
|
|
ev: MatrixEvent,
|
|
|
|
client: MatrixClient,
|
|
|
|
allowJSX = false,
|
|
|
|
showHiddenEvents?: boolean,
|
|
|
|
): string | React.ReactNode {
|
2019-12-20 03:45:24 +03:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2023-06-05 20:12:23 +03:00
|
|
|
return handler?.(ev, client, allowJSX, showHiddenEvents)?.() || "";
|
2019-12-20 03:45:24 +03:00
|
|
|
}
|