diff --git a/skins/base/views/molecules/MRoomMemberTile.js b/skins/base/views/molecules/MRoomMemberTile.js index 996b6f9c6..e5a7f7153 100644 --- a/skins/base/views/molecules/MRoomMemberTile.js +++ b/skins/base/views/molecules/MRoomMemberTile.js @@ -22,6 +22,7 @@ var MRoomMemberTileController = require("../../../../src/controllers/molecules/M var MatrixClientPeg = require("../../../../src/MatrixClientPeg"); var ComponentBroker = require('../../../../src/ComponentBroker'); +var TextForEvent = require('../../../../src/TextForEvent'); var MessageTimestamp = ComponentBroker.get('atoms/MessageTimestamp'); module.exports = React.createClass({ @@ -29,18 +30,7 @@ module.exports = React.createClass({ mixins: [MRoomMemberTileController], getMemberEventText: function() { - var ev = this.props.mxEvent; - // XXX: SYJS-16 - var senderName = ev.sender ? ev.sender.name : "Someone"; - var targetName = ev.target ? ev.target.name : "Someone"; - switch (ev.getContent().membership) { - case 'invite': - return senderName + " invited " + targetName + "."; - case 'join': - return targetName + " joined the room."; - case 'leave': - return targetName + " left the room."; - } + return TextForEvent.textForEvent(this.props.mxEvent); }, render: function() { diff --git a/skins/base/views/organisms/Notifier.js b/skins/base/views/organisms/Notifier.js index 09f1921ac..34b372463 100644 --- a/skins/base/views/organisms/Notifier.js +++ b/skins/base/views/organisms/Notifier.js @@ -19,32 +19,14 @@ limitations under the License. var NotifierController = require("../../../../src/controllers/organisms/Notifier"); var MatrixClientPeg = require("../../../../src/MatrixClientPeg"); +var TextForEvent = require("../../../../src/TextForEvent"); var extend = require("../../../../src/extend"); var dis = require("../../../../src/dispatcher"); var NotifierView = { notificationMessageForEvent: function(ev) { - var senderDisplayName = ev.sender ? ev.sender.name : ''; - var message = null; - - if (ev.event.type === "m.room.message") { - message = ev.getContent().body; - if (ev.getContent().msgtype === "m.emote") { - message = "* " + senderDisplayName + " " + message; - } else if (ev.getContent().msgtype === "m.image") { - message = senderDisplayName + " sent an image."; - } - } else if (ev.event.type == "m.room.member") { - if (ev.event.state_key !== MatrixClientPeg.get().credentials.userId && "join" === ev.getContent().membership) { - // Notify when another user joins - message = senderDisplayName + " joined"; - } else if (ev.event.state_key === MatrixClientPeg.get().credentials.userId && "invite" === ev.getContent().membership) { - // notify when you are invited - message = senderDisplayName + " invited you to a room"; - } - } - return message; + return TextForEvent.textForEvent(ev); }, displayNotification: function(ev, room) { diff --git a/src/TextForEvent.js b/src/TextForEvent.js new file mode 100644 index 000000000..e53bb3ef3 --- /dev/null +++ b/src/TextForEvent.js @@ -0,0 +1,38 @@ + +function textForMemberEvent(ev) { + // XXX: SYJS-16 + var senderName = ev.sender ? ev.sender.name : ev.getSender(); + var targetName = ev.target ? ev.target.name : ev.getContent().target; + switch (ev.getContent().membership) { + case 'invite': + return senderName + " invited " + targetName + "."; + case 'join': + if (ev.getPrevContent() && ev.getPrevContent().membership == 'join') { + if (ev.getPrevContent().displayname && ev.getContent().displayname) { + return ev.getSender() + " changed their display name from " + + ev.getPrevContent().displayname + " to " + + ev.getContent().displayname; + } else if (!ev.getPrevContent().displayname && ev.getContent().displayname) { + return ev.getSender() + " set their display name to " + ev.getContent().displayname; + } else if (ev.getPrevContent().displayname && !ev.getContent().displayname) { + return ev.getSender() + " removed their display name"; + } + } else { + return targetName + " joined the room."; + } + case 'leave': + return targetName + " left the room."; + } +}; + +var handlers = { + 'm.room.member': textForMemberEvent +}; + +module.exports = { + textForEvent(ev) { + var hdlr = handlers[ev.getType()]; + if (!hdlr) return "Unknown entry event"; + return hdlr(ev); + } +}