From 6a4e3792d4aa563c521eadfd1bc858a343894742 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 6 Oct 2017 12:07:38 +0100 Subject: [PATCH 1/3] split handlers into state and non-states Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/TextForEvent.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index a21eb5c251..fa8efe028f 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -291,12 +291,15 @@ function textForWidgetEvent(event) { const handlers = { 'm.room.message': textForMessageEvent, - 'm.room.name': textForRoomNameEvent, - 'm.room.topic': textForTopicEvent, - 'm.room.member': textForMemberEvent, 'm.call.invite': textForCallInviteEvent, 'm.call.answer': textForCallAnswerEvent, '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.history_visibility': textForHistoryVisibilityEvent, 'm.room.encryption': textForEncryptionEvent, @@ -307,8 +310,8 @@ const handlers = { module.exports = { textForEvent: function(ev) { - const hdlr = handlers[ev.getType()]; - if (!hdlr) return ''; - return hdlr(ev); + const handler = ev.isState() ? stateHandlers[ev.getType()] : handlers[ev.getType()]; + if (handler) return handler(ev); + return ''; }, }; From 91ba939e23eef52634a5618041008cbe30c73e2b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 6 Oct 2017 12:10:07 +0100 Subject: [PATCH 2/3] tiny bit of de-lint for consistency Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/TextForEvent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index fa8efe028f..ccb4c29a9c 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -243,7 +243,7 @@ function textForPowerEvent(event) { if (to !== from) { diff.push( _t('%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s', { - userId: userId, + userId, fromPowerLevel: Roles.textualPowerLevel(from, userDefault), toPowerLevel: Roles.textualPowerLevel(to, userDefault), }), @@ -254,7 +254,7 @@ function textForPowerEvent(event) { return ''; } return _t('%(senderName)s changed the power level of %(powerLevelDiffText)s.', { - senderName: senderName, + senderName, powerLevelDiffText: diff.join(", "), }); } From 152499a17d0683a565608a7f019ae99740a29b97 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 6 Oct 2017 12:16:54 +0100 Subject: [PATCH 3/3] DRY map lookup Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/TextForEvent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index ccb4c29a9c..6345403f09 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -310,7 +310,7 @@ const stateHandlers = { module.exports = { textForEvent: function(ev) { - const handler = ev.isState() ? stateHandlers[ev.getType()] : handlers[ev.getType()]; + const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()]; if (handler) return handler(ev); return ''; },