Skip to content

Commit 25b9011

Browse files
committed
Fixed: new post count and duplicates.
1 parent ecf1be2 commit 25b9011

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

app/main/posts/views/post-view-data.directive.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,16 @@ function PostViewDataController(
489489
});
490490
}
491491

492+
function getUnique(arr, comp) {
493+
const unique = arr
494+
.map(ele => ele[comp]) // store the keys of the unique objects
495+
.map((ele, i, final) => final.indexOf(ele) === i && i) // eliminate the dead keys & store unique objects
496+
.filter(ele => arr[ele])
497+
.map(ele => arr[ele]);
498+
499+
return unique;
500+
}
501+
492502
function getNewPosts() {
493503
let existingFilters = PostFilters.getQueryParams($scope.filters);
494504
let filterDate = moment(existingFilters.date_before).utc();
@@ -518,9 +528,12 @@ function PostViewDataController(
518528
created_after_by_id: $scope.posts[0].id
519529
});
520530
}
531+
521532
PostEndpoint.query(postQuery).$promise.then(function (postsResponse) {
522533
Array.prototype.unshift.apply(recentPosts, postsResponse.results);
523-
$scope.newPostsCount += postsResponse.count;
534+
recentPosts = getUnique(recentPosts, 'id');
535+
$scope.newPostsCount = postsResponse.count;
536+
524537
});
525538
}
526539
}

0 commit comments

Comments
 (0)