@@ -1060,55 +1060,93 @@ PrivacyListProxy.prototype = {
1060
1060
} ,
1061
1061
1062
1062
create : function ( list , callback ) {
1063
- var iq , self = this ,
1064
- userId , userJid ,
1065
- userAction , userMuc ,
1066
- listObj = { } ,
1067
- listKeys = [ ] ;
1068
-
1069
- iq = $iq ( {
1070
- from : connection . jid ,
1071
- type : 'set' ,
1072
- id : connection . getUniqueId ( 'edit' )
1073
- } ) . c ( 'query' , {
1074
- xmlns : Strophe . NS . PRIVACY_LIST
1075
- } ) . c ( 'list' , {
1076
- name : list . name
1077
- } ) ;
1078
-
1079
- $ ( list . items ) . each ( function ( e , i ) {
1080
- listObj [ i . user_id ] = i . action ;
1081
- } ) ;
1063
+ var self = this ,
1064
+ userId , userJid , userMuc ,
1065
+ userAction ,
1066
+ mutualBlock ,
1067
+ listPrivacy = { } ,
1068
+ listUserId = [ ] ;
1069
+
1070
+ /** Filled listPrivacys */
1071
+ for ( var i = list . items . length - 1 ; i >= 0 ; i -- ) {
1072
+ var user = list . items [ i ] ;
1073
+
1074
+ listPrivacy [ user . user_id ] = {
1075
+ action : user . action ,
1076
+ mutualBlock : user . mutualBlock === true ? true : false
1077
+ } ;
1078
+ }
1082
1079
1083
- listKeys = Object . keys ( listObj ) ;
1080
+ /** Filled listUserId */
1081
+ listUserId = Object . keys ( listPrivacy ) ;
1084
1082
1085
- for ( var index = 0 , i = 0 , len = listKeys . length ; index < len ; index ++ , i = i + 2 ) {
1086
- userId = listKeys [ index ] ;
1087
- userAction = listObj [ userId ] ;
1088
- userJid = self . helpers . jidOrUserId ( parseInt ( userId , 10 ) ) ;
1089
- userMuc = self . helpers . getUserNickWithMucDomain ( userId ) ;
1083
+ var iqParams = {
1084
+ type : 'set' ,
1085
+ from : connection . jid ,
1086
+ id : connection . getUniqueId ( 'edit' )
1087
+ } ,
1088
+ iq = $iq ( iqParams ) . c ( 'query' , {
1089
+ xmlns : Strophe . NS . PRIVACY_LIST
1090
+ } ) . c ( 'list' , {
1091
+ name : list . name
1092
+ } ) ;
1090
1093
1094
+ function createPrivacyItem ( iq , params ) {
1091
1095
iq . c ( 'item' , {
1092
1096
type : 'jid' ,
1093
- value : userJid ,
1094
- action : userAction ,
1095
- order : i + 1
1096
- } ) . c ( 'message' , {
1097
- } ) . up ( ) . c ( 'presence-in' , {
1098
- } ) . up ( ) . c ( 'presence-out' , {
1099
- } ) . up ( ) . c ( 'iq' , {
1100
- } ) . up ( ) . up ( ) ;
1097
+ value : params . jidOrMuc ,
1098
+ action : params . userAction ,
1099
+ order : params . order
1100
+ } ) . c ( 'message' , { } )
1101
+ . up ( ) . c ( 'presence-in' , { } )
1102
+ . up ( ) . c ( 'presence-out' , { } )
1103
+ . up ( ) . c ( 'iq' , { } )
1104
+ . up ( ) . up ( ) ;
1105
+ return iq ;
1106
+ }
1101
1107
1108
+ function createPrivacyItemMutal ( iq , params ) {
1102
1109
iq . c ( 'item' , {
1103
1110
type : 'jid' ,
1104
- value : userMuc ,
1105
- action : userAction ,
1106
- order : i + 2
1107
- } ) . c ( 'message' , {
1108
- } ) . up ( ) . c ( 'presence-in' , {
1109
- } ) . up ( ) . c ( 'presence-out' , {
1110
- } ) . up ( ) . c ( 'iq' , {
1111
- } ) . up ( ) . up ( ) ;
1111
+ value : params . jidOrMuc ,
1112
+ action : params . userAction ,
1113
+ order : params . order
1114
+ } ) . up ( ) ;
1115
+
1116
+ return iq ;
1117
+ }
1118
+
1119
+ for ( var index = 0 , i = 0 , len = listUserId . length ; index < len ; index ++ , i = i + 2 ) {
1120
+ userId = listUserId [ index ] ;
1121
+ mutualBlock = listPrivacy [ userId ] . mutualBlock ;
1122
+
1123
+ userAction = listPrivacy [ userId ] . action ;
1124
+ userJid = self . helpers . jidOrUserId ( parseInt ( userId , 10 ) ) ;
1125
+ userMuc = self . helpers . getUserNickWithMucDomain ( userId ) ;
1126
+
1127
+ if ( mutualBlock && userAction === 'deny' ) {
1128
+ iq = createPrivacyItemMutal ( iq , {
1129
+ order : i + 1 ,
1130
+ jidOrMuc : userJid ,
1131
+ userAction : userAction
1132
+ } ) ;
1133
+ iq = createPrivacyItemMutal ( iq , {
1134
+ order : i + 2 ,
1135
+ jidOrMuc : userMuc ,
1136
+ userAction : userAction
1137
+ } ) . up ( ) . up ( ) ;
1138
+ } else {
1139
+ iq = createPrivacyItem ( iq , {
1140
+ order : i + 1 ,
1141
+ jidOrMuc : userJid ,
1142
+ userAction : userAction
1143
+ } ) ;
1144
+ iq = createPrivacyItem ( iq , {
1145
+ order : i + 2 ,
1146
+ jidOrMuc : userMuc ,
1147
+ userAction : userAction
1148
+ } ) ;
1149
+ }
1112
1150
}
1113
1151
1114
1152
connection . sendIQ ( iq , function ( stanzaResult ) {
@@ -1121,6 +1159,7 @@ PrivacyListProxy.prototype = {
1121
1159
callback ( Utils . getError ( 408 ) ) ;
1122
1160
}
1123
1161
} ) ;
1162
+
1124
1163
} ,
1125
1164
1126
1165
update : function ( list , callback ) {
0 commit comments