Browse Source

dev push notification

Marino Faggiana 6 years ago
parent
commit
48afb36bfa

+ 0 - 16
Nextcloud.xcodeproj/project.pbxproj

@@ -407,8 +407,6 @@
 		F7B2DEF11F976859007CF4D2 /* english.txt in Resources */ = {isa = PBXBuildFile; fileRef = F7B2DEED1F976785007CF4D2 /* english.txt */; };
 		F7B3A4EE1E97818A000DACE8 /* CCLoginWeb.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B3A4ED1E97818A000DACE8 /* CCLoginWeb.swift */; };
 		F7B4F1CB1F44356F00B53B42 /* NCUchardet.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B4F1C81F44356F00B53B42 /* NCUchardet.m */; };
-		F7B7ED3F211340EB00C89FFA /* NCPushNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B7ED3E211340EB00C89FFA /* NCPushNotification.m */; };
-		F7B7ED40211340EB00C89FFA /* NCPushNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = F7B7ED3E211340EB00C89FFA /* NCPushNotification.m */; };
 		F7BAADC81ED5A87C00B7EAD4 /* NCDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB41ED5A87C00B7EAD4 /* NCDatabase.swift */; };
 		F7BAADC91ED5A87C00B7EAD4 /* NCDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB41ED5A87C00B7EAD4 /* NCDatabase.swift */; };
 		F7BAADCB1ED5A87C00B7EAD4 /* NCManageDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB51ED5A87C00B7EAD4 /* NCManageDatabase.swift */; };
@@ -1358,8 +1356,6 @@
 		F7B4F1C81F44356F00B53B42 /* NCUchardet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCUchardet.m; sourceTree = "<group>"; };
 		F7B7ED3A21133A4300C89FFA /* Notification_Service_Extension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Notification_Service_Extension.entitlements; sourceTree = "<group>"; };
 		F7B7ED3B21133A6000C89FFA /* Notification_Service_Extension.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Notification_Service_Extension.plist; sourceTree = "<group>"; };
-		F7B7ED3D211340EB00C89FFA /* NCPushNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCPushNotification.h; sourceTree = "<group>"; };
-		F7B7ED3E211340EB00C89FFA /* NCPushNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCPushNotification.m; sourceTree = "<group>"; };
 		F7BAADB41ED5A87C00B7EAD4 /* NCDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCDatabase.swift; sourceTree = "<group>"; };
 		F7BAADB51ED5A87C00B7EAD4 /* NCManageDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCManageDatabase.swift; sourceTree = "<group>"; };
 		F7BB04821FD58ACA00BBFD2A /* cs-CZ */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "cs-CZ"; path = "cs-CZ.lproj/CTAssetsPicker.strings"; sourceTree = "<group>"; };
@@ -2712,15 +2708,6 @@
 			path = NCUchardet;
 			sourceTree = "<group>";
 		};
-		F7B7ED3C211340EB00C89FFA /* PushNotification */ = {
-			isa = PBXGroup;
-			children = (
-				F7B7ED3D211340EB00C89FFA /* NCPushNotification.h */,
-				F7B7ED3E211340EB00C89FFA /* NCPushNotification.m */,
-			);
-			path = PushNotification;
-			sourceTree = "<group>";
-		};
 		F7BAAD951ED5A63D00B7EAD4 /* Database */ = {
 			isa = PBXGroup;
 			children = (
@@ -3192,7 +3179,6 @@
 				F74D3DB81BAC1941000BAE4B /* Networking */,
 				F7C5259A1E3B441D00FFE02C /* Notification */,
 				F7FCFFD51D70798C000E6E29 /* PeekPop */,
-				F7B7ED3C211340EB00C89FFA /* PushNotification */,
 				F7BE6E2A1D2D5C3B00106933 /* QuickActions */,
 				F7FE125B1BAC03FB0041924B /* Security */,
 				F7ACE4281BAC0268006C0017 /* Settings */,
@@ -3756,7 +3742,6 @@
 				F72D101B210B74CA009C96B7 /* UICKeyChainStore.m in Sources */,
 				F72D103F210B77B8009C96B7 /* NCPushNotificationEncryption.m in Sources */,
 				F72D103E210B77A5009C96B7 /* OCActivity.m in Sources */,
-				F7B7ED40211340EB00C89FFA /* NCPushNotification.m in Sources */,
 				F72D1042210B783D009C96B7 /* NCEndToEndEncryption.m in Sources */,
 				F72D103B210B76A1009C96B7 /* NCManageDatabase.swift in Sources */,
 			);
@@ -4099,7 +4084,6 @@
 				F73CC06C1E813DFF006E3047 /* BKPasscodeField.m in Sources */,
 				F77B0ED51D118A16002130FE /* PHAsset+Utility.m in Sources */,
 				F73B4EFD1F470D9100BBEE4B /* LangHebrewModel.cpp in Sources */,
-				F7B7ED3F211340EB00C89FFA /* NCPushNotification.m in Sources */,
 				F70022CE1EC4C9100080073F /* OCShareUser.m in Sources */,
 				F77B0ED91D118A16002130FE /* main.m in Sources */,
 			);

