2016-03-05 03:30:18 +01: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.
|
|
|
|
*/
|
2017-09-25 10:48:00 +02:00
|
|
|
import MatrixClientPeg from './MatrixClientPeg';
|
|
|
|
import CallHandler from './CallHandler';
|
2017-05-25 12:39:08 +02:00
|
|
|
import { _t } from './languageHandler';
|
2017-04-10 11:09:26 +02:00
|
|
|
import * as Roles from './Roles';
|
2017-04-06 18:02:35 +02:00
|
|
|
|
2015-09-16 15:48:49 +02:00
|
|
|
function textForMemberEvent(ev) {
|
2015-10-30 03:07:04 +01:00
|
|
|
// XXX: SYJS-16 "sender is sometimes null for join messages"
|
2017-09-25 10:48:00 +02: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 ConferenceHandler = CallHandler.getConferenceHandler();
|
|
|
|
const reason = content.reason ? (_t('Reason') + ': ' + content.reason) : '';
|
|
|
|
switch (content.membership) {
|
|
|
|
case 'invite': {
|
|
|
|
const threePidContent = content.third_party_invite;
|
2015-12-17 16:48:14 +01:00
|
|
|
if (threePidContent) {
|
2016-03-02 17:04:24 +01:00
|
|
|
if (threePidContent.display_name) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(targetName)s accepted the invitation for %(displayName)s.', {
|
|
|
|
targetName,
|
2017-09-25 10:48:00 +02:00
|
|
|
displayName: threePidContent.display_name,
|
|
|
|
});
|
2016-03-02 17:04:24 +01:00
|
|
|
} else {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(targetName)s accepted an invitation.', {targetName});
|
2016-03-02 17:04:24 +01:00
|
|
|
}
|
2017-09-25 10:48:00 +02:00
|
|
|
} else {
|
2016-03-05 03:30:18 +01:00
|
|
|
if (ConferenceHandler && ConferenceHandler.isConferenceUser(ev.getStateKey())) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s requested a VoIP conference.', {senderName});
|
2017-09-25 10:48:00 +02:00
|
|
|
} else {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s invited %(targetName)s.', {senderName, targetName});
|
2016-03-05 03:30:18 +01:00
|
|
|
}
|
2015-12-17 16:48:14 +01:00
|
|
|
}
|
2017-09-25 10:48:00 +02:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
case 'ban':
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s banned %(targetName)s.', {senderName, targetName}) + ' ' + reason;
|
2015-09-16 15:48:49 +02:00
|
|
|
case 'join':
|
2017-09-25 10:48:00 +02:00
|
|
|
if (prevContent && prevContent.membership === 'join') {
|
|
|
|
if (prevContent.displayname && content.displayname && prevContent.displayname !== content.displayname) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(oldDisplayName)s changed their display name to %(displayName)s.', {
|
|
|
|
oldDisplayName: prevContent.displayname,
|
|
|
|
displayName: content.displayname,
|
2017-09-25 10:48:00 +02:00
|
|
|
});
|
|
|
|
} else if (!prevContent.displayname && content.displayname) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s set their display name to %(displayName)s.', {
|
|
|
|
senderName: ev.getSender(),
|
|
|
|
displayName: content.displayname,
|
2017-09-25 10:48:00 +02:00
|
|
|
});
|
|
|
|
} else if (prevContent.displayname && !content.displayname) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s removed their display name (%(oldDisplayName)s).', {
|
|
|
|
senderName,
|
|
|
|
oldDisplayName: prevContent.displayname,
|
2017-09-25 10:48:00 +02:00
|
|
|
});
|
2017-09-25 16:49:48 +02:00
|
|
|
} else if (prevContent.avatar_url && !content.avatar_url) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s removed their profile picture.', {senderName});
|
2017-09-25 10:48:00 +02:00
|
|
|
} else if (prevContent.avatar_url && content.avatar_url &&
|
|
|
|
prevContent.avatar_url !== content.avatar_url) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s changed their profile picture.', {senderName});
|
2017-09-25 10:48:00 +02:00
|
|
|
} else if (!prevContent.avatar_url && content.avatar_url) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s set a profile picture.', {senderName});
|
2016-09-02 17:54:27 +02:00
|
|
|
} else {
|
2017-05-06 02:45:28 +02:00
|
|
|
// suppress null rejoins
|
|
|
|
return '';
|
2015-09-16 15:48:49 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ev.target) console.warn("Join message has no target! -- " + ev.getContent().state_key);
|
2016-03-05 03:30:18 +01:00
|
|
|
if (ConferenceHandler && ConferenceHandler.isConferenceUser(ev.getStateKey())) {
|
2017-05-27 15:55:55 +02:00
|
|
|
return _t('VoIP conference started.');
|
2017-09-25 10:48:00 +02:00
|
|
|
} else {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(targetName)s joined the room.', {targetName});
|
2016-03-05 03:30:18 +01:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
}
|
|
|
|
case 'leave':
|
|
|
|
if (ev.getSender() === ev.getStateKey()) {
|
2016-03-05 03:30:18 +01:00
|
|
|
if (ConferenceHandler && ConferenceHandler.isConferenceUser(ev.getStateKey())) {
|
2017-05-27 15:55:55 +02:00
|
|
|
return _t('VoIP conference finished.');
|
2017-09-25 10:48:00 +02:00
|
|
|
} else if (prevContent.membership === "invite") {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(targetName)s rejected the invitation.', {targetName});
|
2017-09-25 10:48:00 +02:00
|
|
|
} else {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(targetName)s left the room.', {targetName});
|
2016-03-05 03:30:18 +01:00
|
|
|
}
|
2017-09-25 10:48:00 +02:00
|
|
|
} else if (prevContent.membership === "ban") {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s unbanned %(targetName)s.', {senderName, targetName});
|
2017-09-25 10:48:00 +02:00
|
|
|
} else if (prevContent.membership === "join") {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s kicked %(targetName)s.', {senderName, targetName}) + ' ' + reason;
|
2017-09-25 10:48:00 +02:00
|
|
|
} else if (prevContent.membership === "invite") {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s withdrew %(targetName)s\'s invitation.', {
|
|
|
|
senderName,
|
|
|
|
targetName,
|
|
|
|
}) + ' ' + reason;
|
2017-09-25 10:48:00 +02:00
|
|
|
} else {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(targetName)s left the room.', {targetName});
|
2015-09-16 15:48:49 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
|
|
|
|
function textForTopicEvent(ev) {
|
2017-09-25 10:48:00 +02:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderDisplayName)s changed the topic to "%(topic)s".', {
|
|
|
|
senderDisplayName,
|
2017-09-25 10:48:00 +02:00
|
|
|
topic: ev.getContent().topic,
|
|
|
|
});
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
|
2015-10-30 03:07:04 +01:00
|
|
|
function textForRoomNameEvent(ev) {
|
2017-09-25 10:48:00 +02:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2017-06-10 15:26:27 +02:00
|
|
|
|
2017-05-30 07:21:14 +02:00
|
|
|
if (!ev.getContent().name || ev.getContent().name.trim().length === 0) {
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderDisplayName)s removed the room name.', {senderDisplayName});
|
2017-05-30 07:21:14 +02:00
|
|
|
}
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderDisplayName)s changed the room name to %(roomName)s.', {
|
|
|
|
senderDisplayName,
|
2017-09-25 10:48:00 +02:00
|
|
|
roomName: ev.getContent().name,
|
|
|
|
});
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-10-30 03:07:04 +01:00
|
|
|
|
2019-01-10 23:15:45 +01: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 20:14:58 +01: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.
|
|
|
|
return _t('%(senderDisplayName)s changed the join rules to %(rule)s', {
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 11:18:31 +02:00
|
|
|
function textForServerACLEvent(ev) {
|
2018-07-06 17:36:26 +02:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2018-07-06 17:54:28 +02:00
|
|
|
const prevContent = ev.getPrevContent();
|
2018-07-06 17:36:26 +02:00
|
|
|
const changes = [];
|
2018-07-06 17:54:28 +02:00
|
|
|
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),
|
|
|
|
};
|
2018-07-06 11:18:31 +02:00
|
|
|
let text = "";
|
2018-07-06 16:31:21 +02:00
|
|
|
if (prev.deny.length === 0 && prev.allow.length === 0) {
|
|
|
|
text = `${senderDisplayName} set server ACLs for this room: `;
|
2018-07-06 11:18:31 +02:00
|
|
|
} else {
|
2018-07-06 16:31:21 +02:00
|
|
|
text = `${senderDisplayName} changed the server ACLs for this room: `;
|
2018-07-06 11:18:31 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 21:22:37 +02:00
|
|
|
if (!Array.isArray(current.allow)) {
|
|
|
|
current.allow = [];
|
|
|
|
}
|
2018-07-06 17:36:44 +02:00
|
|
|
/* If we know for sure everyone is banned, don't bother showing the diff view */
|
2018-07-06 17:54:28 +02:00
|
|
|
if (current.allow.length === 0) {
|
2018-07-06 17:36:44 +02:00
|
|
|
return text + "🎉 All servers are banned from participating! This room can no longer be used.";
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:54:28 +02:00
|
|
|
if (!Array.isArray(current.deny)) {
|
2018-07-06 17:38:04 +02:00
|
|
|
current.deny = [];
|
2018-07-06 11:18:31 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 16:31:21 +02:00
|
|
|
const bannedServers = current.deny.filter((srv) => typeof(srv) === 'string' && !prev.deny.includes(srv));
|
|
|
|
const unbannedServers = prev.deny.filter((srv) => typeof(srv) === 'string' && !current.deny.includes(srv));
|
|
|
|
const allowedServers = current.allow.filter((srv) => typeof(srv) === 'string' && !prev.allow.includes(srv));
|
|
|
|
const unallowedServers = prev.allow.filter((srv) => typeof(srv) === 'string' && !current.allow.includes(srv));
|
|
|
|
|
2018-07-06 11:18:31 +02:00
|
|
|
if (bannedServers.length > 0) {
|
2018-07-06 20:17:01 +02:00
|
|
|
changes.push(`Servers matching ${bannedServers.join(", ")} are now banned.`);
|
2017-05-30 07:21:14 +02:00
|
|
|
}
|
2018-07-06 11:18:31 +02:00
|
|
|
|
|
|
|
if (unbannedServers.length > 0) {
|
2018-07-06 20:17:01 +02:00
|
|
|
changes.push(`Servers matching ${unbannedServers.join(", ")} were removed from the ban list.`);
|
2018-07-06 11:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (allowedServers.length > 0) {
|
2018-07-06 20:17:01 +02:00
|
|
|
changes.push(`Servers matching ${allowedServers.join(", ")} are now allowed.`);
|
2018-07-06 11:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unallowedServers.length > 0) {
|
2018-07-06 20:17:01 +02:00
|
|
|
changes.push(`Servers matching ${unallowedServers.join(", ")} were removed from the allowed list.`);
|
2018-07-06 11:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prev.allow_ip_literals !== current.allow_ip_literals) {
|
|
|
|
const allowban = current.allow_ip_literals ? "allowed" : "banned";
|
2018-07-06 16:31:21 +02:00
|
|
|
changes.push(`Participating from a server using an IP literal hostname is now ${allowban}.`);
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:37:40 +02:00
|
|
|
return text + changes.join(" ");
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-10-30 03:07:04 +01:00
|
|
|
|
2015-09-16 15:48:49 +02:00
|
|
|
function textForMessageEvent(ev) {
|
2017-09-25 10:48:00 +02:00
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
let message = senderDisplayName + ': ' + ev.getContent().body;
|
2015-09-16 15:48:49 +02:00
|
|
|
if (ev.getContent().msgtype === "m.emote") {
|
|
|
|
message = "* " + senderDisplayName + " " + message;
|
|
|
|
} else if (ev.getContent().msgtype === "m.image") {
|
2018-07-03 11:30:08 +02:00
|
|
|
message = _t('%(senderDisplayName)s sent an image.', {senderDisplayName});
|
2015-09-16 15:48:49 +02:00
|
|
|
}
|
|
|
|
return message;
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
|
2017-09-14 14:43:46 +02:00
|
|
|
function textForRoomAliasesEvent(ev) {
|
2018-09-17 19:27:17 +02:00
|
|
|
// An alternative implementation of this as a first-class event can be found at
|
|
|
|
// https://github.com/matrix-org/matrix-react-sdk/blob/dc7212ec2bd12e1917233ed7153b3e0ef529a135/src/components/views/messages/RoomAliasesEvent.js
|
|
|
|
// This feels a bit overkill though, and it's not clear the i18n really needs it
|
|
|
|
// so instead it's landing as a simple textual event.
|
|
|
|
|
2018-09-17 19:20:12 +02:00
|
|
|
const senderName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2017-09-14 14:43:46 +02:00
|
|
|
const oldAliases = ev.getPrevContent().aliases || [];
|
|
|
|
const newAliases = ev.getContent().aliases || [];
|
|
|
|
|
|
|
|
const addedAliases = newAliases.filter((x) => !oldAliases.includes(x));
|
|
|
|
const removedAliases = oldAliases.filter((x) => !newAliases.includes(x));
|
|
|
|
|
|
|
|
if (!addedAliases.length && !removedAliases.length) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addedAliases.length && !removedAliases.length) {
|
2018-09-17 19:20:12 +02:00
|
|
|
return _t('%(senderName)s added %(count)s %(addedAddresses)s as addresses for this room.', {
|
2017-09-14 14:43:46 +02:00
|
|
|
senderName: senderName,
|
2017-09-14 18:39:18 +02:00
|
|
|
count: addedAliases.length,
|
2017-09-14 14:43:46 +02:00
|
|
|
addedAddresses: addedAliases.join(', '),
|
|
|
|
});
|
|
|
|
} else if (!addedAliases.length && removedAliases.length) {
|
2018-09-17 19:20:12 +02:00
|
|
|
return _t('%(senderName)s removed %(count)s %(removedAddresses)s as addresses for this room.', {
|
2017-09-14 14:43:46 +02:00
|
|
|
senderName: senderName,
|
2017-09-14 18:39:18 +02:00
|
|
|
count: removedAliases.length,
|
2017-09-14 14:43:46 +02:00
|
|
|
removedAddresses: removedAliases.join(', '),
|
|
|
|
});
|
|
|
|
} else {
|
2018-09-17 19:20:12 +02:00
|
|
|
return _t(
|
2018-09-27 19:55:57 +02:00
|
|
|
'%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.', {
|
|
|
|
senderName: senderName,
|
|
|
|
addedAddresses: addedAliases.join(', '),
|
|
|
|
removedAddresses: removedAliases.join(', '),
|
|
|
|
},
|
2018-09-17 19:20:12 +02:00
|
|
|
);
|
2017-09-14 14:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:07:01 +02:00
|
|
|
function textForCanonicalAliasEvent(ev) {
|
|
|
|
const senderName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
|
|
|
const oldAlias = ev.getPrevContent().alias;
|
|
|
|
const newAlias = ev.getContent().alias;
|
|
|
|
|
|
|
|
if (newAlias) {
|
2018-09-20 12:41:59 +02:00
|
|
|
return _t('%(senderName)s set the main address for this room to %(address)s.', {
|
2018-09-20 02:07:01 +02:00
|
|
|
senderName: senderName,
|
|
|
|
address: ev.getContent().alias,
|
|
|
|
});
|
2018-10-03 05:12:26 +02:00
|
|
|
} else if (oldAlias) {
|
2018-09-20 12:41:59 +02:00
|
|
|
return _t('%(senderName)s removed the main address for this room.', {
|
2018-09-20 02:07:01 +02:00
|
|
|
senderName: senderName,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 15:48:49 +02:00
|
|
|
function textForCallAnswerEvent(event) {
|
2017-09-25 10:48:00 +02:00
|
|
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
|
|
|
const supported = MatrixClientPeg.get().supportsVoip() ? '' : _t('(not supported by this browser)');
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s answered the call.', {senderName}) + ' ' + supported;
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
|
|
|
|
function textForCallHangupEvent(event) {
|
2017-06-10 15:26:27 +02:00
|
|
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
|
|
|
const eventContent = event.getContent();
|
|
|
|
let reason = "";
|
2017-11-16 14:19:36 +01:00
|
|
|
if (!MatrixClientPeg.get().supportsVoip()) {
|
2017-06-11 08:19:19 +02:00
|
|
|
reason = _t('(not supported by this browser)');
|
2017-11-16 14:19:36 +01:00
|
|
|
} else if (eventContent.reason) {
|
2017-06-11 08:19:19 +02:00
|
|
|
if (eventContent.reason === "ice_failed") {
|
|
|
|
reason = _t('(could not connect media)');
|
|
|
|
} else if (eventContent.reason === "invite_timeout") {
|
|
|
|
reason = _t('(no answer)');
|
2018-09-28 00:51:03 +02:00
|
|
|
} else if (eventContent.reason === "user hangup") {
|
|
|
|
// workaround for https://github.com/vector-im/riot-web/issues/5178
|
|
|
|
// 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
|
|
|
|
reason = '';
|
2017-06-11 08:19:19 +02:00
|
|
|
} else {
|
|
|
|
reason = _t('(unknown failure: %(reason)s)', {reason: eventContent.reason});
|
|
|
|
}
|
2017-06-10 15:26:27 +02:00
|
|
|
}
|
2017-06-10 15:35:11 +02:00
|
|
|
return _t('%(senderName)s ended the call.', {senderName}) + ' ' + reason;
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
|
|
|
|
function textForCallInviteEvent(event) {
|
2017-09-25 10:48:00 +02:00
|
|
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
2015-09-16 15:48:49 +02:00
|
|
|
// FIXME: Find a better way to determine this from the event?
|
2017-09-25 10:48:00 +02:00
|
|
|
let callType = "voice";
|
2015-09-16 15:48:49 +02:00
|
|
|
if (event.getContent().offer && event.getContent().offer.sdp &&
|
|
|
|
event.getContent().offer.sdp.indexOf('m=video') !== -1) {
|
2017-09-25 10:48:00 +02:00
|
|
|
callType = "video";
|
2015-09-16 15:48:49 +02:00
|
|
|
}
|
2017-09-25 10:48:00 +02:00
|
|
|
const supported = MatrixClientPeg.get().supportsVoip() ? "" : _t('(not supported by this browser)');
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s placed a %(callType)s call.', {senderName, callType}) + ' ' + supported;
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-09-16 15:48:49 +02:00
|
|
|
|
2015-12-17 16:48:14 +01:00
|
|
|
function textForThreePidInviteEvent(event) {
|
2017-09-25 10:48:00 +02:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s sent an invitation to %(targetDisplayName)s to join the room.', {
|
|
|
|
senderName,
|
2017-09-25 10:48:00 +02:00
|
|
|
targetDisplayName: event.getContent().display_name,
|
|
|
|
});
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2015-12-17 16:48:14 +01:00
|
|
|
|
2016-03-16 00:47:40 +01:00
|
|
|
function textForHistoryVisibilityEvent(event) {
|
2017-09-17 14:28:17 +02:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
|
|
|
switch (event.getContent().history_visibility) {
|
|
|
|
case 'invited':
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s made future room history visible to all room members, '
|
|
|
|
+ 'from the point they are invited.', {senderName});
|
2017-09-17 14:28:17 +02:00
|
|
|
case 'joined':
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s made future room history visible to all room members, '
|
|
|
|
+ 'from the point they joined.', {senderName});
|
2017-09-17 14:28:17 +02:00
|
|
|
case 'shared':
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s made future room history visible to all room members.', {senderName});
|
2017-09-17 14:28:17 +02:00
|
|
|
case 'world_readable':
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s made future room history visible to anyone.', {senderName});
|
2017-09-17 14:28:17 +02:00
|
|
|
default:
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s made future room history visible to unknown (%(visibility)s).', {
|
|
|
|
senderName,
|
2017-09-17 14:28:17 +02:00
|
|
|
visibility: event.getContent().history_visibility,
|
|
|
|
});
|
2016-03-16 00:47:40 +01:00
|
|
|
}
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function textForEncryptionEvent(event) {
|
2017-09-25 10:48:00 +02:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2018-07-03 11:30:08 +02:00
|
|
|
return _t('%(senderName)s turned on end-to-end encryption (algorithm %(algorithm)s).', {
|
|
|
|
senderName,
|
2017-09-25 10:48:00 +02:00
|
|
|
algorithm: event.getContent().algorithm,
|
|
|
|
});
|
2016-09-15 18:01:02 +02:00
|
|
|
}
|
2016-03-16 00:47:40 +01:00
|
|
|
|
2017-04-06 18:02:35 +02: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();
|
|
|
|
if (!event.getPrevContent() || !event.getPrevContent().users) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
const userDefault = event.getContent().users_default || 0;
|
|
|
|
// Construct set of userIds
|
2017-09-25 10:48:00 +02:00
|
|
|
const users = [];
|
2017-04-06 18:02:35 +02:00
|
|
|
Object.keys(event.getContent().users).forEach(
|
|
|
|
(userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
2017-09-25 10:48:00 +02:00
|
|
|
},
|
2017-04-06 18:02:35 +02:00
|
|
|
);
|
|
|
|
Object.keys(event.getPrevContent().users).forEach(
|
|
|
|
(userId) => {
|
|
|
|
if (users.indexOf(userId) === -1) users.push(userId);
|
2017-09-25 10:48:00 +02:00
|
|
|
},
|
2017-04-06 18:02:35 +02:00
|
|
|
);
|
2017-09-25 10:48:00 +02:00
|
|
|
const diff = [];
|
2017-05-25 20:21:18 +02:00
|
|
|
// XXX: This is also surely broken for i18n
|
2017-04-06 18:02:35 +02: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 11:30:08 +02:00
|
|
|
_t('%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s', {
|
|
|
|
userId,
|
2017-05-27 16:52:24 +02:00
|
|
|
fromPowerLevel: Roles.textualPowerLevel(from, userDefault),
|
2017-09-25 10:48:00 +02:00
|
|
|
toPowerLevel: Roles.textualPowerLevel(to, userDefault),
|
|
|
|
}),
|
2017-04-06 18:02:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!diff.length) {
|
|
|
|
return '';
|
|
|
|
}
|
2017-05-27 16:52:24 +02:00
|
|
|
return _t('%(senderName)s changed the power level of %(powerLevelDiffText)s.', {
|
2018-07-03 11:30:08 +02:00
|
|
|
senderName,
|
2017-08-28 09:19:39 +02:00
|
|
|
powerLevelDiffText: diff.join(", "),
|
2017-05-27 16:52:24 +02:00
|
|
|
});
|
2017-04-06 18:02:35 +02:00
|
|
|
}
|
|
|
|
|
2017-09-28 19:03:13 +02:00
|
|
|
function textForPinnedEvent(event) {
|
2018-07-03 11:30:08 +02:00
|
|
|
const senderName = event.getSender();
|
|
|
|
return _t("%(senderName)s changed the pinned messages for the room.", {senderName});
|
2017-09-28 19:03:13 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 18:46:20 +02:00
|
|
|
function textForWidgetEvent(event) {
|
2017-08-28 09:19:39 +02:00
|
|
|
const senderName = event.getSender();
|
|
|
|
const {name: prevName, type: prevType, url: prevUrl} = event.getPrevContent();
|
2017-08-18 13:03:29 +02:00
|
|
|
const {name, type, url} = event.getContent() || {};
|
2017-08-28 09:19:39 +02:00
|
|
|
|
|
|
|
let widgetName = name || prevName || type || prevType || '';
|
2017-08-18 19:02:50 +02:00
|
|
|
// Apply sentence case to widget name
|
|
|
|
if (widgetName && widgetName.length > 0) {
|
|
|
|
widgetName = widgetName[0].toUpperCase() + widgetName.slice(1) + ' ';
|
|
|
|
}
|
2017-08-16 18:46:20 +02:00
|
|
|
|
2017-08-18 13:04:34 +02:00
|
|
|
// If the widget was removed, its content should be {}, but this is sufficiently
|
|
|
|
// equivalent to that condition.
|
2017-08-18 11:45:43 +02:00
|
|
|
if (url) {
|
2017-08-28 09:19:39 +02: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 18:46:20 +02:00
|
|
|
} else {
|
2017-08-18 19:02:50 +02:00
|
|
|
return _t('%(widgetName)s widget removed by %(senderName)s', {
|
|
|
|
widgetName, senderName,
|
2017-08-16 18:46:20 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 10:48:00 +02:00
|
|
|
const handlers = {
|
2015-09-16 15:48:49 +02:00
|
|
|
'm.room.message': textForMessageEvent,
|
2017-09-25 10:48:00 +02:00
|
|
|
'm.call.invite': textForCallInviteEvent,
|
|
|
|
'm.call.answer': textForCallAnswerEvent,
|
|
|
|
'm.call.hangup': textForCallHangupEvent,
|
2017-10-06 13:07:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const stateHandlers = {
|
2017-09-14 14:43:46 +02:00
|
|
|
'm.room.aliases': textForRoomAliasesEvent,
|
2018-09-20 02:07:01 +02:00
|
|
|
'm.room.canonical_alias': textForCanonicalAliasEvent,
|
2017-10-06 13:07:38 +02:00
|
|
|
'm.room.name': textForRoomNameEvent,
|
|
|
|
'm.room.topic': textForTopicEvent,
|
|
|
|
'm.room.member': textForMemberEvent,
|
2016-03-16 00:47:40 +01:00
|
|
|
'm.room.third_party_invite': textForThreePidInviteEvent,
|
|
|
|
'm.room.history_visibility': textForHistoryVisibilityEvent,
|
2016-09-15 18:01:02 +02:00
|
|
|
'm.room.encryption': textForEncryptionEvent,
|
2017-04-06 18:02:35 +02:00
|
|
|
'm.room.power_levels': textForPowerEvent,
|
2017-09-28 19:03:13 +02:00
|
|
|
'm.room.pinned_events': textForPinnedEvent,
|
2018-07-06 11:18:31 +02:00
|
|
|
'm.room.server_acl': textForServerACLEvent,
|
2019-01-10 23:15:45 +01:00
|
|
|
'm.room.tombstone': textForTombstoneEvent,
|
2019-02-07 20:14:58 +01:00
|
|
|
'm.room.join_rules': textForJoinRulesEvent,
|
|
|
|
'm.room.guest_access': textForGuestAccessEvent,
|
2017-08-16 18:46:20 +02:00
|
|
|
|
|
|
|
'im.vector.modular.widgets': textForWidgetEvent,
|
2015-09-16 15:48:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
textForEvent: function(ev) {
|
2017-10-06 13:16:54 +02:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2017-10-06 13:07:38 +02:00
|
|
|
if (handler) return handler(ev);
|
|
|
|
return '';
|
2017-09-25 10:48:00 +02:00
|
|
|
},
|
2017-01-20 15:22:27 +01:00
|
|
|
};
|