1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-12-26 09:28:49 -05:00

Add unread count in page title and app badge.

This commit is contained in:
Lance Stout 2013-09-27 09:47:54 -07:00
parent 56407a7d54
commit f21afd2b5d
4 changed files with 42 additions and 5 deletions

View File

@ -17,6 +17,7 @@ module.exports = HumanModel.define({
this.setActiveContact(this._activeContact);
}, this);
this.contacts.bind('change:unreadCount', this.updateUnreadCount, this);
app.state.bind('change:active', this.updateIdlePresence, this);
},
session: {
@ -113,5 +114,13 @@ module.exports = HumanModel.define({
}
app.api.sendPresence(update);
},
updateUnreadCount: function () {
var unreadCounts = this.contacts.pluck('unreadCount');
var count = unreadCounts.reduce(function (a, b) { return a + b; });
if (count === 0) {
count = '';
}
app.state.badge = '' + count;
}
});

View File

@ -13,6 +13,13 @@ module.exports = HumanModel.define({
self.focused = true;
self.markActive();
});
if (window.macgap) {
document.addEventListener('sleep', function () {
clearTimeout(this.idleTimer);
self.markInactive();
}, true);
}
this.markActive();
},
session: {
@ -21,7 +28,22 @@ module.exports = HumanModel.define({
connected: ['bool', true, false],
hasConnected: ['bool', true, false],
idleTimeout: ['number', true, 600000],
idleSince: 'date'
idleSince: 'date',
allowAlerts: ['bool', true, false],
badge: 'string',
pageTitle: 'string'
},
derived: {
title: {
deps: ['pageTitle', 'badge'],
fn: function () {
var base = this.pageTitle ? 'Otalk - ' + this.pageTitle : 'Otalk';
if (this.badge) {
return this.badge + ' • ' + base;
}
return base;
}
}
},
markActive: function () {
clearTimeout(this.idleTimer);

View File

@ -22,10 +22,7 @@ module.exports = HumanView.extend({
app.currentPage = this;
document.title = function () {
var title = _.result(self, 'title');
return title ? title + '- Otalk' : 'Otalk';
}();
app.state.pageTitle = _.result(self, 'title');
this.trigger('pageloaded');

View File

@ -9,6 +9,9 @@ var MUCListItem = require('../views/mucListItem');
module.exports = HumanView.extend({
template: templates.body,
initialize: function () {
this.listenTo(app.state, 'change:title', this.handleTitle);
},
events: {
'click a[href]': 'handleLinkClick',
'click .reconnect': 'handleReconnect'
@ -38,5 +41,11 @@ module.exports = HumanView.extend({
app.navigate(path);
return false;
}
},
handleTitle: function (e) {
document.title = app.state.title;
if (window.macgap) {
window.macgap.dock.badge = app.state.badge;
}
}
});