diff --git a/app/model/README.md b/app/model/README.md
index 2446be32..fd11f488 100644
--- a/app/model/README.md
+++ b/app/model/README.md
@@ -1,29 +1,25 @@
-# Adding a service
-
-The available services are stored in the [ServicesList.js](../store/ServicesList.js).
+## Adding a service
+The available services are stored in the [ServiceList.js](app/store/ServicesList.js).
Structure of a service entry:
-| Name | Description | Required |
-| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
-| id | Unique identifier for the service, e.g. "**slack**" | yes |
-| logo | File name of the service logo located in `/resources/icons/`, e.g. "**slack.png**" | yes |
-| name | Visible name for the service, e.g. "**Slack**" | yes |
-| description | A short description of the service, e.g. "**Slack brings all your communication together...**" | yes |
-| url | URL of the service, e.g. "". "\_\_\_" may be used as a placeholder, that can be configured when adding a service. | yes |
-| type | Defines the type of the service. Must be one of `email` or `messaging`. | yes |
-| allow_popups | Set to `true` to allow popup windows for the service. | no |
-| note | Additional info to display when adding the service. | no |
-| manual_notifications | Set to `true` to let Rambox trigger notifications. Can be used for services that doesn't support browser notifications. | no |
-| js_unread | JavaScript code for setting the unread count (see below). | no |
-| dont_update_unread_from_title | Set to `true` to prevent updating the unread count from the window title (see below). | no |
-
-## Setting the unread count
+|Name|Description|Required|
+|---|---|---|
+|id|Unique identifier for the service, e.g. "slack"|yes|
+|logo|File name of the service logo located in "/resources/icons/", e.g. "slack.png"|yes|
+|name|Visible name for the service, e.g. "Slack"|yes|
+|description|A short description of the service, e.g. "Slack brings all your communication together..."|yes|
+|url|URL of the service, e.g. "https://\_\_\_.slack.com/". "\_\_\_" may be used as a placeholder, that can be configured when adding a service.|yes|
+|type|Defines the type of the service. Must be one of `email` or `messaging`.|yes|
+|allow_popups|Set to `true` to allow popup windows for the service.|no|
+|note|Additional info to display when adding the service.|no|
+|manual_notifications|Set to `true` to let Rambox trigger notifications. Can be used for services that doesn't support browser notifications.|no|
+|js_unread|JavaScript code for setting the unread count (see below).|no|
-While there is also a way to set the unread count by adding `(COUNT)` to the window title, this describes the preferred way of doing it:
+### Setting the unread count
-First set `dont_update_unread_from_title` in the service config to `true`.
+While by default the unread count is determined by looking for ` (COUNT)` to the window title, this describes the preferred way of doing it:
Code provided by `js_unread` will be injected into the service website.
You can retrieve the unread count in this JavaScript code e.g. by parsing elements.
-Set the unread count by calling `rambox.setUnreadCount(COUNT)` or clear it by calling `rambox.clearUnreadCount()`.
+Set the unread count by calling `rambox.setUnreadCount(COUNT)` or clear it by calling `rambox.clearUnreadCount()`.
diff --git a/app/model/ServiceList.js b/app/model/ServiceList.js
index a2c45e93..db337612 100644
--- a/app/model/ServiceList.js
+++ b/app/model/ServiceList.js
@@ -48,9 +48,5 @@ Ext.define('Rambox.model.ServiceList', {
name: 'custom_domain'
,type: 'boolean'
,defaultValue: false
- },{
- name: 'dont_update_unread_from_title'
- ,type: 'boolean'
- ,defaultValue: false
}]
});
diff --git a/app/store/ServicesList.js b/app/store/ServicesList.js
index 4c7727fc..e49f3dd2 100644
--- a/app/store/ServicesList.js
+++ b/app/store/ServicesList.js
@@ -29,7 +29,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.whatsapp.com/'
,type: 'messaging'
,js_unread: 'function checkUnread(){const elements = document.querySelectorAll(\'.CxUIE, .unread\');let count = 0;for (let i = 0; i < elements.length; i++) {if (elements[i].querySelectorAll(\'*[data-icon="muted"]\').length === 0) {count++;}}updateBadge(count);}function updateBadge(count){if(count && count>=1){rambox.setUnreadCount(count);}else{rambox.clearUnreadCount();}}setInterval(checkUnread, 1e3);'
- ,dont_update_unread_from_title: true
},
{
id: 'slack'
@@ -38,7 +37,7 @@ Ext.define('Rambox.store.ServicesList', {
,description: locale['services[1]']
,url: 'https://___.slack.com/'
,type: 'messaging'
- ,js_unread: 'function checkUnread(){var e=$(".p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)").length,a=0;$(".p-channel_sidebar__badge").each(function(){a+=isNaN(parseInt($(this).html()))?0:parseInt($(this).html())}),updateBadge(e,a)}function updateBadge(e,a){var n=a>0?"("+a+") ":e>0?"(•) ":"";document.title=n+originalTitle}var originalTitle=document.title;setInterval(checkUnread,3e3);'
+ ,js_unread: 'function checkUnread(){var e=$(".p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)").length,n=0;$(".p-channel_sidebar__badge").each(function(){n+=isNaN(parseInt($(this).html()))?0:parseInt($(this).html())}),count=0=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
},
{
@@ -98,7 +96,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.telegram.org/'
,type: 'messaging'
,js_unread: 'function checkUnread(){var e=document.getElementsByClassName("im_dialog_badge badge"),t=0;for(i=0;i=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
- ,dont_update_unread_from_title: true
},
{
id: 'wechat'
@@ -118,7 +115,6 @@ Ext.define('Rambox.store.ServicesList', {
,allow_popups: true
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("aim")[0];updateBadge(-1!=a.textContent.indexOf("(")&&(t=parseInt(a.textContent.replace(/[^0-9]/g,""))))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
,note: 'To enable desktop notifications, you have to go to Settings inside Gmail. Read more...'
- ,dont_update_unread_from_title: true
},
{
id: 'inbox'
@@ -149,7 +145,6 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'messaging'
,note: 'To enable desktop notifications, you have to go to Options inside GroupMe. To count unread messages, be sure to be in Chats.'
,js_unread: 'function checkUnread(){var a=document.querySelectorAll(".badge-count:not(.ng-hide)"),b=0;for(i=0;i=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
- ,dont_update_unread_from_title: true
},
{
id: 'grape'
@@ -514,7 +509,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://www.icloud.com/#mail'
,type: 'email'
,js_unread: 'function checkUnread(){updateBadge(document.querySelector(".current-app").querySelector(".sb-badge").style.display==="none"?0:parseInt(document.querySelector(".current-app").querySelector(".text").innerHTML.trim()))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
- ,dont_update_unread_from_title: true
},
{
id: 'rainloop'
@@ -644,7 +638,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://web.flock.co/'
,type: 'messaging'
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unreadMessages no-unread-mentions has-unread"),b=0;for(i=0;i=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
- ,dont_update_unread_from_title: true
},
{
@@ -671,7 +664,6 @@ Ext.define('Rambox.store.ServicesList', {
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: 'threema',
@@ -681,7 +673,6 @@ Ext.define('Rambox.store.ServicesList', {
url: 'https://web.threema.ch/',
type: 'messaging',
js_unread: '(function () { let unreadCount = 0; function checkUnread() { let newUnread = 0; try { let webClientService = angular.element(document.documentElement).injector().get(\'WebClientService\'); let conversations = webClientService.conversations.conversations; conversations.forEach(function(conversation) { newUnread += conversation.unreadCount; }); } catch (e) { } if (newUnread !== unreadCount) { unreadCount = newUnread; updateBadge(unreadCount); } } 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'
@@ -733,7 +724,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://app.zyptonite.com/'
,type: 'messaging'
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("z-messages"),b=0;for(i=0;i=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
- ,dont_update_unread_from_title: true
},
{
id: 'fastmail'
@@ -806,7 +796,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://___/chat'
,type: 'messaging'
,js_unread: 'function checkUnread(){updateBadge(parseInt(document.getElementsByClassName("sidebar-notification-indicator").length > 0 ? document.getElementsByClassName("sidebar-notification-indicator")[0].innerHTML : 0))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
- ,dont_update_unread_from_title: true
},
{
id: 'clocktweets'
@@ -824,7 +813,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://app.intercom.io'
,type: 'messaging'
,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unread")[0];updateBadge(t=a===undefined?0:parseInt(a.textContent.replace(/[^0-9]/g,"")))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
- ,dont_update_unread_from_title: true
},
{
id: 'allo'
@@ -834,7 +822,6 @@ Ext.define('Rambox.store.ServicesList', {
,url: 'https://allo.google.com/web'
,type: 'messaging'
,js_unread: 'function checkUnread(){var e=document.querySelectorAll(".hasUnread.conversation_item"),n=0;for(i=0;i=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);'
- ,dont_update_unread_from_title: true
},
{
id: 'Kune'
@@ -906,7 +893,6 @@ Ext.define('Rambox.store.ServicesList', {
,type: 'messaging'
,titleBlink: true
,manual_notifications: true
- ,dont_update_unread_from_title: true
,js_unread: 'function checkUnread(){updateBadge(document.querySelectorAll(".SSPGKf.EyyDtb.Q6oXP:not(.oCHqfe) .eM5l9e.FVKzAb").length)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);'
},
{
diff --git a/app/ux/WebView.js b/app/ux/WebView.js
index 03820aaf..daaffce9 100644
--- a/app/ux/WebView.js
+++ b/app/ux/WebView.js
@@ -477,14 +477,14 @@ Ext.define('Rambox.ux.WebView',{
/**
* Handles 'rambox.setUnreadCount' messages.
- * Sets the badge text if the event contains an integer as first argument.
+ * Sets the badge text if the event contains an integer or a '•' (indicating non-zero but unknown number of unreads) as first argument.
*
* @param event
*/
function handleSetUnreadCount(event) {
if (Array.isArray(event.args) === true && event.args.length > 0) {
var count = event.args[0];
- if (count === parseInt(count, 10)) {
+ if (count === parseInt(count, 10) || "•" === count) {
me.setUnreadCount(count);
}
}
@@ -497,9 +497,9 @@ Ext.define('Rambox.ux.WebView',{
});
/**
- * Register page title update event listener only for services that don't prevent it by setting 'dont_update_unread_from_title' to true.
+ * Register page title update event listener only for services that don't specify a js_unread
*/
- if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('dont_update_unread_from_title') !== true) {
+ if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('js_unread') === '' && me.record.get('js_unread') === '') {
webview.addEventListener("page-title-updated", function(e) {
var count = e.title.match(/\(([^)]+)\)/); // Get text between (...)
count = count ? count[1] : '0';