2016-03-05 02:30:18 +00: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.
|
|
|
|
*/
|
2019-12-20 21:13:46 +00:00
|
|
|
import {MatrixClientPeg} from './MatrixClientPeg';
|
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';
|
2019-03-29 17:45:07 +00:00
|
|
|
import {isValid3pidInvite} from "./RoomInvite";
|
2019-06-26 19:22:01 +00:00
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
2019-12-10 03:36:00 +00:00
|
|
|
import {ALL_RULE_TYPES, ROOM_RULE_TYPES, SERVER_RULE_TYPES, USER_RULE_TYPES} from "./mjolnir/BanList";
|
2017-04-06 16:02:35 +00:00
|
|
|
|
2015-09-16 13:48:49 +00:00
|
|
|
function textForMemberEvent(ev) {
|
2015-10-30 02:07:04 +00:00
|
|
|
// XXX: SYJS-16 "sender is sometimes null for join messages"
|
2017-09-25 08:48:00 +00: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();
|
|
|
|
|
|
|
|
const reason = content.reason ? (_t('Reason') + ': ' + content.reason) : '';
|
|
|
|
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) {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(targetName)s accepted the invitation for %(displayName)s.', {
|
|
|
|
targetName,
|
2017-09-25 08:48:00 +00:00
|
|
|
displayName: threePidContent.display_name,
|
|
|
|
});
|
2016-03-02 16:04:24 +00:00
|
|
|
} else {
|
2018-07-03 09:30:08 +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 {
|
2020-09-24 15:16:20 +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':
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s banned %(targetName)s.', {senderName, targetName}) + ' ' + reason;
|
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) {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(oldDisplayName)s changed their display name to %(displayName)s.', {
|
|
|
|
oldDisplayName: prevContent.displayname,
|
|
|
|
displayName: content.displayname,
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
|
|
|
} else if (!prevContent.displayname && content.displayname) {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s set their display name to %(displayName)s.', {
|
|
|
|
senderName: ev.getSender(),
|
|
|
|
displayName: content.displayname,
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
|
|
|
} else if (prevContent.displayname && !content.displayname) {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s removed their display name (%(oldDisplayName)s).', {
|
|
|
|
senderName,
|
|
|
|
oldDisplayName: 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) {
|
2018-07-03 09:30:08 +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) {
|
2018-07-03 09:30:08 +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) {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s set a profile picture.', {senderName});
|
2019-06-26 19:22:01 +00:00
|
|
|
} else if (SettingsStore.getValue("showHiddenEventsInTimeline")) {
|
2019-06-23 20:41:28 +00:00
|
|
|
// This is a null rejoin, it will only be visible if the Labs option is enabled
|
|
|
|
return _t("%(senderName)s made no change.", {senderName});
|
2019-06-26 19:22:01 +00:00
|
|
|
} else {
|
|
|
|
return "";
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ev.target) console.warn("Join message has no target! -- " + ev.getContent().state_key);
|
2020-09-24 15:16:20 +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") {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(targetName)s rejected the invitation.', {targetName});
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _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") {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s unbanned %(targetName)s.', {senderName, targetName});
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.membership === "invite") {
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s withdrew %(targetName)s\'s invitation.', {
|
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
}) + ' ' + reason;
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2019-07-10 07:57:00 +00:00
|
|
|
// sender is not target and made the target leave, if not from invite/ban then this is a kick
|
|
|
|
return _t('%(senderName)s kicked %(targetName)s.', {senderName, targetName}) + ' ' + reason;
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
|
|
|
function textForTopicEvent(ev) {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderDisplayName)s changed the topic to "%(topic)s".', {
|
|
|
|
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
|
|
|
|
2015-10-30 02:07:04 +00:00
|
|
|
function textForRoomNameEvent(ev) {
|
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) {
|
2018-07-03 09:30:08 +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) {
|
|
|
|
return _t('%(senderDisplayName)s changed the room name from %(oldRoomName)s to %(newRoomName)s.', {
|
|
|
|
senderDisplayName,
|
|
|
|
oldRoomName: ev.getPrevContent().name,
|
|
|
|
newRoomName: ev.getContent().name,
|
|
|
|
});
|
|
|
|
}
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderDisplayName)s changed the room name to %(roomName)s.', {
|
|
|
|
senderDisplayName,
|
2017-09-25 08:48:00 +00:00
|
|
|
roomName: ev.getContent().name,
|
|
|
|
});
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-10-30 02:07:04 +00:00
|
|
|
|
2019-01-10 22:15:45 +00:00
|
|
|
function textForTombstoneEvent(ev) {
|
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
return _t('%(senderDisplayName)s upgraded this room.', {senderDisplayName});
|
|
|
|
}
|
|
|
|
|
2019-02-07 19:14:58 +00:00
|
|
|
function textForJoinRulesEvent(ev) {
|
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().join_rule) {
|
|
|
|
case "public":
|
|
|
|
return _t('%(senderDisplayName)s made the room public to whoever knows the link.', {senderDisplayName});
|
|
|
|
case "invite":
|
|
|
|
return _t('%(senderDisplayName)s made the room invite only.', {senderDisplayName});
|
|
|
|
default:
|
|
|
|
// The spec supports "knock" and "private", however nothing implements these.
|
2019-02-08 16:15:12 +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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function textForGuestAccessEvent(ev) {
|
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
switch (ev.getContent().guest_access) {
|
|
|
|
case "can_join":
|
|
|
|
return _t('%(senderDisplayName)s has allowed guests to join the room.', {senderDisplayName});
|
|
|
|
case "forbidden":
|
|
|
|
return _t('%(senderDisplayName)s has prevented guests from joining the room.', {senderDisplayName});
|
|
|
|
default:
|
|
|
|
// There's no other options we can expect, however just for safety's sake we'll do this.
|
|
|
|
return _t('%(senderDisplayName)s changed guest access to %(rule)s', {
|
|
|
|
senderDisplayName,
|
|
|
|
rule: ev.getContent().guest_access,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 00:03:15 +00:00
|
|
|
function textForRelatedGroupsEvent(ev) {
|
|
|
|
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) {
|
|
|
|
return _t('%(senderDisplayName)s enabled flair for %(groups)s in this room.', {
|
|
|
|
senderDisplayName,
|
|
|
|
groups: added.join(', '),
|
|
|
|
});
|
|
|
|
} else if (!added.length && removed.length) {
|
|
|
|
return _t('%(senderDisplayName)s disabled flair for %(groups)s in this room.', {
|
|
|
|
senderDisplayName,
|
|
|
|
groups: removed.join(', '),
|
|
|
|
});
|
|
|
|
} else if (added.length && removed.length) {
|
|
|
|
return _t('%(senderDisplayName)s enabled flair for %(newGroups)s and disabled flair for ' +
|
|
|
|
'%(oldGroups)s in this room.', {
|
|
|
|
senderDisplayName,
|
|
|
|
newGroups: added.join(', '),
|
|
|
|
oldGroups: removed.join(', '),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Don't bother rendering this change (because there were no changes)
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 09:18:31 +00:00
|
|
|
function textForServerACLEvent(ev) {
|
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 : [],
|
|
|
|
allow_ip_literals: !(prevContent.allow_ip_literals === false),
|
|
|
|
};
|
2020-10-13 21:08:04 +00:00
|
|
|
|
2018-07-06 09:18:31 +00:00
|
|
|
let text = "";
|
2018-07-06 14:31:21 +00:00
|
|
|
if (prev.deny.length === 0 && prev.allow.length === 0) {
|
2020-10-13 21:11:48 +00:00
|
|
|
text = _t("%(senderDisplayName)s set the server ACLs for this room.", {senderDisplayName});
|
2018-07-06 09:18:31 +00:00
|
|
|
} else {
|
2020-10-13 21:11:48 +00:00
|
|
|
text = _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) {
|
2020-10-13 21:11:48 +00:00
|
|
|
return text + " " + _t("🎉 All servers are banned from participating! This room can no longer be used.");
|
2018-07-06 15:36:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 21:11:48 +00:00
|
|
|
return text;
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-10-30 02:07:04 +00:00
|
|
|
|
2020-06-25 22:26:07 +00:00
|
|
|
function textForMessageEvent(ev) {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
let message = senderDisplayName + ': ' + ev.getContent().body;
|
2020-06-25 22:26:07 +00:00
|
|
|
if (ev.getContent().msgtype === "m.emote") {
|
|
|
|
message = "* " + senderDisplayName + " " + message;
|
|
|
|
} else if (ev.getContent().msgtype === "m.image") {
|
|
|
|
message = _t('%(senderDisplayName)s sent an image.', {senderDisplayName});
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
return message;
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
2018-09-20 00:07:01 +00:00
|
|
|
function textForCanonicalAliasEvent(ev) {
|
|
|
|
const senderName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
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) {
|
|
|
|
return _t('%(senderName)s set the main address for this room to %(address)s.', {
|
|
|
|
senderName: senderName,
|
|
|
|
address: ev.getContent().alias,
|
|
|
|
});
|
|
|
|
} else if (oldAlias) {
|
|
|
|
return _t('%(senderName)s removed the main address for this room.', {
|
|
|
|
senderName: senderName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (newAlias === oldAlias) {
|
|
|
|
if (addedAltAliases.length && !removedAltAliases.length) {
|
|
|
|
return _t('%(senderName)s added the alternative addresses %(addresses)s for this room.', {
|
|
|
|
senderName: senderName,
|
|
|
|
addresses: addedAltAliases.join(", "),
|
|
|
|
count: addedAltAliases.length,
|
|
|
|
});
|
|
|
|
} if (removedAltAliases.length && !addedAltAliases.length) {
|
|
|
|
return _t('%(senderName)s removed the alternative addresses %(addresses)s for this room.', {
|
|
|
|
senderName: senderName,
|
|
|
|
addresses: removedAltAliases.join(", "),
|
|
|
|
count: removedAltAliases.length,
|
|
|
|
});
|
|
|
|
} if (removedAltAliases.length && addedAltAliases.length) {
|
|
|
|
return _t('%(senderName)s changed the alternative addresses for this room.', {
|
|
|
|
senderName: senderName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-10 17:45:51 +00:00
|
|
|
// both alias and alt_aliases where modified
|
2020-03-09 17:24:48 +00:00
|
|
|
return _t('%(senderName)s changed the main and alternative addresses for this room.', {
|
2018-09-20 00:07:01 +00:00
|
|
|
senderName: senderName,
|
|
|
|
});
|
|
|
|
}
|
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
|
|
|
|
return _t('%(senderName)s changed the addresses for this room.', {
|
|
|
|
senderName: senderName,
|
|
|
|
});
|
2018-09-20 00:07:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 13:48:49 +00:00
|
|
|
function textForCallAnswerEvent(event) {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
|
|
|
const supported = MatrixClientPeg.get().supportsVoip() ? '' : _t('(not supported by this browser)');
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s answered the call.', {senderName}) + ' ' + supported;
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
|
|
|
function textForCallHangupEvent(event) {
|
2017-06-10 13:26:27 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
|
|
|
const eventContent = event.getContent();
|
|
|
|
let reason = "";
|
2017-11-16 13:19:36 +00:00
|
|
|
if (!MatrixClientPeg.get().supportsVoip()) {
|
2017-06-11 06:19:19 +00:00
|
|
|
reason = _t('(not supported by this browser)');
|
2017-11-16 13:19:36 +00:00
|
|
|
} else if (eventContent.reason) {
|
2017-06-11 06:19:19 +00:00
|
|
|
if (eventContent.reason === "ice_failed") {
|
2020-10-15 13:54:03 +00:00
|
|
|
// We couldn't establish a connection at all
|
2017-06-11 06:19:19 +00:00
|
|
|
reason = _t('(could not connect media)');
|
2020-10-15 13:54:03 +00:00
|
|
|
} else if (eventContent.reason === "ice_timeout") {
|
|
|
|
// We established a connection but it died
|
|
|
|
reason = _t('(connection failed)');
|
|
|
|
} else if (eventContent.reason === "user_media_failed") {
|
|
|
|
// The other side couldn't open capture devices
|
|
|
|
reason = _t("(their device couldn't start the camera / microphone)");
|
|
|
|
} else if (eventContent.reason === "unknown_error") {
|
|
|
|
// An error code the other side doesn't have a way to express
|
|
|
|
// (as opposed to an error code they gave but we don't know about,
|
|
|
|
// in which case we show the error code)
|
|
|
|
reason = _t("(an error occurred)");
|
2017-06-11 06:19:19 +00:00
|
|
|
} else if (eventContent.reason === "invite_timeout") {
|
|
|
|
reason = _t('(no answer)');
|
2020-10-15 13:54:03 +00:00
|
|
|
} else if (eventContent.reason === "user hangup" || eventContent.reason === "user_hangup") {
|
2020-08-03 15:02:26 +00:00
|
|
|
// workaround for https://github.com/vector-im/element-web/issues/5178
|
2018-09-27 22:51:03 +00:00
|
|
|
// it seems Android randomly sets a reason of "user hangup" which is
|
|
|
|
// interpreted as an error code :(
|
|
|
|
// https://github.com/vector-im/riot-android/issues/2623
|
2020-10-15 13:54:03 +00:00
|
|
|
// Also the correct hangup code as of VoIP v1 (with underscore)
|
2018-09-27 22:51:03 +00:00
|
|
|
reason = '';
|
2017-06-11 06:19:19 +00:00
|
|
|
} else {
|
|
|
|
reason = _t('(unknown failure: %(reason)s)', {reason: eventContent.reason});
|
|
|
|
}
|
2017-06-10 13:26:27 +00:00
|
|
|
}
|
2017-06-10 13:35:11 +00:00
|
|
|
return _t('%(senderName)s ended the call.', {senderName}) + ' ' + reason;
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
2020-10-15 13:54:03 +00:00
|
|
|
function textForCallRejectEvent(event) {
|
|
|
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
|
|
|
return _t('%(senderName)s declined the call.', {senderName});
|
|
|
|
}
|
|
|
|
|
2015-09-16 13:48:49 +00:00
|
|
|
function textForCallInviteEvent(event) {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
2015-09-16 13:48:49 +00:00
|
|
|
// FIXME: Find a better way to determine this from the event?
|
2019-11-27 20:03:51 +00:00
|
|
|
let isVoice = true;
|
2015-09-16 13:48:49 +00:00
|
|
|
if (event.getContent().offer && event.getContent().offer.sdp &&
|
|
|
|
event.getContent().offer.sdp.indexOf('m=video') !== -1) {
|
2019-11-27 20:03:51 +00:00
|
|
|
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
|
2019-11-28 16:08:24 +00:00
|
|
|
// and more accurate, we break out the string-based variables to a couple booleans.
|
2019-11-27 20:03:51 +00:00
|
|
|
if (isVoice && isSupported) {
|
|
|
|
return _t("%(senderName)s placed a voice call.", {senderName});
|
|
|
|
} else if (isVoice && !isSupported) {
|
|
|
|
return _t("%(senderName)s placed a voice call. (not supported by this browser)", {senderName});
|
|
|
|
} else if (!isVoice && isSupported) {
|
|
|
|
return _t("%(senderName)s placed a video call.", {senderName});
|
|
|
|
} else if (!isVoice && !isSupported) {
|
|
|
|
return _t("%(senderName)s placed a video call. (not supported by this browser)", {senderName});
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
|
2015-12-17 15:48:14 +00:00
|
|
|
function textForThreePidInviteEvent(event) {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2019-03-29 02:38:15 +00:00
|
|
|
|
2019-03-29 17:45:07 +00:00
|
|
|
if (!isValid3pidInvite(event)) {
|
2019-03-29 02:38:15 +00:00
|
|
|
const targetDisplayName = event.getPrevContent().display_name || _t("Someone");
|
|
|
|
return _t('%(senderName)s revoked the invitation for %(targetDisplayName)s to join the room.', {
|
|
|
|
senderName,
|
|
|
|
targetDisplayName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s sent an invitation to %(targetDisplayName)s to join the room.', {
|
|
|
|
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
|
|
|
|
2016-03-15 23:47:40 +00:00
|
|
|
function textForHistoryVisibilityEvent(event) {
|
2017-09-17 12:28:17 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
|
|
|
switch (event.getContent().history_visibility) {
|
|
|
|
case 'invited':
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s made future room history visible to all room members, '
|
|
|
|
+ 'from the point they are invited.', {senderName});
|
2017-09-17 12:28:17 +00:00
|
|
|
case 'joined':
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s made future room history visible to all room members, '
|
|
|
|
+ 'from the point they joined.', {senderName});
|
2017-09-17 12:28:17 +00:00
|
|
|
case 'shared':
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s made future room history visible to all room members.', {senderName});
|
2017-09-17 12:28:17 +00:00
|
|
|
case 'world_readable':
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s made future room history visible to anyone.', {senderName});
|
2017-09-17 12:28:17 +00:00
|
|
|
default:
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t('%(senderName)s made future room history visible to unknown (%(visibility)s).', {
|
|
|
|
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
|
|
|
|
function textForPowerEvent(event) {
|
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2019-07-12 16:50:13 +00:00
|
|
|
if (!event.getPrevContent() || !event.getPrevContent().users ||
|
|
|
|
!event.getContent() || !event.getContent().users) {
|
2017-04-06 16:02:35 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
const userDefault = event.getContent().users_default || 0;
|
|
|
|
// Construct set of userIds
|
2017-09-25 08:48:00 +00:00
|
|
|
const users = [];
|
2017-04-06 16:02:35 +00:00
|
|
|
Object.keys(event.getContent().users).forEach(
|
|
|
|
(userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
2017-09-25 08:48:00 +00:00
|
|
|
},
|
2017-04-06 16:02:35 +00:00
|
|
|
);
|
|
|
|
Object.keys(event.getPrevContent().users).forEach(
|
|
|
|
(userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
2017-09-25 08:48:00 +00:00
|
|
|
},
|
2017-04-06 16:02:35 +00:00
|
|
|
);
|
2017-09-25 08:48:00 +00:00
|
|
|
const diff = [];
|
2017-05-25 18:21:18 +00:00
|
|
|
// XXX: This is also surely broken for i18n
|
2017-04-06 16:02:35 +00:00
|
|
|
users.forEach((userId) => {
|
|
|
|
// Previous power level
|
|
|
|
const from = event.getPrevContent().users[userId];
|
|
|
|
// Current power level
|
|
|
|
const to = event.getContent().users[userId];
|
|
|
|
if (to !== from) {
|
|
|
|
diff.push(
|
2018-07-03 09:30:08 +00:00
|
|
|
_t('%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s', {
|
|
|
|
userId,
|
2017-05-27 14:52:24 +00:00
|
|
|
fromPowerLevel: Roles.textualPowerLevel(from, userDefault),
|
2017-09-25 08:48:00 +00:00
|
|
|
toPowerLevel: Roles.textualPowerLevel(to, userDefault),
|
|
|
|
}),
|
2017-04-06 16:02:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!diff.length) {
|
|
|
|
return '';
|
|
|
|
}
|
2017-05-27 14:52:24 +00:00
|
|
|
return _t('%(senderName)s changed the power level of %(powerLevelDiffText)s.', {
|
2018-07-03 09:30:08 +00:00
|
|
|
senderName,
|
2017-08-28 07:19:39 +00:00
|
|
|
powerLevelDiffText: diff.join(", "),
|
2017-05-27 14:52:24 +00:00
|
|
|
});
|
2017-04-06 16:02:35 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 17:03:13 +00:00
|
|
|
function textForPinnedEvent(event) {
|
2020-01-06 05:04:42 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2018-07-03 09:30:08 +00:00
|
|
|
return _t("%(senderName)s changed the pinned messages for the room.", {senderName});
|
2017-09-28 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 16:46:20 +00:00
|
|
|
function textForWidgetEvent(event) {
|
2017-08-28 07:19:39 +00:00
|
|
|
const senderName = event.getSender();
|
|
|
|
const {name: prevName, type: prevType, url: prevUrl} = event.getPrevContent();
|
2017-08-18 11:03:29 +00:00
|
|
|
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) {
|
|
|
|
return _t('%(widgetName)s widget modified by %(senderName)s', {
|
|
|
|
widgetName, senderName,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return _t('%(widgetName)s widget added by %(senderName)s', {
|
|
|
|
widgetName, senderName,
|
|
|
|
});
|
|
|
|
}
|
2017-08-16 16:46:20 +00:00
|
|
|
} else {
|
2017-08-18 17:02:50 +00:00
|
|
|
return _t('%(widgetName)s widget removed by %(senderName)s', {
|
|
|
|
widgetName, senderName,
|
2017-08-16 16:46:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 03:36:00 +00:00
|
|
|
function textForMjolnirEvent(event) {
|
|
|
|
const senderName = event.getSender();
|
2019-12-10 03:38:56 +00:00
|
|
|
const {entity: prevEntity} = event.getPrevContent();
|
2019-12-10 03:36:00 +00:00
|
|
|
const {entity, recommendation, reason} = event.getContent();
|
|
|
|
|
|
|
|
// Rule removed
|
|
|
|
if (!entity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s removed the rule banning users matching %(glob)s",
|
|
|
|
{senderName, glob: prevEntity});
|
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s removed the rule banning rooms matching %(glob)s",
|
|
|
|
{senderName, glob: prevEntity});
|
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s removed the rule banning servers matching %(glob)s",
|
|
|
|
{senderName, glob: prevEntity});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something, but we shouldn't end up here.
|
|
|
|
return _t("%(senderName)s removed a ban rule matching %(glob)s", {senderName, glob: prevEntity});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid rule
|
|
|
|
if (!recommendation || !reason) return _t(`%(senderName)s updated an invalid ban rule`, {senderName});
|
|
|
|
|
|
|
|
// Rule updated
|
|
|
|
if (entity === prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s updated the rule banning users matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s updated the rule banning rooms matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s updated the rule banning servers matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
|
|
|
return _t("%(senderName)s updated a ban rule matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
}
|
|
|
|
|
|
|
|
// New rule
|
|
|
|
if (!prevEntity) {
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s created a rule banning users matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s created a rule banning rooms matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s created a rule banning servers matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
|
|
|
return _t("%(senderName)s created a ban rule matching %(glob)s for %(reason)s",
|
|
|
|
{senderName, glob: entity, reason});
|
|
|
|
}
|
|
|
|
|
|
|
|
// else the entity !== prevEntity - count as a removal & add
|
|
|
|
if (USER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s changed a rule that was banning users matching %(oldGlob)s to matching " +
|
|
|
|
"%(newGlob)s for %(reason)s",
|
|
|
|
{senderName, oldGlob: prevEntity, newGlob: entity, reason});
|
|
|
|
} else if (ROOM_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s changed a rule that was banning rooms matching %(oldGlob)s to matching " +
|
|
|
|
"%(newGlob)s for %(reason)s",
|
|
|
|
{senderName, oldGlob: prevEntity, newGlob: entity, reason});
|
|
|
|
} else if (SERVER_RULE_TYPES.includes(event.getType())) {
|
|
|
|
return _t("%(senderName)s changed a rule that was banning servers matching %(oldGlob)s to matching " +
|
|
|
|
"%(newGlob)s for %(reason)s",
|
|
|
|
{senderName, oldGlob: prevEntity, newGlob: entity, reason});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown type. We'll say something but we shouldn't end up here.
|
|
|
|
return _t("%(senderName)s updated a ban rule that was matching %(oldGlob)s to matching %(newGlob)s " +
|
|
|
|
"for %(reason)s", {senderName, oldGlob: prevEntity, newGlob: entity, reason});
|
|
|
|
}
|
|
|
|
|
2017-09-25 08:48:00 +00:00
|
|
|
const handlers = {
|
2015-09-16 13:48:49 +00:00
|
|
|
'm.room.message': textForMessageEvent,
|
2017-09-25 08:48:00 +00:00
|
|
|
'm.call.invite': textForCallInviteEvent,
|
|
|
|
'm.call.answer': textForCallAnswerEvent,
|
|
|
|
'm.call.hangup': textForCallHangupEvent,
|
2020-10-15 13:54:03 +00:00
|
|
|
'm.call.reject': textForCallRejectEvent,
|
2017-10-06 11:07:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const stateHandlers = {
|
2018-09-20 00:07:01 +00:00
|
|
|
'm.room.canonical_alias': textForCanonicalAliasEvent,
|
2017-10-06 11:07:38 +00:00
|
|
|
'm.room.name': textForRoomNameEvent,
|
|
|
|
'm.room.topic': textForTopicEvent,
|
|
|
|
'm.room.member': textForMemberEvent,
|
2016-03-15 23:47:40 +00:00
|
|
|
'm.room.third_party_invite': textForThreePidInviteEvent,
|
|
|
|
'm.room.history_visibility': textForHistoryVisibilityEvent,
|
2017-04-06 16:02:35 +00:00
|
|
|
'm.room.power_levels': textForPowerEvent,
|
2017-09-28 17:03:13 +00:00
|
|
|
'm.room.pinned_events': textForPinnedEvent,
|
2018-07-06 09:18:31 +00:00
|
|
|
'm.room.server_acl': textForServerACLEvent,
|
2019-01-10 22:15:45 +00:00
|
|
|
'm.room.tombstone': textForTombstoneEvent,
|
2019-02-07 19:14:58 +00:00
|
|
|
'm.room.join_rules': textForJoinRulesEvent,
|
|
|
|
'm.room.guest_access': textForGuestAccessEvent,
|
2019-02-22 00:03:15 +00:00
|
|
|
'm.room.related_groups': textForRelatedGroupsEvent,
|
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,
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-25 22:26:07 +00:00
|
|
|
export function textForEvent(ev) {
|
2019-12-20 00:45:24 +00:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2020-06-25 22:26:07 +00:00
|
|
|
if (handler) return handler(ev);
|
2019-12-20 00:45:24 +00:00
|
|
|
return '';
|
|
|
|
}
|