Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
'Mark As Read' notification action
  • Loading branch information
c99koder committed Feb 7, 2019
1 parent 1259be2 commit aca9a2b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions IRCCloud/Classes/AppDelegate.m
Expand Up @@ -109,10 +109,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
UNNotificationAction *joinAction = [UNNotificationAction actionWithIdentifier:@"join" title:@"Join" options:UNNotificationActionOptionForeground];
UNNotificationAction *acceptAction = [UNNotificationAction actionWithIdentifier:@"accept" title:@"Accept" options:UNNotificationActionOptionNone];
UNNotificationAction *retryAction = [UNNotificationAction actionWithIdentifier:@"retry" title:@"Retry" options:UNNotificationActionOptionNone];
UNNotificationAction *readAction = [UNNotificationAction actionWithIdentifier:@"read" title:@"Mark As Read" options:UNNotificationActionOptionNone];

[center setNotificationCategories:[NSSet setWithObjects:
[UNNotificationCategory categoryWithIdentifier:@"buffer_msg" actions:@[replyAction] intentIdentifiers:@[INSendMessageIntentIdentifier] options:UNNotificationCategoryOptionNone],
[UNNotificationCategory categoryWithIdentifier:@"buffer_me_msg" actions:@[replyAction] intentIdentifiers:@[INSendMessageIntentIdentifier] options:UNNotificationCategoryOptionNone],
[UNNotificationCategory categoryWithIdentifier:@"buffer_msg" actions:@[replyAction,readAction] intentIdentifiers:@[INSendMessageIntentIdentifier] options:UNNotificationCategoryOptionNone],
[UNNotificationCategory categoryWithIdentifier:@"buffer_me_msg" actions:@[replyAction,readAction] intentIdentifiers:@[INSendMessageIntentIdentifier] options:UNNotificationCategoryOptionNone],
[UNNotificationCategory categoryWithIdentifier:@"channel_invite" actions:@[joinAction] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone],
[UNNotificationCategory categoryWithIdentifier:@"callerid" actions:@[acceptAction] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone],
[UNNotificationCategory categoryWithIdentifier:@"retry" actions:@[retryAction] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone],
Expand Down Expand Up @@ -704,6 +705,8 @@ -(void)handleAction:(NSString *)identifier userInfo:(NSDictionary *)userInfo res
result = [[NetworkConnection sharedInstance] POSTsay:[NSString stringWithFormat:@"/accept %@", [[[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] objectForKey:@"loc-args"] objectAtIndex:0]]
to:@""
cid:[[[userInfo objectForKey:@"d"] objectAtIndex:0] intValue]];
} else if([identifier isEqualToString:@"read"]) {
result = [[NetworkConnection sharedInstance] POSTheartbeat:[[[userInfo objectForKey:@"d"] objectAtIndex:1] intValue] cid:[[[userInfo objectForKey:@"d"] objectAtIndex:0] intValue] bid:[[[userInfo objectForKey:@"d"] objectAtIndex:1] intValue] lastSeenEid:[[[userInfo objectForKey:@"d"] objectAtIndex:2] doubleValue]];
}

if([[result objectForKey:@"success"] intValue] == 1) {
Expand Down
2 changes: 2 additions & 0 deletions IRCCloud/Classes/NetworkConnection.h
Expand Up @@ -207,6 +207,8 @@ typedef void (^IRCCloudAPIResultHandler)(IRCCloudJSONObject *result);
-(int)reply:(NSString *)message to:(NSString *)to cid:(int)cid msgid:(NSString *)msgid handler:(IRCCloudAPIResultHandler)handler;
-(int)heartbeat:(int)selectedBuffer cid:(int)cid bid:(int)bid lastSeenEid:(NSTimeInterval)lastSeenEid handler:(IRCCloudAPIResultHandler)handler;
-(int)heartbeat:(int)selectedBuffer cids:(NSArray *)cids bids:(NSArray *)bids lastSeenEids:(NSArray *)lastSeenEids handler:(IRCCloudAPIResultHandler)handler;
-(NSDictionary *)POSTheartbeat:(int)selectedBuffer cid:(int)cid bid:(int)bid lastSeenEid:(NSTimeInterval)lastSeenEid;
-(NSDictionary *)POSTheartbeat:(int)selectedBuffer cids:(NSArray *)cids bids:(NSArray *)bids lastSeenEids:(NSArray *)lastSeenEids;
-(int)join:(NSString *)channel key:(NSString *)key cid:(int)cid handler:(IRCCloudAPIResultHandler)handler;
-(int)part:(NSString *)channel msg:(NSString *)msg cid:(int)cid handler:(IRCCloudAPIResultHandler)handler;
-(int)kick:(NSString *)nick chan:(NSString *)chan msg:(NSString *)msg cid:(int)cid handler:(IRCCloudAPIResultHandler)handler;
Expand Down
19 changes: 19 additions & 0 deletions IRCCloud/Classes/NetworkConnection.m
Expand Up @@ -1455,6 +1455,25 @@ -(int)heartbeat:(int)selectedBuffer cid:(int)cid bid:(int)bid lastSeenEid:(NSTim
return [self heartbeat:selectedBuffer cids:@[@(cid)] bids:@[@(bid)] lastSeenEids:@[@(lastSeenEid)] handler:resultHandler];
}

-(NSDictionary *)POSTheartbeat:(int)selectedBuffer cids:(NSArray *)cids bids:(NSArray *)bids lastSeenEids:(NSArray *)lastSeenEids {
@synchronized(self->_writer) {
NSMutableDictionary *heartbeat = [[NSMutableDictionary alloc] init];
for(int i = 0; i < cids.count; i++) {
NSMutableDictionary *d = [heartbeat objectForKey:[NSString stringWithFormat:@"%@",[cids objectAtIndex:i]]];
if(!d) {
d = [[NSMutableDictionary alloc] init];
[heartbeat setObject:d forKey:[NSString stringWithFormat:@"%@",[cids objectAtIndex:i]]];
}
[d setObject:[lastSeenEids objectAtIndex:i] forKey:[NSString stringWithFormat:@"%@",[bids objectAtIndex:i]]];
}
NSString *seenEids = [self->_writer stringWithObject:heartbeat];
return [self _postRequest:@"/chat/heartbeat" args:@{@"selectedBuffer":[@(selectedBuffer) stringValue], @"seenEids":seenEids}];
}
}
-(NSDictionary *)POSTheartbeat:(int)selectedBuffer cid:(int)cid bid:(int)bid lastSeenEid:(NSTimeInterval)lastSeenEid {
return [self POSTheartbeat:selectedBuffer cids:@[@(cid)] bids:@[@(bid)] lastSeenEids:@[@(lastSeenEid)]];
}

-(int)join:(NSString *)channel key:(NSString *)key cid:(int)cid handler:(IRCCloudAPIResultHandler)resultHandler {
if(key.length) {
return [self _sendRequest:@"join" args:@{@"cid":@(cid), @"channel":channel, @"key":key} handler:resultHandler];
Expand Down

0 comments on commit aca9a2b

Please sign in to comment.