+ 18 - 7
Notification Service Extension/NotificationService.swift

@@ -35,9 +35,9 @@ class NotificationService: UNNotificationServiceExtension {
         bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
         
         if let bestAttemptContent = bestAttemptContent {
-            
+
             bestAttemptContent.title = ""
-            bestAttemptContent.body = "Nextcloud notification 🔔"
+            bestAttemptContent.body = "Nextcloud notification"
             
             let message = bestAttemptContent.userInfo["subject"] as! String
             
@@ -51,12 +51,23 @@ class NotificationService: UNNotificationServiceExtension {
                 return
             }
             
-            let pushNotification = NCPushNotification.init(fromDecryptedString: decryptedMessage)
-            if (pushNotification != nil) {
-                bestAttemptContent.title = pushNotification!.app.uppercased()
-                bestAttemptContent.body = pushNotification!.bodyForRemoteAlerts()
+            guard let data = decryptedMessage.data(using: .utf8) else {
+                contentHandler(bestAttemptContent)
+                return
             }
             
+            do {
+                let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String: AnyObject]
+                if let app = json["app"] as? String {
+                    bestAttemptContent.title = app.uppercased()
+                }
+                if let subject = json["subject"] as? String {
+                    bestAttemptContent.body = subject
+                }
+            } catch let error as NSError {
+                print("Failed : \(error.localizedDescription)")
+            }
+          
             contentHandler(bestAttemptContent)
         }
     }
@@ -66,7 +77,7 @@ class NotificationService: UNNotificationServiceExtension {
         if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
             
             bestAttemptContent.title = ""
-            bestAttemptContent.body = "Nextcloud notification 🔔"
+            bestAttemptContent.body = "Nextcloud notification"
             
             contentHandler(bestAttemptContent)
         }

+ 0 - 1
Notification Service Extension/NotificationServiceExtension-Bridging-Header.h

@@ -23,7 +23,6 @@
 
 #import "CCUtility.h"
 #import "NCPushNotificationEncryption.h"
-#import "NCPushNotification.h"
 
 #import "OCActivity.h"
 #import "OCUserProfile.h"

+ 30 - 36
iOSClient/AppDelegate.m

@@ -38,7 +38,6 @@
 #import "NCAutoUpload.h"
 #import "Firebase.h"
 #import "NCPushNotificationEncryption.h"
-#import "NCPushNotification.h"
 
 @interface AppDelegate () <UNUserNotificationCenterDelegate, FIRMessagingDelegate>
 
