NCPushNotification.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // NCPushNotification.m
  3. // VideoCalls
  4. //
  5. // Created by Ivan Sein on 24.11.17.
  6. // Copyright © 2017 struktur AG. All rights reserved.
  7. //
  8. #import "NCPushNotification.h"
  9. @implementation NCPushNotification
  10. NSString * const kNCPNAppKey = @"app";
  11. NSString * const kNCPNTypeKey = @"type";
  12. NSString * const kNCPNSubjectKey = @"subject";
  13. NSString * const kNCPNIdKey = @"id";
  14. NSString * const kNCPNTypeCallKey = @"call";
  15. NSString * const kNCPNTypeRoomKey = @"room";
  16. NSString * const kNCPNTypeChatKey = @"chat";
  17. NSString * const kNCPNTypeCommentKey = @"comment";
  18. + (instancetype)pushNotificationFromDecryptedString:(NSString *)decryptedString
  19. {
  20. if (!decryptedString) {
  21. return nil;
  22. }
  23. NSData *data = [decryptedString dataUsingEncoding:NSUTF8StringEncoding];
  24. id jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  25. NCPushNotification *pushNotification = [NCPushNotification new];
  26. pushNotification.app = [jsonDict objectForKey:kNCPNAppKey];
  27. pushNotification.subject = [jsonDict objectForKey:kNCPNSubjectKey];
  28. pushNotification.pnId = [[jsonDict objectForKey:kNCPNIdKey] integerValue];
  29. NSString *type = [jsonDict objectForKey:kNCPNTypeKey];
  30. pushNotification.type = NCPushNotificationTypeUnknown;
  31. if ([type isEqualToString:kNCPNTypeCallKey]) {
  32. pushNotification.type = NCPushNotificationTypeCall;
  33. } else if ([type isEqualToString:kNCPNTypeRoomKey]) {
  34. pushNotification.type = NCPushNotificationTypeRoom;
  35. } else if ([type isEqualToString:kNCPNTypeChatKey]) {
  36. pushNotification.type = NCPushNotificationTypeChat;
  37. } else if ([type isEqualToString:kNCPNTypeCommentKey]) {
  38. pushNotification.type = NCPushNotificationTypeComment;
  39. } else {
  40. pushNotification.type = NCPushNotificationTypeUnknown;
  41. }
  42. return pushNotification;
  43. }
  44. - (NSString *)bodyForRemoteAlerts
  45. {
  46. switch (_type) {
  47. case NCPushNotificationTypeCall:
  48. return [NSString stringWithFormat:@"📞 %@", _subject];
  49. break;
  50. case NCPushNotificationTypeRoom:
  51. return [NSString stringWithFormat:@"🔔 %@", _subject];
  52. break;
  53. case NCPushNotificationTypeChat:
  54. return [NSString stringWithFormat:@"💬 %@", _subject];
  55. break;
  56. case NCPushNotificationTypeComment:
  57. return [NSString stringWithFormat:@"💬 %@", _subject];
  58. break;
  59. case NCPushNotificationTypeUnknown:
  60. return _subject;
  61. break;
  62. }
  63. }
  64. @end