This repository has been archived by the owner on Apr 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
394 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
[Martin Grünbaum](https://github.com/alathon) | ||
|
||
Ivan Toshkov | ||
[Simon Joda Stößer](https://github.com/SimJoSt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
/** | ||
* Singleton class for notification dispatching. | ||
*/ | ||
Ext.define('Rambox.util.Notifier', { | ||
|
||
singleton: true, | ||
|
||
constructor: function(config) { | ||
|
||
config = config || {}; | ||
|
||
/** | ||
* Returns the notification text depending on the service type. | ||
* | ||
* @param view | ||
* @param count | ||
* @return {*} | ||
*/ | ||
function getNotificationText(view, count) { | ||
var text; | ||
switch (Ext.getStore('ServicesList').getById(view.type).get('type')) { | ||
case 'messaging': | ||
text = 'You have ' + Ext.util.Format.plural(count, 'new message', 'new messages') + '.'; | ||
break; | ||
case 'email': | ||
text = 'You have ' + Ext.util.Format.plural(count, 'new email', 'new emails') + '.'; | ||
break; | ||
default: | ||
text = 'You have ' + Ext.util.Format.plural(count, 'new activity', 'new activities') + '.'; | ||
break; | ||
} | ||
return text; | ||
} | ||
|
||
/** | ||
* Dispatches a notification for a specific service. | ||
* | ||
* @param view The view of the service | ||
* @param {number} count The unread count | ||
*/ | ||
this.dispatchNotification = function(view, count) { | ||
var text = getNotificationText(view, count); | ||
|
||
var notification = new Notification(view.record.get('name'), { | ||
body: text, | ||
icon: view.tab.icon, | ||
silent: view.record.get('muted') | ||
}); | ||
|
||
notification.onclick = function() { | ||
require('electron').remote.getCurrentWindow().show(); | ||
Ext.cq1('app-main').setActiveTab(view); | ||
}; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Singleton class to handle the global unread counter. | ||
*/ | ||
Ext.define('Rambox.util.UnreadCounter', { | ||
|
||
singleton: true, | ||
|
||
constructor: function(config) { | ||
|
||
config = config || {}; | ||
|
||
/** | ||
* Map for storing the global unread count. | ||
* service id -> unread count | ||
* | ||
* @type {Map} | ||
*/ | ||
var unreadCountByService = new Map(); | ||
|
||
/** | ||
* Holds the global unread count for internal usage. | ||
* | ||
* @type {number} | ||
*/ | ||
var totalUnreadCount = 0; | ||
|
||
/** | ||
* Sets the application's unread count to tracked unread count. | ||
*/ | ||
function updateAppUnreadCounter() { | ||
Rambox.app.setTotalNotifications(totalUnreadCount); | ||
} | ||
|
||
/** | ||
* Returns the global unread count. | ||
* | ||
* @return {number} | ||
*/ | ||
this.getTotalUnreadCount = function() { | ||
return totalUnreadCount; | ||
}; | ||
|
||
/** | ||
* Sets the global unread count for a specific service. | ||
* | ||
* @param {*} id Id of the service to set the global unread count for. | ||
* @param {number} unreadCount The global unread count for the service. | ||
*/ | ||
this.setUnreadCountForService = function(id, unreadCount) { | ||
unreadCount = parseInt(unreadCount, 10); | ||
|
||
if (unreadCountByService.has(id)) { | ||
totalUnreadCount -= unreadCountByService.get(id); | ||
} | ||
totalUnreadCount += unreadCount; | ||
unreadCountByService.set(id, unreadCount); | ||
|
||
updateAppUnreadCounter(); | ||
}; | ||
|
||
/** | ||
* Clears the global unread count for a specific service. | ||
* | ||
* @param {*} id Id of the service to clear the global unread count for. | ||
*/ | ||
this.clearUnreadCountForService = function(id) { | ||
if (unreadCountByService.has(id)) { | ||
totalUnreadCount -= unreadCountByService.get(id); | ||
} | ||
unreadCountByService['delete'](id); | ||
|
||
updateAppUnreadCounter(); | ||
} | ||
} | ||
}); |
Oops, something went wrong.