|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "TSInteraction.h"
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract message class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@class TSAttachmentPointer;
|
|
|
|
|
|
|
|
@interface TSMessage : TSInteraction
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) NSMutableArray<NSString *> *attachmentIds;
|
|
|
|
@property (nonatomic, readonly, nullable) NSString *body;
|
|
|
|
@property (nonatomic, readonly) uint32_t expiresInSeconds;
|
|
|
|
@property (nonatomic, readonly) uint64_t expireStartedAt;
|
|
|
|
@property (nonatomic, readonly) uint64_t expiresAt;
|
|
|
|
@property (nonatomic, readonly) BOOL isExpiringMessage;
|
|
|
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp;
|
|
|
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread;
|
|
|
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
|
|
|
inThread:(nullable TSThread *)thread
|
|
|
|
messageBody:(nullable NSString *)body;
|
|
|
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
|
|
|
inThread:(nullable TSThread *)thread
|
|
|
|
messageBody:(nullable NSString *)body
|
|
|
|
attachmentIds:(NSArray<NSString *> *)attachmentIds;
|
|
|
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
|
|
|
inThread:(nullable TSThread *)thread
|
|
|
|
messageBody:(nullable NSString *)body
|
|
|
|
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
|
|
|
expiresInSeconds:(uint32_t)expiresInSeconds;
|
|
|
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
|
|
|
inThread:(nullable TSThread *)thread
|
|
|
|
messageBody:(nullable NSString *)body
|
|
|
|
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
|
|
|
expiresInSeconds:(uint32_t)expiresInSeconds
|
|
|
|
expireStartedAt:(uint64_t)expireStartedAt NS_DESIGNATED_INITIALIZER;
|
|
|
|
|
|
|
|
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
|
|
|
|
|
|
|
- (BOOL)hasAttachments;
|
|
|
|
|
|
|
|
- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction;
|
|
|
|
|
|
|
|
- (BOOL)shouldStartExpireTimer;
|
|
|
|
- (BOOL)shouldStartExpireTimer:(YapDatabaseReadTransaction *)transaction;
|
|
|
|
|
|
|
|
#pragma mark - Update 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 these "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) An 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)updateWithExpireStartedAt:(uint64_t)expireStartedAt transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|