Commit 905f4e4d authored by JC Brand's avatar JC Brand

Propagate offline state to other clients.

parent 99f1a9c9
...@@ -163,6 +163,7 @@ ...@@ -163,6 +163,7 @@
Strophe.addNamespace('ROSTERX', 'http://jabber.org/protocol/rosterx'); Strophe.addNamespace('ROSTERX', 'http://jabber.org/protocol/rosterx');
Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm'); Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm');
Strophe.addNamespace('XFORM', 'jabber:x:data'); Strophe.addNamespace('XFORM', 'jabber:x:data');
Strophe.addNamespace('CONVERSEJS', 'http://conversejs.org/protocol/custom');
// Add Strophe Statuses // Add Strophe Statuses
var i = 0; var i = 0;
...@@ -4645,11 +4646,14 @@ ...@@ -4645,11 +4646,14 @@
var jid = presence.getAttribute('from'), var jid = presence.getAttribute('from'),
bare_jid = Strophe.getBareJidFromJid(jid), bare_jid = Strophe.getBareJidFromJid(jid),
resource = Strophe.getResourceFromJid(jid), resource = Strophe.getResourceFromJid(jid),
chat_status = $presence.find('show').text() || 'online', chat_status = $presence.find('show').text() ||
presence_type === 'unavailable' && 'offline' ||
'online',
status_message = $presence.find('status'), status_message = $presence.find('status'),
contact = this.get(bare_jid); contact = this.get(bare_jid);
if (this.isSelf(bare_jid)) { if (this.isSelf(bare_jid)) {
if ((converse.connection.jid !== jid)&&(presence_type !== 'unavailable')) { if ((converse.connection.jid !== jid) ||
(presence_type === 'unavailable') && $presence.has('customstatus[xmlns="'+Strophe.NS.CONVERSEJS+'"]').length) {
// Another resource has changed its status, we'll update ours as well. // Another resource has changed its status, we'll update ours as well.
converse.xmppstatus.save({'status': chat_status}); converse.xmppstatus.save({'status': chat_status});
if (status_message.length) { converse.xmppstatus.save({'status_message': status_message.text()}); } if (status_message.length) { converse.xmppstatus.save({'status_message': status_message.text()}); }
...@@ -4682,8 +4686,7 @@ ...@@ -4682,8 +4686,7 @@
} }
}); });
this.RosterGroup = Backbone.Model.extend({ this.RosterGroup = Backbone.Model.extend({ initialize: function (attributes, options) {
initialize: function (attributes, options) {
this.set(_.extend({ this.set(_.extend({
description: DESC_GROUP_TOGGLE, description: DESC_GROUP_TOGGLE,
state: OPENED state: OPENED
...@@ -5261,15 +5264,15 @@ ...@@ -5261,15 +5264,15 @@
}, },
constructPresence: function (type, status_message) { constructPresence: function (type, status_message) {
var presence;
if (typeof type === 'undefined') { if (typeof type === 'undefined') {
type = this.get('status') || 'online'; type = this.get('status') || 'online';
} }
if (typeof status_message === 'undefined') { if (typeof status_message === 'undefined') {
status_message = this.get('status_message'); status_message = this.get('status_message');
} }
var presence;
// Most of these presence types are actually not explicitly sent, // Most of these presence types are actually not explicitly sent,
// but I add all of them here fore reference and future proofing. // but I add all of them here for reference and future proofing.
if ((type === 'unavailable') || if ((type === 'unavailable') ||
(type === 'probe') || (type === 'probe') ||
(type === 'error') || (type === 'error') ||
...@@ -5283,6 +5286,13 @@ ...@@ -5283,6 +5286,13 @@
if (status_message) { if (status_message) {
presence.c('show').t(type); presence.c('show').t(type);
} }
// The user has specifically set their status to offline.
// We need to make sure to indicate this, so that it
// gets propagated to other connected converse.js instances
// (usually other browser tabs).
// XXX: The custom:status element could potentially also be
// used to implement an 'invisible' state.
presence.c('customstatus', {xmlns: Strophe.NS.CONVERSEJS}).t(type);
} else { } else {
if (type === 'online') { if (type === 'online') {
presence = $pres(); presence = $pres();
......
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