2016-03-05 02:30:18 +00:00
|
|
|
/*
|
2022-01-13 17:03:37 +00:00
|
|
|
Copyright 2015 - 2022 The Matrix.org Foundation C.I.C.
|
2016-03-05 02:30:18 +00: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 14:28:22 +00:00
|
|
|
|
2021-06-24 08:40:30 +00:00
|
|
|
import React from "react";
|
2021-10-22 22:23:32 +00:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
import { removeDirectionOverrideChars } from "matrix-js-sdk/src/utils";
|
2021-10-28 02:53:09 +00:00
|
|
|
import { GuestAccess, HistoryVisibility, JoinRule } from "matrix-js-sdk/src/@types/partials";
|
|
|
|
import { EventType, MsgType } from "matrix-js-sdk/src/@types/event";
|
2023-01-10 16:21:03 +00:00
|
|
|
import {
|
|
|
|
M_EMOTE,
|
|
|
|
M_NOTICE,
|
|
|
|
M_MESSAGE,
|
|
|
|
MessageEvent,
|
|
|
|
M_POLL_START,
|
|
|
|
M_POLL_END,
|
|
|
|
PollStartEvent,
|
|
|
|
} from "matrix-events-sdk";
|
2021-10-22 22:23:32 +00:00
|
|
|
|
2017-05-25 10:39:08 +00:00
|
|
|
import { _t } from "./languageHandler";
|
2017-04-10 09:09:26 +00:00
|
|
|
import * as Roles from "./Roles";
|
2021-06-22 06:42:37 +00:00
|
|
|
import { isValid3pidInvite } from "./RoomInvite";
|
2019-06-26 19:22:01 +00:00
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
2021-06-29 12:11:58 +00: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 15:14:44 +00:00
|
|
|
import { RightPanelPhases } from "./stores/right-panel/RightPanelStorePhases";
|
2021-06-24 08:40:30 +00:00
|
|
|
import defaultDispatcher from "./dispatcher/dispatcher";
|
2021-08-02 12:34:18 +00:00
|
|
|
import { MatrixClientPeg } from "./MatrixClientPeg";
|
2021-10-26 14:28:22 +00:00
|
|
|
import { ROOM_SECURITY_TAB } from "./components/views/dialogs/RoomSettingsDialog";
|
2022-01-07 09:40:53 +00:00
|
|
|
import AccessibleButton from "./components/views/elements/AccessibleButton";
|
2022-01-05 15:14:44 +00:00
|
|
|
import RightPanelStore from "./stores/right-panel/RightPanelStore";
|
2022-12-12 15:09:11 +00:00
|
|
|
import { highlightEvent, isLocationEvent } from "./utils/EventUtils";
|
2022-10-06 14:27:12 +00:00
|
|
|
import { ElementCall } from "./models/Call";
|
2022-12-12 15:09:11 +00:00
|
|
|
import { textForVoiceBroadcastStoppedEvent, VoiceBroadcastInfoEventType } from "./voice-broadcast";
|
2022-12-16 11:01:16 +00:00
|
|
|
import { getSenderName } from "./utils/event/getSenderName";
|
2022-01-19 00:58:31 +00:00
|
|
|
|
2022-02-11 09:25:14 +00:00
|
|
|
function getRoomMemberDisplayname(event: MatrixEvent, userId = event.getSender()): string {
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const roomId = event.getRoomId();
|
|
|
|
const member = client.getRoom(roomId)?.getMember(userId);
|
2022-09-22 07:42:07 +00:00
|
|
|
return member?.name || member?.rawDisplayName || userId || _t("Someone");
|
2022-02-11 09:25:14 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 14:27:12 +00:00
|
|
|
function textForCallEvent(event: MatrixEvent): () => string {
|
|
|
|
const roomName = MatrixClientPeg.get().getRoom(event.getRoomId()!).name;
|
|
|
|
const isSupported = MatrixClientPeg.get().supportsVoip();
|
|
|
|
|
|
|
|
return isSupported
|
|
|
|
? () => _t("Video call started in %(roomName)s.", { roomName })
|
|
|
|
: () => _t("Video call started in %(roomName)s. (not supported by this browser)", { roomName });
|
|
|
|
}
|
|
|
|
|
2021-06-07 03:06:56 +00: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.
|
|
|
|
|
2021-08-02 12:34:18 +00:00
|
|
|
function textForCallInviteEvent(event: MatrixEvent): () => string | null {
|
2022-01-19 00:58:31 +00:00
|
|
|
const senderName = getSenderName(event);
|
2021-08-02 12:34:18 +00:00
|
|
|
// FIXME: Find a better way to determine this from the event?
|
2022-02-09 09:09:28 +00:00
|
|
|
const isVoice = !event.getContent().offer?.sdp?.includes("m=video");
|
2021-08-02 12:34:18 +00:00
|
|
|
const isSupported = MatrixClientPeg.get().supportsVoip();
|
|
|
|
|
|
|
|
// 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) {
|
2022-02-09 09:09:28 +00:00
|
|
|
return () => _t("%(senderName)s placed a voice call.", { senderName });
|
2021-08-02 12:34:18 +00:00
|
|
|
} else if (isVoice && !isSupported) {
|
2022-02-09 09:09:28 +00:00
|
|
|
return () => _t("%(senderName)s placed a voice call. (not supported by this browser)", { senderName });
|
2021-08-02 12:34:18 +00:00
|
|
|
} else if (!isVoice && isSupported) {
|
2022-02-09 09:09:28 +00:00
|
|
|
return () => _t("%(senderName)s placed a video call.", { senderName });
|
2021-08-02 12:34:18 +00:00
|
|
|
} else if (!isVoice && !isSupported) {
|
2022-02-09 09:09:28 +00:00
|
|
|
return () => _t("%(senderName)s placed a video call. (not supported by this browser)", { senderName });
|
2021-08-02 12:34:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 02:13:18 +00:00
|
|
|
function textForMemberEvent(ev: MatrixEvent, allowJSX: boolean, showHiddenEvents?: boolean): () => string | null {
|
2015-10-30 02:07:04 +00:00
|
|
|
// XXX: SYJS-16 "sender is sometimes null for join messages"
|
2022-02-11 09:25:14 +00:00
|
|
|
const senderName = ev.sender?.name || getRoomMemberDisplayname(ev);
|
|
|
|
const targetName = ev.target?.name || getRoomMemberDisplayname(ev, ev.getStateKey());
|
2017-09-25 08:48:00 +00:00
|
|
|
const prevContent = ev.getPrevContent();
|
|
|
|
const content = ev.getContent();
|
2021-06-23 16:31:08 +00:00
|
|
|
const reason = content.reason;
|
2017-09-25 08:48:00 +00:00
|
|
|
|
|
|
|
switch (content.membership) {
|
|
|
|
case "invite": {
|
|
|
|
const threePidContent = content.third_party_invite;
|
2015-12-17 15:48:14 +00:00
|
|
|
if (threePidContent) {
|
2016-03-02 16:04:24 +00:00
|
|
|
if (threePidContent.display_name) {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(targetName)s accepted the invitation for %(displayName)s", {
|
2018-07-03 09:30:08 +00:00
|
|
|
targetName,
|
2017-09-25 08:48:00 +00:00
|
|
|
displayName: threePidContent.display_name,
|
|
|
|
});
|
2016-03-02 16:04:24 +00:00
|
|
|
} else {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(targetName)s accepted an invitation", { targetName });
|
2016-03-02 16:04:24 +00:00
|
|
|
}
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(senderName)s invited %(targetName)s", { senderName, targetName });
|
2015-12-17 15:48:14 +00:00
|
|
|
}
|
2017-09-25 08:48:00 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
case "ban":
|
2021-06-23 16:31:08 +00:00
|
|
|
return () =>
|
|
|
|
reason
|
2021-06-24 01:42:47 +00:00
|
|
|
? _t("%(senderName)s banned %(targetName)s: %(reason)s", { senderName, targetName, reason })
|
|
|
|
: _t("%(senderName)s banned %(targetName)s", { senderName, targetName });
|
2015-09-16 13:48:49 +00:00
|
|
|
case "join":
|
2017-09-25 08:48:00 +00:00
|
|
|
if (prevContent && prevContent.membership === "join") {
|
|
|
|
if (prevContent.displayname && content.displayname && prevContent.displayname !== content.displayname) {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(oldDisplayName)s changed their display name to %(displayName)s", {
|
2021-10-20 16:14:11 +00: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
|
|
|
|
oldDisplayName: removeDirectionOverrideChars(prevContent.displayname),
|
|
|
|
displayName: removeDirectionOverrideChars(content.displayname),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
|
|
|
} else if (!prevContent.displayname && content.displayname) {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s set their display name to %(displayName)s", {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderName: ev.getSender(),
|
2021-10-20 16:14:11 +00:00
|
|
|
displayName: removeDirectionOverrideChars(content.displayname),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
|
|
|
} else if (prevContent.displayname && !content.displayname) {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s removed their display name (%(oldDisplayName)s)", {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderName,
|
2021-10-20 16:14:11 +00:00
|
|
|
oldDisplayName: removeDirectionOverrideChars(prevContent.displayname),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
2017-09-25 14:49:48 +00:00
|
|
|
} else if (prevContent.avatar_url && !content.avatar_url) {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(senderName)s removed their profile picture", { senderName });
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (
|
|
|
|
prevContent.avatar_url &&
|
|
|
|
content.avatar_url &&
|
|
|
|
prevContent.avatar_url !== content.avatar_url
|
|
|
|
) {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(senderName)s changed their profile picture", { senderName });
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (!prevContent.avatar_url && content.avatar_url) {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(senderName)s set a profile picture", { senderName });
|
2021-06-15 22:59:42 +00:00
|
|
|
} else if (showHiddenEvents ?? SettingsStore.getValue("showHiddenEventsInTimeline")) {
|
2021-06-24 01:42:47 +00:00
|
|
|
// This is a null rejoin, it will only be visible if using 'show hidden events' (labs)
|
|
|
|
return () => _t("%(senderName)s made no change", { senderName });
|
2019-06-26 19:22:01 +00:00
|
|
|
} else {
|
2021-06-07 03:06:56 +00:00
|
|
|
return null;
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-10-15 14:31:29 +00:00
|
|
|
if (!ev.target) logger.warn("Join message has no target! -- " + ev.getContent().state_key);
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(targetName)s joined the room", { targetName });
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
case "leave":
|
|
|
|
if (ev.getSender() === ev.getStateKey()) {
|
2020-09-24 15:16:20 +00:00
|
|
|
if (prevContent.membership === "invite") {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(targetName)s rejected the invitation", { targetName });
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2021-06-23 16:31:08 +00:00
|
|
|
return () =>
|
|
|
|
reason
|
2021-06-24 01:42:47 +00:00
|
|
|
? _t("%(targetName)s left the room: %(reason)s", { targetName, reason })
|
|
|
|
: _t("%(targetName)s left the room", { targetName });
|
2016-03-05 02:30:18 +00:00
|
|
|
}
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.membership === "ban") {
|
2021-06-24 01:42:47 +00:00
|
|
|
return () => _t("%(senderName)s unbanned %(targetName)s", { senderName, targetName });
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.membership === "invite") {
|
2021-06-23 16:31:08 +00:00
|
|
|
return () =>
|
|
|
|
reason
|
2021-06-24 01:42:47 +00:00
|
|
|
? _t("%(senderName)s withdrew %(targetName)s's invitation: %(reason)s", {
|
2021-06-23 16:31:08 +00:00
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
reason,
|
|
|
|
})
|
2021-06-29 12:11:58 +00:00
|
|
|
: _t("%(senderName)s withdrew %(targetName)s's invitation", { senderName, targetName });
|
2021-04-12 11:13:28 +00:00
|
|
|
} else if (prevContent.membership === "join") {
|
2021-06-23 16:31:08 +00:00
|
|
|
return () =>
|
|
|
|
reason
|
2022-01-14 13:08:34 +00:00
|
|
|
? _t("%(senderName)s removed %(targetName)s: %(reason)s", {
|
2021-06-23 16:31:08 +00:00
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
reason,
|
|
|
|
})
|
2022-01-14 13:08:34 +00:00
|
|
|
: _t("%(senderName)s removed %(targetName)s", { senderName, targetName });
|
2021-04-12 11:13:28 +00:00
|
|
|
} else {
|
2021-06-07 03:06:56 +00:00
|
|
|
return null;
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForTopicEvent(ev: MatrixEvent): () => string | null {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t('%(senderDisplayName)s changed the topic to "%(topic)s".', {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderDisplayName,
|
2017-09-25 08:48:00 +00:00
|
|
|
topic: ev.getContent().topic,
|
|
|
|
});
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
2021-06-22 07:20:15 +00:00
|
|
|
function textForRoomAvatarEvent(ev: MatrixEvent): () => string | null {
|
2021-08-13 03:29:28 +00:00
|
|
|
const senderDisplayName = ev?.sender?.name || ev.getSender();
|
2021-06-29 04:43:14 +00:00
|
|
|
return () => _t("%(senderDisplayName)s changed the room avatar.", { senderDisplayName });
|
2021-06-22 07:20:15 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForRoomNameEvent(ev: MatrixEvent): () => string | null {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2017-06-10 13:26:27 +00:00
|
|
|
|
2017-05-30 05:21:14 +00:00
|
|
|
if (!ev.getContent().name || ev.getContent().name.trim().length === 0) {
|
2021-06-29 12:11:58 +00:00
|
|
|
return () => _t("%(senderDisplayName)s removed the room name.", { senderDisplayName });
|
2017-05-30 05:21:14 +00:00
|
|
|
}
|
2020-03-07 18:36:24 +00:00
|
|
|
if (ev.getPrevContent().name) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderDisplayName)s changed the room name from %(oldRoomName)s to %(newRoomName)s.", {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderDisplayName,
|
2020-03-07 18:36:24 +00:00
|
|
|
oldRoomName: ev.getPrevContent().name,
|
|
|
|
newRoomName: ev.getContent().name,
|
2022-12-12 11:24:14 +00:00
|
|
|
});
|
|
|
|
}
|
2021-06-29 12:11:58 +00:00
|
|
|
return () =>
|
2021-06-07 03:06:56 +00:00
|
|
|
_t("%(senderDisplayName)s changed the room name to %(roomName)s.", {
|
2020-03-07 18:36:24 +00:00
|
|
|
senderDisplayName,
|
|
|
|
roomName: ev.getContent().name,
|
|
|
|
});
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-10-30 02:07:04 +00:00
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForTombstoneEvent(ev: MatrixEvent): () => string | null {
|
2019-01-10 22:15:45 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2021-06-29 12:11:58 +00:00
|
|
|
return () => _t("%(senderDisplayName)s upgraded this room.", { senderDisplayName });
|
2019-01-10 22:15:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 14:28:22 +00:00
|
|
|
const onViewJoinRuleSettingsClick = () => {
|
|
|
|
defaultDispatcher.dispatch({
|
|
|
|
action: "open_room_settings",
|
|
|
|
initial_tab_id: ROOM_SECURITY_TAB,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-05-03 21:04:37 +00:00
|
|
|
function textForJoinRulesEvent(ev: MatrixEvent, allowJSX: boolean): () => Renderable {
|
2019-02-07 19:14:58 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().join_rule) {
|
2021-10-26 14:28:22 +00:00
|
|
|
case JoinRule.Public:
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderDisplayName)s made the room public to whoever knows the link.", {
|
|
|
|
senderDisplayName,
|
|
|
|
});
|
2021-10-26 14:28:22 +00:00
|
|
|
case JoinRule.Invite:
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderDisplayName)s made the room invite only.", {
|
|
|
|
senderDisplayName,
|
|
|
|
});
|
2021-10-26 14:28:22 +00:00
|
|
|
case JoinRule.Restricted:
|
|
|
|
if (allowJSX) {
|
|
|
|
return () => (
|
|
|
|
<span>
|
|
|
|
{_t(
|
|
|
|
"%(senderDisplayName)s changed who can join this room. <a>View settings</a>.",
|
|
|
|
{
|
|
|
|
senderDisplayName,
|
|
|
|
},
|
|
|
|
{
|
2022-01-07 09:40:53 +00:00
|
|
|
a: (sub) => (
|
|
|
|
<AccessibleButton kind="link_inline" onClick={onViewJoinRuleSettingsClick}>
|
2021-10-26 14:28:22 +00:00
|
|
|
{sub}
|
2022-01-07 09:40:53 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-10-26 14:28:22 +00:00
|
|
|
},
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => _t("%(senderDisplayName)s changed who can join this room.", { senderDisplayName });
|
2019-02-07 19:14:58 +00:00
|
|
|
default:
|
|
|
|
// The spec supports "knock" and "private", however nothing implements these.
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderDisplayName)s changed the join rule to %(rule)s", {
|
2019-02-07 19:14:58 +00:00
|
|
|
senderDisplayName,
|
|
|
|
rule: ev.getContent().join_rule,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForGuestAccessEvent(ev: MatrixEvent): () => string | null {
|
2019-02-07 19:14:58 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().guest_access) {
|
2021-10-26 14:28:22 +00:00
|
|
|
case GuestAccess.CanJoin:
|
2021-06-29 12:11:58 +00:00
|
|
|
return () => _t("%(senderDisplayName)s has allowed guests to join the room.", { senderDisplayName });
|
2021-10-26 14:28:22 +00:00
|
|
|
case GuestAccess.Forbidden:
|
2021-06-29 12:11:58 +00:00
|
|
|
return () => _t("%(senderDisplayName)s has prevented guests from joining the room.", { senderDisplayName });
|
2019-02-07 19:14:58 +00:00
|
|
|
default:
|
|
|
|
// There's no other options we can expect, however just for safety's sake we'll do this.
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderDisplayName)s changed guest access to %(rule)s", {
|
2019-02-07 19:14:58 +00:00
|
|
|
senderDisplayName,
|
|
|
|
rule: ev.getContent().guest_access,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForServerACLEvent(ev: MatrixEvent): () => string | null {
|
2018-07-06 15:36:26 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2018-07-06 15:54:28 +00: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-03 21:04:37 +00:00
|
|
|
allow_ip_literals: prevContent.allow_ip_literals !== false,
|
2018-07-06 15:54:28 +00:00
|
|
|
};
|
2020-10-13 21:08:04 +00:00
|
|
|
|
2021-06-07 03:06:56 +00:00
|
|
|
let getText = null;
|
2018-07-06 14:31:21 +00:00
|
|
|
if (prev.deny.length === 0 && prev.allow.length === 0) {
|
2021-06-29 12:11:58 +00:00
|
|
|
getText = () => _t("%(senderDisplayName)s set the server ACLs for this room.", { senderDisplayName });
|
2018-07-06 09:18:31 +00:00
|
|
|
} else {
|
2021-06-29 12:11:58 +00:00
|
|
|
getText = () => _t("%(senderDisplayName)s changed the server ACLs for this room.", { senderDisplayName });
|
2018-07-06 09:18:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 19:22:37 +00:00
|
|
|
if (!Array.isArray(current.allow)) {
|
|
|
|
current.allow = [];
|
|
|
|
}
|
2020-10-13 21:08:04 +00:00
|
|
|
|
|
|
|
// If we know for sure everyone is banned, mark the room as obliterated
|
2018-07-06 15:54:28 +00:00
|
|
|
if (current.allow.length === 0) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
getText() + " " + _t("🎉 All servers are banned from participating! This room can no longer be used.");
|
2018-07-06 15:36:44 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 03:06:56 +00:00
|
|
|
return getText;
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-10-30 02:07:04 +00:00
|
|
|
|
2021-06-22 06:42:37 +00:00
|
|
|
function textForMessageEvent(ev: MatrixEvent): () => string | null {
|
2022-05-10 15:39:28 +00:00
|
|
|
if (isLocationEvent(ev)) {
|
2022-01-19 00:58:31 +00:00
|
|
|
return textForLocationEvent(ev);
|
|
|
|
}
|
|
|
|
|
2021-06-07 03:06:56 +00:00
|
|
|
return () => {
|
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2021-06-17 05:16:08 +00:00
|
|
|
let message = ev.getContent().body;
|
2021-06-22 09:23:48 +00:00
|
|
|
if (ev.isRedacted()) {
|
2022-04-11 09:10:16 +00:00
|
|
|
message = textForRedactedPollAndMessageEvent(ev);
|
2021-06-22 09:23:48 +00:00
|
|
|
}
|
2022-01-13 17:03:37 +00:00
|
|
|
|
2023-01-10 16:21:03 +00:00
|
|
|
if (SettingsStore.isEnabled("feature_extensible_events")) {
|
|
|
|
const extev = ev.unstableExtensibleEvent as MessageEvent;
|
|
|
|
if (extev) {
|
|
|
|
if (extev.isEquivalentTo(M_EMOTE)) {
|
|
|
|
return `* ${senderDisplayName} ${extev.text}`;
|
|
|
|
} else if (extev.isEquivalentTo(M_NOTICE) || extev.isEquivalentTo(M_MESSAGE)) {
|
|
|
|
return `${senderDisplayName}: ${extev.text}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 14:28:22 +00:00
|
|
|
if (ev.getContent().msgtype === MsgType.Emote) {
|
2021-06-07 03:06:56 +00:00
|
|
|
message = "* " + senderDisplayName + " " + message;
|
2021-10-26 14:28:22 +00:00
|
|
|
} else if (ev.getContent().msgtype === MsgType.Image) {
|
2021-06-30 08:38:22 +00:00
|
|
|
message = _t("%(senderDisplayName)s sent an image.", { senderDisplayName });
|
2021-10-26 14:28:22 +00:00
|
|
|
} else if (ev.getType() == EventType.Sticker) {
|
2021-06-30 08:38:22 +00:00
|
|
|
message = _t("%(senderDisplayName)s sent a sticker.", { senderDisplayName });
|
2021-08-13 18:14:07 +00:00
|
|
|
} else {
|
|
|
|
// in this case, parse it as a plain text message
|
|
|
|
message = senderDisplayName + ": " + message;
|
|
|
|
}
|
2021-06-07 03:06:56 +00:00
|
|
|
return message;
|
|
|
|
};
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForCanonicalAliasEvent(ev: MatrixEvent): () => string | null {
|
2022-02-09 09:09:28 +00:00
|
|
|
const senderName = getSenderName(ev);
|
2018-09-20 00:07:01 +00:00
|
|
|
const oldAlias = ev.getPrevContent().alias;
|
2020-03-09 17:24:48 +00:00
|
|
|
const oldAltAliases = ev.getPrevContent().alt_aliases || [];
|
2018-09-20 00:07:01 +00:00
|
|
|
const newAlias = ev.getContent().alias;
|
2020-03-09 17:24:48 +00:00
|
|
|
const newAltAliases = ev.getContent().alt_aliases || [];
|
|
|
|
const removedAltAliases = oldAltAliases.filter((alias) => !newAltAliases.includes(alias));
|
|
|
|
const addedAltAliases = newAltAliases.filter((alias) => !oldAltAliases.includes(alias));
|
2018-09-20 00:07:01 +00:00
|
|
|
|
2020-03-09 17:24:48 +00:00
|
|
|
if (!removedAltAliases.length && !addedAltAliases.length) {
|
|
|
|
if (newAlias) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s set the main address for this room to %(address)s.", {
|
2022-02-09 09:09:28 +00:00
|
|
|
senderName,
|
2020-03-09 17:24:48 +00:00
|
|
|
address: ev.getContent().alias,
|
|
|
|
});
|
|
|
|
} else if (oldAlias) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s removed the main address for this room.", {
|
2022-02-09 09:09:28 +00:00
|
|
|
senderName,
|
2020-03-09 17:24:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (newAlias === oldAlias) {
|
|
|
|
if (addedAltAliases.length && !removedAltAliases.length) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s added the alternative addresses %(addresses)s for this room.", {
|
2022-02-09 09:09:28 +00:00
|
|
|
senderName,
|
2020-03-09 17:24:48 +00:00
|
|
|
addresses: addedAltAliases.join(", "),
|
|
|
|
count: addedAltAliases.length,
|
|
|
|
});
|
2022-05-03 21:04:37 +00:00
|
|
|
}
|
|
|
|
if (removedAltAliases.length && !addedAltAliases.length) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s removed the alternative addresses %(addresses)s for this room.", {
|
2022-02-09 09:09:28 +00:00
|
|
|
senderName,
|
2020-03-09 17:24:48 +00:00
|
|
|
addresses: removedAltAliases.join(", "),
|
|
|
|
count: removedAltAliases.length,
|
|
|
|
});
|
2022-05-03 21:04:37 +00:00
|
|
|
}
|
|
|
|
if (removedAltAliases.length && addedAltAliases.length) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s changed the alternative addresses for this room.", {
|
2022-02-09 09:09:28 +00:00
|
|
|
senderName,
|
2020-03-09 17:24:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-10 17:45:51 +00:00
|
|
|
// both alias and alt_aliases where modified
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s changed the main and alternative addresses for this room.", {
|
2022-02-09 09:09:28 +00:00
|
|
|
senderName,
|
2018-09-20 00:07:01 +00:00
|
|
|
});
|
|
|
|
}
|
2020-03-10 17:45:51 +00: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 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s changed the addresses for this room.", {
|
2022-02-09 09:09:28 +00:00
|
|
|
senderName,
|
2020-03-10 17:45:51 +00:00
|
|
|
});
|
2018-09-20 00:07:01 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForThreePidInviteEvent(event: MatrixEvent): () => string | null {
|
2022-01-19 00:58:31 +00:00
|
|
|
const senderName = getSenderName(event);
|
2019-03-29 02:38:15 +00:00
|
|
|
|
2019-03-29 17:45:07 +00:00
|
|
|
if (!isValid3pidInvite(event)) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s revoked the invitation for %(targetDisplayName)s to join the room.", {
|
2019-03-29 02:38:15 +00:00
|
|
|
senderName,
|
2021-06-07 03:06:56 +00:00
|
|
|
targetDisplayName: event.getPrevContent().display_name || _t("Someone"),
|
2019-03-29 02:38:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s sent an invitation to %(targetDisplayName)s to join the room.", {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderName,
|
2017-09-25 08:48:00 +00:00
|
|
|
targetDisplayName: event.getContent().display_name,
|
|
|
|
});
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-12-17 15:48:14 +00:00
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForHistoryVisibilityEvent(event: MatrixEvent): () => string | null {
|
2022-01-19 00:58:31 +00:00
|
|
|
const senderName = getSenderName(event);
|
2017-09-17 12:28:17 +00:00
|
|
|
switch (event.getContent().history_visibility) {
|
2021-10-26 14:28:22 +00:00
|
|
|
case HistoryVisibility.Invited:
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t(
|
|
|
|
"%(senderName)s made future room history visible to all room members, " +
|
2021-06-29 12:11:58 +00:00
|
|
|
"from the point they are invited.",
|
|
|
|
{ senderName },
|
|
|
|
);
|
2021-10-26 14:28:22 +00:00
|
|
|
case HistoryVisibility.Joined:
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t(
|
|
|
|
"%(senderName)s made future room history visible to all room members, " +
|
2021-06-29 12:11:58 +00:00
|
|
|
"from the point they joined.",
|
|
|
|
{ senderName },
|
|
|
|
);
|
2021-10-26 14:28:22 +00:00
|
|
|
case HistoryVisibility.Shared:
|
2021-06-29 12:11:58 +00:00
|
|
|
return () => _t("%(senderName)s made future room history visible to all room members.", { senderName });
|
2021-10-26 14:28:22 +00:00
|
|
|
case HistoryVisibility.WorldReadable:
|
2021-06-29 12:11:58 +00:00
|
|
|
return () => _t("%(senderName)s made future room history visible to anyone.", { senderName });
|
2017-09-17 12:28:17 +00:00
|
|
|
default:
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s made future room history visible to unknown (%(visibility)s).", {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderName,
|
2017-09-17 12:28:17 +00:00
|
|
|
visibility: event.getContent().history_visibility,
|
|
|
|
});
|
2016-03-15 23:47:40 +00:00
|
|
|
}
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 16:02:35 +00:00
|
|
|
// Currently will only display a change if a user's power level is changed
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForPowerEvent(event: MatrixEvent): () => string | null {
|
2022-01-19 00:58:31 +00:00
|
|
|
const senderName = getSenderName(event);
|
2022-08-10 13:33:13 +00:00
|
|
|
if (!event.getPrevContent()?.users || !event.getContent()?.users) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return null;
|
2017-04-06 16:02:35 +00:00
|
|
|
}
|
2022-08-10 13:33:13 +00:00
|
|
|
const previousUserDefault: number = event.getPrevContent().users_default || 0;
|
|
|
|
const currentUserDefault: number = event.getContent().users_default || 0;
|
2017-04-06 16:02:35 +00:00
|
|
|
// Construct set of userIds
|
2022-08-10 13:33:13 +00: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 16:02:35 +00:00
|
|
|
users.forEach((userId) => {
|
|
|
|
// Previous power level
|
2022-08-10 13:33:13 +00:00
|
|
|
let from: number = event.getPrevContent().users[userId];
|
2021-06-23 03:35:47 +00:00
|
|
|
if (!Number.isInteger(from)) {
|
|
|
|
from = previousUserDefault;
|
|
|
|
}
|
2017-04-06 16:02:35 +00:00
|
|
|
// Current power level
|
2021-06-23 03:48:01 +00:00
|
|
|
let to = event.getContent().users[userId];
|
2021-06-23 03:35:47 +00:00
|
|
|
if (!Number.isInteger(to)) {
|
|
|
|
to = currentUserDefault;
|
|
|
|
}
|
|
|
|
if (from === previousUserDefault && to === currentUserDefault) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-06 16:02:35 +00:00
|
|
|
if (to !== from) {
|
2022-09-22 07:42:07 +00:00
|
|
|
const name = getRoomMemberDisplayname(event, userId);
|
2022-01-25 09:40:02 +00:00
|
|
|
diffs.push({ userId, name, from, to });
|
2017-04-06 16:02:35 +00:00
|
|
|
}
|
|
|
|
});
|
2021-06-07 03:06:56 +00:00
|
|
|
if (!diffs.length) {
|
|
|
|
return null;
|
2017-04-06 16:02:35 +00:00
|
|
|
}
|
2022-01-25 09:40:02 +00:00
|
|
|
|
2021-06-07 03:06:56 +00:00
|
|
|
// XXX: This is also surely broken for i18n
|
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s changed the power level of %(powerLevelDiffText)s.", {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderName,
|
2021-06-07 03:06:56 +00:00
|
|
|
powerLevelDiffText: diffs
|
|
|
|
.map((diff) =>
|
|
|
|
_t("%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s", {
|
2022-01-25 09:40:02 +00:00
|
|
|
userId: diff.name,
|
2021-06-23 03:35:47 +00:00
|
|
|
fromPowerLevel: Roles.textualPowerLevel(diff.from, previousUserDefault),
|
|
|
|
toPowerLevel: Roles.textualPowerLevel(diff.to, currentUserDefault),
|
2021-06-07 03:06:56 +00:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
.join(", "),
|
2017-05-27 14:52:24 +00:00
|
|
|
});
|
2017-04-06 16:02:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 14:58:56 +00:00
|
|
|
const onPinnedMessagesClick = (): void => {
|
2022-01-05 15:14:44 +00:00
|
|
|
RightPanelStore.instance.setCard({ phase: RightPanelPhases.PinnedMessages }, false);
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2021-06-24 14:58:56 +00:00
|
|
|
|
2022-05-03 21:04:37 +00:00
|
|
|
function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => Renderable {
|
2021-06-24 08:40:30 +00:00
|
|
|
if (!SettingsStore.getValue("feature_pinning")) return null;
|
2022-01-19 00:58:31 +00:00
|
|
|
const senderName = getSenderName(event);
|
2021-07-27 15:58:53 +00:00
|
|
|
const roomId = event.getRoomId();
|
2021-06-24 08:40:30 +00:00
|
|
|
|
2021-07-27 14:37:05 +00:00
|
|
|
const pinned = event.getContent().pinned ?? [];
|
|
|
|
const previouslyPinned = event.getPrevContent().pinned ?? [];
|
|
|
|
const newlyPinned = pinned.filter((item) => previouslyPinned.indexOf(item) < 0);
|
2021-07-27 15:58:53 +00:00
|
|
|
const newlyUnpinned = previouslyPinned.filter((item) => pinned.indexOf(item) < 0);
|
2021-07-27 14:37:05 +00:00
|
|
|
|
2021-08-11 13:56:59 +00:00
|
|
|
if (newlyPinned.length === 1 && newlyUnpinned.length === 0) {
|
2021-07-27 14:37:05 +00:00
|
|
|
// A single message was pinned, include a link to that message.
|
|
|
|
if (allowJSX) {
|
|
|
|
const messageId = newlyPinned.pop();
|
|
|
|
|
|
|
|
return () => (
|
|
|
|
<span>
|
2021-08-10 14:50:23 +00:00
|
|
|
{_t(
|
|
|
|
"%(senderName)s pinned <a>a message</a> to this room. See all <b>pinned messages</b>.",
|
|
|
|
{ senderName },
|
|
|
|
{
|
|
|
|
a: (sub) => (
|
2022-12-12 15:09:11 +00:00
|
|
|
<AccessibleButton kind="link_inline" onClick={(e) => highlightEvent(roomId, messageId)}>
|
2021-08-10 14:50:23 +00:00
|
|
|
{sub}
|
2022-01-07 09:40:53 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 14:50:23 +00:00
|
|
|
b: (sub) => (
|
2022-01-07 09:40:53 +00:00
|
|
|
<AccessibleButton kind="link_inline" onClick={onPinnedMessagesClick}>
|
2021-08-10 14:50:23 +00:00
|
|
|
{sub}
|
2022-01-07 09:40:53 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 14:50:23 +00:00
|
|
|
},
|
|
|
|
)}
|
2021-07-27 14:37:05 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => _t("%(senderName)s pinned a message to this room. See all pinned messages.", { senderName });
|
|
|
|
}
|
|
|
|
|
2021-08-11 13:56:59 +00:00
|
|
|
if (newlyUnpinned.length === 1 && newlyPinned.length === 0) {
|
2021-07-27 15:58:53 +00:00
|
|
|
// A single message was unpinned, include a link to that message.
|
|
|
|
if (allowJSX) {
|
|
|
|
const messageId = newlyUnpinned.pop();
|
|
|
|
|
|
|
|
return () => (
|
|
|
|
<span>
|
2021-08-10 14:50:23 +00:00
|
|
|
{_t(
|
|
|
|
"%(senderName)s unpinned <a>a message</a> from this room. See all <b>pinned messages</b>.",
|
|
|
|
{ senderName },
|
|
|
|
{
|
|
|
|
a: (sub) => (
|
2022-12-12 15:09:11 +00:00
|
|
|
<AccessibleButton kind="link_inline" onClick={(e) => highlightEvent(roomId, messageId)}>
|
2021-08-10 14:50:23 +00:00
|
|
|
{sub}
|
2022-01-07 09:40:53 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 14:50:23 +00:00
|
|
|
b: (sub) => (
|
2022-01-07 09:40:53 +00:00
|
|
|
<AccessibleButton kind="link_inline" onClick={onPinnedMessagesClick}>
|
2021-08-10 14:50:23 +00:00
|
|
|
{sub}
|
2022-01-07 09:40:53 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-08-10 14:50:23 +00:00
|
|
|
},
|
|
|
|
)}
|
2021-07-27 15:58:53 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => _t("%(senderName)s unpinned a message from this room. See all pinned messages.", { senderName });
|
|
|
|
}
|
2021-06-24 08:40:30 +00:00
|
|
|
|
2021-06-24 12:02:06 +00:00
|
|
|
if (allowJSX) {
|
|
|
|
return () => (
|
|
|
|
<span>
|
2021-08-10 14:50:23 +00:00
|
|
|
{_t(
|
|
|
|
"%(senderName)s changed the <a>pinned messages</a> for the room.",
|
|
|
|
{ senderName },
|
2022-01-07 09:40:53 +00:00
|
|
|
{
|
|
|
|
a: (sub) => (
|
|
|
|
<AccessibleButton kind="link_inline" onClick={onPinnedMessagesClick}>
|
|
|
|
{sub}
|
|
|
|
</AccessibleButton>
|
|
|
|
),
|
|
|
|
},
|
2021-08-10 14:50:23 +00:00
|
|
|
)}
|
2021-06-24 12:02:06 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
2021-06-24 15:27:53 +00:00
|
|
|
|
2021-06-24 15:23:42 +00:00
|
|
|
return () => _t("%(senderName)s changed the pinned messages for the room.", { senderName });
|
2017-09-28 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForWidgetEvent(event: MatrixEvent): () => string | null {
|
2022-02-09 09:09:28 +00:00
|
|
|
const senderName = getSenderName(event);
|
2021-06-29 12:11:58 +00:00
|
|
|
const { name: prevName, type: prevType, url: prevUrl } = event.getPrevContent();
|
|
|
|
const { name, type, url } = event.getContent() || {};
|
2017-08-28 07:19:39 +00:00
|
|
|
|
|
|
|
let widgetName = name || prevName || type || prevType || "";
|
2017-08-18 17:02:50 +00:00
|
|
|
// Apply sentence case to widget name
|
|
|
|
if (widgetName && widgetName.length > 0) {
|
2020-11-24 11:27:02 +00:00
|
|
|
widgetName = widgetName[0].toUpperCase() + widgetName.slice(1);
|
2017-08-18 17:02:50 +00:00
|
|
|
}
|
2017-08-16 16:46:20 +00:00
|
|
|
|
2017-08-18 11:04:34 +00:00
|
|
|
// If the widget was removed, its content should be {}, but this is sufficiently
|
|
|
|
// equivalent to that condition.
|
2017-08-18 09:45:43 +00:00
|
|
|
if (url) {
|
2017-08-28 07:19:39 +00:00
|
|
|
if (prevUrl) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(widgetName)s widget modified by %(senderName)s", {
|
2017-08-28 07:19:39 +00:00
|
|
|
widgetName,
|
|
|
|
senderName,
|
|
|
|
});
|
|
|
|
} else {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(widgetName)s widget added by %(senderName)s", {
|
2017-08-28 07:19:39 +00:00
|
|
|
widgetName,
|
|
|
|
senderName,
|
|
|
|
});
|
|
|
|
}
|
2017-08-16 16:46:20 +00:00
|
|
|
} else {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(widgetName)s widget removed by %(senderName)s", {
|
2017-08-18 17:02:50 +00:00
|
|
|
widgetName,
|
|
|
|
senderName,
|
2017-08-16 16:46:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForWidgetLayoutEvent(event: MatrixEvent): () => string | null {
|
2022-02-09 09:09:28 +00:00
|
|
|
const senderName = getSenderName(event);
|
2021-11-16 14:44:19 +00:00
|
|
|
return () => _t("%(senderName)s has updated the room layout", { senderName });
|
2021-01-19 02:31:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 22:52:40 +00:00
|
|
|
function textForMjolnirEvent(event: MatrixEvent): () => string | null {
|
2022-02-09 09:09:28 +00:00
|
|
|
const senderName = getSenderName(event);
|
2021-06-29 12:11:58 +00:00
|
|
|
const { entity: prevEntity } = event.getPrevContent();
|
|
|
|
const { entity, recommendation, reason } = event.getContent();
|
2019-12-10 03:36:00 +00:00
|
|
|
|
|
|
|
// Rule removed
|
|
|
|
if (!entity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s removed the rule banning users matching %(glob)s", { senderName, glob: prevEntity });
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s removed the rule banning rooms matching %(glob)s", { senderName, glob: prevEntity });
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s removed the rule banning servers matching %(glob)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: prevEntity,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something, but we shouldn't end up here.
|
2021-06-29 12:11:58 +00:00
|
|
|
return () => _t("%(senderName)s removed a ban rule matching %(glob)s", { senderName, glob: prevEntity });
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid rule
|
2021-06-29 12:11:58 +00:00
|
|
|
if (!recommendation || !reason) return () => _t(`%(senderName)s updated an invalid ban rule`, { senderName });
|
2019-12-10 03:36:00 +00:00
|
|
|
|
|
|
|
// Rule updated
|
|
|
|
if (entity === prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s updated the rule banning users matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s updated the rule banning rooms matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s updated the rule banning servers matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s updated a ban rule matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New rule
|
|
|
|
if (!prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s created a rule banning users matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s created a rule banning rooms matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s created a rule banning servers matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s created a ban rule matching %(glob)s for %(reason)s", {
|
2021-06-29 12:11:58 +00:00
|
|
|
senderName,
|
|
|
|
glob: entity,
|
|
|
|
reason,
|
|
|
|
});
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// else the entity !== prevEntity - count as a removal & add
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t(
|
2021-04-29 17:57:02 +00:00
|
|
|
"%(senderName)s changed a rule that was banning users matching %(oldGlob)s to matching " +
|
2019-12-10 03:36:00 +00:00
|
|
|
"%(newGlob)s for %(reason)s",
|
2021-06-29 12:11:58 +00:00
|
|
|
{ senderName, oldGlob: prevEntity, newGlob: entity, reason },
|
2021-04-29 17:57:02 +00:00
|
|
|
);
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t(
|
2021-04-29 17:57:02 +00:00
|
|
|
"%(senderName)s changed a rule that was banning rooms matching %(oldGlob)s to matching " +
|
2019-12-10 03:36:00 +00:00
|
|
|
"%(newGlob)s for %(reason)s",
|
2021-06-29 12:11:58 +00:00
|
|
|
{ senderName, oldGlob: prevEntity, newGlob: entity, reason },
|
2021-04-29 17:57:02 +00:00
|
|
|
);
|
2019-12-10 03:36:00 +00:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t(
|
2021-04-29 17:57:02 +00:00
|
|
|
"%(senderName)s changed a rule that was banning servers matching %(oldGlob)s to matching " +
|
2019-12-10 03:36:00 +00:00
|
|
|
"%(newGlob)s for %(reason)s",
|
2021-06-29 12:11:58 +00:00
|
|
|
{ senderName, oldGlob: prevEntity, newGlob: entity, reason },
|
2021-04-29 17:57:02 +00:00
|
|
|
);
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 03:06:56 +00:00
|
|
|
return () =>
|
|
|
|
_t(
|
|
|
|
"%(senderName)s updated a ban rule that was matching %(oldGlob)s to matching %(newGlob)s " +
|
2021-06-29 12:11:58 +00:00
|
|
|
"for %(reason)s",
|
|
|
|
{ senderName, oldGlob: prevEntity, newGlob: entity, reason },
|
|
|
|
);
|
2019-12-10 03:36:00 +00:00
|
|
|
}
|
|
|
|
|
2022-01-19 00:58:31 +00:00
|
|
|
export function textForLocationEvent(event: MatrixEvent): () => string | null {
|
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s has shared their location", {
|
|
|
|
senderName: getSenderName(event),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-11 09:10:16 +00:00
|
|
|
function textForRedactedPollAndMessageEvent(ev: MatrixEvent): string {
|
|
|
|
let message = _t("Message deleted");
|
|
|
|
const unsigned = ev.getUnsigned();
|
|
|
|
const redactedBecauseUserId = unsigned?.redacted_because?.sender;
|
|
|
|
if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) {
|
|
|
|
const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
|
|
|
|
const sender = room?.getMember(redactedBecauseUserId);
|
|
|
|
message = _t("Message deleted by %(name)s", {
|
|
|
|
name: sender?.name || redactedBecauseUserId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2022-01-19 00:58:31 +00:00
|
|
|
function textForPollStartEvent(event: MatrixEvent): () => string | null {
|
2022-04-11 09:10:16 +00:00
|
|
|
return () => {
|
|
|
|
let message = "";
|
|
|
|
|
|
|
|
if (event.isRedacted()) {
|
|
|
|
message = textForRedactedPollAndMessageEvent(event);
|
|
|
|
const senderDisplayName = event.sender?.name ?? event.getSender();
|
|
|
|
message = senderDisplayName + ": " + message;
|
|
|
|
} else {
|
|
|
|
message = _t("%(senderName)s has started a poll - %(pollQuestion)s", {
|
|
|
|
senderName: getSenderName(event),
|
|
|
|
pollQuestion: (event.unstableExtensibleEvent as PollStartEvent)?.question?.text,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
};
|
2022-01-19 00:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function textForPollEndEvent(event: MatrixEvent): () => string | null {
|
|
|
|
return () =>
|
|
|
|
_t("%(senderName)s has ended a poll", {
|
|
|
|
senderName: getSenderName(event),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-12 15:03:56 +00:00
|
|
|
type Renderable = string | React.ReactNode | null;
|
2022-05-03 21:04:37 +00:00
|
|
|
|
2021-06-09 01:58:48 +00:00
|
|
|
interface IHandlers {
|
2021-06-30 02:13:18 +00:00
|
|
|
[type: string]: (ev: MatrixEvent, allowJSX: boolean, showHiddenEvents?: boolean) => () => Renderable;
|
2021-06-09 01:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const handlers: IHandlers = {
|
2021-10-26 14:28:22 +00:00
|
|
|
[EventType.RoomMessage]: textForMessageEvent,
|
|
|
|
[EventType.Sticker]: textForMessageEvent,
|
|
|
|
[EventType.CallInvite]: textForCallInviteEvent,
|
2022-01-19 00:58:31 +00:00
|
|
|
[M_POLL_START.name]: textForPollStartEvent,
|
|
|
|
[M_POLL_END.name]: textForPollEndEvent,
|
|
|
|
[M_POLL_START.altName]: textForPollStartEvent,
|
|
|
|
[M_POLL_END.altName]: textForPollEndEvent,
|
2017-10-06 11:07:38 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 01:58:48 +00:00
|
|
|
const stateHandlers: IHandlers = {
|
2021-10-26 14:28:22 +00: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 16:46:20 +00:00
|
|
|
|
2020-08-03 15:02:26 +00:00
|
|
|
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
|
2017-08-16 16:46:20 +00:00
|
|
|
"im.vector.modular.widgets": textForWidgetEvent,
|
2021-01-19 02:31:11 +00:00
|
|
|
[WIDGET_LAYOUT_EVENT_TYPE]: textForWidgetLayoutEvent,
|
2022-12-12 15:03:56 +00:00
|
|
|
[VoiceBroadcastInfoEventType]: textForVoiceBroadcastStoppedEvent,
|
2015-09-16 13:48:49 +00:00
|
|
|
};
|
|
|
|
|
2019-12-10 03:36:00 +00:00
|
|
|
// Add all the Mjolnir stuff to the renderer
|
|
|
|
for (const evType of ALL_RULE_TYPES) {
|
|
|
|
stateHandlers[evType] = textForMjolnirEvent;
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:27:12 +00:00
|
|
|
// Add both stable and unstable m.call events
|
|
|
|
for (const evType of ElementCall.CALL_EVENT_TYPE.names) {
|
|
|
|
stateHandlers[evType] = textForCallEvent;
|
|
|
|
}
|
|
|
|
|
2021-06-15 22:59:42 +00:00
|
|
|
/**
|
|
|
|
* Determines whether the given event has text to display.
|
|
|
|
* @param ev The event
|
|
|
|
* @param showHiddenEvents An optional cached setting value for showHiddenEventsInTimeline
|
|
|
|
* to avoid hitting the settings store
|
|
|
|
*/
|
|
|
|
export function hasText(ev: MatrixEvent, showHiddenEvents?: boolean): boolean {
|
2021-06-07 03:06:56 +00:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2021-06-30 02:13:18 +00:00
|
|
|
return Boolean(handler?.(ev, false, showHiddenEvents));
|
2021-06-07 03:06:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 22:59:42 +00:00
|
|
|
/**
|
|
|
|
* Gets the textual content of the given event.
|
|
|
|
* @param ev The event
|
2021-06-30 02:13:18 +00:00
|
|
|
* @param allowJSX Whether to output rich JSX content
|
2021-06-15 22:59:42 +00:00
|
|
|
* @param showHiddenEvents An optional cached setting value for showHiddenEventsInTimeline
|
|
|
|
* to avoid hitting the settings store
|
|
|
|
*/
|
2021-06-24 12:31:04 +00:00
|
|
|
export function textForEvent(ev: MatrixEvent): string;
|
2022-12-12 15:03:56 +00:00
|
|
|
export function textForEvent(ev: MatrixEvent, allowJSX: true, showHiddenEvents?: boolean): string | React.ReactNode;
|
|
|
|
export function textForEvent(ev: MatrixEvent, allowJSX = false, showHiddenEvents?: boolean): string | React.ReactNode {
|
2019-12-20 00:45:24 +00:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2021-07-14 03:26:09 +00:00
|
|
|
return handler?.(ev, allowJSX, showHiddenEvents)?.() || "";
|
2019-12-20 00:45:24 +00:00
|
|
|
}
|