From 37108ac56c071c4516827ffe7dd9907dbaaa7ab9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 17 Jul 2015 11:56:55 +0100 Subject: [PATCH] Make notifications sensible again and have information once and only once. --- skins/base/views/organisms/Notifier.js | 10 ++++++++++ src/TextForEvent.js | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/skins/base/views/organisms/Notifier.js b/skins/base/views/organisms/Notifier.js index 34b3724630..7df76e29f1 100644 --- a/skins/base/views/organisms/Notifier.js +++ b/skins/base/views/organisms/Notifier.js @@ -43,8 +43,18 @@ var NotifierView = { var title; if (!ev.sender || room.name == ev.sender.name) { title = room.name; + // notificationMessageForEvent includes sender, + // but we already have the sender here + if (ev.getContent().body) msg = ev.getContent().body; + } else if (ev.getType() == 'm.room.member') { + // context is all in the message here, we don't need + // to display sender info + title = room.name; } else if (ev.sender) { title = ev.sender.name + " (" + room.name + ")"; + // notificationMessageForEvent includes sender, + // but we've just out sender in the title + if (ev.getContent().body) msg = ev.getContent().body; } var notification = new global.Notification( diff --git a/src/TextForEvent.js b/src/TextForEvent.js index e53bb3ef33..4788c9e8d8 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -25,7 +25,20 @@ function textForMemberEvent(ev) { } }; +function textForMessageEvent(ev) { + var senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); + + var message = senderDisplayName + ': ' + ev.getContent().body; + if (ev.getContent().msgtype === "m.emote") { + message = "* " + senderDisplayName + " " + message; + } else if (ev.getContent().msgtype === "m.image") { + message = senderDisplayName + " sent an image."; + } + return message; +}; + var handlers = { + 'm.room.message': textForMessageEvent, 'm.room.member': textForMemberEvent };