Skip to content

Commit f61d195

Browse files
committed
rebuild
2 parents 8bf6c6a + c8c4404 commit f61d195

File tree

4 files changed

+85
-46
lines changed

4 files changed

+85
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For correct work of JS SDK you must include the library in your html before `qu
2020

2121
```html
2222
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
23-
<script src="https://cdnjs.cloudflare.com/ajax/libs/quickblox/2.2.1/quickblox.min.js"></script>
23+
<script src="https://cdnjs.cloudflare.com/ajax/libs/quickblox/2.2.2/quickblox.min.js"></script>
2424
```
2525

2626
## Bower and RequireJS

quickblox.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/QB-ChatSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ describe('Chat API', function() {
245245
//
246246
it("can create new list with items", function(done) {
247247
var usersObj = [
248-
{user_id: 1111111, action: "deny"},
248+
{user_id: 1111111, action: "deny", mutualBlock: true},
249249
{user_id: 1010101, action: "allow"}
250250
];
251251

src/modules/qbChat.js

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,55 +1060,93 @@ PrivacyListProxy.prototype = {
10601060
},
10611061

10621062
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+
}
10821079

1083-
listKeys = Object.keys(listObj);
1080+
/** Filled listUserId */
1081+
listUserId = Object.keys(listPrivacy);
10841082

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+
});
10901093

1094+
function createPrivacyItem(iq, params){
10911095
iq.c('item', {
10921096
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+
}
11011107

1108+
function createPrivacyItemMutal(iq, params) {
11021109
iq.c('item', {
11031110
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+
}
11121150
}
11131151

11141152
connection.sendIQ(iq, function(stanzaResult) {
@@ -1121,6 +1159,7 @@ PrivacyListProxy.prototype = {
11211159
callback(Utils.getError(408));
11221160
}
11231161
});
1162+
11241163
},
11251164

11261165
update: function(list, callback) {

0 commit comments

Comments
 (0)