Commit 6de07c5c authored by Ariel Fuggini's avatar Ariel Fuggini Committed by JC Brand

Adds setting to toggle showing unread message counter in page title

parent cf94a519
......@@ -1954,6 +1954,13 @@ Converse render the emojis with `Twemoji <https://twemoji.twitter.com/>`_.
See also `emoji_image_path`_.
update_title
------------
* Default: ``true``
Determines whether to shows unread messages counter in the page title.
visible_toolbar_buttons
-----------------------
......
......@@ -1058,16 +1058,16 @@ describe("Chatboxes", function () {
await mock.openControlBox(_converse);
expect(document.title).toBe('Converse Tests');
_converse.api.settings.set('update_title', false);
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
const previous_state = _converse.windowState;
const message = 'This message will increment the message counter';
const msg = $msg({
from: sender_jid,
to: _converse.connection.jid,
type: 'chat',
id: u.getUniqueId()
}).c('body').t(message).up()
}).c('body').t('This message will increment the message counter').up()
.c('active', {'xmlns': Strophe.NS.CHATSTATES}).tree();
_converse.windowState = 'hidden';
......@@ -1078,8 +1078,21 @@ describe("Chatboxes", function () {
await _converse.handleMessageStanza(msg);
expect(_converse.incrementMsgCounter).toHaveBeenCalled();
expect(_converse.clearMsgCounter).not.toHaveBeenCalled();
expect(document.title).toBe('Messages (1) Converse Tests');
expect(document.title).toBe('Converse Tests');
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
_converse.api.settings.set('update_title', true);
const msg2 = $msg({
from: sender_jid,
to: _converse.connection.jid,
type: 'chat',
id: u.getUniqueId()
}).c('body').t('This message increment the message counter AND update the page title').up()
.c('active', {'xmlns': Strophe.NS.CHATSTATES}).tree();
await _converse.handleMessageStanza(msg2);
expect(document.title).toBe('Messages (2) Converse Tests');
_converse.windowSate = previous_state;
done();
}));
......
......@@ -32,32 +32,40 @@ converse.plugins.add('converse-chatboxes', {
'privateChatsAutoJoined'
]);
api.settings.extend({
'update_title': true
});
let msg_counter = 0;
const favicon = new Favico({type : 'circle', position: 'up', animation: 'none'});
_converse.incrementMsgCounter = function () {
msg_counter += 1;
favicon.badge(msg_counter);
const title = document.title;
if (!title) {
return;
}
if (title.search(/^Messages \(\d+\) /) === -1) {
document.title = `Messages (${msg_counter}) ${title}`;
} else {
document.title = title.replace(/^Messages \(\d+\) /, `Messages (${msg_counter}) `);
if (api.settings.get('update_title')) {
const title = document.title;
if (!title) {
return;
}
if (title.search(/^Messages \(\d+\) /) === -1) {
document.title = `Messages (${msg_counter}) ${title}`;
} else {
document.title = title.replace(/^Messages \(\d+\) /, `Messages (${msg_counter}) `);
}
}
};
_converse.clearMsgCounter = function () {
msg_counter = 0;
favicon.badge(msg_counter);
const title = document.title;
if (!title) {
return;
}
if (title.search(/^Messages \(\d+\) /) !== -1) {
document.title = title.replace(/^Messages \(\d+\) /, "");
if (api.settings.get('update_title')) {
const title = document.title;
if (!title) {
return;
}
if (title.search(/^Messages \(\d+\) /) !== -1) {
document.title = title.replace(/^Messages \(\d+\) /, "");
}
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment