Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit ed21653

Browse files
authored
Merge pull request #1798 from OpenBazaar/noDuplicatesInDiscover
Prevents duplicate users in the Discover/Pages views.
2 parents 6c0130e + 88e800b commit ed21653

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

js/views/homeVw.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = pageVw.extend({
5050
this.onlyFollowing = true;
5151
this.showNSFW = JSON.parse(localStorage.getItem('NSFWFilter'));
5252
this.cachedScrollPositions = {};
53+
this.loadedUsers = [];
5354

5455
this.model.set({user: this.options.userModel.toJSON(), page: this.userProfile.toJSON()});
5556

@@ -96,7 +97,7 @@ module.exports = pageVw.extend({
9697
}
9798

9899
this.obContainer.on('scroll', this.scrollHandler);
99-
},
100+
},
100101

101102
onCacheWillDetach: function(e) {
102103
if (e.view !== this) return;
@@ -147,7 +148,7 @@ module.exports = pageVw.extend({
147148
if ($('.homeGridItems .gridItem').length === 0){
148149
self.$el.find('.js-loadingMessage').removeClass('fadeOut');
149150
self.$el.find('.js-loadingMessage .spinner').addClass('fadeOut');
150-
151+
151152
if (self.searchItemsText) {
152153
self.$el.find('.js-loadingText').html(
153154
window.polyglot.t('discover.noTaggedResults')
@@ -186,7 +187,7 @@ module.exports = pageVw.extend({
186187
this.loadingVendors = false;
187188
this.renderUser(data.vendor);
188189
}
189-
190+
190191
this.resetLookingCount();
191192
},
192193

@@ -268,7 +269,7 @@ module.exports = pageVw.extend({
268269

269270
item.ownFollowing = this.ownFollowing.indexOf(item.guid) != -1;
270271

271-
blocked = this.userModel.get('blocked_guids') || [];
272+
blocked = this.userModel.get('blocked_guids') || [];
272273
item.isBlocked = blocked.indexOf(item.guid) !== -1;
273274

274275
var newItem = function(){
@@ -314,6 +315,12 @@ module.exports = pageVw.extend({
314315
newUserModel,
315316
storeShort;
316317

318+
//don't load duplicates
319+
if (this.loadedUsers.indexOf(user.guid) !== -1){
320+
return;
321+
}
322+
this.loadedUsers.push(user.guid);
323+
317324
if (blocked.indexOf(user.guid) !== -1) return;
318325

319326
if (user.nsfw && !this.showNSFW) return;
@@ -323,10 +330,7 @@ module.exports = pageVw.extend({
323330
user.serverUrl = this.userModel.get('serverUrl');
324331
user.userID = user.guid;
325332
user.avatarURL = this.userModel.get('serverUrl')+"get_image?hash="+user.avatar_hash+"&guid="+user.guid;
326-
327-
if (this.ownFollowing.indexOf(user.guid) != -1){
328-
user.ownFollowing = true;
329-
}
333+
user.ownFollowing = this.ownFollowing.indexOf(user.guid) != -1;
330334

331335
newUserModel = new userShortModel(user);
332336
storeShort = new userShortView({model: newUserModel});
@@ -336,7 +340,7 @@ module.exports = pageVw.extend({
336340
self.removeUserView(storeShort);
337341
}
338342
});
339-
343+
340344
this.$el.find('.js-vendors .js-loadingSpinner').before(storeShort.el);
341345
this.registerChild(storeShort);
342346
this.userViews.push(storeShort);
@@ -427,7 +431,7 @@ module.exports = pageVw.extend({
427431
console.log(status);
428432
console.log(errorThrown);
429433
}
430-
});
434+
});
431435
},
432436

433437
followUser: function(options){
@@ -545,15 +549,15 @@ module.exports = pageVw.extend({
545549
searchItems: function(searchItemsText){
546550
if (searchItemsText){
547551
var hashedItem = "#" + searchItemsText;
548-
552+
549553
window.obEventBus.trigger('searchingText', hashedItem);
550-
554+
551555
this.searchItemsText = searchItemsText;
552556
this.clearItems();
553557
this.socketItemsID = "";
554558
this.socketSearchID = Math.random().toString(36).slice(2);
555559
this.socketView.search(this.socketSearchID, searchItemsText);
556-
this.setSocketTimeout();
560+
this.setSocketTimeout();
557561
this.$el.find('.js-discoverHeading').html(hashedItem);
558562
this.$el.find('.js-loadingText').html(
559563
this.$el.find('.js-loadingText')
@@ -585,7 +589,7 @@ module.exports = pageVw.extend({
585589
count = count || 0;
586590
if (this._blockedItemCount === count) return;
587591
this._blockedItemCount = count;
588-
592+
589593
if (count) {
590594
text = count + ' blocked item' + (count !== 1 ? 's' : '') + ' not shown';
591595
}
@@ -651,7 +655,7 @@ module.exports = pageVw.extend({
651655
fragment: 'cancel'
652656
}, {
653657
text: window.polyglot.t('ShowUnlfilteredListings'),
654-
fragment: 'showUnlfilteredListings'
658+
fragment: 'showUnlfilteredListings'
655659
}]
656660
}).on('click-cancel', () => {
657661
this.safeListingsDialog.close();

0 commit comments

Comments
 (0)