Skip to content

Commit

Permalink
MOB-806: Investigate client-side comment display filtering optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Van Milligan committed Jan 10, 2018
1 parent 641470c commit 1b520da
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 201 deletions.
2 changes: 1 addition & 1 deletion BVSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Pod::Spec.new do |s|
curationsui.source_files = 'Pod/BVCurationsUI/**/*.{h,m}'
curationsui.dependency 'BVSDK/BVCurations'
curationsui.dependency 'BVSDK/BVCommonUI'
curationsui.resources = ["Pod/BVCurationsUI/Assets/*.xcassets"]
curationsui.resources = ["Pod/BVCurationsUI/SocialMediaIcons/*.xcassets"]
end

s.subspec 'BVNotifications' do |notifications|
Expand Down
15 changes: 9 additions & 6 deletions Pod/BVConversations/Display/Requests/BVCommentsRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@

@interface BVCommentsRequest : BVConversationsRequest

@property(nonnull, readonly) NSString *reviewId;
@property(nonnull, readonly) NSString *productId;
@property(nullable, readonly) NSString *reviewId;
@property(nullable, readonly) NSString *commentId;
@property(nonatomic, assign, readonly) UInt16 limit;
@property(nonatomic, assign, readonly) UInt16 offset;
@property(nonnull, nonatomic, strong, readonly) NSMutableArray<BVSort *> *sorts;
@property(nonnull, nonatomic, strong, readonly)
NSMutableArray<BVFilter *> *filters;
@property(nonnull, nonatomic, strong, readonly)
NSMutableArray<NSString *> *includes;
@property(nonnull, readonly) NSString *commentId;

- (nonnull instancetype)initWithReviewId:(nonnull NSString *)reviewId
limit:(UInt16)limit
offset:(UInt16)offset;
- (nonnull instancetype)initWithCommentId:(nonnull NSString *)commentId;
- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId
andReviewId:(nonnull NSString *)reviewId
limit:(UInt16)limit
offset:(UInt16)offset;
- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId
andCommentId:(nonnull NSString *)commentId;

- (nonnull instancetype)__unavailable init;

Expand Down
42 changes: 30 additions & 12 deletions Pod/BVConversations/Display/Requests/BVCommentsRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

@implementation BVCommentsRequest

- (nonnull instancetype)initWithReviewId:(nonnull NSString *)reviewId
limit:(UInt16)limit
offset:(UInt16)offset {
- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId
andReviewId:(nonnull NSString *)reviewId
limit:(UInt16)limit
offset:(UInt16)offset {
self = [super init];
if (self) {
_productId = productId;
_reviewId = reviewId;
_limit = limit;
_offset = offset;
Expand All @@ -29,9 +31,11 @@ - (nonnull instancetype)initWithReviewId:(nonnull NSString *)reviewId
return self;
}

- (nonnull instancetype)initWithCommentId:(nonnull NSString *)commentId {
- (nonnull instancetype)initWithProductId:(nonnull NSString *)productId
andCommentId:(nonnull NSString *)commentId {
self = [super init];
if (self) {
_productId = productId;
_commentId = commentId;
_filters = [NSMutableArray array];
_sorts = [NSMutableArray array];
Expand Down Expand Up @@ -96,15 +100,32 @@ - (void)sendCommentImpressionAnalytics:(NSArray<BVComment *> *)comments {
}

- (nonnull NSMutableArray *)createParams {

NSMutableArray<BVStringKeyValuePair *> *params = [super createParams];

// There are two ways to make a request: 1) with a review Id to get a bunch
// of comments or 2) just get single review.
// There are two ways to make a request with a product identifier: 1) with a
// review identifier to get a bunch of comments or 2) with a comment
// identifier to just get single review.
NSAssert(self.productId, @"You must supply a valid product identifier in the "
@"supplied initiaizers.");

NSAssert(self.commentId || self.reviewId, @"You must also supply a valid "
@"comment or review identifier in "
@"the supplied initiaizers.");

if (self.productId) {
[params
addObject:[BVStringKeyValuePair
pairWithKey:@"Filter"
value:[NSString stringWithFormat:@"ProductId:%@",
self.productId]]];
}

if (self.reviewId) {
[params
addObject:[BVStringKeyValuePair
pairWithKey:@"Filter"
value:[NSString stringWithFormat:@"reviewId:%@",
value:[NSString stringWithFormat:@"ReviewId:%@",
self.reviewId]]];
[params addObject:[BVStringKeyValuePair
pairWithKey:@"Limit"
Expand All @@ -114,19 +135,16 @@ - (nonnull NSMutableArray *)createParams {
pairWithKey:@"Offset"
value:[NSString stringWithFormat:@"%i",
self.offset]]];
}

} else if (self.commentId) {
if (self.commentId) {
BVFilter *commentIdFilter =
[[BVFilter alloc] initWithType:BVProductFilterTypeId
filterOperator:BVFilterOperatorEqualTo
value:self.commentId];
[params addObject:[BVStringKeyValuePair
pairWithKey:@"Filter"
value:[commentIdFilter toParameterString]]];

} else {
NSAssert(NO, @"You must supply a valid comment or review ID in the "
@"supplied initiaizers.");
}

for (BVFilter *filter in self.filters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#import "BVDiagnosticHelpers.h"
#import "BVSDKConfiguration.h"
#import "BVSDKManager.h"
#import "BVStoreReviewsResponse.h"

@interface BVConversationsRequest ()
@property(strong, nonatomic)
Expand Down
Loading

0 comments on commit 1b520da

Please sign in to comment.