@@ -459,45 +458,40 @@
         NSString *decryptedMessage = [[NCPushNotificationEncryption sharedInstance] decryptPushNotification:message withDevicePrivateKey:privateKey];
         if (decryptedMessage) {
            
-            NCPushNotification *pushNotification = [NCPushNotification pushNotificationFromDecryptedString:decryptedMessage];
-            if (pushNotification) {
-                switch (pushNotification.type) {
-                    case NCPushNotificationTypeComment:
-                    case NCPushNotificationTypeUnknown:
-                    {
-                        UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
-                        UINavigationController *navigationControllerMore;
-                        UITabBarController *tabBarController;
-                        
-                        if (splitViewController.isCollapsed) {
-                            
-                            tabBarController = splitViewController.viewControllers.firstObject;
-                            for (UINavigationController *nvc in tabBarController.viewControllers) {
-                                
-                                if ([nvc.topViewController isKindOfClass:[CCDetail class]])
-                                    [nvc popToRootViewControllerAnimated:NO];
-                                
-                                if ([nvc.topViewController isKindOfClass:[CCMore class]])
-                                    navigationControllerMore = nvc;
-                            }
-                            
-                        } else {
-                            
-                            UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
-                            [nvcDetail popToRootViewControllerAnimated:NO];
-                            
-                            tabBarController = splitViewController.viewControllers.firstObject;
-                        }
+            NSData *data = [decryptedMessage dataUsingEncoding:NSUTF8StringEncoding];
+            NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
+            NSString *app = [json objectForKey:@"app"];
+            
+            if ([app isEqualToString:@"spreed"] == NO) {
+                
+                UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
+                UINavigationController *navigationControllerMore;
+                UITabBarController *tabBarController;
+                
+                if (splitViewController.isCollapsed) {
+                    
+                    tabBarController = splitViewController.viewControllers.firstObject;
+                    for (UINavigationController *nvc in tabBarController.viewControllers) {
                         
-                        if (tabBarController)
-                            [tabBarController setSelectedIndex: k_tabBarApplicationIndexMore];
-                        if (navigationControllerMore)
-                            [navigationControllerMore performSegueWithIdentifier:@"segueActivity" sender:navigationControllerMore];
+                        if ([nvc.topViewController isKindOfClass:[CCDetail class]])
+                            [nvc popToRootViewControllerAnimated:NO];
                         
+                        if ([nvc.topViewController isKindOfClass:[CCMore class]])
+                            navigationControllerMore = nvc;
                     }
-                    default:
-                        break;
+                    
+                } else {
+                    
+                    UINavigationController *nvcDetail = splitViewController.viewControllers.lastObject;
+                    [nvcDetail popToRootViewControllerAnimated:NO];
+                    
+                    tabBarController = splitViewController.viewControllers.firstObject;
                 }
+                
+                if (tabBarController)
+                    [tabBarController setSelectedIndex: k_tabBarApplicationIndexMore];
+                if (navigationControllerMore)
+                    [navigationControllerMore performSegueWithIdentifier:@"segueActivity" sender:navigationControllerMore];
             }
         }
     }

+ 0 - 37
iOSClient/PushNotification/NCPushNotification.h

@@ -1,37 +0,0 @@
-//
-//  NCPushNotification.h
-//  VideoCalls
-//
-//  Created by Ivan Sein on 24.11.17.
-//  Copyright © 2017 struktur AG. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-typedef NS_ENUM(NSInteger, NCPushNotificationType) {
-    NCPushNotificationTypeUnknown,
-    NCPushNotificationTypeCall,
-    NCPushNotificationTypeRoom,
-    NCPushNotificationTypeChat,
-    NCPushNotificationTypeComment
-};
-
-extern NSString * const kNCPNAppKey;
-extern NSString * const kNCPNTypeKey;
-extern NSString * const kNCPNSubjectKey;
-extern NSString * const kNCPNIdKey;
-extern NSString * const kNCPNTypeCallKey;
-extern NSString * const kNCPNTypeRoomKey;
-extern NSString * const kNCPNTypeChatKey;
-
-@interface NCPushNotification : NSObject
-
-@property (nonatomic, copy) NSString *app;
-@property (nonatomic, assign) NCPushNotificationType type;
-@property (nonatomic, copy) NSString *subject;
-@property (nonatomic, assign) NSInteger pnId;
-
-+ (instancetype)pushNotificationFromDecryptedString:(NSString *)decryptedString;
-- (NSString *)bodyForRemoteAlerts;
-
-@end

+ 0 - 75
iOSClient/PushNotification/NCPushNotification.m

@@ -1,75 +0,0 @@
-//
-//  NCPushNotification.m
-//  VideoCalls
-//
-//  Created by Ivan Sein on 24.11.17.
-//  Copyright © 2017 struktur AG. All rights reserved.
-//
-
-#import "NCPushNotification.h"
-
-@implementation NCPushNotification
-
-NSString * const kNCPNAppKey            = @"app";
-NSString * const kNCPNTypeKey           = @"type";
-NSString * const kNCPNSubjectKey        = @"subject";
-NSString * const kNCPNIdKey             = @"id";
-NSString * const kNCPNTypeCallKey       = @"call";
-NSString * const kNCPNTypeRoomKey       = @"room";
-NSString * const kNCPNTypeChatKey       = @"chat";
-NSString * const kNCPNTypeCommentKey    = @"comment";
-
-+ (instancetype)pushNotificationFromDecryptedString:(NSString *)decryptedString
-{
-    if (!decryptedString) {
-        return nil;
-    }
-    
-    NSData *data = [decryptedString dataUsingEncoding:NSUTF8StringEncoding];
-    id jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
-    
-    NCPushNotification *pushNotification = [NCPushNotification new];
-    pushNotification.app = [jsonDict objectForKey:kNCPNAppKey];
-    pushNotification.subject = [jsonDict objectForKey:kNCPNSubjectKey];
-    pushNotification.pnId = [[jsonDict objectForKey:kNCPNIdKey] integerValue];
-    
-    NSString *type = [jsonDict objectForKey:kNCPNTypeKey];
-    pushNotification.type = NCPushNotificationTypeUnknown;
-    
-    if ([type isEqualToString:kNCPNTypeCallKey]) {
-        pushNotification.type = NCPushNotificationTypeCall;
-    } else if ([type isEqualToString:kNCPNTypeRoomKey]) {
-        pushNotification.type = NCPushNotificationTypeRoom;
-    } else if ([type isEqualToString:kNCPNTypeChatKey]) {
-        pushNotification.type = NCPushNotificationTypeChat;
-    } else if ([type isEqualToString:kNCPNTypeCommentKey]) {
-        pushNotification.type = NCPushNotificationTypeComment;
-    } else {
-        pushNotification.type = NCPushNotificationTypeUnknown;
-    }
-    
-    return pushNotification;
-}
-
-- (NSString *)bodyForRemoteAlerts
-{
-    switch (_type) {
-        case NCPushNotificationTypeCall:
-            return [NSString stringWithFormat:@"📞 %@", _subject];
-            break;
-        case NCPushNotificationTypeRoom:
-            return [NSString stringWithFormat:@"🔔 %@", _subject];
-            break;
-        case NCPushNotificationTypeChat:
-            return [NSString stringWithFormat:@"💬 %@", _subject];
-            break;
-        case NCPushNotificationTypeComment:
-            return [NSString stringWithFormat:@"💬 %@", _subject];
-            break;
-        case NCPushNotificationTypeUnknown:
-            return _subject;
-            break;
-    }
-}
-
-@end