From 2b37e5334aba5422d88e63b632d79bdb50c9655c Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 30 Nov 2015 15:05:00 +0000 Subject: [PATCH] Remove Notifier and put it in react-sdk --- src/skins/vector/skindex.js | 1 - .../vector/views/molecules/MatrixToolbar.js | 4 +- src/skins/vector/views/organisms/Notifier.js | 100 ------------------ src/skins/vector/views/pages/MatrixChat.js | 2 +- 4 files changed, 2 insertions(+), 105 deletions(-) delete mode 100644 src/skins/vector/views/organisms/Notifier.js diff --git a/src/skins/vector/skindex.js b/src/skins/vector/skindex.js index 95680a8b..d12d5fb7 100644 --- a/src/skins/vector/skindex.js +++ b/src/skins/vector/skindex.js @@ -88,7 +88,6 @@ skin['molecules.SenderProfile'] = require('./views/molecules/SenderProfile'); skin['organisms.LeftPanel'] = require('./views/organisms/LeftPanel'); skin['organisms.LogoutPrompt'] = require('./views/organisms/LogoutPrompt'); skin['organisms.MemberList'] = require('./views/organisms/MemberList'); -skin['organisms.Notifier'] = require('./views/organisms/Notifier'); skin['organisms.RightPanel'] = require('./views/organisms/RightPanel'); skin['organisms.RoomDirectory'] = require('./views/organisms/RoomDirectory'); skin['organisms.RoomList'] = require('./views/organisms/RoomList'); diff --git a/src/skins/vector/views/molecules/MatrixToolbar.js b/src/skins/vector/views/molecules/MatrixToolbar.js index 5b613f56..bf333540 100644 --- a/src/skins/vector/views/molecules/MatrixToolbar.js +++ b/src/skins/vector/views/molecules/MatrixToolbar.js @@ -17,19 +17,17 @@ limitations under the License. 'use strict'; var React = require('react'); - +var Notifier = require("matrix-react-sdk/lib/Notifier"); var sdk = require('matrix-react-sdk') module.exports = React.createClass({ displayName: 'MatrixToolbar', hideToolbar: function() { - var Notifier = sdk.getComponent('organisms.Notifier'); Notifier.setToolbarHidden(true); }, onClick: function() { - var Notifier = sdk.getComponent('organisms.Notifier'); Notifier.setEnabled(true); }, diff --git a/src/skins/vector/views/organisms/Notifier.js b/src/skins/vector/views/organisms/Notifier.js deleted file mode 100644 index b214b4cd..00000000 --- a/src/skins/vector/views/organisms/Notifier.js +++ /dev/null @@ -1,100 +0,0 @@ -/* -Copyright 2015 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. -*/ - -'use strict'; - -var NotifierController = require('matrix-react-sdk/lib/controllers/organisms/Notifier') - -var TextForEvent = require('matrix-react-sdk/lib/TextForEvent'); -var extend = require('matrix-react-sdk/lib/extend'); -var dis = require('matrix-react-sdk/lib/dispatcher'); - -var Avatar = require('../../../../Avatar'); - - -var NotifierView = { - notificationMessageForEvent: function(ev) { - return TextForEvent.textForEvent(ev); - }, - - displayNotification: function(ev, room) { - if (!global.Notification || global.Notification.permission != 'granted') { - return; - } - if (global.document.hasFocus()) { - return; - } - - var msg = this.notificationMessageForEvent(ev); - if (!msg) return; - - 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 avatarUrl = ev.sender ? Avatar.avatarUrlForMember( - ev.sender, 40, 40, 'crop' - ) : null; - - var notification = new global.Notification( - title, - { - "body": msg, - "icon": avatarUrl, - "tag": "vector" - } - ); - - notification.onclick = function() { - dis.dispatch({ - action: 'view_room', - room_id: room.roomId - }); - global.focus(); - }; - - /*var audioClip; - - if (audioNotification) { - audioClip = playAudio(audioNotification); - }*/ - - global.setTimeout(function() { - notification.close(); - }, 5 * 1000); - - } -}; - -var NotifierClass = function() {}; -extend(NotifierClass.prototype, NotifierController); -extend(NotifierClass.prototype, NotifierView); - -module.exports = new NotifierClass(); - diff --git a/src/skins/vector/views/pages/MatrixChat.js b/src/skins/vector/views/pages/MatrixChat.js index 13ac90e6..fa1c2b2c 100644 --- a/src/skins/vector/views/pages/MatrixChat.js +++ b/src/skins/vector/views/pages/MatrixChat.js @@ -24,6 +24,7 @@ var MatrixChatController = require('matrix-react-sdk/lib/controllers/pages/Matri var dis = require('matrix-react-sdk/lib/dispatcher'); var Matrix = require("matrix-js-sdk"); +var Notifier = require("matrix-react-sdk/lib/Notifier"); var ContextualMenu = require("matrix-react-sdk/lib/ContextualMenu"); var Login = require("../../../../components/structures/login/Login"); var Registration = require("../../../../components/structures/login/Registration"); @@ -132,7 +133,6 @@ module.exports = React.createClass({ var CreateRoom = sdk.getComponent('structures.CreateRoom'); var RoomDirectory = sdk.getComponent('organisms.RoomDirectory'); var MatrixToolbar = sdk.getComponent('molecules.MatrixToolbar'); - var Notifier = sdk.getComponent('organisms.Notifier'); // needs to be before normal PageTypes as you are logged in technically if (this.state.screen == 'post_registration') {