-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for interactive notifications (fixes #625) #1777
Changes from 1 commit
6a90ff0
125aecb
21ec4c6
31e3501
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1067,8 +1067,24 @@ - (void)registerUserNotificationSettings | |
{ | ||
if (!isPushRegistered) | ||
{ | ||
NSMutableSet* notificationCategories = [NSMutableSet set]; | ||
if ([[UIMutableUserNotificationAction class] instancesRespondToSelector:@selector(behavior)]) | ||
{ | ||
UIMutableUserNotificationAction* quickReply = [[UIMutableUserNotificationAction alloc] init]; | ||
quickReply.title = NSLocalizedStringFromTable(@"room_message_short_placeholder", @"Vector", nil); | ||
quickReply.identifier = @"inline-reply"; | ||
quickReply.activationMode = UIUserNotificationActivationModeBackground; | ||
quickReply.authenticationRequired = true; | ||
quickReply.behavior = UIUserNotificationActionBehaviorTextInput; | ||
|
||
UIMutableUserNotificationCategory* quickReplyCategory = [[UIMutableUserNotificationCategory alloc] init]; | ||
quickReplyCategory.identifier = @"QUICK_REPLY"; | ||
[quickReplyCategory setActions:[NSArray arrayWithObjects:quickReply, nil] forContext:UIUserNotificationActionContextDefault]; | ||
[notificationCategories addObject:quickReplyCategory]; | ||
} | ||
|
||
// Registration on iOS 8 and later | ||
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:nil]; | ||
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:notificationCategories]; | ||
[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; | ||
} | ||
} | ||
|
@@ -1097,6 +1113,46 @@ - (void)application:(UIApplication *)application didRegisterUserNotificationSett | |
} | ||
} | ||
|
||
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler | ||
{ | ||
if ([identifier isEqualToString: @"inline-reply"]) | ||
{ | ||
NSString* roomId = notification.userInfo[@"room_id"]; | ||
if (roomId.length) | ||
{ | ||
NSArray* mxAccounts = [MXKAccountManager sharedManager].activeAccounts; | ||
MXRoom* room = nil; | ||
for (MXKAccount* account in mxAccounts) | ||
{ | ||
room = [account.mxSession roomWithRoomId:roomId]; | ||
if (room) | ||
{ | ||
break; | ||
} | ||
} | ||
if (room == nil) | ||
{ | ||
NSLog(@"[AppDelegate][Push] handleActionWithIdentifier: room with id %@ not found", roomId); | ||
} | ||
else | ||
{ | ||
NSString* responseText = [responseInfo objectForKey:UIUserNotificationActionResponseTypedTextKey]; | ||
if (responseText != nil && responseText.length != 0) | ||
{ | ||
NSLog(@"[AppDelegate][Push] handleActionWithIdentifier: sending message to room: %@", roomId); | ||
[room sendTextMessage:responseText success:^(NSString* eventId) {} failure:^(NSError* error) { | ||
NSLog(@"[AppDelegate][Push] handleActionWithIdentifier: error sending text message: %@", error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How to deal better with the error? Is it possible to display it to the end user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I encountered that issue in my testing... Couldn’t figure out how to properly notify the user. How about another local notification that indicates there was an error sending the message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good idea. The user should be able to go the room when clicking on this notification. Then, the app will automatically propose them to resend the message. This failure flow seems not too bad. |
||
}]; | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
NSLog(@"[AppDelegate][Push] handleActionWithIdentifier: unhandled identifier %@", identifier); | ||
} | ||
} | ||
|
||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification | ||
{ | ||
NSLog(@"[AppDelegate][Push] didReceiveLocalNotification: applicationState: %@", @(application.applicationState)); | ||
|
@@ -1350,6 +1406,11 @@ - (void)handleLocalNotificationsForAccount:(MXKAccount*)account | |
@"user_id": account.mxCredentials.userId | ||
}; | ||
|
||
if (event.eventType == MXEventTypeRoomMessage || (event.eventType == MXEventTypeRoomEncrypted && event.isEncrypted && account.showDecryptedContentInNotifications)) | ||
{ | ||
eventNotification.category = @"QUICK_REPLY"; | ||
} | ||
|
||
// Set sound name based on the value provided in action of MXPushRule | ||
for (MXPushRuleAction *action in rule.actions) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the
sendTextMessage
method ofMXKRoomDataSource
, instead?It does a bit more processing on text before sending. Plus, it will manage local echo if the user opens the room while the message is being sent.