NCPushNotification.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. NSString *app = [jsonDict objectForKey:kNCPNAppKey];
  31. if (![app isEqualToString:kNCPNAppIdKeyComments]) {
  32. return nil;
  33. }
  34. NCPushNotification *pushNotification = [[NCPushNotification alloc] init];
  35. pushNotification.app = app;
  36. pushNotification.subject = [jsonDict objectForKey:kNCPNSubjectKey];
  37. pushNotification.pnId = [[jsonDict objectForKey:kNCPNIdKey] integerValue];
  38. NSString *type = [jsonDict objectForKey:kNCPNTypeKey];
  39. pushNotification.type = NCPushNotificationTypeUnknown;
  40. if ([type isEqualToString:kNCPNTypeCallKey]) {
  41. pushNotification.type = NCPushNotificationTypeCall;
  42. } else if ([type isEqualToString:kNCPNTypeRoomKey]) {
  43. pushNotification.type = NCPushNotificationTypeRoom;
  44. } else if ([type isEqualToString:kNCPNTypeChatKey]) {
  45. pushNotification.type = NCPushNotificationTypeChat;
  46. } else if ([type isEqualToString:kNCPNTypeCommentKey]) {
  47. pushNotification.type = NCPushNotificationTypeComment;
  48. }
  49. return pushNotification;
  50. }
  51. - (NSString *)bodyForRemoteAlerts
  52. {
  53. switch (_type) {
  54. case NCPushNotificationTypeCall:
  55. return [NSString stringWithFormat:@"📞 %@", _subject];
  56. break;
  57. case NCPushNotificationTypeRoom:
  58. return [NSString stringWithFormat:@"🔔 %@", _subject];
  59. break;
  60. case NCPushNotificationTypeChat:
  61. return [NSString stringWithFormat:@"💬 %@", _subject];
  62. break;
  63. case NCPushNotificationTypeComment:
  64. return [NSString stringWithFormat:@"💬 %@", _subject];
  65. break;
  66. case NCPushNotificationTypeUnknown:
  67. return _subject;
  68. break;
  69. }
  70. }
  71. @end