parent
654ef89049
commit
bf18b1f286
|
@ -19,7 +19,7 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
|
|||
TSErrorMessageUnknownContactBlockOffer,
|
||||
};
|
||||
|
||||
-(instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSThread *)thread
|
||||
failedMessageType:(TSErrorMessageType)errorMessageType NS_DESIGNATED_INITIALIZER;
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
messageBody:nil
|
||||
attachmentIds:@[]
|
||||
expiresInSeconds:0
|
||||
expireStartedAt:0];
|
||||
expireStartedAt:0
|
||||
groupMetaMessage:TSGroupMessageNone];
|
||||
|
||||
if (!self) {
|
||||
return self;
|
||||
|
|
|
@ -47,7 +47,8 @@ NSString *const TSIncomingMessageWasReadOnThisDeviceNotification = @"TSIncomingM
|
|||
messageBody:body
|
||||
attachmentIds:attachmentIds
|
||||
expiresInSeconds:expiresInSeconds
|
||||
expireStartedAt:0];
|
||||
expireStartedAt:0
|
||||
groupMetaMessage:TSGroupMessageNone];
|
||||
|
||||
if (!self) {
|
||||
return self;
|
||||
|
|
|
@ -19,8 +19,8 @@ typedef NS_ENUM(NSInteger, TSInfoMessageType) {
|
|||
|
||||
+ (instancetype)userNotRegisteredMessageInThread:(TSThread *)thread;
|
||||
|
||||
@property TSInfoMessageType messageType;
|
||||
@property NSString *customMessage;
|
||||
@property (atomic, readonly) TSInfoMessageType messageType;
|
||||
@property (atomic, readonly) NSString *customMessage;
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
messageBody:nil
|
||||
attachmentIds:@[]
|
||||
expiresInSeconds:0
|
||||
expireStartedAt:0];
|
||||
expireStartedAt:0
|
||||
groupMetaMessage:TSGroupMessageNone];
|
||||
|
||||
if (!self) {
|
||||
return self;
|
||||
|
|
|
@ -104,7 +104,6 @@
|
|||
|
||||
TSThread *fetchedThread = [TSThread fetchObjectWithUniqueID:self.uniqueThreadId transaction:transaction];
|
||||
|
||||
|
||||
[fetchedThread updateWithLastMessage:self transaction:transaction];
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
|
|||
|
||||
@property (nonatomic, readonly) NSMutableArray<NSString *> *attachmentIds;
|
||||
@property (nullable, nonatomic) NSString *body;
|
||||
@property (nonatomic) TSGroupMetaMessage groupMetaMessage;
|
||||
@property (atomic, readonly) TSGroupMetaMessage groupMetaMessage;
|
||||
@property (nonatomic) uint32_t expiresInSeconds;
|
||||
@property (nonatomic) uint64_t expireStartedAt;
|
||||
@property (nonatomic, readonly) uint64_t expiresAt;
|
||||
|
@ -58,7 +58,15 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
|
|||
messageBody:(nullable NSString *)body
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
expiresInSeconds:(uint32_t)expiresInSeconds
|
||||
expireStartedAt:(uint64_t)expireStartedAt NS_DESIGNATED_INITIALIZER;
|
||||
expireStartedAt:(uint64_t)expireStartedAt;
|
||||
|
||||
- (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
|
||||
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#import "TSAttachment.h"
|
||||
#import "TSAttachmentPointer.h"
|
||||
#import "TSThread.h"
|
||||
#import <YapDatabase/YapDatabase.h>
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
@ -35,8 +36,12 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
|
|||
*/
|
||||
@property (nonatomic, readonly) NSUInteger schemaVersion;
|
||||
|
||||
@property (atomic) TSGroupMetaMessage groupMetaMessage;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation TSMessage
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
|
@ -88,6 +93,23 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
|
|||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
expiresInSeconds:(uint32_t)expiresInSeconds
|
||||
expireStartedAt:(uint64_t)expireStartedAt
|
||||
{
|
||||
return [self initWithTimestamp:timestamp
|
||||
inThread:thread
|
||||
messageBody:body
|
||||
attachmentIds:attachmentIds
|
||||
expiresInSeconds:expiresInSeconds
|
||||
expireStartedAt:expireStartedAt
|
||||
groupMetaMessage:TSGroupMessageNone];
|
||||
}
|
||||
|
||||
- (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
|
||||
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp inThread:thread];
|
||||
|
||||
|
@ -103,6 +125,7 @@ static const NSUInteger OWSMessageSchemaVersion = 3;
|
|||
_expireStartedAt = expireStartedAt;
|
||||
[self updateExpiresAt];
|
||||
_receivedAtDate = [NSDate date];
|
||||
_groupMetaMessage = groupMetaMessage;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@ typedef NS_ENUM(NSInteger, TSOutgoingMessageState) {
|
|||
inThread:(nullable TSThread *)thread
|
||||
messageBody:(nullable NSString *)body;
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(nullable TSThread *)thread
|
||||
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage;
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(nullable TSThread *)thread
|
||||
messageBody:(nullable NSString *)body
|
||||
|
@ -49,7 +53,15 @@ typedef NS_ENUM(NSInteger, TSOutgoingMessageState) {
|
|||
messageBody:(nullable NSString *)body
|
||||
attachmentIds:(NSMutableArray<NSString *> *)attachmentIds
|
||||
expiresInSeconds:(uint32_t)expiresInSeconds
|
||||
expireStartedAt:(uint64_t)expireStartedAt NS_DESIGNATED_INITIALIZER;
|
||||
expireStartedAt:(uint64_t)expireStartedAt;
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(nullable TSThread *)thread
|
||||
messageBody:(nullable NSString *)body
|
||||
attachmentIds:(NSMutableArray<NSString *> *)attachmentIds
|
||||
expiresInSeconds:(uint32_t)expiresInSeconds
|
||||
expireStartedAt:(uint64_t)expireStartedAt
|
||||
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
|
|
|
@ -110,13 +110,46 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|||
attachmentIds:(NSMutableArray<NSString *> *)attachmentIds
|
||||
expiresInSeconds:(uint32_t)expiresInSeconds
|
||||
expireStartedAt:(uint64_t)expireStartedAt
|
||||
{
|
||||
TSGroupMetaMessage groupMetaMessage
|
||||
= ([thread isKindOfClass:[TSGroupThread class]] ? TSGroupMessageDeliver : TSGroupMessageNone);
|
||||
return [self initWithTimestamp:timestamp
|
||||
inThread:thread
|
||||
messageBody:body
|
||||
attachmentIds:attachmentIds
|
||||
expiresInSeconds:expiresInSeconds
|
||||
expireStartedAt:expireStartedAt
|
||||
groupMetaMessage:groupMetaMessage];
|
||||
}
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(nullable TSThread *)thread
|
||||
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage
|
||||
{
|
||||
return [self initWithTimestamp:timestamp
|
||||
inThread:thread
|
||||
messageBody:@""
|
||||
attachmentIds:[NSMutableArray new]
|
||||
expiresInSeconds:0
|
||||
expireStartedAt:0
|
||||
groupMetaMessage:groupMetaMessage];
|
||||
}
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(nullable TSThread *)thread
|
||||
messageBody:(nullable NSString *)body
|
||||
attachmentIds:(NSMutableArray<NSString *> *)attachmentIds
|
||||
expiresInSeconds:(uint32_t)expiresInSeconds
|
||||
expireStartedAt:(uint64_t)expireStartedAt
|
||||
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp
|
||||
inThread:thread
|
||||
messageBody:body
|
||||
attachmentIds:attachmentIds
|
||||
expiresInSeconds:expiresInSeconds
|
||||
expireStartedAt:expireStartedAt];
|
||||
expireStartedAt:expireStartedAt
|
||||
groupMetaMessage:groupMetaMessage];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
@ -125,11 +158,6 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|||
_sentRecipients = [NSArray new];
|
||||
_hasSyncedTranscript = NO;
|
||||
|
||||
if ([thread isKindOfClass:[TSGroupThread class]]) {
|
||||
self.groupMetaMessage = TSGroupMessageDeliver;
|
||||
} else {
|
||||
self.groupMetaMessage = TSGroupMessageNone;
|
||||
}
|
||||
_attachmentFilenameMap = [NSMutableDictionary new];
|
||||
|
||||
OWSAssert(self.receivedAtDate);
|
||||
|
@ -169,15 +197,15 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|||
|
||||
#pragma mark - Update Methods
|
||||
|
||||
- (void)applyChangeToSelfAndLatest:(YapDatabaseReadWriteTransaction *)transaction
|
||||
changeBlock:(void (^)(TSOutgoingMessage *))changeBlock
|
||||
- (void)applyChangeToSelfAndLatestOutgoingMessage:(YapDatabaseReadWriteTransaction *)transaction
|
||||
changeBlock:(void (^)(TSOutgoingMessage *))changeBlock
|
||||
{
|
||||
OWSAssert(transaction);
|
||||
|
||||
changeBlock(self);
|
||||
|
||||
TSOutgoingMessage *latestMessage =
|
||||
[transaction objectForKey:self.uniqueId inCollection:[TSOutgoingMessage collection]];
|
||||
NSString *collection = [[self class] collection];
|
||||
TSOutgoingMessage *latestMessage = [transaction objectForKey:self.uniqueId inCollection:collection];
|
||||
if (latestMessage) {
|
||||
changeBlock(latestMessage);
|
||||
[latestMessage saveWithTransaction:transaction];
|
||||
|
@ -192,31 +220,31 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|||
OWSAssert(error);
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self applyChangeToSelfAndLatest:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setMessageState:TSOutgoingMessageStateUnsent];
|
||||
[message setMostRecentFailureText:error.localizedDescription];
|
||||
}];
|
||||
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setMessageState:TSOutgoingMessageStateUnsent];
|
||||
[message setMostRecentFailureText:error.localizedDescription];
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)updateWithMessageState:(TSOutgoingMessageState)messageState
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self applyChangeToSelfAndLatest:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setMessageState:messageState];
|
||||
}];
|
||||
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setMessageState:messageState];
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)updateWithHasSyncedTranscript:(BOOL)hasSyncedTranscript
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self applyChangeToSelfAndLatest:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setHasSyncedTranscript:hasSyncedTranscript];
|
||||
}];
|
||||
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setHasSyncedTranscript:hasSyncedTranscript];
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
|
@ -225,10 +253,10 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|||
OWSAssert(customMessage);
|
||||
OWSAssert(transaction);
|
||||
|
||||
[self applyChangeToSelfAndLatest:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setCustomMessage:customMessage];
|
||||
}];
|
||||
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setCustomMessage:customMessage];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)updateWithCustomMessage:(NSString *)customMessage
|
||||
|
@ -242,10 +270,10 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|||
{
|
||||
OWSAssert(transaction);
|
||||
|
||||
[self applyChangeToSelfAndLatest:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setWasDelivered:YES];
|
||||
}];
|
||||
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message setWasDelivered:YES];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)updateWithWasDelivered
|
||||
|
@ -297,10 +325,10 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|||
- (void)updateWithSentRecipient:(NSString *)contactId transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(transaction);
|
||||
[self applyChangeToSelfAndLatest:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message addSentRecipient:contactId];
|
||||
}];
|
||||
[self applyChangeToSelfAndLatestOutgoingMessage:transaction
|
||||
changeBlock:^(TSOutgoingMessage *message) {
|
||||
[message addSentRecipient:contactId];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)updateWithSentRecipient:(NSString *)contactId
|
||||
|
|
Loading…
Reference in New Issue