Merge pull request #1453 from matrix-org/t3chguy/textForEvent

Only allow event state event handlers on state events
This commit is contained in:
Luke Barnard 2017-10-11 14:30:02 +02:00 committed by GitHub
commit 8aee5e1c25

View file

@ -243,7 +243,7 @@ function textForPowerEvent(event) {
if (to !== from) { if (to !== from) {
diff.push( diff.push(
_t('%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s', { _t('%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s', {
userId: userId, userId,
fromPowerLevel: Roles.textualPowerLevel(from, userDefault), fromPowerLevel: Roles.textualPowerLevel(from, userDefault),
toPowerLevel: Roles.textualPowerLevel(to, userDefault), toPowerLevel: Roles.textualPowerLevel(to, userDefault),
}), }),
@ -254,7 +254,7 @@ function textForPowerEvent(event) {
return ''; return '';
} }
return _t('%(senderName)s changed the power level of %(powerLevelDiffText)s.', { return _t('%(senderName)s changed the power level of %(powerLevelDiffText)s.', {
senderName: senderName, senderName,
powerLevelDiffText: diff.join(", "), powerLevelDiffText: diff.join(", "),
}); });
} }
@ -291,12 +291,15 @@ function textForWidgetEvent(event) {
const handlers = { const handlers = {
'm.room.message': textForMessageEvent, 'm.room.message': textForMessageEvent,
'm.room.name': textForRoomNameEvent,
'm.room.topic': textForTopicEvent,
'm.room.member': textForMemberEvent,
'm.call.invite': textForCallInviteEvent, 'm.call.invite': textForCallInviteEvent,
'm.call.answer': textForCallAnswerEvent, 'm.call.answer': textForCallAnswerEvent,
'm.call.hangup': textForCallHangupEvent, 'm.call.hangup': textForCallHangupEvent,
};
const stateHandlers = {
'm.room.name': textForRoomNameEvent,
'm.room.topic': textForTopicEvent,
'm.room.member': textForMemberEvent,
'm.room.third_party_invite': textForThreePidInviteEvent, 'm.room.third_party_invite': textForThreePidInviteEvent,
'm.room.history_visibility': textForHistoryVisibilityEvent, 'm.room.history_visibility': textForHistoryVisibilityEvent,
'm.room.encryption': textForEncryptionEvent, 'm.room.encryption': textForEncryptionEvent,
@ -307,8 +310,8 @@ const handlers = {
module.exports = { module.exports = {
textForEvent: function(ev) { textForEvent: function(ev) {
const hdlr = handlers[ev.getType()]; const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
if (!hdlr) return ''; if (handler) return handler(ev);
return hdlr(ev); return '';
}, },
}; };