fix captions in groups and sync messages (#42)

* Fix incoming group caption for groups.
* sync message transcript captions are expired

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 40cdc7f224
commit 34868b9b0f

@ -48,12 +48,13 @@ NS_ASSUME_NONNULL_BEGIN
messagesManager:self.messagesManager];
// TODO group updates. Currently desktop doesn't support group updates, so not a problem yet.
TSOutgoingMessage *outgoingMessage = [[TSOutgoingMessage alloc] initWithTimestamp:transcript.timestamp
inThread:thread
messageBody:transcript.body
attachmentIds:attachmentsProcessor.attachmentIds
expiresInSeconds:transcript.expirationDuration
expireStartedAt:transcript.expirationStartedAt];
TSOutgoingMessage *outgoingMessage =
[[TSOutgoingMessage alloc] initWithTimestamp:transcript.timestamp
inThread:thread
messageBody:transcript.body
attachmentIds:[attachmentsProcessor.attachmentIds mutableCopy]
expiresInSeconds:transcript.expirationDuration
expireStartedAt:transcript.expirationStartedAt];
if (transcript.isExpirationTimerUpdate) {
[self.messagesManager becomeConsistentWithDisappearingConfigurationForMessage:outgoingMessage];
@ -71,7 +72,10 @@ NS_ASSUME_NONNULL_BEGIN
uint64_t textMessageTimestamp = transcript.timestamp + 1;
TSOutgoingMessage *textMessage = [[TSOutgoingMessage alloc] initWithTimestamp:textMessageTimestamp
inThread:thread
messageBody:transcript.body];
messageBody:transcript.body
attachmentIds:[NSMutableArray new]
expiresInSeconds:transcript.expirationDuration
expireStartedAt:transcript.expirationStartedAt];
textMessage.messageState = TSOutgoingMessageStateDelivered;
[textMessage save];
}

