Merge pull request #256 from RyanRory/open-group-message-time

Fix Open Group Date Handling
pull/258/head
Niels Andriesse 5 years ago committed by GitHub
commit b7b2f0e5bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)processIncomingSentMessageTranscript:(OWSIncomingSentMessageTranscript *)incomingSentMessageTranscript
serverID:(uint64_t)serverID
serverTimestamp:(uint64_t)serverTimestamp
attachmentHandler:(void (^)(
NSArray<TSAttachmentStream *> *attachmentStreams))attachmentHandler
transaction:(YapDatabaseReadWriteTransaction *)transaction;

@ -62,6 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)processIncomingSentMessageTranscript:(OWSIncomingSentMessageTranscript *)transcript
serverID:(uint64_t)serverID
serverTimestamp:(uint64_t)serverTimestamp
attachmentHandler:(void (^)(
NSArray<TSAttachmentStream *> *attachmentStreams))attachmentHandler
transaction:(YapDatabaseReadWriteTransaction *)transaction
@ -104,6 +105,14 @@ NS_ASSUME_NONNULL_BEGIN
contactShare:transcript.contact
linkPreview:transcript.linkPreview];
if (transcript.thread.isGroupThread) {
TSGroupThread *thread = (TSGroupThread *)transcript.thread;
if (thread.isPublicChat) {
[outgoingMessage setServerTimestampAsReceiveTimestamp:serverTimestamp];
}
}
if (serverID != 0) {
outgoingMessage.openGroupServerMessageID = serverID;
}

@ -174,6 +174,7 @@ public final class PublicChatPoller : NSObject {
envelope.setSource(senderPublicKey)
envelope.setSourceDevice(OWSDevicePrimaryDeviceId)
envelope.setContent(try! content.build().serializedData())
envelope.setServerTimestamp(message.serverTimestamp)
try! Storage.writeSync { transaction in
transaction.setObject(senderDisplayName, forKey: senderPublicKey, inCollection: publicChat.id)
let messageServerID = message.serverID

@ -42,6 +42,10 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value);
/// Used for public chats where a message sent from a slave device is interpreted as having been sent from the master device.
@property (nonatomic) NSString *actualSenderHexEncodedPublicKey;
- (void)setServerTimestampAsReceiveTimestamp:(uint64_t)receivedAtTimestamp;
- (uint64_t)timestamp;
- (NSDate *)receivedAtDate;
- (OWSInteractionType)interactionType;

@ -41,6 +41,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
@implementation TSInteraction
@synthesize timestamp = _timestamp;
+ (NSArray<TSInteraction *> *)interactionsWithTimestamp:(uint64_t)timestamp
ofClass:(Class)clazz
withTransaction:(YapDatabaseReadTransaction *)transaction
@ -175,11 +177,27 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
#pragma mark Date operations
- (uint64_t)timestamp
{
if (self.thread.isGroupThread) {
TSGroupThread *thread = (TSGroupThread *)self.thread;
if (thread.isPublicChat) {
return _receivedAtTimestamp;
}
}
return _timestamp;
}
- (uint64_t)timestampForLegacySorting
{
return self.timestamp;
}
- (void)setServerTimestampAsReceiveTimestamp:(uint64_t)receivedAtTimestamp
{
_receivedAtTimestamp = receivedAtTimestamp;
}
- (NSDate *)receivedAtDate
{
return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp];

@ -915,6 +915,7 @@ NS_ASSUME_NONNULL_BEGIN
[OWSRecordTranscriptJob
processIncomingSentMessageTranscript:transcript
serverID:0
serverTimestamp:0
attachmentHandler:^(NSArray<TSAttachmentStream *> *attachmentStreams) {
OWSAssertDebug(attachmentStreams.count == 1);
TSAttachmentStream *attachmentStream = attachmentStreams.firstObject;
@ -943,6 +944,7 @@ NS_ASSUME_NONNULL_BEGIN
[OWSRecordTranscriptJob
processIncomingSentMessageTranscript:transcript
serverID:(serverID ?: 0)
serverTimestamp:(uint64_t)envelope.serverTimestamp
attachmentHandler:^(NSArray<TSAttachmentStream *> *attachmentStreams) {
OWSLogDebug(@"successfully fetched transcript attachments: %lu",
(unsigned long)attachmentStreams.count);
@ -1417,6 +1419,11 @@ NS_ASSUME_NONNULL_BEGIN
serverTimestamp:serverTimestamp
wasReceivedByUD:wasReceivedByUD];
//For open group messages, use server timestamp as the receive timestamp
if (oldGroupThread.isPublicChat) {
[incomingMessage setServerTimestampAsReceiveTimestamp:(uint64_t)envelope.serverTimestamp];
}
// Loki: Set open group server ID if needed
if (dataMessage.publicChatInfo != nil && dataMessage.publicChatInfo.hasServerID) {
incomingMessage.openGroupServerMessageID = dataMessage.publicChatInfo.serverID;

Loading…
Cancel
Save