Changeset View
Changeset View
Standalone View
Standalone View
native/ios/Comm/AppDelegate.mm
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
#import <string> | #import <string> | ||||
#import <ReactCommon/RCTTurboModuleManager.h> | #import <ReactCommon/RCTTurboModuleManager.h> | ||||
#import <RNReanimated/REAInitializer.h> | #import <RNReanimated/REAInitializer.h> | ||||
#import <UserNotifications/UserNotifications.h> | #import <UserNotifications/UserNotifications.h> | ||||
NSString *const backgroundNotificationTypeKey = @"backgroundNotifType"; | |||||
NSString *const setUnreadStatusKey = @"setUnreadStatus"; | NSString *const setUnreadStatusKey = @"setUnreadStatus"; | ||||
NSString *const threadIDKey = @"threadID"; | NSString *const threadIDKey = @"threadID"; | ||||
@interface AppDelegate () < | @interface AppDelegate () < | ||||
RCTCxxBridgeDelegate, | RCTCxxBridgeDelegate, | ||||
RCTTurboModuleManagerDelegate> { | RCTTurboModuleManagerDelegate> { | ||||
} | } | ||||
@end | @end | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// Required for the notification event. You must call the completion handler | // Required for the notification event. You must call the completion handler | ||||
// after handling the remote notification. | // after handling the remote notification. | ||||
- (void)application:(UIApplication *)application | - (void)application:(UIApplication *)application | ||||
didReceiveRemoteNotification:(NSDictionary *)notification | didReceiveRemoteNotification:(NSDictionary *)notification | ||||
fetchCompletionHandler: | fetchCompletionHandler: | ||||
(void (^)(UIBackgroundFetchResult))completionHandler { | (void (^)(UIBackgroundFetchResult))completionHandler { | ||||
BOOL handled = NO; | |||||
if (notification[@"aps"][@"content-available"] && | |||||
notification[backgroundNotificationTypeKey]) { | |||||
handled = [self handleBackgroundNotification:notification | |||||
fetchCompletionHandler:completionHandler]; | |||||
} | |||||
if (handled) { | |||||
return; | |||||
} | |||||
[CommIOSNotifications didReceiveRemoteNotification:notification | [CommIOSNotifications didReceiveRemoteNotification:notification | ||||
fetchCompletionHandler:completionHandler]; | fetchCompletionHandler:completionHandler]; | ||||
} | } | ||||
- (BOOL)handleBackgroundNotification:(NSDictionary *)notification | |||||
fetchCompletionHandler: | |||||
(void (^)(UIBackgroundFetchResult))completionHandler { | |||||
if ([notification[backgroundNotificationTypeKey] isEqualToString:@"CLEAR"]) { | |||||
if (notification[setUnreadStatusKey] && notification[@"threadID"]) { | |||||
std::string threadID = | |||||
std::string([notification[@"threadID"] UTF8String]); | |||||
// this callback may be called from inactive state so we need | |||||
// to initialize the database | |||||
[self attemptDatabaseInitialization]; | |||||
comm::GlobalDBSingleton::instance.scheduleOrRun([threadID]() mutable { | |||||
comm::ThreadOperations::updateSQLiteUnreadStatus(threadID, false); | |||||
}); | |||||
} | |||||
[CommIOSNotifications | |||||
clearNotificationFromNotificationsCenter:notification[@"notificationId"] | |||||
completionHandler:completionHandler]; | |||||
return YES; | |||||
} | |||||
return NO; | |||||
} | |||||
- (UIInterfaceOrientationMask)application:(UIApplication *)application | - (UIInterfaceOrientationMask)application:(UIApplication *)application | ||||
supportedInterfaceOrientationsForWindow:(UIWindow *)window { | supportedInterfaceOrientationsForWindow:(UIWindow *)window { | ||||
return [Orientation getOrientation]; | return [Orientation getOrientation]; | ||||
} | } | ||||
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { | ||||
#if DEBUG | #if DEBUG | ||||
return | return | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |