mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 02:05:45 +03:00
Move Notifier to src/ since it isn't a component.
This commit is contained in:
parent
8a98fcd427
commit
945a65f4b5
3 changed files with 75 additions and 9 deletions
|
@ -16,8 +16,10 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
|
||||
var MatrixClientPeg = require("../../MatrixClientPeg");
|
||||
var dis = require("../../dispatcher");
|
||||
var MatrixClientPeg = require("./MatrixClientPeg");
|
||||
var TextForEvent = require('./TextForEvent');
|
||||
var Avatar = require('./Avatar');
|
||||
var dis = require("./dispatcher");
|
||||
|
||||
/*
|
||||
* Dispatches:
|
||||
|
@ -28,10 +30,76 @@ var dis = require("../../dispatcher");
|
|||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
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);
|
||||
|
||||
},
|
||||
|
||||
start: function() {
|
||||
this.boundOnRoomTimeline = this.onRoomTimeline.bind(this);
|
||||
MatrixClientPeg.get().on('Room.timeline', this.boundOnRoomTimeline);
|
||||
this.state = { 'toolbarHidden' : false };
|
||||
this.toolbarHidden = false;
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
|
@ -96,7 +164,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
setToolbarHidden: function(hidden) {
|
||||
this.state.toolbarHidden = hidden;
|
||||
this.toolbarHidden = hidden;
|
||||
dis.dispatch({
|
||||
action: "notifier_enabled",
|
||||
value: this.isEnabled()
|
||||
|
@ -104,7 +172,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
isToolbarHidden: function() {
|
||||
return this.state.toolbarHidden;
|
||||
return this.toolbarHidden;
|
||||
},
|
||||
|
||||
onRoomTimeline: function(ev, room, toStartOfTimeline) {
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
'use strict';
|
||||
var React = require("react");
|
||||
var Notifier = require("../../../Notifier");
|
||||
var sdk = require('../../../index');
|
||||
var dis = require("../../../dispatcher");
|
||||
|
||||
|
@ -38,12 +39,10 @@ module.exports = React.createClass({
|
|||
},
|
||||
|
||||
enabled: function() {
|
||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
||||
return Notifier.isEnabled();
|
||||
},
|
||||
|
||||
onClick: function() {
|
||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
||||
var self = this;
|
||||
if (!Notifier.supportsDesktopNotifications()) {
|
||||
return;
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
var MatrixClientPeg = require("../../MatrixClientPeg");
|
||||
var Notifier = require("../../Notifier");
|
||||
var RoomListSorter = require("../../RoomListSorter");
|
||||
var UserActivity = require("../../UserActivity");
|
||||
var Presence = require("../../Presence");
|
||||
|
@ -96,7 +97,6 @@ module.exports = {
|
|||
|
||||
onAction: function(payload) {
|
||||
var roomIndexDelta = 1;
|
||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
||||
|
||||
var self = this;
|
||||
switch (payload.action) {
|
||||
|
@ -317,7 +317,6 @@ module.exports = {
|
|||
},
|
||||
|
||||
startMatrixClient: function() {
|
||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
||||
var cli = MatrixClientPeg.get();
|
||||
var self = this;
|
||||
cli.on('sync', function(state) {
|
||||
|
|
Loading…
Reference in a new issue