FIRMessagingRmqManager.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRMessagingPersistentSyncMessage;
  18. /**
  19. * This manages the RMQ persistent store.
  20. *
  21. * The store is used to store all the S2D id's that were received by the client and were ACK'ed
  22. * by us but the server hasn't confirmed the ACK. We don't delete these id's until the server
  23. * ACK's us that they have received them.
  24. *
  25. * We also store the upstream messages(d2s) that were sent by the client.
  26. *
  27. * Also store the lastRMQId that was sent by us so that for a new connection being setup we don't
  28. * duplicate RMQ Id's for the new messages.
  29. */
  30. @interface FIRMessagingRmqManager : NSObject
  31. // designated initializer
  32. - (instancetype)initWithDatabaseName:(NSString *)databaseName;
  33. - (void)loadRmqId;
  34. /**
  35. * Save Server to device message with the given RMQ-ID.
  36. *
  37. * @param rmqID The rmqID of the s2d message to save.
  38. *
  39. */
  40. - (void)saveS2dMessageWithRmqId:(NSString *)rmqID;
  41. #pragma mark - Sync Messages
  42. /**
  43. * Get persisted sync message with rmqID.
  44. *
  45. * @param rmqID The rmqID of the persisted sync message.
  46. *
  47. * @return A valid persistent sync message with the given rmqID if found in the RMQ else nil.
  48. */
  49. - (FIRMessagingPersistentSyncMessage *)querySyncMessageWithRmqID:(NSString *)rmqID;
  50. /**
  51. * Delete the expired sync messages from persisten store. Also deletes messages that have been
  52. * delivered both via APNS and MCS.
  53. */
  54. - (void)deleteExpiredOrFinishedSyncMessages;
  55. /**
  56. * Save sync message received by the device.
  57. *
  58. * @param rmqID The rmqID of the message received.
  59. * @param expirationTime The expiration time of the sync message received.
  60. *
  61. */
  62. - (void)saveSyncMessageWithRmqID:(NSString *)rmqID expirationTime:(int64_t)expirationTime;
  63. /**
  64. * Update sync message received via APNS.
  65. *
  66. * @param rmqID The rmqID of the received message.
  67. *
  68. */
  69. - (void)updateSyncMessageViaAPNSWithRmqID:(NSString *)rmqID;
  70. /**
  71. * Returns path for database with specified name.
  72. * @param databaseName The database name without extension: "<databaseName>.sqlite".
  73. * @return Path to the database with the specified name.
  74. */
  75. + (NSString *)pathForDatabaseWithName:(NSString *)databaseName;
  76. @end