FSTWatchChange.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  18. #include "Firestore/core/src/firebase/firestore/model/types.h"
  19. #include "Firestore/core/src/firebase/firestore/remote/existence_filter.h"
  20. @class FSTMaybeDocument;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /**
  23. * FSTWatchChange is the internal representation of the watcher API protocol buffers.
  24. * This is an empty abstract class so that all the different kinds of changes can have a common
  25. * base class.
  26. */
  27. @interface FSTWatchChange : NSObject
  28. @end
  29. /**
  30. * FSTDocumentWatchChange represents a changed document and a list of target ids to which this
  31. * change applies. If the document has been deleted, the deleted document will be provided.
  32. */
  33. @interface FSTDocumentWatchChange : FSTWatchChange
  34. - (instancetype)initWithUpdatedTargetIDs:(NSArray<NSNumber *> *)updatedTargetIDs
  35. removedTargetIDs:(NSArray<NSNumber *> *)removedTargetIDs
  36. documentKey:(firebase::firestore::model::DocumentKey)documentKey
  37. document:(nullable FSTMaybeDocument *)document
  38. NS_DESIGNATED_INITIALIZER;
  39. - (instancetype)init NS_UNAVAILABLE;
  40. /** The key of the document for this change. */
  41. - (const firebase::firestore::model::DocumentKey &)documentKey;
  42. /** The new document applies to all of these targets. */
  43. @property(nonatomic, strong, readonly) NSArray<NSNumber *> *updatedTargetIDs;
  44. /** The new document is removed from all of these targets. */
  45. @property(nonatomic, strong, readonly) NSArray<NSNumber *> *removedTargetIDs;
  46. /**
  47. * The new document or DeletedDocument if it was deleted. Is null if the document went out of
  48. * view without the server sending a new document.
  49. */
  50. @property(nonatomic, strong, readonly, nullable) FSTMaybeDocument *document;
  51. @end
  52. /**
  53. * An ExistenceFilterWatchChange applies to the targets and is required to verify the current client
  54. * state against expected state sent from the server.
  55. */
  56. @interface FSTExistenceFilterWatchChange : FSTWatchChange
  57. + (instancetype)changeWithFilter:(firebase::firestore::remote::ExistenceFilter)filter
  58. targetID:(firebase::firestore::model::TargetId)targetID;
  59. - (instancetype)init NS_UNAVAILABLE;
  60. - (const firebase::firestore::remote::ExistenceFilter &)filter;
  61. @property(nonatomic, assign, readonly) firebase::firestore::model::TargetId targetID;
  62. @end
  63. /** FSTWatchTargetChangeState is the kind of change that happened to the watch target. */
  64. typedef NS_ENUM(NSInteger, FSTWatchTargetChangeState) {
  65. FSTWatchTargetChangeStateNoChange,
  66. FSTWatchTargetChangeStateAdded,
  67. FSTWatchTargetChangeStateRemoved,
  68. FSTWatchTargetChangeStateCurrent,
  69. FSTWatchTargetChangeStateReset,
  70. };
  71. /** FSTWatchTargetChange is a change to a watch target. */
  72. @interface FSTWatchTargetChange : FSTWatchChange
  73. - (instancetype)initWithState:(FSTWatchTargetChangeState)state
  74. targetIDs:(NSArray<NSNumber *> *)targetIDs
  75. resumeToken:(NSData *)resumeToken
  76. cause:(nullable NSError *)cause NS_DESIGNATED_INITIALIZER;
  77. - (instancetype)init NS_UNAVAILABLE;
  78. /** What kind of change occurred to the watch target. */
  79. @property(nonatomic, assign, readonly) FSTWatchTargetChangeState state;
  80. /** The target IDs that were added/removed/set. */
  81. @property(nonatomic, strong, readonly) NSArray<NSNumber *> *targetIDs;
  82. /**
  83. * An opaque, server-assigned token that allows watching a query to be resumed after disconnecting
  84. * without retransmitting all the data that matches the query. The resume token essentially
  85. * identifies a point in time from which the server should resume sending results.
  86. */
  87. @property(nonatomic, strong, readonly) NSData *resumeToken;
  88. /** An RPC error indicating why the watch failed. */
  89. @property(nonatomic, strong, readonly, nullable) NSError *cause;
  90. @end
  91. NS_ASSUME_NONNULL_END