Mercurial > eldonilo > lightstring
comparison plugins/presence.js @ 32:8b739d4e094b
[presence] Don’t require the object to be passed.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 28 Jan 2012 04:02:10 +0100 |
parents | fbb08a31921d |
children | a118a7822410 |
comparison
equal
deleted
inserted
replaced
31:fbb08a31921d | 32:8b739d4e094b |
---|---|
22 //////////// | 22 //////////// |
23 (function() { | 23 (function() { |
24 var legal_types = ['error', 'probe', 'subscribe', 'subscribed', 'unavailable', 'unsubscribe', 'unsubscribed']; | 24 var legal_types = ['error', 'probe', 'subscribe', 'subscribed', 'unavailable', 'unsubscribe', 'unsubscribed']; |
25 | 25 |
26 Lightstring.stanza.presence = function(object) { | 26 Lightstring.stanza.presence = function(object) { |
27 var aPriority, aShow, aStatus; | 27 if (object) { |
28 var payloads = ""; | 28 var payloads = ""; |
29 var attributs = ""; | 29 var attributs = ""; |
30 if (object.type && legal_types.indexOf(object.type) !== -1) | |
31 attributs += " type='" + object.type + "'"; | |
30 | 32 |
31 if (object.type && legal_types.indexOf(object.type) !== -1) | 33 if (object.priority) |
32 attributs += " type='" + object.type + "'"; | 34 payloads += "<priority>" + object.priority + "</priority>"; |
33 | 35 |
34 if (object.priority) | 36 if (object.show) |
35 payloads += "<priority>" + object.priority + "</priority>"; | 37 payloads += "<show>" + object.show + "</show>"; |
36 | 38 |
37 if (object.show) | 39 if (object.status) |
38 payloads += "<show>" + object.show + "</show>"; | 40 payloads += "<status>" + object.status + "</status>"; |
39 | 41 |
40 if (object.status) | 42 if (object.payload) |
41 payloads += "<status>" + object.status + "</status>"; | 43 payloads += object.payload; |
42 | 44 |
43 if (object.payload) | 45 if (payloads) |
44 payloads += object.payload; | 46 return "<presence" + attributs + ">" + payloads + "</presence>"; |
47 else | |
48 return "<presence" + attributs + "/>"; | |
45 | 49 |
46 if (payloads) | 50 } else |
47 return "<presence" + attributs + ">" + payloads + "</presence>"; | 51 return "<presence/>"; |
48 else | |
49 return "<presence" + attributs + "/>"; | |
50 }; | 52 }; |
51 | 53 |
52 Lightstring.presence = function(aConnection, aPriority) { | 54 Lightstring.presence = function(aConnection, aObject) { |
53 aConnection.send(Lightstring.stanza.presence(aPriority)); | 55 aConnection.send(Lightstring.stanza.presence(aObject)); |
54 }; | 56 }; |
55 })(); | 57 })(); |