1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-29 04:32:15 -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.setActiveContact(this._activeContact);
}, this); }, this);
this.contacts.bind('change:unreadCount', this.updateUnreadCount, this);
app.state.bind('change:active', this.updateIdlePresence, this); app.state.bind('change:active', this.updateIdlePresence, this);
}, },
session: { session: {
@ -113,5 +114,13 @@ module.exports = HumanModel.define({
} }
app.api.sendPresence(update); 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.focused = true;
self.markActive(); self.markActive();
}); });
if (window.macgap) {
document.addEventListener('sleep', function () {
clearTimeout(this.idleTimer);
self.markInactive();
}, true);
}
this.markActive(); this.markActive();
}, },
session: { session: {
@ -21,7 +28,22 @@ module.exports = HumanModel.define({
connected: ['bool', true, false], connected: ['bool', true, false],
hasConnected: ['bool', true, false], hasConnected: ['bool', true, false],
idleTimeout: ['number', true, 600000], 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 () { markActive: function () {
clearTimeout(this.idleTimer); clearTimeout(this.idleTimer);

View File

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

View File

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