@ -12,43 +12,6 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
@interface TSIncomingMessage : TSMessage
/**
* Inits an incoming (non-group) message with no attachments.
*
* @param timestamp
* When the message was created in milliseconds since epoch
* @param thread
* Thread to which the message belongs
* @param body
* Body of the message
* @param attachmentIds
* The uniqueIds for the message's attachments
*
* @return initiated incoming message
*/
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSContactThread *)thread
messageBody:(nullable NSString *)body;
/**
* Inits an incoming (non-group) message with attachments.
*
* @param timestamp
* When the message was created in milliseconds since epoch
* @param thread
* Thread to which the message belongs
* @param body
* Body of the message
* @param attachmentIds
* The uniqueIds for the message's attachments
*
* @return initiated incoming message
*/
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSContactThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds;
/**
* Inits an incoming group message without attachments
*
@ -64,8 +27,8 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
* @return initiated incoming group message
*/
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSGroupThread *)thread
authorId:(nullable NSString *)authorId
inThread:(TSThread *)thread
authorId:(NSString *)authorId
messageBody:(nullable NSString *)body;
/**
@ -85,8 +48,8 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
* @return initiated incoming group message
*/
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSGroupThread *)thread
authorId:(nullable NSString *)authorId
inThread:(TSThread *)thread
authorId:(NSString *)authorId
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds;
@ -109,11 +72,39 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
* @return initiated incoming group message
*/
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSGroupThread *)thread
authorId:(nullable NSString *)authorId
inThread:(TSThread *)thread
authorId:(NSString *)authorId
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
expiresInSeconds:(uint32_t)expiresInSeconds NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
/**
* For sake of a smaller API, you must specify an author id for all incoming messages
* though we technically could get the author id from a contact thread.
*/
- (instancetype)initWithTimestamp:(uint64_t)timestamp NS_UNAVAILABLE;
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread NS_UNAVAILABLE;
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body NS_UNAVAILABLE;
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds NS_UNAVAILABLE;
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
expiresInSeconds:(uint32_t)expiresInSeconds NS_UNAVAILABLE;
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
expiresInSeconds:(uint32_t)expiresInSeconds;
expiresInSeconds:(uint32_t)expiresInSeconds
expireStartedAt:(uint64_t)expireStartedAt NS_UNAVAILABLE;
/*
* Find a message matching the senderId and timestamp, if any.

@ -13,91 +13,36 @@ NSString *const TSIncomingMessageWasReadOnThisDeviceNotification = @"TSIncomingM
@implementation TSIncomingMessage
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSContactThread *)thread
messageBody:(nullable NSString *)body
{
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:@[]];
if (!self) {
return self;
}
// _authorId was nil for contact thread messages prior to 2.6.0
_authorId = [thread contactIdentifier];
_read = NO;
_receivedAt = [NSDate date];
return self;
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
expiresInSeconds:(uint32_t)expiresInSeconds
{
self = [self initWithTimestamp:timestamp
inThread:thread
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:expiresInSeconds
expireStartedAt:0];
if (!self) {
return self;
}
// _authorId was nil for contact thread messages prior to 2.6.0
_authorId = [thread contactIdentifier];
_read = NO;
_receivedAt = [NSDate date];
return self;
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSContactThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:attachmentIds];
if (!self) {
return self;
}
// _authorId was nil for contact thread messages prior to 2.6.0
_authorId = [thread contactIdentifier];
_read = NO;
_receivedAt = [NSDate date];
return self;
return [super initWithCoder:coder];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSGroupThread *)thread
authorId:(nullable NSString *)authorId
inThread:(TSThread *)thread
authorId:(NSString *)authorId
messageBody:(nullable NSString *)body
{
return [self initWithTimestamp:timestamp inThread:thread authorId:authorId messageBody:body attachmentIds:@[]];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSGroupThread *)thread
authorId:(nullable NSString *)authorId
inThread:(TSThread *)thread
authorId:(NSString *)authorId
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
{
return [self initWithTimestamp:timestamp
inThread:thread
authorId:authorId
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:0];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSGroupThread *)thread
authorId:(nullable NSString *)authorId
inThread:(TSThread *)thread
authorId:(NSString *)authorId
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
expiresInSeconds:(uint32_t)expiresInSeconds
@ -106,7 +51,8 @@ NSString *const TSIncomingMessageWasReadOnThisDeviceNotification = @"TSIncomingM
inThread:thread
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:expiresInSeconds];
expiresInSeconds:expiresInSeconds
expireStartedAt:0];
if (!self) {
return self;

@ -17,6 +17,33 @@ typedef NS_ENUM(NSInteger, TSOutgoingMessageState) {
TSOutgoingMessageStateDelivered
};
- (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:(NSMutableArray<NSString *> *)attachmentIds;
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSMutableArray<NSString *> *)attachmentIds
expiresInSeconds:(uint32_t)expiresInSeconds;
- (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 NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
@property (nonatomic) TSOutgoingMessageState messageState;
@property BOOL hasSyncedTranscript;

@ -12,11 +12,26 @@ NS_ASSUME_NONNULL_BEGIN
@implementation TSOutgoingMessage
- (instancetype)initWithCoder:(NSCoder *)coder
{
return [super initWithCoder:coder];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
{
return [self initWithTimestamp:timestamp inThread:nil];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread
{
return [self initWithTimestamp:timestamp inThread:nil messageBody:nil];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
{
return [self initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:@[]];
return [self initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:[NSMutableArray new]];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
@ -24,8 +39,11 @@ NS_ASSUME_NONNULL_BEGIN
messageBody:(nullable NSString *)body
attachmentIds:(NSMutableArray<NSString *> *)attachmentIds
{
return [self initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:@[] expiresInSeconds:0];
return [self initWithTimestamp:timestamp
inThread:thread
messageBody:body
attachmentIds:[NSMutableArray new]
expiresInSeconds:0];
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
@ -35,12 +53,27 @@ NS_ASSUME_NONNULL_BEGIN
expiresInSeconds:(uint32_t)expiresInSeconds
{
uint64_t now = [NSDate ows_millisecondTimeStamp];
return [self initWithTimestamp:timestamp
inThread:thread
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:expiresInSeconds
expireStartedAt:now];
}
- (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
{
self = [super initWithTimestamp:timestamp
inThread:thread
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:expiresInSeconds
expireStartedAt:now];
expireStartedAt:expireStartedAt];
if (!self) {
return self;
}

@ -399,6 +399,7 @@ dispatch_queue_t sendingQueue() {
TSIncomingMessage *incomingMessage =
[[TSIncomingMessage alloc] initWithTimestamp:(outgoingMessage.timestamp + 1)
inThread:cThread
authorId:[cThread contactIdentifier]
messageBody:outgoingMessage.body
attachmentIds:outgoingMessage.attachmentIds
expiresInSeconds:outgoingMessage.expiresInSeconds];

@ -452,6 +452,7 @@ NS_ASSUME_NONNULL_BEGIN
incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:timestamp
inThread:cThread
authorId:[cThread contactIdentifier]
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:dataMessage.expireTimer];
@ -476,6 +477,7 @@ NS_ASSUME_NONNULL_BEGIN
TSContactThread *cThread = (TSContactThread *)thread;
textMessage = [[TSIncomingMessage alloc] initWithTimestamp:textMessageTimestamp
inThread:cThread
authorId:[cThread contactIdentifier]
messageBody:body];
}
textMessage.expiresInSeconds = dataMessage.expireTimer;

Loading…
Cancel
Save