Code cleanup.

No need to use contactThread method to get recipient ID since we still
have the envelope.

And with that, it's pretty easy to justify getting rid of one of our now
barely used IncomingMessage initializers.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 975726e022
commit b389bb3bb8

@ -36,31 +36,6 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
sourceDeviceId:(uint32_t)sourceDeviceId sourceDeviceId:(uint32_t)sourceDeviceId
messageBody:(nullable NSString *)body; messageBody:(nullable NSString *)body;
/**
* Inits an incoming group message with attachments
*
* @param timestamp
* When the message was created in milliseconds since epoch
* @param thread
* Thread to which the message belongs
* @param authorId
* Signal ID (i.e. e164) of the user who sent the message
* @param sourceDeviceId
* Numeric ID of the device used to send the message. Used to detect duplicate messages.
* @param body
* Body of the message
* @param attachmentIds
* The uniqueIds for the message's attachments
*
* @return initiated incoming group message
*/
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
authorId:(NSString *)authorId
sourceDeviceId:(uint32_t)sourceDeviceId
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds;
/** /**
* Inits an incoming group message that expires. * Inits an incoming group message that expires.
* *
@ -93,8 +68,8 @@ extern NSString *const TSIncomingMessageWasReadOnThisDeviceNotification;
/** /**
* For sake of a smaller API, you must specify an author id for all incoming messages * For sake of a smaller API, and simplifying assumptions elsewhere, you must specify an author id for *all* incoming
* though we technically could get the author id from a contact thread. * messages, even though we technically could infer the author id for a contact threads.
*/ */
- (instancetype)initWithTimestamp:(uint64_t)timestamp NS_UNAVAILABLE; - (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 NS_UNAVAILABLE;

@ -30,22 +30,7 @@ NSString *const TSIncomingMessageWasReadOnThisDeviceNotification = @"TSIncomingM
authorId:authorId authorId:authorId
sourceDeviceId:sourceDeviceId sourceDeviceId:sourceDeviceId
messageBody:body messageBody:body
attachmentIds:@[]]; attachmentIds:@[]
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
authorId:(NSString *)authorId
sourceDeviceId:(uint32_t)sourceDeviceId
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds
{
return [self initWithTimestamp:timestamp
inThread:thread
authorId:authorId
sourceDeviceId:sourceDeviceId
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:0]; expiresInSeconds:0];
} }

@ -662,27 +662,18 @@ NS_ASSUME_NONNULL_BEGIN
[incomingMessage markAsReadLocallyWithTransaction:transaction]; [incomingMessage markAsReadLocallyWithTransaction:transaction];
} }
// Android allows attachments to be sent with body. // Other clients allow attachments to be sent along with body, we want the text displayed as a separate
// message
if ([attachmentIds count] > 0 && body != nil && ![body isEqualToString:@""]) { if ([attachmentIds count] > 0 && body != nil && ![body isEqualToString:@""]) {
// We want the text to be displayed under the attachment // We want the text to be displayed under the attachment
uint64_t textMessageTimestamp = timestamp + 1; uint64_t textMessageTimestamp = timestamp + 1;
TSIncomingMessage *textMessage; TSIncomingMessage *textMessage = [[TSIncomingMessage alloc] initWithTimestamp:textMessageTimestamp
if ([thread isGroupThread]) { inThread:thread
TSGroupThread *gThread = (TSGroupThread *)thread; authorId:envelope.source
textMessage = [[TSIncomingMessage alloc] initWithTimestamp:textMessageTimestamp sourceDeviceId:envelope.sourceDevice
inThread:gThread messageBody:body
authorId:envelope.source attachmentIds:@[]
sourceDeviceId:envelope.sourceDevice expiresInSeconds:dataMessage.expireTimer];
messageBody:body];
} else {
TSContactThread *cThread = (TSContactThread *)thread;
textMessage = [[TSIncomingMessage alloc] initWithTimestamp:textMessageTimestamp
inThread:cThread
authorId:[cThread contactIdentifier]
sourceDeviceId:envelope.sourceDevice
messageBody:body];
}
textMessage.expiresInSeconds = dataMessage.expireTimer;
[textMessage saveWithTransaction:transaction]; [textMessage saveWithTransaction:transaction];
} }
} }

Loading…
Cancel
Save