1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
//>>built
// wrapped by build app
define("dojox/xmpp/UserService", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
dojo.provide("dojox.xmpp.UserService");
dojo.declare("dojox.xmpp.UserService", null, {
constructor: function(xmppService){
this.session= xmppService;
},
getPersonalProfile: function(){
var req={
id: this.session.getNextIqId(),
type: 'get'
}
var request = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",req,false));
request.append(dojox.xmpp.util.createElement("query",{xmlns:"jabber:iq:private"},false));
request.append(dojox.xmpp.util.createElement("sunmsgr",{xmlsns:'sun:xmpp:properties'},true));
request.append("</query></iq>");
var def = this.session.dispatchPacket(request.toString(),"iq",req.id);
def.addCallback(this, "_onGetPersonalProfile");
},
setPersonalProfile: function(props){
var req={
id: this.session.getNextIqId(),
type: 'set'
}
var request = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",req,false));
request.append(dojox.xmpp.util.createElement("query",{xmlns:"jabber:iq:private"},false));
request.append(dojox.xmpp.util.createElement("sunmsgr",{xmlsns:'sun:xmpp:properties'},false));
for (var key in props){
request.append(dojox.xmpp.util.createElement("property",{name: key},false));
request.append(dojox.xmpp.util.createElement("value",{},false));
request.append(props[key]);
request.append("</value></props>");
}
request.append("</sunmsgr></query></iq>");
var def = this.session.dispatchPacket(request.toString(), "iq", req.id);
def.addCallback(this, "_onSetPersonalProfile");
},
_onSetPersonalProfile: function(response){
if(response.getAttribute('type')=='result'){
this.onSetPersonalProfile(response.getAttribute('id'));
}else if(response.getAttribute('type')=='error'){
var err = this.session.processXmppError(response);
this.onSetPersonalProfileFailure(err);
}
},
onSetPersonalProfile: function(id){},
onSetPersonalProfileFailure: function(err){},
_onGetPersonalProfile: function(profile){
if (profile.getAttribute('type')=='result'){
var props = {};
if (profile.hasChildNodes()){
var queryNode = profile.firstChild;
if ((queryNode.nodeName=="query")&&(queryNode.getAttribute('xmlns')=='jabber:iq:private')){
var sunNode = queryNode.firstChild;
if ((sunNode.nodeName=='query')&&(sunNode.getAttributes('xmlns')=='sun:xmpp:properties')){
for (var i=0; i<sunNode.childNodes.length;i++){
var n = sunNode.childNodes[i];
if(n.nodeName == 'property'){
var name = n.getAttribute('name');
var val = n.firstChild || "";
props[name]=val;
}
}
}
}
this.onGetPersonalProfile(props);
}
}else if (profile.getAttribute('type')=='error'){
var err = this.session.processXmppError(profile);
this.onGetPersonalProfileFailure(err);
}
return profile;
},
onGetPersonalProfile: function(profile){
//console.log("UserService::onGetPersonalProfile() ", profile);
},
onGetPersonalProfileFailure: function(err){
//console.log("UserService::onGetPersonalProfileFailure() ", err);
}
});
});
|