@@ -17,7 +17,7 @@ if (isBrowser) {
1717 // add extra namespaces for Strophe
1818 Strophe . addNamespace ( 'CARBONS' , 'urn:xmpp:carbons:2' ) ;
1919 Strophe . addNamespace ( 'CHAT_MARKERS' , 'urn:xmpp:chat-markers:0' ) ;
20- Strophe . addNamespace ( 'BLOCKING_COMMAND ' , 'urn:xmpp:blocking ' ) ;
20+ Strophe . addNamespace ( 'PRIVACY_LIST ' , 'jabber:iq:privacy ' ) ;
2121 Strophe . addNamespace ( 'CHAT_STATES' , 'http://jabber.org/protocol/chatstates' ) ;
2222}
2323
@@ -38,6 +38,7 @@ function ChatProxy(service, webrtcModule, conn) {
3838 if ( isBrowser ) {
3939 this . roster = new RosterProxy ( service ) ;
4040 this . muc = new MucProxy ( service ) ;
41+ this . privacylist = new PrivacyListProxy ( service ) ;
4142
4243 this . _isLogout = false ;
4344 this . _isDisconnected = false ;
@@ -121,9 +122,9 @@ function ChatProxy(service, webrtcModule, conn) {
121122 return true ;
122123 }
123124
124- // autosend 'received' status
125+ // autosend 'received' status (ignore messages from self)
125126 //
126- if ( markable ) {
127+ if ( markable && userId != self . helpers . getIdFromNode ( connection . jid ) ) {
127128 var params = {
128129 messageId : messageId ,
129130 userId : userId ,
@@ -226,6 +227,22 @@ function ChatProxy(service, webrtcModule, conn) {
226227 } ;
227228
228229 this . _onIQ = function ( stanza ) {
230+ // var type = stanza.getAttribute('type'),
231+ // typeId = stanza.getAttribute('id').split(':')[1];
232+
233+ // if (typeof self.onListEditListener === 'function' && typeId === 'push') {
234+ // var listName = (stanza.getElementsByTagName('list')[0]).getAttribute('name');
235+
236+ // var iq = $iq({
237+ // from: connection.jid,
238+ // type: 'result',
239+ // id: connection.getUniqueId('push')
240+ // });
241+
242+ // connection.sendIQ(iq);
243+
244+ // Utils.safeCallbackCall(self.onListEditListener(listName));
245+ // }
229246
230247 // we must return true to keep the handler alive
231248 // returning false would remove it after it finishes
@@ -914,6 +931,257 @@ MucProxy.prototype = {
914931} ;
915932
916933
934+ /* Chat module: Privacy list
935+ *
936+ * Privacy list
937+ * http://xmpp.org/extensions/xep-0016.html
938+ *
939+ ----------------------------------------------------------------------------- */
940+ function PrivacyListProxy ( service ) {
941+ this . service = service ;
942+ this . helpers = new Helpers ( ) ;
943+ }
944+
945+ PrivacyListProxy . prototype = {
946+
947+ getNames : function ( callback ) {
948+ var iq = $iq ( {
949+ from : connection . jid ,
950+ type : 'get' ,
951+ id : connection . getUniqueId ( 'getNames' )
952+ } ) . c ( 'query' , {
953+ xmlns : Strophe . NS . PRIVACY_LIST
954+ } ) ;
955+
956+ connection . sendIQ ( iq , function ( stanzaResult ) {
957+ var allNames = [ ] , namesList = { } ,
958+ defaultList = stanzaResult . getElementsByTagName ( 'default' ) ,
959+ activeList = stanzaResult . getElementsByTagName ( 'active' ) ,
960+ allLists = stanzaResult . getElementsByTagName ( 'list' ) ,
961+ defaultName = defaultList [ 0 ] . getAttribute ( 'name' ) ,
962+ activeName = activeList [ 0 ] . getAttribute ( 'name' ) ;
963+ for ( var i = 0 , len = allLists . length ; i < len ; i ++ ) {
964+ allNames . push ( allLists [ i ] . getAttribute ( 'name' ) ) ;
965+ }
966+ namesList = {
967+ 'default' : defaultName ,
968+ 'active' : activeName ,
969+ 'names' : allNames
970+ } ;
971+ callback ( null , namesList ) ;
972+ } , function ( stanzaError ) {
973+ if ( stanzaError ) {
974+ var errorObject = getErrorFromXMLNode ( stanzaError ) ;
975+ callback ( errorObject , null ) ;
976+ } else {
977+ callback ( getError ( 408 ) , null ) ;
978+ }
979+ } ) ;
980+ } ,
981+
982+ getList : function ( name , callback ) {
983+ var iq , self = this ,
984+ items , userJid , userId ,
985+ usersList = [ ] , list = { } ;
986+
987+ iq = $iq ( {
988+ from : connection . jid ,
989+ type : 'get' ,
990+ id : connection . getUniqueId ( 'getlist' )
991+ } ) . c ( 'query' , {
992+ xmlns : Strophe . NS . PRIVACY_LIST
993+ } ) . c ( 'list' , {
994+ name : name
995+ } ) ;
996+
997+ connection . sendIQ ( iq , function ( stanzaResult ) {
998+ items = stanzaResult . getElementsByTagName ( 'item' ) ;
999+ for ( var i = 0 , len = items . length ; i < len ; i = i + 2 ) {
1000+ userJid = items [ i ] . getAttribute ( 'value' ) ,
1001+ userId = self . helpers . getIdFromNode ( userJid ) ;
1002+ usersList . push ( {
1003+ user_id : userId ,
1004+ action : items [ i ] . getAttribute ( 'action' )
1005+ } ) ;
1006+ }
1007+ list = {
1008+ name : name ,
1009+ items : usersList
1010+ } ;
1011+ callback ( null , list ) ;
1012+ } , function ( stanzaError ) {
1013+ if ( stanzaError ) {
1014+ var errorObject = getErrorFromXMLNode ( stanzaError ) ;
1015+ callback ( errorObject , null ) ;
1016+ } else {
1017+ callback ( getError ( 408 ) , null ) ;
1018+ }
1019+ } ) ;
1020+ } ,
1021+
1022+ create : function ( list , callback ) {
1023+ var iq , self = this ,
1024+ userId , userJid ,
1025+ userAction , userMuc ,
1026+ listObj = { } ,
1027+ listKeys = [ ] ;
1028+
1029+ iq = $iq ( {
1030+ from : connection . jid ,
1031+ type : 'set' ,
1032+ id : connection . getUniqueId ( 'edit' )
1033+ } ) . c ( 'query' , {
1034+ xmlns : Strophe . NS . PRIVACY_LIST
1035+ } ) . c ( 'list' , {
1036+ name : list . name
1037+ } ) ;
1038+
1039+ $ ( list . items ) . each ( function ( e , i ) {
1040+ listObj [ i . user_id ] = i . action ;
1041+ } ) ;
1042+
1043+ listKeys = Object . keys ( listObj ) ;
1044+
1045+ for ( var index = 0 , i = 0 , len = listKeys . length ; index < len ; index ++ , i = i + 2 ) {
1046+ userId = listKeys [ index ] ;
1047+ userAction = listObj [ userId ] ;
1048+ userJid = self . helpers . jidOrUserId ( parseInt ( userId , 10 ) ) ;
1049+ userMuc = self . helpers . getUserNickWithMucDomain ( userId ) ;
1050+
1051+ iq . c ( 'item' , {
1052+ type : 'jid' ,
1053+ value : userJid ,
1054+ action : userAction ,
1055+ order : i + 1
1056+ } ) . c ( 'message' , {
1057+ } ) . up ( ) . c ( 'presence-in' , {
1058+ } ) . up ( ) . c ( 'presence-out' , {
1059+ } ) . up ( ) . c ( 'iq' , {
1060+ } ) . up ( ) . up ( ) ;
1061+
1062+ iq . c ( 'item' , {
1063+ type : 'jid' ,
1064+ value : userMuc ,
1065+ action : userAction ,
1066+ order : i + 2
1067+ } ) . c ( 'message' , {
1068+ } ) . up ( ) . c ( 'presence-in' , {
1069+ } ) . up ( ) . c ( 'presence-out' , {
1070+ } ) . up ( ) . c ( 'iq' , {
1071+ } ) . up ( ) . up ( ) ;
1072+ }
1073+
1074+ connection . sendIQ ( iq , function ( stanzaResult ) {
1075+ callback ( null ) ;
1076+ } , function ( stanzaError ) {
1077+ if ( stanzaError ) {
1078+ var errorObject = getErrorFromXMLNode ( stanzaError ) ;
1079+ callback ( errorObject ) ;
1080+ } else {
1081+ callback ( getError ( 408 ) ) ;
1082+ }
1083+ } ) ;
1084+ } ,
1085+
1086+ update : function ( list , callback ) {
1087+ var self = this , copyList = list ;
1088+
1089+ self . getList ( copyList . name , function ( error , response ) {
1090+ if ( error ) {
1091+ callback ( error , null ) ;
1092+ } else {
1093+ var oldArray = response . items ,
1094+ newArray = copyList . items ,
1095+ updatedArray = [ ] ,
1096+ createList = { } ;
1097+
1098+ updatedArray = $ . merge ( oldArray , newArray ) ;
1099+ copyList . items = updatedArray ;
1100+ createList = copyList ;
1101+
1102+ self . create ( createList , function ( error , response ) {
1103+ if ( error ) {
1104+ callback ( error , null ) ;
1105+ } else {
1106+ callback ( null , createList ) ;
1107+ }
1108+ } ) ;
1109+ }
1110+ } ) ;
1111+ } ,
1112+
1113+ delete : function ( name , callback ) {
1114+ var iq = $iq ( {
1115+ from : connection . jid ,
1116+ type : 'set' ,
1117+ id : connection . getUniqueId ( 'remove' )
1118+ } ) . c ( 'query' , {
1119+ xmlns : Strophe . NS . PRIVACY_LIST
1120+ } ) . c ( 'list' , {
1121+ name : name ? name : ''
1122+ } ) ;
1123+
1124+ connection . sendIQ ( iq , function ( stanzaResult ) {
1125+ callback ( null ) ;
1126+ } , function ( stanzaError ) {
1127+ if ( stanzaError ) {
1128+ var errorObject = getErrorFromXMLNode ( stanzaError ) ;
1129+ callback ( errorObject ) ;
1130+ } else {
1131+ callback ( getError ( 408 ) ) ;
1132+ }
1133+ } ) ;
1134+ } ,
1135+
1136+ setAsDefault : function ( name , callback ) {
1137+ var iq = $iq ( {
1138+ from : connection . jid ,
1139+ type : 'set' ,
1140+ id : connection . getUniqueId ( 'default' )
1141+ } ) . c ( 'query' , {
1142+ xmlns : Strophe . NS . PRIVACY_LIST
1143+ } ) . c ( 'default' , {
1144+ name : name ? name : ''
1145+ } ) ;
1146+
1147+ connection . sendIQ ( iq , function ( stanzaResult ) {
1148+ callback ( null ) ;
1149+ } , function ( stanzaError ) {
1150+ if ( stanzaError ) {
1151+ var errorObject = getErrorFromXMLNode ( stanzaError ) ;
1152+ callback ( errorObject ) ;
1153+ } else {
1154+ callback ( getError ( 408 ) ) ;
1155+ }
1156+ } ) ;
1157+ } ,
1158+
1159+ setAsActive : function ( name , callback ) {
1160+ var iq = $iq ( {
1161+ from : connection . jid ,
1162+ type : 'set' ,
1163+ id : connection . getUniqueId ( 'active' )
1164+ } ) . c ( 'query' , {
1165+ xmlns : Strophe . NS . PRIVACY_LIST
1166+ } ) . c ( 'active' , {
1167+ name : name ? name : ''
1168+ } ) ;
1169+
1170+ connection . sendIQ ( iq , function ( stanzaResult ) {
1171+ callback ( null ) ;
1172+ } , function ( stanzaError ) {
1173+ if ( stanzaError ) {
1174+ var errorObject = getErrorFromXMLNode ( stanzaError ) ;
1175+ callback ( errorObject ) ;
1176+ } else {
1177+ callback ( getError ( 408 ) ) ;
1178+ }
1179+ } ) ;
1180+ }
1181+
1182+ } ;
1183+
1184+
9171185/* Chat module: History
9181186----------------------------------------------------------------------------- */
9191187
0 commit comments