Changeset View
Standalone View
native/ios/NotificationService/NotificationService.mm
Show All 17 Lines | |||||
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request | - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request | ||||
withContentHandler: | withContentHandler: | ||||
(void (^)(UNNotificationContent *_Nonnull)) | (void (^)(UNNotificationContent *_Nonnull)) | ||||
contentHandler { | contentHandler { | ||||
self.contentHandler = contentHandler; | self.contentHandler = contentHandler; | ||||
self.bestAttemptContent = [request.content mutableCopy]; | self.bestAttemptContent = [request.content mutableCopy]; | ||||
[self persistMessagePayload:self.bestAttemptContent.userInfo]; | |||||
// Message payload persistence is a higher priority task, so it has | |||||
// to happen prior to potential notification center clearing. | |||||
if ([self isRescind:self.bestAttemptContent.userInfo]) { | if ([self isRescind:self.bestAttemptContent.userInfo]) { | ||||
[self removeNotificationWithIdentifier:self.bestAttemptContent | [self removeNotificationWithIdentifier:self.bestAttemptContent | ||||
.userInfo[@"notificationId"]]; | .userInfo[@"notificationId"]]; | ||||
self.contentHandler([[UNNotificationContent alloc] init]); | self.contentHandler([[UNNotificationContent alloc] init]); | ||||
return; | return; | ||||
} | } | ||||
NSString *message = self.bestAttemptContent.userInfo[@"messageInfos"]; | |||||
if (message) { | |||||
TemporaryMessageStorage *temporaryStorage = | |||||
[[TemporaryMessageStorage alloc] init]; | |||||
[temporaryStorage writeMessage:message]; | |||||
} | |||||
// TODO modify self.bestAttemptContent here | // TODO modify self.bestAttemptContent here | ||||
atul: Is this TODO still relevant? Might be helpful to link some sort of Linear ticket associated… | |||||
marcinAuthorUnsubmitted Done Inline ActionsThis TODO was introduced here: https://phab.comm.dev/D3162. I am pretty sure that this TODO was automatically added when NotificationService.mm file was generated, but I will check with @tomek about this. Nevertheless I don't see any reason to remove this TODO until we actually put there some code that handles notification decryption and modifies self.bestAttemptContent. marcin: This `TODO` was introduced here: https://phab.comm.dev/D3162. I am pretty sure that this `TODO`… | |||||
tomekUnsubmitted Not Done Inline ActionsYeah, this was added to indicate where we should put the code that modifies the message content. We can replace this with the code / function that actually modifies the message - when it will be introduced. tomek: Yeah, this was added to indicate where we should put the code that modifies the message content. | |||||
self.contentHandler(self.bestAttemptContent); | self.contentHandler(self.bestAttemptContent); | ||||
} | } | ||||
- (void)serviceExtensionTimeWillExpire { | - (void)serviceExtensionTimeWillExpire { | ||||
// Called just before the extension will be terminated by the system. | // Called just before the extension will be terminated by the system. | ||||
// Use this as an opportunity to deliver your "best attempt" at modified | // Use this as an opportunity to deliver your "best attempt" at modified | ||||
// content, otherwise the original push payload will be used. | // content, otherwise the original push payload will be used. | ||||
Show All 31 Lines | [UNUserNotificationCenter.currentNotificationCenter | ||||
} | } | ||||
postRemovalCallback(); | postRemovalCallback(); | ||||
} | } | ||||
}]; | }]; | ||||
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | ||||
} | } | ||||
- (void)persistMessagePayload:(NSDictionary *)payload { | |||||
if (payload[@"messageInfos"]) { | |||||
TemporaryMessageStorage *temporaryStorage = | |||||
[[TemporaryMessageStorage alloc] init]; | |||||
[temporaryStorage writeMessage:payload[@"messageInfos"]]; | |||||
return; | |||||
tomekUnsubmitted Not Done Inline ActionsIs it possible that a message has messageInfos and is a rescind at the same time? tomek: Is it possible that a message has `messageInfos` and is a rescind at the same time? | |||||
marcinAuthorUnsubmitted Done Inline ActionsAccording to the keyserver code messageInfos field is never introduced to rescind payload and I can't imagine why would we do so. However technically no type system or unit tests prevent us from inserting this field in future. cc @atul, @ashoat - is it ever possible that rescind might have messageInfos field? marcin: According to the keyserver code `messageInfos` field is never introduced to rescind payload and… | |||||
ashoatUnsubmitted Not Done Inline ActionsNo, I don't think this is possible ashoat: No, I don't think this is possible | |||||
marcinAuthorUnsubmitted Done Inline ActionsTherefore I assume it is safe early return here once messageInfos content is persisted. marcin: Therefore I assume it is safe early return here once `messageInfos` content is persisted. | |||||
} | |||||
if (![self isRescind:payload]) { | |||||
return; | |||||
} | |||||
NSError *jsonError = nil; | |||||
NSData *binarySerializedRescindPayload = | |||||
[NSJSONSerialization dataWithJSONObject:payload | |||||
options:0 | |||||
error:&jsonError]; | |||||
if (jsonError) { | |||||
comm::Logger::log( | |||||
"NSE: Failed to serialize rescind payload. Details: " + | |||||
std::string([jsonError.localizedDescription UTF8String])); | |||||
return; | |||||
} | |||||
NSString *serializedRescindPayload = | |||||
[[NSString alloc] initWithData:binarySerializedRescindPayload | |||||
encoding:NSUTF8StringEncoding]; | |||||
TemporaryMessageStorage *temporaryRescindsStorage = | |||||
[[TemporaryMessageStorage alloc] initForRescinds]; | |||||
[temporaryRescindsStorage writeMessage:serializedRescindPayload]; | |||||
} | |||||
- (BOOL)isRescind:(NSDictionary *)payload { | - (BOOL)isRescind:(NSDictionary *)payload { | ||||
return payload[@"backgroundNotifType"] && | return payload[@"backgroundNotifType"] && | ||||
[payload[@"backgroundNotifType"] isEqualToString:@"CLEAR"]; | [payload[@"backgroundNotifType"] isEqualToString:@"CLEAR"]; | ||||
} | } | ||||
@end | @end |
Is this TODO still relevant? Might be helpful to link some sort of Linear ticket associated with it?
(Realize this is outside the scope of this diff)