Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into xing-522
Browse files Browse the repository at this point in the history
  • Loading branch information
saenzramiro committed Jan 16, 2017
2 parents 76571ac + a9fa899 commit d07e321
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 108 deletions.
1 change: 1 addition & 0 deletions Backers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
[Martin Grünbaum](https://github.com/alathon)

Ivan Toshkov
[Simon Joda Stößer](https://github.com/SimJoSt)
11 changes: 8 additions & 3 deletions app/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ Ext.define('Rambox.Application', {
var tabPanel = Ext.cq1('app-main');
var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab());
var i = activeIndex + 1;
if ( i >= tabPanel.items.items.length - 1 ) i = 0;
while ( tabPanel.items.items[i].id === 'tbfill' ) i++;
tabPanel.setActiveTab( i );

// "cycle" (go to the start) when the end is reached or the end is the spacer "tbfill"
if (i === tabPanel.items.items.length || i === tabPanel.items.items.length - 1 && tabPanel.items.items[i].id === 'tbfill') i = 0;

// skip spacer
while (tabPanel.items.items[i].id === 'tbfill') i++;

tabPanel.setActiveTab(i);
}
}
,{
Expand Down
13 changes: 12 additions & 1 deletion app/model/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ Ext.define('Rambox.model.Service', {
name: 'muted'
,type: 'boolean'
,defaultValue: false
},{
},
{
name: 'displayTabUnreadCounter',
type: 'boolean',
defaultValue: true
},
{
name: 'includeInGlobalUnreadCounter',
type: 'boolean',
defaultValue: true
},
{
name: 'trust'
,type: 'boolean'
,defaultValue: false
Expand Down
6 changes: 4 additions & 2 deletions app/store/Services.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ Ext.define('Rambox.store.Services', {
,icon: service.get('type') !== 'custom' ? 'resources/icons/'+service.get('logo') : ( service.get('logo') === '' ? 'resources/icons/custom.png' : service.get('logo'))
,src: service.get('url')
,type: service.get('type')
,muted: service.get('muted')
,enabled: service.get('enabled')
,muted: service.get('muted'),
includeInGlobalUnreadCounter: service.get('includeInGlobalUnreadCounter'),
displayTabUnreadCounter: service.get('displayTabUnreadCounter'),
enabled: service.get('enabled')
,record: service
,tabConfig: {
service: service
Expand Down
30 changes: 19 additions & 11 deletions app/store/ServicesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.telegram.org/'
,type: 'messaging'
,titleBlink: true
,js_unread: 'function checkUnread(){var e=document.getElementsByClassName("im_dialog_badge badge"),t=0;for(i=0;i<e.length;i++)t+=parseInt(e[i].innerHTML.trim());updateBadge(t)}function updateBadge(e){document.title="("+e+") RamboxService"}setInterval(checkUnread,3000);'
,js_unread: 'function checkUnread(){var e=document.getElementsByClassName("im_dialog_badge badge"),t=0;for(i=0;i<e.length;i++)if(!e[i].classList.contains("im_dialog_badge_muted")){t+=parseInt(e[i].innerHTML.trim())}}function updateBadge(e){document.title="("+e+") RamboxService"}setInterval(checkUnread,3000);'
},
{
id: 'wechat'
Expand Down Expand Up @@ -459,7 +459,7 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'email'
},
{
id: ' irccloud'
id: 'irccloud'
,logo: 'irccloud.png'
,name: 'IRCCloud'
,description: 'IRCCloud is a modern IRC client that keeps you connected, with none of the baggage.'
Expand Down Expand Up @@ -662,14 +662,22 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'messaging'
},
{
id: 'xing',
logo: 'xing.png',
name: 'XING',
description: 'Career-oriented social networking',
url: 'https://www.xing.com/messages/conversations',
type: 'messaging',
js_unread: '(function() { let originalTitle = document.title; function checkUnread() { let count = null; let notificationElement = document.querySelector(\'[data-update="unread_conversations"]\'); if (notificationElement && notificationElement.style.display !== \'none\') { count = parseInt(notificationElement.textContent.trim(), 10); } updateBadge(count); } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();',
dont_update_unread_from_title: true
id: 'xing'
,logo: 'xing.png'
,name: 'XING'
,description: 'Career-oriented social networking'
,url: 'https://www.xing.com/messages/conversations'
,type: 'messaging'
,js_unread: '(function() { let originalTitle = document.title; function checkUnread() { let count = null; let notificationElement = document.querySelector(\'[data-update="unread_conversations"]\'); if (notificationElement && notificationElement.style.display !== \'none\') { count = parseInt(notificationElement.textContent.trim(), 10); } updateBadge(count); } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();'
,dont_update_unread_from_title: true
},
{
id: 'Workplace'
,logo: 'workplace.png'
,name: 'Workplace by Facebook'
,description: 'Connect everyone in your company and turn ideas into action. Through group discussion, a personalised News Feed, and voice and video calling, work together and get more done. Workplace is an ad-free space, separate from your personal Facebook account.'
,url: 'https://___.facebook.com/'
,type: 'messaging'
}
]
]
});
57 changes: 57 additions & 0 deletions app/util/Notifier.js
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);
};
}
}
});
75 changes: 75 additions & 0 deletions app/util/UnreadCounter.js
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();
}
}
});
Loading

0 comments on commit d07e321

Please sign in to comment.