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';
|
'use strict';
|
||||||
|
|
||||||
var MatrixClientPeg = require("../../MatrixClientPeg");
|
var MatrixClientPeg = require("./MatrixClientPeg");
|
||||||
var dis = require("../../dispatcher");
|
var TextForEvent = require('./TextForEvent');
|
||||||
|
var Avatar = require('./Avatar');
|
||||||
|
var dis = require("./dispatcher");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dispatches:
|
* Dispatches:
|
||||||
|
@ -28,10 +30,76 @@ var dis = require("../../dispatcher");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
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() {
|
start: function() {
|
||||||
this.boundOnRoomTimeline = this.onRoomTimeline.bind(this);
|
this.boundOnRoomTimeline = this.onRoomTimeline.bind(this);
|
||||||
MatrixClientPeg.get().on('Room.timeline', this.boundOnRoomTimeline);
|
MatrixClientPeg.get().on('Room.timeline', this.boundOnRoomTimeline);
|
||||||
this.state = { 'toolbarHidden' : false };
|
this.toolbarHidden = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
stop: function() {
|
stop: function() {
|
||||||
|
@ -96,7 +164,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
setToolbarHidden: function(hidden) {
|
setToolbarHidden: function(hidden) {
|
||||||
this.state.toolbarHidden = hidden;
|
this.toolbarHidden = hidden;
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: "notifier_enabled",
|
action: "notifier_enabled",
|
||||||
value: this.isEnabled()
|
value: this.isEnabled()
|
||||||
|
@ -104,7 +172,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
isToolbarHidden: function() {
|
isToolbarHidden: function() {
|
||||||
return this.state.toolbarHidden;
|
return this.toolbarHidden;
|
||||||
},
|
},
|
||||||
|
|
||||||
onRoomTimeline: function(ev, room, toStartOfTimeline) {
|
onRoomTimeline: function(ev, room, toStartOfTimeline) {
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
var React = require("react");
|
var React = require("react");
|
||||||
|
var Notifier = require("../../../Notifier");
|
||||||
var sdk = require('../../../index');
|
var sdk = require('../../../index');
|
||||||
var dis = require("../../../dispatcher");
|
var dis = require("../../../dispatcher");
|
||||||
|
|
||||||
|
@ -38,12 +39,10 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
enabled: function() {
|
enabled: function() {
|
||||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
|
||||||
return Notifier.isEnabled();
|
return Notifier.isEnabled();
|
||||||
},
|
},
|
||||||
|
|
||||||
onClick: function() {
|
onClick: function() {
|
||||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!Notifier.supportsDesktopNotifications()) {
|
if (!Notifier.supportsDesktopNotifications()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var MatrixClientPeg = require("../../MatrixClientPeg");
|
var MatrixClientPeg = require("../../MatrixClientPeg");
|
||||||
|
var Notifier = require("../../Notifier");
|
||||||
var RoomListSorter = require("../../RoomListSorter");
|
var RoomListSorter = require("../../RoomListSorter");
|
||||||
var UserActivity = require("../../UserActivity");
|
var UserActivity = require("../../UserActivity");
|
||||||
var Presence = require("../../Presence");
|
var Presence = require("../../Presence");
|
||||||
|
@ -96,7 +97,6 @@ module.exports = {
|
||||||
|
|
||||||
onAction: function(payload) {
|
onAction: function(payload) {
|
||||||
var roomIndexDelta = 1;
|
var roomIndexDelta = 1;
|
||||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
|
@ -317,7 +317,6 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
startMatrixClient: function() {
|
startMatrixClient: function() {
|
||||||
var Notifier = sdk.getComponent('organisms.Notifier');
|
|
||||||
var cli = MatrixClientPeg.get();
|
var cli = MatrixClientPeg.get();
|
||||||
var self = this;
|
var self = this;
|
||||||
cli.on('sync', function(state) {
|
cli.on('sync', function(state) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue