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.
|
|
|
|
*/
|
2017-09-25 08:48:00 +00:00
|
|
|
import MatrixClientPeg from './MatrixClientPeg';
|
|
|
|
import CallHandler from './CallHandler';
|
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';
|
2018-06-07 00:02:34 +00:00
|
|
|
import dis from "./dispatcher";
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
function onUsernameClick(e) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'insert_mention',
|
|
|
|
user_id: e.target.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeUsernameSpan(mxid, text) {
|
|
|
|
return <span className="mx_TextForEvent_username" dir="auto" onClick={onUsernameClick} id={mxid}>{ text }</span>;
|
|
|
|
}
|
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();
|
2018-06-07 00:02:34 +00:00
|
|
|
|
|
|
|
const sender = makeUsernameSpan(ev.getSender(), senderName);
|
|
|
|
const target = makeUsernameSpan(ev.getStateKey(), targetName);
|
|
|
|
|
2017-09-25 08:48:00 +00:00
|
|
|
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 15:48:14 +00:00
|
|
|
if (threePidContent) {
|
2016-03-02 16:04:24 +00:00
|
|
|
if (threePidContent.display_name) {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<target> accepted the invitation for %(displayName)s.', {
|
2017-09-25 08:48:00 +00:00
|
|
|
displayName: threePidContent.display_name,
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
target,
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
2016-03-02 16:04:24 +00:00
|
|
|
} else {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<target> accepted an invitation.', {}, {target});
|
2016-03-02 16:04:24 +00:00
|
|
|
}
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2016-03-05 02:30:18 +00:00
|
|
|
if (ConferenceHandler && ConferenceHandler.isConferenceUser(ev.getStateKey())) {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> requested a VoIP conference.', {}, {sender});
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> invited <target>.', {}, {sender, target});
|
2016-03-05 02:30:18 +00:00
|
|
|
}
|
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-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> banned <target>.', {}, {sender, target}) + ' ' + 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-06-07 00:02:34 +00:00
|
|
|
return _t('<oldDisplayName> changed their display name to <displayName>.', {}, {
|
|
|
|
oldDisplayName: makeUsernameSpan(ev.getStateKey(), prevContent.displayname),
|
|
|
|
displayName: makeUsernameSpan(ev.getStateKey(), content.displayname),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
|
|
|
} else if (!prevContent.displayname && content.displayname) {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> set their display name to <displayName>.', {}, {
|
|
|
|
sender,
|
|
|
|
displayName: makeUsernameSpan(ev.getSender(), content.displayname),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
|
|
|
} else if (prevContent.displayname && !content.displayname) {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> removed their display name (<oldDisplayName>).', {
|
|
|
|
sender,
|
|
|
|
oldDisplayName: makeUsernameSpan(ev.getSender(), 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-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> removed their profile picture.', {}, {sender});
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.avatar_url && content.avatar_url &&
|
|
|
|
prevContent.avatar_url !== content.avatar_url) {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> changed their profile picture.', {}, {sender});
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (!prevContent.avatar_url && content.avatar_url) {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> set a profile picture.', {}, {sender});
|
2016-09-02 15:54:27 +00:00
|
|
|
} else {
|
2017-05-06 00:45:28 +00:00
|
|
|
// suppress null rejoins
|
|
|
|
return '';
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ev.target) console.warn("Join message has no target! -- " + ev.getContent().state_key);
|
2016-03-05 02:30:18 +00:00
|
|
|
if (ConferenceHandler && ConferenceHandler.isConferenceUser(ev.getStateKey())) {
|
2017-05-27 13:55:55 +00:00
|
|
|
return _t('VoIP conference started.');
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<target> joined the room.', {}, {target});
|
2016-03-05 02:30:18 +00:00
|
|
|
}
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
|
|
|
case 'leave':
|
|
|
|
if (ev.getSender() === ev.getStateKey()) {
|
2016-03-05 02:30:18 +00:00
|
|
|
if (ConferenceHandler && ConferenceHandler.isConferenceUser(ev.getStateKey())) {
|
2017-05-27 13:55:55 +00:00
|
|
|
return _t('VoIP conference finished.');
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.membership === "invite") {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<target> rejected the invitation.', {}, {target});
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<target> left the room.', {}, {target});
|
2016-03-05 02:30:18 +00:00
|
|
|
}
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.membership === "ban") {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> unbanned <target>.', {}, {sender, target});
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.membership === "join") {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> kicked <target>.', {}, {sender, target}) + ' ' + reason;
|
2017-09-25 08:48:00 +00:00
|
|
|
} else if (prevContent.membership === "invite") {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> withdrew <target>\'s invitation.', {}, {sender, target}) + ' ' + reason;
|
2017-09-25 08:48:00 +00:00
|
|
|
} else {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<target> left the room.', {}, {target});
|
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-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> changed the topic to "%(topic)s".', {
|
2017-09-25 08:48:00 +00:00
|
|
|
topic: ev.getContent().topic,
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
sender: makeUsernameSpan(ev.getSender(), senderDisplayName),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
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();
|
2018-06-07 00:02:34 +00:00
|
|
|
const sender = makeUsernameSpan(ev.getSender(), senderDisplayName);
|
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-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> removed the room name.', {}, {sender});
|
2017-05-30 05:21:14 +00:00
|
|
|
}
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> changed the room name to %(roomName)s.', {
|
2017-09-25 08:48:00 +00:00
|
|
|
roomName: ev.getContent().name,
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
sender,
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2015-10-30 02:07:04 +00:00
|
|
|
|
2015-09-16 13:48:49 +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;
|
2015-09-16 13:48:49 +00:00
|
|
|
if (ev.getContent().msgtype === "m.emote") {
|
|
|
|
message = "* " + senderDisplayName + " " + message;
|
|
|
|
} else if (ev.getContent().msgtype === "m.image") {
|
2018-06-07 00:02:34 +00:00
|
|
|
message = _t('<sender> sent an image.', {}, {
|
|
|
|
sender: makeUsernameSpan(ev.getSender(), 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
|
|
|
|
|
|
|
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-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> answered the call.', {}, {
|
|
|
|
sender: makeUsernameSpan(event.getSender(), 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") {
|
|
|
|
reason = _t('(could not connect media)');
|
|
|
|
} else if (eventContent.reason === "invite_timeout") {
|
|
|
|
reason = _t('(no answer)');
|
|
|
|
} else {
|
|
|
|
reason = _t('(unknown failure: %(reason)s)', {reason: eventContent.reason});
|
|
|
|
}
|
2017-06-10 13:26:27 +00:00
|
|
|
}
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> ended the call.', {}, {
|
|
|
|
sender: makeUsernameSpan(event.getSender(), senderName),
|
|
|
|
}) + ' ' + reason;
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
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');
|
2018-06-07 00:02:34 +00:00
|
|
|
const sender = makeUsernameSpan(event.getSender(), senderName);
|
2015-09-16 13:48:49 +00:00
|
|
|
// FIXME: Find a better way to determine this from the event?
|
2017-09-25 08:48:00 +00:00
|
|
|
let callType = "voice";
|
2015-09-16 13:48:49 +00:00
|
|
|
if (event.getContent().offer && event.getContent().offer.sdp &&
|
|
|
|
event.getContent().offer.sdp.indexOf('m=video') !== -1) {
|
2017-09-25 08:48:00 +00:00
|
|
|
callType = "video";
|
2015-09-16 13:48:49 +00:00
|
|
|
}
|
2017-09-25 08:48:00 +00:00
|
|
|
const supported = MatrixClientPeg.get().supportsVoip() ? "" : _t('(not supported by this browser)');
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> placed a %(callType)s call.', {callType}, {sender}) + ' ' + supported;
|
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();
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> sent an invitation to %(targetDisplayName)s to join the room.', {
|
2017-09-25 08:48:00 +00:00
|
|
|
targetDisplayName: event.getContent().display_name,
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
sender: makeUsernameSpan(event.getSender(), senderName),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
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();
|
2018-06-07 00:02:34 +00:00
|
|
|
const sender = makeUsernameSpan(event.getSender(), senderName);
|
2017-09-17 12:28:17 +00:00
|
|
|
switch (event.getContent().history_visibility) {
|
|
|
|
case 'invited':
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> made future room history visible to all room members, '
|
|
|
|
+ 'from the point they are invited.', {}, {sender});
|
2017-09-17 12:28:17 +00:00
|
|
|
case 'joined':
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> made future room history visible to all room members, '
|
|
|
|
+ 'from the point they joined.', {}, {sender});
|
2017-09-17 12:28:17 +00:00
|
|
|
case 'shared':
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> made future room history visible to all room members.', {}, {sender});
|
2017-09-17 12:28:17 +00:00
|
|
|
case 'world_readable':
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> made future room history visible to anyone.', {}, {sender});
|
2017-09-17 12:28:17 +00:00
|
|
|
default:
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> made future room history visible to unknown (%(visibility)s).', {
|
2017-09-17 12:28:17 +00:00
|
|
|
visibility: event.getContent().history_visibility,
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
sender,
|
2017-09-17 12:28:17 +00:00
|
|
|
});
|
2016-03-15 23:47:40 +00:00
|
|
|
}
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function textForEncryptionEvent(event) {
|
2017-09-25 08:48:00 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> turned on end-to-end encryption (algorithm %(algorithm)s).', {
|
2017-09-25 08:48:00 +00:00
|
|
|
algorithm: event.getContent().algorithm,
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
sender: makeUsernameSpan(event.getSender(), senderName),
|
2017-09-25 08:48:00 +00:00
|
|
|
});
|
2016-09-15 16:01:02 +00:00
|
|
|
}
|
2016-03-15 23:47:40 +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();
|
|
|
|
if (!event.getPrevContent() || !event.getPrevContent().users) {
|
|
|
|
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-06-07 00:02:34 +00:00
|
|
|
_t('<user> from %(fromPowerLevel)s to %(toPowerLevel)s', {
|
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),
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
user: makeUsernameSpan(userId, userId),
|
2017-09-25 08:48:00 +00:00
|
|
|
}),
|
2017-04-06 16:02:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!diff.length) {
|
|
|
|
return '';
|
|
|
|
}
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('<sender> changed the power level of %(powerLevelDiffText)s.', {
|
2017-08-28 07:19:39 +00:00
|
|
|
powerLevelDiffText: diff.join(", "),
|
2018-06-07 00:02:34 +00:00
|
|
|
}, {
|
|
|
|
sender: makeUsernameSpan(event.getSender(), senderName),
|
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) {
|
2018-06-07 00:02:34 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
|
|
|
const sender = makeUsernameSpan(event.getSender(), senderName);
|
|
|
|
return _t("<sender> changed the pinned messages for the room.", {}, {sender});
|
2017-09-28 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 16:46:20 +00:00
|
|
|
function textForWidgetEvent(event) {
|
2018-06-07 00:02:34 +00:00
|
|
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
|
|
|
const sender = makeUsernameSpan(event.getSender(), senderName);
|
|
|
|
|
2017-08-28 07:19:39 +00:00
|
|
|
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) {
|
|
|
|
widgetName = widgetName[0].toUpperCase() + widgetName.slice(1) + ' ';
|
|
|
|
}
|
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) {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('%(widgetName)s widget modified by <sender>', {widgetName}, {sender});
|
2017-08-28 07:19:39 +00:00
|
|
|
} else {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('%(widgetName)s widget added by <sender>', {widgetName}, {sender});
|
2017-08-28 07:19:39 +00:00
|
|
|
}
|
2017-08-16 16:46:20 +00:00
|
|
|
} else {
|
2018-06-07 00:02:34 +00:00
|
|
|
return _t('%(widgetName)s widget removed by <sender>', {widgetName}, {sender});
|
2017-08-16 16:46:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2017-10-06 11:07:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const stateHandlers = {
|
|
|
|
'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,
|
2016-09-15 16:01:02 +00:00
|
|
|
'm.room.encryption': textForEncryptionEvent,
|
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,
|
2017-08-16 16:46:20 +00:00
|
|
|
|
|
|
|
'im.vector.modular.widgets': textForWidgetEvent,
|
2015-09-16 13:48:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
textForEvent: function(ev) {
|
2017-10-06 11:16:54 +00:00
|
|
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
2017-10-06 11:07:38 +00:00
|
|
|
if (handler) return handler(ev);
|
|
|
|
return '';
|
2017-09-25 08:48:00 +00:00
|
|
|
},
|
2017-01-20 14:22:27 +00:00
|
|
|
};
|