2016-03-05 10:30:18 +08:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
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-06-24 16:40:30 +08:00
|
|
|
import React from 'react';
|
2017-05-25 18:39:08 +08:00
|
|
|
import { _t } from './languageHandler';
|
2017-04-10 17:09:26 +08:00
|
|
|
import * as Roles from './Roles';
|
2021-06-29 20:11:58 +08:00
|
|
|
import { isValid3pidInvite } from "./RoomInvite";
|
2019-06-27 03:22:01 +08:00
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
2021-06-29 20:11:58 +08: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";
|
2021-06-24 16:40:30 +08:00
|
|
|
import { RightPanelPhases } from './stores/RightPanelStorePhases';
|
|
|
|
import { Action } from './dispatcher/actions';
|
|
|
|
import defaultDispatcher from './dispatcher/dispatcher';
|
|
|
|
import { SetRightPanelPhasePayload } from './dispatcher/payloads/SetRightPanelPhasePayload';
|
2021-06-24 18:24:42 +08:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
2021-08-02 20:34:18 +08:00
|
|
|
import { MatrixClientPeg } from "./MatrixClientPeg";
|
2017-04-07 00:02:35 +08:00
|
|
|
|
2021-06-07 11:06:56 +08: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 20:34:18 +08:00
|
|
|
function textForCallInviteEvent(event: MatrixEvent): () => string | null {
|
|
|
|
const getSenderName = () => event.sender ? event.sender.name : _t('Someone');
|
|
|
|
// FIXME: Find a better way to determine this from the event?
|
|
|
|
let isVoice = true;
|
|
|
|
if (event.getContent().offer && event.getContent().offer.sdp &&
|
|
|
|
event.getContent().offer.sdp.indexOf('m=video') !== -1) {
|
|
|
|
isVoice = false;
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
return () => _t("%(senderName)s placed a voice call.", {
|
|
|
|
senderName: getSenderName(),
|
|
|
|
});
|
|
|
|
} else if (isVoice && !isSupported) {
|
|
|
|
return () => _t("%(senderName)s placed a voice call. (not supported by this browser)", {
|
|
|
|
senderName: getSenderName(),
|
|
|
|
});
|
|
|
|
} else if (!isVoice && isSupported) {
|
|
|
|
return () => _t("%(senderName)s placed a video call.", {
|
|
|
|
senderName: getSenderName(),
|
|
|
|
});
|
|
|
|
} else if (!isVoice && !isSupported) {
|
|
|
|
return () => _t("%(senderName)s placed a video call. (not supported by this browser)", {
|
|
|
|
senderName: getSenderName(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 10:13:18 +08:00
|
|
|
function textForMemberEvent(ev: MatrixEvent, allowJSX: boolean, showHiddenEvents?: boolean): () => string | null {
|
2015-10-30 10:07:04 +08:00
|
|
|
// XXX: SYJS-16 "sender is sometimes null for join messages"
|
2017-09-25 16:48:00 +08:00
|
|
|
const senderName = ev.sender ? ev.sender.name : ev.getSender();
|
|
|
|
const targetName = ev.target ? ev.target.name : ev.getStateKey();
|
|
|
|
const prevContent = ev.getPrevContent();
|
|
|
|
const content = ev.getContent();
|
2021-06-24 00:31:08 +08:00
|
|
|
const reason = content.reason;
|
2017-09-25 16:48:00 +08:00
|
|
|
|
|
|
|
switch (content.membership) {
|
|
|
|
case 'invite': {
|
|
|
|
const threePidContent = content.third_party_invite;
|
2015-12-17 23:48:14 +08:00
|
|
|
if (threePidContent) {
|
2016-03-03 00:04:24 +08:00
|
|
|
if (threePidContent.display_name) {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(targetName)s accepted the invitation for %(displayName)s', {
|
2018-07-03 17:30:08 +08:00
|
|
|
targetName,
|
2017-09-25 16:48:00 +08:00
|
|
|
displayName: threePidContent.display_name,
|
|
|
|
});
|
2016-03-03 00:04:24 +08:00
|
|
|
} else {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(targetName)s accepted an invitation', { targetName });
|
2016-03-03 00:04:24 +08:00
|
|
|
}
|
2017-09-25 16:48:00 +08:00
|
|
|
} else {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(senderName)s invited %(targetName)s', { senderName, targetName });
|
2015-12-17 23:48:14 +08:00
|
|
|
}
|
2017-09-25 16:48:00 +08:00
|
|
|
}
|
2015-09-16 21:48:49 +08:00
|
|
|
case 'ban':
|
2021-06-24 00:31:08 +08:00
|
|
|
return () => reason
|
2021-06-24 09:42:47 +08:00
|
|
|
? _t('%(senderName)s banned %(targetName)s: %(reason)s', { senderName, targetName, reason })
|
|
|
|
: _t('%(senderName)s banned %(targetName)s', { senderName, targetName });
|
2015-09-16 21:48:49 +08:00
|
|
|
case 'join':
|
2017-09-25 16:48:00 +08:00
|
|
|
if (prevContent && prevContent.membership === 'join') {
|
|
|
|
if (prevContent.displayname && content.displayname && prevContent.displayname !== content.displayname) {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(oldDisplayName)s changed their display name to %(displayName)s', {
|
2018-07-03 17:30:08 +08:00
|
|
|
oldDisplayName: prevContent.displayname,
|
|
|
|
displayName: content.displayname,
|
2017-09-25 16:48:00 +08:00
|
|
|
});
|
|
|
|
} else if (!prevContent.displayname && content.displayname) {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(senderName)s set their display name to %(displayName)s', {
|
2018-07-03 17:30:08 +08:00
|
|
|
senderName: ev.getSender(),
|
|
|
|
displayName: content.displayname,
|
2017-09-25 16:48:00 +08:00
|
|
|
});
|
|
|
|
} else if (prevContent.displayname && !content.displayname) {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(senderName)s removed their display name (%(oldDisplayName)s)', {
|
2018-07-03 17:30:08 +08:00
|
|
|
senderName,
|
|
|
|
oldDisplayName: prevContent.displayname,
|
2017-09-25 16:48:00 +08:00
|
|
|
});
|
2017-09-25 22:49:48 +08:00
|
|
|
} else if (prevContent.avatar_url && !content.avatar_url) {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(senderName)s removed their profile picture', { senderName });
|
2017-09-25 16:48:00 +08:00
|
|
|
} else if (prevContent.avatar_url && content.avatar_url &&
|
|
|
|
prevContent.avatar_url !== content.avatar_url) {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(senderName)s changed their profile picture', { senderName });
|
2017-09-25 16:48:00 +08:00
|
|
|
} else if (!prevContent.avatar_url && content.avatar_url) {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(senderName)s set a profile picture', { senderName });
|
2021-06-16 06:59:42 +08:00
|
|
|
} else if (showHiddenEvents ?? SettingsStore.getValue("showHiddenEventsInTimeline")) {
|
2021-06-24 09:42:47 +08: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-27 03:22:01 +08:00
|
|
|
} else {
|
2021-06-07 11:06:56 +08:00
|
|
|
return null;
|
2015-09-16 21:48:49 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ev.target) console.warn("Join message has no target! -- " + ev.getContent().state_key);
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(targetName)s joined the room', { targetName });
|
2015-09-16 21:48:49 +08:00
|
|
|
}
|
|
|
|
case 'leave':
|
|
|
|
if (ev.getSender() === ev.getStateKey()) {
|
2020-09-24 23:16:20 +08:00
|
|
|
if (prevContent.membership === "invite") {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(targetName)s rejected the invitation', { targetName });
|
2017-09-25 16:48:00 +08:00
|
|
|
} else {
|
2021-06-24 00:31:08 +08:00
|
|
|
return () => reason
|
2021-06-24 09:42:47 +08:00
|
|
|
? _t('%(targetName)s left the room: %(reason)s', { targetName, reason })
|
|
|
|
: _t('%(targetName)s left the room', { targetName });
|
2016-03-05 10:30:18 +08:00
|
|
|
}
|
2017-09-25 16:48:00 +08:00
|
|
|
} else if (prevContent.membership === "ban") {
|
2021-06-24 09:42:47 +08:00
|
|
|
return () => _t('%(senderName)s unbanned %(targetName)s', { senderName, targetName });
|
2017-09-25 16:48:00 +08:00
|
|
|
} else if (prevContent.membership === "invite") {
|
2021-06-24 00:31:08 +08:00
|
|
|
return () => reason
|
2021-06-24 09:42:47 +08:00
|
|
|
? _t('%(senderName)s withdrew %(targetName)s\'s invitation: %(reason)s', {
|
2021-06-24 00:31:08 +08:00
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
reason,
|
|
|
|
})
|
2021-06-29 20:11:58 +08:00
|
|
|
: _t('%(senderName)s withdrew %(targetName)s\'s invitation', { senderName, targetName });
|
2021-04-12 19:13:28 +08:00
|
|
|
} else if (prevContent.membership === "join") {
|
2021-06-24 00:31:08 +08:00
|
|
|
return () => reason
|
2021-06-24 09:42:47 +08:00
|
|
|
? _t('%(senderName)s kicked %(targetName)s: %(reason)s', {
|
2021-06-24 00:31:08 +08:00
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
reason,
|
|
|
|
})
|
2021-06-24 09:42:47 +08:00
|
|
|
: _t('%(senderName)s kicked %(targetName)s', { senderName, targetName });
|
2021-04-12 19:13:28 +08:00
|
|
|
} else {
|
2021-06-07 11:06:56 +08:00
|
|
|
return null;
|
2015-09-16 21:48:49 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-16 00:01:02 +08:00
|
|
|
}
|
2015-09-16 21:48:49 +08:00
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForTopicEvent(ev: MatrixEvent): () => string | null {
|
2017-09-25 16:48:00 +08:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s changed the topic to "%(topic)s".', {
|
2018-07-03 17:30:08 +08:00
|
|
|
senderDisplayName,
|
2017-09-25 16:48:00 +08:00
|
|
|
topic: ev.getContent().topic,
|
|
|
|
});
|
2016-09-16 00:01:02 +08:00
|
|
|
}
|
2015-09-16 21:48:49 +08:00
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForRoomNameEvent(ev: MatrixEvent): () => string | null {
|
2017-09-25 16:48:00 +08:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2017-06-10 21:26:27 +08:00
|
|
|
|
2017-05-30 13:21:14 +08:00
|
|
|
if (!ev.getContent().name || ev.getContent().name.trim().length === 0) {
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t('%(senderDisplayName)s removed the room name.', { senderDisplayName });
|
2017-05-30 13:21:14 +08:00
|
|
|
}
|
2020-03-08 02:36:24 +08:00
|
|
|
if (ev.getPrevContent().name) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s changed the room name from %(oldRoomName)s to %(newRoomName)s.', {
|
2020-03-08 02:36:24 +08:00
|
|
|
senderDisplayName,
|
|
|
|
oldRoomName: ev.getPrevContent().name,
|
|
|
|
newRoomName: ev.getContent().name,
|
|
|
|
});
|
|
|
|
}
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s changed the room name to %(roomName)s.', {
|
2018-07-03 17:30:08 +08:00
|
|
|
senderDisplayName,
|
2017-09-25 16:48:00 +08:00
|
|
|
roomName: ev.getContent().name,
|
|
|
|
});
|
2016-09-16 00:01:02 +08:00
|
|
|
}
|
2015-10-30 10:07:04 +08:00
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForTombstoneEvent(ev: MatrixEvent): () => string | null {
|
2019-01-11 06:15:45 +08:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t('%(senderDisplayName)s upgraded this room.', { senderDisplayName });
|
2019-01-11 06:15:45 +08:00
|
|
|
}
|
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForJoinRulesEvent(ev: MatrixEvent): () => string | null {
|
2019-02-08 03:14:58 +08:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().join_rule) {
|
|
|
|
case "public":
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s made the room public to whoever knows the link.', {
|
|
|
|
senderDisplayName,
|
|
|
|
});
|
2019-02-08 03:14:58 +08:00
|
|
|
case "invite":
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s made the room invite only.', {
|
|
|
|
senderDisplayName,
|
|
|
|
});
|
2019-02-08 03:14:58 +08:00
|
|
|
default:
|
|
|
|
// The spec supports "knock" and "private", however nothing implements these.
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s changed the join rule to %(rule)s', {
|
2019-02-08 03:14:58 +08:00
|
|
|
senderDisplayName,
|
|
|
|
rule: ev.getContent().join_rule,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForGuestAccessEvent(ev: MatrixEvent): () => string | null {
|
2019-02-08 03:14:58 +08:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().guest_access) {
|
|
|
|
case "can_join":
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t('%(senderDisplayName)s has allowed guests to join the room.', { senderDisplayName });
|
2019-02-08 03:14:58 +08:00
|
|
|
case "forbidden":
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t('%(senderDisplayName)s has prevented guests from joining the room.', { senderDisplayName });
|
2019-02-08 03:14:58 +08:00
|
|
|
default:
|
|
|
|
// There's no other options we can expect, however just for safety's sake we'll do this.
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s changed guest access to %(rule)s', {
|
2019-02-08 03:14:58 +08:00
|
|
|
senderDisplayName,
|
|
|
|
rule: ev.getContent().guest_access,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForRelatedGroupsEvent(ev: MatrixEvent): () => string | null {
|
2019-02-22 08:03:15 +08:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
const groups = ev.getContent().groups || [];
|
|
|
|
const prevGroups = ev.getPrevContent().groups || [];
|
|
|
|
const added = groups.filter((g) => !prevGroups.includes(g));
|
|
|
|
const removed = prevGroups.filter((g) => !groups.includes(g));
|
|
|
|
|
|
|
|
if (added.length && !removed.length) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s enabled flair for %(groups)s in this room.', {
|
2019-02-22 08:03:15 +08:00
|
|
|
senderDisplayName,
|
|
|
|
groups: added.join(', '),
|
|
|
|
});
|
|
|
|
} else if (!added.length && removed.length) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s disabled flair for %(groups)s in this room.', {
|
2019-02-22 08:03:15 +08:00
|
|
|
senderDisplayName,
|
|
|
|
groups: removed.join(', '),
|
|
|
|
});
|
|
|
|
} else if (added.length && removed.length) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderDisplayName)s enabled flair for %(newGroups)s and disabled flair for ' +
|
2019-02-22 08:03:15 +08:00
|
|
|
'%(oldGroups)s in this room.', {
|
|
|
|
senderDisplayName,
|
|
|
|
newGroups: added.join(', '),
|
|
|
|
oldGroups: removed.join(', '),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Don't bother rendering this change (because there were no changes)
|
2021-06-07 11:06:56 +08:00
|
|
|
return null;
|
2019-02-22 08:03:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForServerACLEvent(ev: MatrixEvent): () => string | null {
|
2018-07-06 23:36:26 +08:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2018-07-06 23:54:28 +08: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 : [],
|
|
|
|
allow_ip_literals: !(prevContent.allow_ip_literals === false),
|
|
|
|
};
|
2020-10-14 05:08:04 +08:00
|
|
|
|
2021-06-07 11:06:56 +08:00
|
|
|
let getText = null;
|
2018-07-06 22:31:21 +08:00
|
|
|
if (prev.deny.length === 0 && prev.allow.length === 0) {
|
2021-06-29 20:11:58 +08:00
|
|
|
getText = () => _t("%(senderDisplayName)s set the server ACLs for this room.", { senderDisplayName });
|
2018-07-06 17:18:31 +08:00
|
|
|
} else {
|
2021-06-29 20:11:58 +08:00
|
|
|
getText = () => _t("%(senderDisplayName)s changed the server ACLs for this room.", { senderDisplayName });
|
2018-07-06 17:18:31 +08:00
|
|
|
}
|
|
|
|
|
2018-07-07 03:22:37 +08:00
|
|
|
if (!Array.isArray(current.allow)) {
|
|
|
|
current.allow = [];
|
|
|
|
}
|
2020-10-14 05:08:04 +08:00
|
|
|
|
|
|
|
// If we know for sure everyone is banned, mark the room as obliterated
|
2018-07-06 23:54:28 +08:00
|
|
|
if (current.allow.length === 0) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => getText() + " " +
|
|
|
|
_t("🎉 All servers are banned from participating! This room can no longer be used.");
|
2018-07-06 23:36:44 +08:00
|
|
|
}
|
|
|
|
|
2021-06-07 11:06:56 +08:00
|
|
|
return getText;
|
2016-09-16 00:01:02 +08:00
|
|
|
}
|
2015-10-30 10:07:04 +08:00
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForMessageEvent(ev: MatrixEvent): () => string | null {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => {
|
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
let message = senderDisplayName + ': ' + ev.getContent().body;
|
|
|
|
if (ev.getContent().msgtype === "m.emote") {
|
|
|
|
message = "* " + senderDisplayName + " " + message;
|
|
|
|
} else if (ev.getContent().msgtype === "m.image") {
|
2021-06-29 20:11:58 +08:00
|
|
|
message = _t('%(senderDisplayName)s sent an image.', { senderDisplayName });
|
2021-06-07 11:06:56 +08:00
|
|
|
}
|
|
|
|
return message;
|
|
|
|
};
|
2016-09-16 00:01:02 +08:00
|
|
|
}
|
2015-09-16 21:48:49 +08:00
|
|
|
|
2021-07-15 19:18:17 +08:00
|
|
|
function textForCanonicalAliasEvent(ev: MatrixEvent): () => string | null {
|
2018-09-20 08:07:01 +08:00
|
|
|
const senderName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
const oldAlias = ev.getPrevContent().alias;
|
2020-03-10 01:24:48 +08:00
|
|
|
const oldAltAliases = ev.getPrevContent().alt_aliases || [];
|
2018-09-20 08:07:01 +08:00
|
|
|
const newAlias = ev.getContent().alias;
|
2020-03-10 01:24:48 +08: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 08:07:01 +08:00
|
|
|
|
2020-03-10 01:24:48 +08:00
|
|
|
if (!removedAltAliases.length && !addedAltAliases.length) {
|
|
|
|
if (newAlias) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s set the main address for this room to %(address)s.', {
|
2020-03-10 01:24:48 +08:00
|
|
|
senderName: senderName,
|
|
|
|
address: ev.getContent().alias,
|
|
|
|
});
|
|
|
|
} else if (oldAlias) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s removed the main address for this room.', {
|
2020-03-10 01:24:48 +08:00
|
|
|
senderName: senderName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (newAlias === oldAlias) {
|
|
|
|
if (addedAltAliases.length && !removedAltAliases.length) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s added the alternative addresses %(addresses)s for this room.', {
|
2020-03-10 01:24:48 +08:00
|
|
|
senderName: senderName,
|
|
|
|
addresses: addedAltAliases.join(", "),
|
|
|
|
count: addedAltAliases.length,
|
|
|
|
});
|
|
|
|
} if (removedAltAliases.length && !addedAltAliases.length) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s removed the alternative addresses %(addresses)s for this room.', {
|
2020-03-10 01:24:48 +08:00
|
|
|
senderName: senderName,
|
|
|
|
addresses: removedAltAliases.join(", "),
|
|
|
|
count: removedAltAliases.length,
|
|
|
|
});
|
|
|
|
} if (removedAltAliases.length && addedAltAliases.length) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s changed the alternative addresses for this room.', {
|
2020-03-10 01:24:48 +08:00
|
|
|
senderName: senderName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-11 01:45:51 +08:00
|
|
|
// both alias and alt_aliases where modified
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s changed the main and alternative addresses for this room.', {
|
2018-09-20 08:07:01 +08:00
|
|
|
senderName: senderName,
|
|
|
|
});
|
|
|
|
}
|
2020-03-11 01:45:51 +08: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 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s changed the addresses for this room.', {
|
2020-03-11 01:45:51 +08:00
|
|
|
senderName: senderName,
|
|
|
|
});
|
2018-09-20 08:07:01 +08:00
|
|
|
}
|
|
|
|
|
2021-06-16 06:52:40 +08:00
|
|
|
function textForThreePidInviteEvent(event: MatrixEvent): () => string | null {
|
2017-09-25 16:48:00 +08:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2019-03-29 10:38:15 +08:00
|
|
|
|
2019-03-30 01:45:07 +08:00
|
|
|
if (!isValid3pidInvite(event)) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s revoked the invitation for %(targetDisplayName)s to join the room.', {
|
2019-03-29 10:38:15 +08:00
|
|
|
senderName,
|
2021-06-07 11:06:56 +08:00
|
|
|
targetDisplayName: event.getPrevContent().display_name || _t("Someone"),
|
2019-03-29 10:38:15 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s sent an invitation to %(targetDisplayName)s to join the room.', {
|
2018-07-03 17:30:08 +08:00
|
|
|
senderName,
|
2017-09-25 16:48:00 +08:00
|
|
|
targetDisplayName: event.getContent().display_name,
|
|
|
|
});
|
2016-09-16 00:01:02 +08:00
|
|
|
}
|
2015-12-17 23:48:14 +08:00
|
|
|
|
2021-06-16 06:52:40 +08:00
|
|
|
function textForHistoryVisibilityEvent(event: MatrixEvent): () => string | null {
|
2017-09-17 20:28:17 +08:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
|
|
|
switch (event.getContent().history_visibility) {
|
|
|
|
case 'invited':
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s made future room history visible to all room members, '
|
2021-06-29 20:11:58 +08:00
|
|
|
+ 'from the point they are invited.', { senderName });
|
2017-09-17 20:28:17 +08:00
|
|
|
case 'joined':
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s made future room history visible to all room members, '
|
2021-06-29 20:11:58 +08:00
|
|
|
+ 'from the point they joined.', { senderName });
|
2017-09-17 20:28:17 +08:00
|
|
|
case 'shared':
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t('%(senderName)s made future room history visible to all room members.', { senderName });
|
2017-09-17 20:28:17 +08:00
|
|
|
case 'world_readable':
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t('%(senderName)s made future room history visible to anyone.', { senderName });
|
2017-09-17 20:28:17 +08:00
|
|
|
default:
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(senderName)s made future room history visible to unknown (%(visibility)s).', {
|
2018-07-03 17:30:08 +08:00
|
|
|
senderName,
|
2017-09-17 20:28:17 +08:00
|
|
|
visibility: event.getContent().history_visibility,
|
|
|
|
});
|
2016-03-16 07:47:40 +08:00
|
|
|
}
|
2016-09-16 00:01:02 +08:00
|
|
|
}
|
|
|
|
|
2017-04-07 00:02:35 +08:00
|
|
|
// Currently will only display a change if a user's power level is changed
|
2021-06-16 06:52:40 +08:00
|
|
|
function textForPowerEvent(event: MatrixEvent): () => string | null {
|
2017-04-07 00:02:35 +08:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2019-07-13 00:50:13 +08:00
|
|
|
if (!event.getPrevContent() || !event.getPrevContent().users ||
|
|
|
|
!event.getContent() || !event.getContent().users) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return null;
|
2017-04-07 00:02:35 +08:00
|
|
|
}
|
2021-06-23 11:35:47 +08:00
|
|
|
const previousUserDefault = event.getPrevContent().users_default || 0;
|
|
|
|
const currentUserDefault = event.getContent().users_default || 0;
|
2017-04-07 00:02:35 +08:00
|
|
|
// Construct set of userIds
|
2017-09-25 16:48:00 +08:00
|
|
|
const users = [];
|
2017-04-07 00:02:35 +08:00
|
|
|
Object.keys(event.getContent().users).forEach(
|
|
|
|
(userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
2017-09-25 16:48:00 +08:00
|
|
|
},
|
2017-04-07 00:02:35 +08:00
|
|
|
);
|
|
|
|
Object.keys(event.getPrevContent().users).forEach(
|
|
|
|
(userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
2017-09-25 16:48:00 +08:00
|
|
|
},
|
2017-04-07 00:02:35 +08:00
|
|
|
);
|
2021-06-07 11:06:56 +08:00
|
|
|
const diffs = [];
|
2017-04-07 00:02:35 +08:00
|
|
|
users.forEach((userId) => {
|
|
|
|
// Previous power level
|
2021-06-23 11:48:01 +08:00
|
|
|
let from = event.getPrevContent().users[userId];
|
2021-06-23 11:35:47 +08:00
|
|
|
if (!Number.isInteger(from)) {
|
|
|
|
from = previousUserDefault;
|
|
|
|
}
|
2017-04-07 00:02:35 +08:00
|
|
|
// Current power level
|
2021-06-23 11:48:01 +08:00
|
|
|
let to = event.getContent().users[userId];
|
2021-06-23 11:35:47 +08:00
|
|
|
if (!Number.isInteger(to)) {
|
|
|
|
to = currentUserDefault;
|
|
|
|
}
|
|
|
|
if (from === previousUserDefault && to === currentUserDefault) { return; }
|
2017-04-07 00:02:35 +08:00
|
|
|
if (to !== from) {
|
2021-06-07 11:06:56 +08:00
|
|
|
diffs.push({ userId, from, to });
|
2017-04-07 00:02:35 +08:00
|
|
|
}
|
|
|
|
});
|
2021-06-07 11:06:56 +08:00
|
|
|
if (!diffs.length) {
|
|
|
|
return null;
|
2017-04-07 00:02:35 +08:00
|
|
|
}
|
2021-06-07 11:06:56 +08:00
|
|
|
// XXX: This is also surely broken for i18n
|
|
|
|
return () => _t('%(senderName)s changed the power level of %(powerLevelDiffText)s.', {
|
2018-07-03 17:30:08 +08:00
|
|
|
senderName,
|
2021-06-07 11:06:56 +08:00
|
|
|
powerLevelDiffText: diffs.map(diff =>
|
|
|
|
_t('%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s', {
|
|
|
|
userId: diff.userId,
|
2021-06-23 11:35:47 +08:00
|
|
|
fromPowerLevel: Roles.textualPowerLevel(diff.from, previousUserDefault),
|
|
|
|
toPowerLevel: Roles.textualPowerLevel(diff.to, currentUserDefault),
|
2021-06-07 11:06:56 +08:00
|
|
|
}),
|
|
|
|
).join(", "),
|
2017-05-27 22:52:24 +08:00
|
|
|
});
|
2017-04-07 00:02:35 +08:00
|
|
|
}
|
|
|
|
|
2021-06-24 22:58:56 +08:00
|
|
|
const onPinnedMessagesClick = (): void => {
|
|
|
|
defaultDispatcher.dispatch<SetRightPanelPhasePayload>({
|
|
|
|
action: Action.SetRightPanelPhase,
|
|
|
|
phase: RightPanelPhases.PinnedMessages,
|
|
|
|
allowClose: false,
|
|
|
|
});
|
2021-06-29 20:11:58 +08:00
|
|
|
};
|
2021-06-24 22:58:56 +08:00
|
|
|
|
2021-06-24 20:02:06 +08:00
|
|
|
function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string | JSX.Element | null {
|
2021-06-24 16:40:30 +08:00
|
|
|
if (!SettingsStore.getValue("feature_pinning")) return null;
|
2020-01-06 13:04:42 +08:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2021-06-24 16:40:30 +08:00
|
|
|
|
2021-06-24 20:02:06 +08:00
|
|
|
if (allowJSX) {
|
|
|
|
return () => (
|
|
|
|
<span>
|
|
|
|
{
|
|
|
|
_t(
|
|
|
|
"%(senderName)s changed the <a>pinned messages</a> for the room.",
|
|
|
|
{ senderName },
|
|
|
|
{ "a": (sub) => <a onClick={onPinnedMessagesClick}> { sub } </a> },
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
2021-06-24 23:27:53 +08:00
|
|
|
|
2021-06-24 23:23:42 +08:00
|
|
|
return () => _t("%(senderName)s changed the pinned messages for the room.", { senderName });
|
2017-09-29 01:03:13 +08:00
|
|
|
}
|
|
|
|
|
2021-06-16 06:52:40 +08:00
|
|
|
function textForWidgetEvent(event: MatrixEvent): () => string | null {
|
2017-08-28 15:19:39 +08:00
|
|
|
const senderName = event.getSender();
|
2021-06-29 20:11:58 +08:00
|
|
|
const { name: prevName, type: prevType, url: prevUrl } = event.getPrevContent();
|
|
|
|
const { name, type, url } = event.getContent() || {};
|
2017-08-28 15:19:39 +08:00
|
|
|
|
|
|
|
let widgetName = name || prevName || type || prevType || '';
|
2017-08-19 01:02:50 +08:00
|
|
|
// Apply sentence case to widget name
|
|
|
|
if (widgetName && widgetName.length > 0) {
|
2020-11-24 19:27:02 +08:00
|
|
|
widgetName = widgetName[0].toUpperCase() + widgetName.slice(1);
|
2017-08-19 01:02:50 +08:00
|
|
|
}
|
2017-08-17 00:46:20 +08:00
|
|
|
|
2017-08-18 19:04:34 +08:00
|
|
|
// If the widget was removed, its content should be {}, but this is sufficiently
|
|
|
|
// equivalent to that condition.
|
2017-08-18 17:45:43 +08:00
|
|
|
if (url) {
|
2017-08-28 15:19:39 +08:00
|
|
|
if (prevUrl) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(widgetName)s widget modified by %(senderName)s', {
|
2017-08-28 15:19:39 +08:00
|
|
|
widgetName, senderName,
|
|
|
|
});
|
|
|
|
} else {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(widgetName)s widget added by %(senderName)s', {
|
2017-08-28 15:19:39 +08:00
|
|
|
widgetName, senderName,
|
|
|
|
});
|
|
|
|
}
|
2017-08-17 00:46:20 +08:00
|
|
|
} else {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t('%(widgetName)s widget removed by %(senderName)s', {
|
2017-08-19 01:02:50 +08:00
|
|
|
widgetName, senderName,
|
2017-08-17 00:46:20 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-16 06:52:40 +08:00
|
|
|
function textForWidgetLayoutEvent(event: MatrixEvent): () => string | null {
|
2021-01-19 10:31:11 +08:00
|
|
|
const senderName = event.sender?.name || event.getSender();
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t("%(senderName)s has updated the widget layout", { senderName });
|
2021-01-19 10:31:11 +08:00
|
|
|
}
|
|
|
|
|
2021-06-16 06:52:40 +08:00
|
|
|
function textForMjolnirEvent(event: MatrixEvent): () => string | null {
|
2019-12-10 11:36:00 +08:00
|
|
|
const senderName = event.getSender();
|
2021-06-29 20:11:58 +08:00
|
|
|
const { entity: prevEntity } = event.getPrevContent();
|
|
|
|
const { entity, recommendation, reason } = event.getContent();
|
2019-12-10 11:36:00 +08:00
|
|
|
|
|
|
|
// Rule removed
|
|
|
|
if (!entity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s removed the rule banning users matching %(glob)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: prevEntity });
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s removed the rule banning rooms matching %(glob)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: prevEntity });
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s removed the rule banning servers matching %(glob)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: prevEntity });
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something, but we shouldn't end up here.
|
2021-06-29 20:11:58 +08:00
|
|
|
return () => _t("%(senderName)s removed a ban rule matching %(glob)s", { senderName, glob: prevEntity });
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid rule
|
2021-06-29 20:11:58 +08:00
|
|
|
if (!recommendation || !reason) return () => _t(`%(senderName)s updated an invalid ban rule`, { senderName });
|
2019-12-10 11:36:00 +08:00
|
|
|
|
|
|
|
// Rule updated
|
|
|
|
if (entity === prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s updated the rule banning users matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s updated the rule banning rooms matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s updated the rule banning servers matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s updated a ban rule matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// New rule
|
|
|
|
if (!prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s created a rule banning users matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s created a rule banning rooms matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s created a rule banning servers matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s created a ban rule matching %(glob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, glob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// else the entity !== prevEntity - count as a removal & add
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t(
|
2021-04-30 01:57:02 +08:00
|
|
|
"%(senderName)s changed a rule that was banning users matching %(oldGlob)s to matching " +
|
2019-12-10 11:36:00 +08:00
|
|
|
"%(newGlob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, oldGlob: prevEntity, newGlob: entity, reason },
|
2021-04-30 01:57:02 +08:00
|
|
|
);
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t(
|
2021-04-30 01:57:02 +08:00
|
|
|
"%(senderName)s changed a rule that was banning rooms matching %(oldGlob)s to matching " +
|
2019-12-10 11:36:00 +08:00
|
|
|
"%(newGlob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, oldGlob: prevEntity, newGlob: entity, reason },
|
2021-04-30 01:57:02 +08:00
|
|
|
);
|
2019-12-10 11:36:00 +08:00
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t(
|
2021-04-30 01:57:02 +08:00
|
|
|
"%(senderName)s changed a rule that was banning servers matching %(oldGlob)s to matching " +
|
2019-12-10 11:36:00 +08:00
|
|
|
"%(newGlob)s for %(reason)s",
|
2021-06-29 20:11:58 +08:00
|
|
|
{ senderName, oldGlob: prevEntity, newGlob: entity, reason },
|
2021-04-30 01:57:02 +08:00
|
|
|
);
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
2021-06-07 11:06:56 +08:00
|
|
|
return () => _t("%(senderName)s updated a ban rule that was matching %(oldGlob)s to matching %(newGlob)s " +
|
2021-06-29 20:11:58 +08:00
|
|
|
"for %(reason)s", { senderName, oldGlob: prevEntity, newGlob: entity, reason });
|
2019-12-10 11:36:00 +08:00
|
|
|
}
|
|
|
|
|
2021-06-09 09:58:48 +08:00
|
|
|
interface IHandlers {
|
2021-06-30 10:13:18 +08:00
|
|
|
[type: string]:
|
|
|
|
(ev: MatrixEvent, allowJSX: boolean, showHiddenEvents?: boolean) =>
|
|
|
|
(() => string | JSX.Element | null);
|
2021-06-09 09:58:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const handlers: IHandlers = {
|
2015-09-16 21:48:49 +08:00
|
|
|
'm.room.message': textForMessageEvent,
|
2021-08-02 20:34:18 +08:00
|
|
|
'm.call.invite': textForCallInviteEvent,
|
2017-10-06 19:07:38 +08:00
|
|
|
};
|
|
|
|
|
2021-06-09 09:58:48 +08:00
|
|
|
const stateHandlers: IHandlers = {
|
2018-09-20 08:07:01 +08:00
|
|
|
'm.room.canonical_alias': textForCanonicalAliasEvent,
|
2017-10-06 19:07:38 +08:00
|
|
|
'm.room.name': textForRoomNameEvent,
|
|
|
|
'm.room.topic': textForTopicEvent,
|
|
|
|
'm.room.member': textForMemberEvent,
|
2016-03-16 07:47:40 +08:00
|
|
|
'm.room.third_party_invite': textForThreePidInviteEvent,
|
|
|
|
'm.room.history_visibility': textForHistoryVisibilityEvent,
|
2017-04-07 00:02:35 +08:00
|
|
|
'm.room.power_levels': textForPowerEvent,
|
2017-09-29 01:03:13 +08:00
|
|
|
'm.room.pinned_events': textForPinnedEvent,
|
2018-07-06 17:18:31 +08:00
|
|
|
'm.room.server_acl': textForServerACLEvent,
|
2019-01-11 06:15:45 +08:00
|
|
|
'm.room.tombstone': textForTombstoneEvent,
|
2019-02-08 03:14:58 +08:00
|
|
|
'm.room.join_rules': textForJoinRulesEvent,
|
|
|
|
'm.room.guest_access': textForGuestAccessEvent,
|
2019-02-22 08:03:15 +08:00
|
|
|
'm.room.related_groups': textForRelatedGroupsEvent,
|
2017-08-17 00:46:20 +08:00
|
|
|
|
2020-08-03 23:02:26 +08:00
|
|
|
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
|
2017-08-17 00:46:20 +08:00
|
|
|
'im.vector.modular.widgets': textForWidgetEvent,
|
2021-01-19 10:31:11 +08:00
|
|
|
[WIDGET_LAYOUT_EVENT_TYPE]: textForWidgetLayoutEvent,
|
2015-09-16 21:48:49 +08:00
|
|
|
};
|
|
|
|
|
2019-12-10 11:36:00 +08:00
|
|
|
// Add all the Mjolnir stuff to the renderer
|
|
|
|
for (const evType of ALL_RULE_TYPES) {
|
|
|
|
stateHandlers[evType] = textForMjolnirEvent;
|
|
|
|
}
|
|
|
|
|
2021-06-16 06:59:42 +08: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 11:06:56 +08:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2021-06-30 10:13:18 +08:00
|
|
|
return Boolean(handler?.(ev, false, showHiddenEvents));
|
2021-06-07 11:06:56 +08:00
|
|
|
}
|
|
|
|
|
2021-06-16 06:59:42 +08:00
|
|
|
/**
|
|
|
|
* Gets the textual content of the given event.
|
|
|
|
* @param ev The event
|
2021-06-30 10:13:18 +08:00
|
|
|
* @param allowJSX Whether to output rich JSX content
|
2021-06-16 06:59:42 +08:00
|
|
|
* @param showHiddenEvents An optional cached setting value for showHiddenEventsInTimeline
|
|
|
|
* to avoid hitting the settings store
|
|
|
|
*/
|
2021-06-24 20:31:04 +08:00
|
|
|
export function textForEvent(ev: MatrixEvent): string;
|
2021-06-30 10:42:46 +08:00
|
|
|
export function textForEvent(ev: MatrixEvent, allowJSX: true, showHiddenEvents?: boolean): string | JSX.Element;
|
|
|
|
export function textForEvent(ev: MatrixEvent, allowJSX = false, showHiddenEvents?: boolean): string | JSX.Element {
|
2019-12-20 08:45:24 +08:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2021-07-14 11:26:09 +08:00
|
|
|
return handler?.(ev, allowJSX, showHiddenEvents)?.() || '';
|
2019-12-20 08:45:24 +08:00
|
|
|
}
|