NCPushNotification.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 kNCPNAppIdKey = @"spreed";
  12. NSString * const kNCPNAppIdKeyComments = @"comments";
  13. NSString * const kNCPNTypeKey = @"type";
  14. NSString * const kNCPNSubjectKey = @"subject";
  15. NSString * const kNCPNIdKey = @"id";
  16. NSString * const kNCPNTypeCallKey = @"call";
  17. NSString * const kNCPNTypeRoomKey = @"room";
  18. NSString * const kNCPNTypeChatKey = @"chat";
  19. NSString * const kNCPNTypeCommentKey = @"comment";
  20. NSString * const NCPushNotificationJoinChatNotification = @"NCPushNotificationJoinChatNotification";
  21. NSString * const NCPushNotificationJoinAudioCallAcceptedNotification = @"NCPushNotificationJoinAudioCallAcceptedNotification";
  22. NSString * const NCPushNotificationJoinVideoCallAcceptedNotification = @"NCPushNotificationJoinVideoCallAcceptedNotification";
  23. + (instancetype)pushNotificationFromDecryptedString:(NSString *)decryptedString
  24. {
  25. if (!decryptedString) {
  26. return nil;
  27. }
  28. NSData *data = [decryptedString dataUsingEncoding:NSUTF8StringEncoding];
  29. id jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  30. NCPushNotification *pushNotification = [NCPushNotification new];
  31. pushNotification.app = [jsonDict objectForKey:kNCPNAppKey];
  32. pushNotification.subject = [jsonDict objectForKey:kNCPNSubjectKey];
  33. pushNotification.pnId = [[jsonDict objectForKey:kNCPNIdKey] integerValue];
  34. NSString *type = [jsonDict objectForKey:kNCPNTypeKey];
  35. pushNotification.type = NCPushNotificationTypeUnknown;
  36. if ([type isEqualToString:kNCPNTypeCallKey]) {
  37. pushNotification.type = NCPushNotificationTypeCall;
  38. } else if ([type isEqualToString:kNCPNTypeRoomKey]) {
  39. pushNotification.type = NCPushNotificationTypeRoom;
  40. } else if ([type isEqualToString:kNCPNTypeChatKey]) {
  41. pushNotification.type = NCPushNotificationTypeChat;
  42. } else if ([type isEqualToString:kNCPNTypeCommentKey]) {
  43. pushNotification.type = NCPushNotificationTypeComment;
  44. } else {
  45. pushNotification.type = NCPushNotificationTypeUnknown;
  46. }
  47. return pushNotification;
  48. }
  49. - (NSString *)bodyForRemoteAlerts
  50. {
  51. switch (_type) {
  52. case NCPushNotificationTypeCall:
  53. return [NSString stringWithFormat:@"📞 %@", _subject];
  54. break;
  55. case NCPushNotificationTypeRoom:
  56. return [NSString stringWithFormat:@"🔔 %@", _subject];
  57. break;
  58. case NCPushNotificationTypeChat:
  59. return [NSString stringWithFormat:@"💬 %@", _subject];
  60. break;
  61. case NCPushNotificationTypeComment:
  62. return [NSString stringWithFormat:@"💬 %@", _subject];
  63. break;
  64. case NCPushNotificationTypeUnknown:
  65. return _subject;
  66. break;
  67. }
  68. }
  69. @end