Skip to content

Commit

Permalink
[MB-1642] support for inbox filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-scig committed Apr 11, 2016
1 parent 4c57278 commit da35912
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Airship/Common/UADefaultMessageCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
*/
@property (nonatomic, strong) UADefaultMessageCenterStyle *style;

/**
* An optional predicate for filtering messages.
*/
@property (nonatomic, strong) NSPredicate *filter;

/**
* Display the message center.
*
Expand Down
1 change: 1 addition & 0 deletions Airship/Common/UADefaultMessageCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ - (void)display:(BOOL)animated {
if (!self.splitViewController) {

self.splitViewController = [[UADefaultMessageCenterSplitViewController alloc] initWithNibName:nil bundle:nil];
self.splitViewController.filter = self.filter;

UADefaultMessageCenterListViewController *lvc = self.splitViewController.listViewController;

Expand Down
5 changes: 5 additions & 0 deletions Airship/Common/UADefaultMessageCenterListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
*/
@property (nonatomic, strong) UADefaultMessageCenterStyle *style;

/**
* An optional predicate for filtering messages.
*/
@property (nonatomic, strong) NSPredicate *filter;

/**
* Block that will be invoked when a message view controller receives a closeWindow message
* from the webView.
Expand Down
12 changes: 10 additions & 2 deletions Airship/Common/UADefaultMessageCenterListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ - (void)refreshStateChanged:(UIRefreshControl *)sender {
}

// Note: since the message list is refreshed with new model objects when reloaded,
// we can't reliably hold onto any single instance. This method is merely for convenience.
// we can't reliably hold onto any single instance. This method is mostly for convenience.
- (NSArray *)messages {
return [UAirship inbox].messageList.messages;
NSArray *allMessages = [UAirship inbox].messageList.messages;
if (self.filter) {
return [allMessages filteredArrayUsingPredicate:self.filter];
} else {
return allMessages;
}
}

- (UIColor *)defaultTintColor {
Expand Down Expand Up @@ -355,6 +360,9 @@ - (void)displayMessage:(UAInboxMessage *)message {
//otherwise, push over a new message view
else {
mvc = [[UADefaultMessageCenterMessageViewController alloc] initWithNibName:@"UADefaultMessageCenterMessageViewController" bundle:[UAirship resources]];

mvc.filter = self.filter;

mvc.closeBlock = ^(BOOL animated){
// Call the close block if present
if (self.closeBlock) {
Expand Down
5 changes: 5 additions & 0 deletions Airship/Common/UADefaultMessageCenterMessageViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
*/
@property (nonatomic, strong) UAInboxMessage *message;

/**
* An optional predicate for filtering messages.
*/
@property (nonatomic, strong) NSPredicate *filter;

/**
* Block that will be invoked when this class receives a closeWindow message from the webView.
*/
Expand Down
9 changes: 7 additions & 2 deletions Airship/Common/UADefaultMessageCenterMessageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ - (void)viewWillDisappear:(BOOL)animated {
}

// Note: since the message list is refreshed with new model objects when reloaded,
// we can't reliably hold onto any single instance. This method is merely for convenience.
// we can't reliably hold onto any single instance. This method is mostly for convenience.
- (NSArray *)messages {
return [UAirship inbox].messageList.messages;
NSArray *allMessages = [UAirship inbox].messageList.messages;
if (self.filter) {
return [allMessages filteredArrayUsingPredicate:self.filter];
} else {
return allMessages;
}
}

#pragma mark -
Expand Down
5 changes: 5 additions & 0 deletions Airship/Common/UADefaultMessageCenterSplitViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
*/
@interface UADefaultMessageCenterSplitViewController : UISplitViewController

/**
* An optional predicate for filtering messages.
*/
@property (nonatomic, strong) NSPredicate *filter;

/**
* The style to apply to the message center
*/
Expand Down
10 changes: 9 additions & 1 deletion Airship/Common/UADefaultMessageCenterSplitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@interface UADefaultMessageCenterSplitViewController ()

@property(nonatomic, strong) UADefaultMessageCenterListViewController *listViewController;
@property(nonatomic, strong) UADefaultMessageCenterMessageViewController *messageViewController;
@property (nonatomic, strong) UINavigationController *listNav;
@property (nonatomic, strong) UINavigationController *messageNav;

Expand All @@ -46,12 +47,13 @@ - (void)configure {
UADefaultMessageCenterListViewController *lvc;
lvc = [[UADefaultMessageCenterListViewController alloc] initWithNibName:@"UADefaultMessageCenterListViewController"
bundle:[UAirship resources]];

UADefaultMessageCenterMessageViewController *mvc;
mvc = [[UADefaultMessageCenterMessageViewController alloc] initWithNibName:@"UADefaultMessageCenterMessageViewController"
bundle:[UAirship resources]];


self.listViewController = lvc;
self.messageViewController = mvc;

self.listNav = [[UINavigationController alloc] initWithRootViewController:lvc];
self.messageNav = [[UINavigationController alloc] initWithRootViewController:mvc];
Expand Down Expand Up @@ -114,6 +116,12 @@ - (void)setStyle:(UADefaultMessageCenterStyle *)style {
}
}

- (void)setFilter:(NSPredicate *)filter {
_filter = filter;
self.listViewController.filter = filter;
self.messageViewController.filter = filter;
}

- (void)setTitle:(NSString *)title {
[super setTitle:title];
self.listViewController.title = title;
Expand Down
10 changes: 10 additions & 0 deletions Airship/Inbox/UAInboxMessageList.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ extern NSString * const UAInboxMessageListUpdatedNotification;
- (nullable UADisposable *)retrieveMessageListWithSuccessBlock:(nullable UAInboxMessageListCallbackBlock)successBlock
withFailureBlock:(nullable UAInboxMessageListCallbackBlock)failureBlock;

/**
* Returns the list of messages on disk as an NSArray, filtered by the supplied predicate.
* @param predicate The predicate to use as a filter over messages.
*/
#if __has_feature(objc_generics)
- (NSArray<UAInboxMessage *> *)messagesFilteredUsingPredicate:(NSPredicate *)predicate;
#else
- (NSArray *)messagesFilteredUsingPredicate:(NSPredicate *)predicate;
#endif

/**
* Returns the number of messages currently in the inbox.
* @return The message count as an integer.
Expand Down
12 changes: 11 additions & 1 deletion Airship/Inbox/UAInboxMessageList.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ + (instancetype)messageListWithUser:(UAUser *)user client:(UAInboxAPIClient *)cl
return [[UAInboxMessageList alloc] initWithUser:user client:client config:config];
}

#pragma mark Custom setters
#pragma mark Accessors

- (void)setMessages:(NSArray *)messages {
@synchronized(self) {
Expand Down Expand Up @@ -96,6 +96,16 @@ - (NSArray *)messages {
}
}

#if __has_feature(objc_generics)
- (NSArray<UAInboxMessage *> *)messagesFilteredUsingPredicate:(NSPredicate *)predicate {
#else
- (NSArray *)messagesFilteredUsingPredicate:(NSPredicate *)predicate {
#endif
@synchronized(self) {
return [_messages filteredArrayUsingPredicate:predicate];
}
}

#pragma mark NSNotificationCenter helper methods

- (void)sendMessageListWillUpdateNotification {
Expand Down

0 comments on commit da35912

Please sign in to comment.