You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/SignalServiceKit/src/Storage/TSYapDatabaseObject.h

158 lines
5.0 KiB
C

//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
10 years ago
#import <Mantle/MTLModel+NSCoding.h>
NS_ASSUME_NONNULL_BEGIN
@class TSStorageManager;
@class YapDatabaseConnection;
@class YapDatabaseReadTransaction;
@class YapDatabaseReadWriteTransaction;
10 years ago
@interface TSYapDatabaseObject : MTLModel
/**
* Initializes a new database object with a unique identifier
*
* @param uniqueId Key used for the key-value store
*
* @return Initialized object
*/
- (instancetype)initWithUniqueId:(NSString *_Nullable)uniqueId NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
10 years ago
/**
* Returns the collection to which the object belongs.
*
* @return Key (string) identifying the collection
*/
+ (NSString *)collection;
/**
* Get the number of keys in the models collection. Be aware that if there
* are multiple object types in this collection that the count will include
* the count of other objects in the same collection.
*
* @return The number of keys in the classes collection.
*/
+ (NSUInteger)numberOfKeysInCollection;
+ (NSUInteger)numberOfKeysInCollectionWithTransaction:(YapDatabaseReadTransaction *)transaction;
/**
* Removes all objects in the classes collection.
*/
+ (void)removeAllObjectsInCollection;
/**
* A memory intesive method to get all objects in the collection. You should prefer using enumeration over this method
* whenever feasible. See `enumerateObjectsInCollectionUsingBlock`
*
* @return All objects in the classes collection.
*/
+ (NSArray *)allObjectsInCollection;
/**
* Enumerates all objects in collection.
*/
+ (void)enumerateCollectionObjectsUsingBlock:(void (^)(id obj, BOOL *stop))block;
+ (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction
usingBlock:(void (^)(id object, BOOL *stop))block;
/**
* @return Shared database connections for reading and writing.
*/
- (YapDatabaseConnection *)dbReadConnection;
+ (YapDatabaseConnection *)dbReadConnection;
- (YapDatabaseConnection *)dbReadWriteConnection;
+ (YapDatabaseConnection *)dbReadWriteConnection;
- (TSStorageManager *)storageManager;
+ (TSStorageManager *)storageManager;
10 years ago
/**
* Fetches the object with the provided identifier
*
* @param uniqueID Unique identifier of the entry in a collection
* @param transaction Transaction used for fetching the object
*
* @return Instance of the object or nil if non-existent
10 years ago
*/
+ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID
transaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(fetch(uniqueId:transaction
:));
+ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID NS_SWIFT_NAME(fetch(uniqueId:));
10 years ago
/**
* Saves the object with the shared readWrite connection.
*
* This method will block if another readWrite transaction is open.
10 years ago
*/
- (void)save;
/**
* Saves the object with the shared readWrite connection - does not block.
*
* Be mindful that this method may clobber other changes persisted
* while waiting to open the readWrite transaction.
*
* @param completionBlock is called on the main thread
*/
- (void)saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock;
10 years ago
/**
* Saves the object with the provided transaction
*
* @param transaction Database transaction
*/
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
Explain send failures for text and media messages Motivation ---------- We were often swallowing errors or yielding generic errors when it would be better to provide specific errors. We also didn't create an attachment when attachments failed to send, making it impossible to show the user what was happening with an in-progress or failed attachment. Primary Changes --------------- - Funnel all message sending through MessageSender, and remove message sending from MessagesManager. - Record most recent sending error so we can expose it in the UI - Can resend attachments. - Update message status for attachments, just like text messages - Extracted UploadingService from MessagesManager - Saving attachment stream before uploading gives uniform API for send vs. resend - update status for downloading transcript attachments - TSAttachments have a local id, separate from the server allocated id This allows us to save the attachment before the allocation request. Which is is good because: 1. can show feedback to user faster. 2. allows us to show an error when allocation fails. Code Cleanup ------------ - Replaced a lot of global singleton access with injected dependencies to make for easier testing. - Never save group meta messages. Rather than checking before (hopefully) every save, do it in the save method. - Don't use callbacks for sync code. - Handle errors on writing attachment data - Fix old long broken tests that weren't even running. =( - Removed dead code - Use constants vs define - Port flaky travis fixes from Signal-iOS // FREEBIE
9 years ago
/**
* `touch` is a cheap way to fire a YapDatabaseModified notification to redraw anythign depending on the model.
*/
- (void)touch;
Explain send failures for text and media messages Motivation ---------- We were often swallowing errors or yielding generic errors when it would be better to provide specific errors. We also didn't create an attachment when attachments failed to send, making it impossible to show the user what was happening with an in-progress or failed attachment. Primary Changes --------------- - Funnel all message sending through MessageSender, and remove message sending from MessagesManager. - Record most recent sending error so we can expose it in the UI - Can resend attachments. - Update message status for attachments, just like text messages - Extracted UploadingService from MessagesManager - Saving attachment stream before uploading gives uniform API for send vs. resend - update status for downloading transcript attachments - TSAttachments have a local id, separate from the server allocated id This allows us to save the attachment before the allocation request. Which is is good because: 1. can show feedback to user faster. 2. allows us to show an error when allocation fails. Code Cleanup ------------ - Replaced a lot of global singleton access with injected dependencies to make for easier testing. - Never save group meta messages. Rather than checking before (hopefully) every save, do it in the save method. - Don't use callbacks for sync code. - Handle errors on writing attachment data - Fix old long broken tests that weren't even running. =( - Removed dead code - Use constants vs define - Port flaky travis fixes from Signal-iOS // FREEBIE
9 years ago
- (void)touchWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
10 years ago
/**
* The unique identifier of the stored object
*/
@property (nonatomic, nullable) NSString *uniqueId;
10 years ago
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)remove;
#pragma mark Update With...
// This method is used by "updateWith..." methods.
//
// This model may be updated from many threads. We don't want to save
// our local copy (this instance) since it may be out of date. We also
// want to avoid re-saving a model that has been deleted. Therefore, we
// use "updateWith..." methods to:
//
// a) Update a property of this instance.
// b) If a copy of this model exists in the database, load an up-to-date copy,
// and update and save that copy.
// b) If a copy of this model _DOES NOT_ exist in the database, do _NOT_ save
// this local instance.
//
// After "updateWith...":
//
// a) Any copy of this model in the database will have been updated.
// b) The local property on this instance will always have been updated.
// c) Other properties on this instance may be out of date.
//
// All mutable properties of this class have been made read-only to
// prevent accidentally modifying them directly.
//
// This isn't a perfect arrangement, but in practice this will prevent
// data loss and will resolve all known issues.
- (void)applyChangeToSelfAndLatestCopy:(YapDatabaseReadWriteTransaction *)transaction
changeBlock:(void (^)(id))changeBlock;
10 years ago
@end
NS_ASSUME_NONNULL_END