Skip to content

Commit 8aa5d3d

Browse files
authored
Merge pull request #155 from QuickBlox/privacyListFix
add the MutualBlock flag
2 parents fd384fd + f9879d2 commit 8aa5d3d

File tree

6 files changed

+94
-55
lines changed

6 files changed

+94
-55
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "2.2.1",
4+
"version": "2.2.2",
55
"homepage": "https://quickblox.com/developers/Javascript",
66
"main": "quickblox.js",
77
"license": "Apache 2.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "2.2.1",
4+
"version": "2.2.2",
55
"homepage": "https://quickblox.com/developers/Javascript",
66
"main": "src/qbMain.js",
77
"license": [

quickblox.min.js

Lines changed: 10 additions & 10 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
@@ -1054,55 +1054,93 @@ PrivacyListProxy.prototype = {
10541054
},
10551055

10561056
create: function(list, callback) {
1057-
var iq, self = this,
1058-
userId, userJid,
1059-
userAction, userMuc,
1060-
listObj = {},
1061-
listKeys = [];
1062-
1063-
iq = $iq({
1064-
from: connection.jid,
1065-
type: 'set',
1066-
id: connection.getUniqueId('edit')
1067-
}).c('query', {
1068-
xmlns: Strophe.NS.PRIVACY_LIST
1069-
}).c('list', {
1070-
name: list.name
1071-
});
1072-
1073-
$(list.items).each(function(e, i){
1074-
listObj[i.user_id] = i.action;
1075-
});
1057+
var self = this,
1058+
userId, userJid, userMuc,
1059+
userAction,
1060+
mutualBlock,
1061+
listPrivacy = {},
1062+
listUserId = [];
1063+
1064+
/** Filled listPrivacys */
1065+
for (var i = list.items.length - 1; i >= 0; i--) {
1066+
var user = list.items[i];
1067+
1068+
listPrivacy[user.user_id] = {
1069+
action: user.action,
1070+
mutualBlock: user.mutualBlock === true ? true : false
1071+
};
1072+
}
10761073

1077-
listKeys = Object.keys(listObj);
1074+
/** Filled listUserId */
1075+
listUserId = Object.keys(listPrivacy);
10781076

1079-
for (var index = 0, i = 0, len = listKeys.length; index < len; index++, i=i+2) {
1080-
userId = listKeys[index];
1081-
userAction = listObj[userId];
1082-
userJid = self.helpers.jidOrUserId(parseInt(userId, 10));
1083-
userMuc = self.helpers.getUserNickWithMucDomain(userId);
1077+
var iqParams = {
1078+
type: 'set',
1079+
from: connection.jid,
1080+
id: connection.getUniqueId('edit')
1081+
},
1082+
iq = $iq(iqParams).c('query', {
1083+
xmlns: Strophe.NS.PRIVACY_LIST
1084+
}).c('list', {
1085+
name: list.name
1086+
});
10841087

1088+
function createPrivacyItem(iq, params){
10851089
iq.c('item', {
10861090
type: 'jid',
1087-
value: userJid,
1088-
action: userAction,
1089-
order: i+1
1090-
}).c('message', {
1091-
}).up().c('presence-in', {
1092-
}).up().c('presence-out', {
1093-
}).up().c('iq', {
1094-
}).up().up();
1091+
value: params.jidOrMuc,
1092+
action: params.userAction,
1093+
order: params.order
1094+
}).c('message', {})
1095+
.up().c('presence-in', {})
1096+
.up().c('presence-out', {})
1097+
.up().c('iq', {})
1098+
.up().up();
1099+
return iq;
1100+
}
10951101

1102+
function createPrivacyItemMutal(iq, params) {
10961103
iq.c('item', {
10971104
type: 'jid',
1098-
value: userMuc,
1099-
action: userAction,
1100-
order: i+2
1101-
}).c('message', {
1102-
}).up().c('presence-in', {
1103-
}).up().c('presence-out', {
1104-
}).up().c('iq', {
1105-
}).up().up();
1105+
value: params.jidOrMuc,
1106+
action: params.userAction,
1107+
order: params.order
1108+
}).up();
1109+
1110+
return iq;
1111+
}
1112+
1113+
for (var index = 0, i = 0, len = listUserId.length; index < len; index++, i=i+2) {
1114+
userId = listUserId[index];
1115+
mutualBlock = listPrivacy[userId].mutualBlock;
1116+
1117+
userAction = listPrivacy[userId].action;
1118+
userJid = self.helpers.jidOrUserId(parseInt(userId, 10));
1119+
userMuc = self.helpers.getUserNickWithMucDomain(userId);
1120+
1121+
if(mutualBlock && userAction === 'deny'){
1122+
iq = createPrivacyItemMutal(iq, {
1123+
order: i+1,
1124+
jidOrMuc: userJid,
1125+
userAction: userAction
1126+
});
1127+
iq = createPrivacyItemMutal(iq, {
1128+
order: i+2,
1129+
jidOrMuc: userMuc,
1130+
userAction: userAction
1131+
}).up().up();
1132+
} else {
1133+
iq = createPrivacyItem(iq, {
1134+
order: i+1,
1135+
jidOrMuc: userJid,
1136+
userAction: userAction
1137+
});
1138+
iq = createPrivacyItem(iq, {
1139+
order: i+2,
1140+
jidOrMuc: userMuc,
1141+
userAction: userAction
1142+
});
1143+
}
11061144
}
11071145

11081146
connection.sendIQ(iq, function(stanzaResult) {
@@ -1115,6 +1153,7 @@ PrivacyListProxy.prototype = {
11151153
callback(Utils.getError(408));
11161154
}
11171155
});
1156+
11181157
},
11191158

11201159
update: function(list, callback) {

src/qbConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
var config = {
13-
version: '2.2.1',
13+
version: '2.2.2',
1414
creds: {
1515
appId: '',
1616
authKey: '',

0 commit comments

Comments
 (0)