From fcc3c27779f3e99be4e9531c4c42b76093da3547 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 12 Apr 2021 16:56:53 +1000 Subject: [PATCH 01/16] fix unread message count bug --- .../Database/Storage+Messaging.swift | 3 +++ .../Messages/Signal/TSInteraction.m | 19 ++++++++++++------- .../Sending & Receiving/MessageReceiver.swift | 6 +++++- .../Read Tracking/OWSReadReceiptManager.m | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/SessionMessagingKit/Database/Storage+Messaging.swift b/SessionMessagingKit/Database/Storage+Messaging.swift index ca4149fa0..852503f2d 100644 --- a/SessionMessagingKit/Database/Storage+Messaging.swift +++ b/SessionMessagingKit/Database/Storage+Messaging.swift @@ -42,6 +42,9 @@ extension Storage { } else { tsMessage = TSIncomingMessage.from(message, quotedMessage: quotedMessage, linkPreview: linkPreview, associatedWith: thread) } + if let serverTimestamp = message.receivedTimestamp, openGroupID != nil { + tsMessage.setServerTimestampToReceivedTimestamp(serverTimestamp) + } tsMessage.save(with: transaction) tsMessage.attachments(with: transaction).forEach { attachment in attachment.albumMessageId = tsMessage.uniqueId! diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index 2c21a3997..e7cc710cf 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -199,13 +199,10 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) // In open groups messages should be sorted by server timestamp. `sortId` represents the order in which messages // were processed. Since in the open group poller we sort messages by their server timestamp, sorting by `sortId` is // effectively the same as sorting by server timestamp. - if ([self isKindOfClass:TSMessage.class] && ((TSMessage *)self).isOpenGroupMessage) { - sortId1 = self.sortId; - sortId2 = other.sortId; - } else { - sortId1 = self.timestamp; - sortId2 = other.timestamp; - } + // sortId == receivedAtTimestamp for open group messages. + // sortId == sendTimestamp for one-to-one and closed group messages. + sortId1 = self.sortId; + sortId2 = other.sortId; if (sortId1 > sortId2) { return NSOrderedDescending; @@ -229,6 +226,14 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) (unsigned long)self.timestamp]; } +- (uint64_t)sortId +{ + if ([self isKindOfClass:TSMessage.class] && ((TSMessage *)self).isOpenGroupMessage) { + return self.receivedAtTimestamp; + } + return self.timestamp; +} + - (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { if (!self.uniqueId) { diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index 20daff6db..63a73a80f 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -145,7 +145,11 @@ public enum MessageReceiver { message.sender = sender message.recipient = userPublicKey message.sentTimestamp = envelope.timestamp - message.receivedTimestamp = NSDate.millisecondTimestamp() + if (isOpenGroupMessage) { + message.receivedTimestamp = envelope.serverTimestamp + } else { + message.receivedTimestamp = NSDate.millisecondTimestamp() + } message.groupPublicKey = groupPublicKey message.openGroupServerMessageID = openGroupMessageServerID // Validate diff --git a/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m b/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m index 13a1b39c2..3a98e6fc3 100644 --- a/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m +++ b/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m @@ -267,6 +267,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE } id possiblyRead = (id)object; if (possiblyRead.sortId > sortId) { + uint64_t test = possiblyRead.sortId; *stop = YES; return; } From b501579917112a8c75bb3f5f227b0f264bc2b5f2 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 14 Apr 2021 09:09:42 +1000 Subject: [PATCH 02/16] clean --- .../Sending & Receiving/Read Tracking/OWSReadReceiptManager.m | 1 - 1 file changed, 1 deletion(-) diff --git a/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m b/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m index 3a98e6fc3..13a1b39c2 100644 --- a/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m +++ b/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSReadReceiptManager.m @@ -267,7 +267,6 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE } id possiblyRead = (id)object; if (possiblyRead.sortId > sortId) { - uint64_t test = possiblyRead.sortId; *stop = YES; return; } From 1893ccac76164a1e808005d36fc6bcf62936c505 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 14 Apr 2021 11:39:04 +1000 Subject: [PATCH 03/16] use TSIncomingMessage's serverTimastamp to make more sense --- .../Database/Storage+Messaging.swift | 3 --- SessionMessagingKit/Messages/Message.swift | 1 + .../Signal/TSIncomingMessage+Conversion.swift | 2 +- .../Messages/Signal/TSInteraction.h | 2 -- .../Messages/Signal/TSInteraction.m | 17 +++++++---------- .../Sending & Receiving/MessageReceiver.swift | 5 ++--- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/SessionMessagingKit/Database/Storage+Messaging.swift b/SessionMessagingKit/Database/Storage+Messaging.swift index 852503f2d..ca4149fa0 100644 --- a/SessionMessagingKit/Database/Storage+Messaging.swift +++ b/SessionMessagingKit/Database/Storage+Messaging.swift @@ -42,9 +42,6 @@ extension Storage { } else { tsMessage = TSIncomingMessage.from(message, quotedMessage: quotedMessage, linkPreview: linkPreview, associatedWith: thread) } - if let serverTimestamp = message.receivedTimestamp, openGroupID != nil { - tsMessage.setServerTimestampToReceivedTimestamp(serverTimestamp) - } tsMessage.save(with: transaction) tsMessage.attachments(with: transaction).forEach { attachment in attachment.albumMessageId = tsMessage.uniqueId! diff --git a/SessionMessagingKit/Messages/Message.swift b/SessionMessagingKit/Messages/Message.swift index f39136b4a..5d7ab3137 100644 --- a/SessionMessagingKit/Messages/Message.swift +++ b/SessionMessagingKit/Messages/Message.swift @@ -10,6 +10,7 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is public var sender: String? public var groupPublicKey: String? public var openGroupServerMessageID: UInt64? + public var openGroupServerTimestamp: UInt64? public var ttl: UInt64 { 2 * 24 * 60 * 60 * 1000 } public var isSelfSendValid: Bool { false } diff --git a/SessionMessagingKit/Messages/Signal/TSIncomingMessage+Conversion.swift b/SessionMessagingKit/Messages/Signal/TSIncomingMessage+Conversion.swift index 48027531e..32916187e 100644 --- a/SessionMessagingKit/Messages/Signal/TSIncomingMessage+Conversion.swift +++ b/SessionMessagingKit/Messages/Signal/TSIncomingMessage+Conversion.swift @@ -19,7 +19,7 @@ public extension TSIncomingMessage { expiresInSeconds: !isOpenGroupMessage ? expiration : 0, // Ensure we don't ever expire open group messages quotedMessage: quotedMessage, linkPreview: linkPreview, - serverTimestamp: nil, + serverTimestamp: visibleMessage.openGroupServerTimestamp as NSNumber?, wasReceivedByUD: true ) result.openGroupServerMessageID = openGroupServerMessageID diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.h b/SessionMessagingKit/Messages/Signal/TSInteraction.h index d21b25555..1d67d12c0 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.h +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.h @@ -41,8 +41,6 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value); @property (nonatomic, readonly) uint64_t receivedAtTimestamp; @property (nonatomic, readonly) BOOL shouldUseServerTime; -- (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp; - - (uint64_t)timestampForUI; - (NSDate *)receivedAtDate; diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index e7cc710cf..8e002d2f2 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -169,8 +169,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)timestampForUI { - if (_shouldUseServerTime) { - return _receivedAtTimestamp; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage) { + return ((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue; } return _timestamp; } @@ -180,14 +180,11 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) return self.timestamp; } -- (void)setServerTimestampToReceivedTimestamp:(uint64_t)receivedAtTimestamp -{ - _shouldUseServerTime = YES; - _receivedAtTimestamp = receivedAtTimestamp; -} - - (NSDate *)receivedAtDate { + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage) { + return [NSDate ows_dateWithMillisecondsSince1970:((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue]; + } return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp]; } @@ -228,8 +225,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)sortId { - if ([self isKindOfClass:TSMessage.class] && ((TSMessage *)self).isOpenGroupMessage) { - return self.receivedAtTimestamp; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage) { + return ((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue; } return self.timestamp; } diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index 63a73a80f..a6a153445 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -145,10 +145,9 @@ public enum MessageReceiver { message.sender = sender message.recipient = userPublicKey message.sentTimestamp = envelope.timestamp + message.receivedTimestamp = NSDate.millisecondTimestamp() if (isOpenGroupMessage) { - message.receivedTimestamp = envelope.serverTimestamp - } else { - message.receivedTimestamp = NSDate.millisecondTimestamp() + message.openGroupServerTimestamp = envelope.serverTimestamp } message.groupPublicKey = groupPublicKey message.openGroupServerMessageID = openGroupMessageServerID From 1b834978dfaceddf44229b71a77089df5c4b28b7 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 15 Apr 2021 10:01:13 +1000 Subject: [PATCH 04/16] Fix crash --- Session/Conversations/ConversationViewModel.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Session/Conversations/ConversationViewModel.m b/Session/Conversations/ConversationViewModel.m index b893fe7f5..2b8952cca 100644 --- a/Session/Conversations/ConversationViewModel.m +++ b/Session/Conversations/ConversationViewModel.m @@ -170,10 +170,10 @@ NS_ASSUME_NONNULL_BEGIN // // PERF: we could do less messages on shorter (older, slower) devices // PERF: we could cache the cell height, since some messages will be much taller. -static const int kYapDatabasePageSize = 100; +static const int kYapDatabasePageSize = 25000; // Never show more than n messages in conversation view when user arrives. -static const int kConversationInitialMaxRangeSize = 100; +static const int kConversationInitialMaxRangeSize = 25000; // Never show more than n messages in conversation view at a time. static const int kYapDatabaseRangeMaxLength = 25000; From 1a12487292a81b7057805730ee75848f1218f114 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 15 Apr 2021 10:09:05 +1000 Subject: [PATCH 05/16] Clean --- SessionMessagingKit/Messages/Message.swift | 8 ++++++++ .../Messages/Signal/TSInteraction.m | 16 ++++++++-------- .../Sending & Receiving/MessageReceiver.swift | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/SessionMessagingKit/Messages/Message.swift b/SessionMessagingKit/Messages/Message.swift index 5d7ab3137..3ea4b46f0 100644 --- a/SessionMessagingKit/Messages/Message.swift +++ b/SessionMessagingKit/Messages/Message.swift @@ -31,6 +31,10 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is if let sentTimestamp = coder.decodeObject(forKey: "sentTimestamp") as! UInt64? { self.sentTimestamp = sentTimestamp } if let receivedTimestamp = coder.decodeObject(forKey: "receivedTimestamp") as! UInt64? { self.receivedTimestamp = receivedTimestamp } if let recipient = coder.decodeObject(forKey: "recipient") as! String? { self.recipient = recipient } + if let sender = coder.decodeObject(forKey: "sender") as! String? { self.sender = sender } + if let groupPublicKey = coder.decodeObject(forKey: "groupPublicKey") as! String? { self.groupPublicKey = groupPublicKey } + if let openGroupServerMessageID = coder.decodeObject(forKey: "openGroupServerMessageID") as! UInt64? { self.openGroupServerMessageID = openGroupServerMessageID } + if let openGroupServerTimestamp = coder.decodeObject(forKey: "openGroupServerTimestamp") as! UInt64? { self.openGroupServerTimestamp = openGroupServerTimestamp } } public func encode(with coder: NSCoder) { @@ -39,6 +43,10 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is coder.encode(sentTimestamp, forKey: "sentTimestamp") coder.encode(receivedTimestamp, forKey: "receivedTimestamp") coder.encode(recipient, forKey: "recipient") + coder.encode(sender, forKey: "sender") + coder.encode(groupPublicKey, forKey: "groupPublicKey") + coder.encode(openGroupServerMessageID, forKey: "openGroupServerMessageID") + coder.encode(openGroupServerTimestamp, forKey: "openGroupServerTimestamp") } // MARK: Proto Conversion diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index 8e002d2f2..d71496f1b 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -169,8 +169,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)timestampForUI { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage) { - return ((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { + return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; } return _timestamp; } @@ -182,8 +182,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (NSDate *)receivedAtDate { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage) { - return [NSDate ows_dateWithMillisecondsSince1970:((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue]; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { + return [NSDate ows_dateWithMillisecondsSince1970:((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue]; } return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp]; } @@ -196,8 +196,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) // In open groups messages should be sorted by server timestamp. `sortId` represents the order in which messages // were processed. Since in the open group poller we sort messages by their server timestamp, sorting by `sortId` is // effectively the same as sorting by server timestamp. - // sortId == receivedAtTimestamp for open group messages. - // sortId == sendTimestamp for one-to-one and closed group messages. + // sortId == serverTimestamp for open group messages. + // sortId == timestamp (the sent timestamp) for one-to-one and closed group messages. sortId1 = self.sortId; sortId2 = other.sortId; @@ -225,8 +225,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)sortId { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage) { - return ((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { + return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; } return self.timestamp; } diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index a6a153445..3547681f3 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -146,7 +146,7 @@ public enum MessageReceiver { message.recipient = userPublicKey message.sentTimestamp = envelope.timestamp message.receivedTimestamp = NSDate.millisecondTimestamp() - if (isOpenGroupMessage) { + if isOpenGroupMessage { message.openGroupServerTimestamp = envelope.serverTimestamp } message.groupPublicKey = groupPublicKey From 0296416b1a6e2d2f6e1b3b0203635cc382e9f5ed Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 15 Apr 2021 10:16:13 +1000 Subject: [PATCH 06/16] Update version number --- Session.xcodeproj/project.pbxproj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index c034527d2..1404940ab 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -5241,7 +5241,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 214; + CURRENT_PROJECT_VERSION = 215; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5262,7 +5262,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.5; + MARKETING_VERSION = 1.9.6; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5310,7 +5310,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 214; + CURRENT_PROJECT_VERSION = 215; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5336,7 +5336,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.5; + MARKETING_VERSION = 1.9.6; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5371,7 +5371,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 214; + CURRENT_PROJECT_VERSION = 215; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5390,7 +5390,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.5; + MARKETING_VERSION = 1.9.6; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -5441,7 +5441,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 214; + CURRENT_PROJECT_VERSION = 215; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5465,7 +5465,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.5; + MARKETING_VERSION = 1.9.6; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -6326,7 +6326,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 214; + CURRENT_PROJECT_VERSION = 215; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6362,7 +6362,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.9.5; + MARKETING_VERSION = 1.9.6; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; @@ -6394,7 +6394,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 214; + CURRENT_PROJECT_VERSION = 215; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6430,7 +6430,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.9.5; + MARKETING_VERSION = 1.9.6; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; From 8a54a243a4ba6a428bd649221cddb69f73b17f8f Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 19 Apr 2021 09:35:09 +1000 Subject: [PATCH 07/16] Fix long conversation crash the right way --- Session/Conversations/ConversationVC.swift | 3 ++- Session/Conversations/ConversationViewModel.h | 18 ++++++++++++++++++ Session/Conversations/ConversationViewModel.m | 18 ------------------ SignalUtilitiesKit/Utilities/ThreadUtil.m | 8 ++++++++ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index be4246af5..61824915d 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -149,7 +149,8 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat Storage.read { transaction in unreadCount = self.thread.unreadMessageCount(transaction: transaction) } - unreadViewItems = unreadCount != 0 ? [ConversationViewItem](viewItems[viewItems.endIndex - Int(unreadCount) ..< viewItems.endIndex]) : [] + let clampedUnreadCount = min(unreadCount, UInt(kConversationInitialMaxRangeSize)) + unreadViewItems = clampedUnreadCount != 0 ? [ConversationViewItem](viewItems[viewItems.endIndex - Int(clampedUnreadCount) ..< viewItems.endIndex]) : [] } required init?(coder: NSCoder) { diff --git a/Session/Conversations/ConversationViewModel.h b/Session/Conversations/ConversationViewModel.h index d679dbcd9..08151c201 100644 --- a/Session/Conversations/ConversationViewModel.h +++ b/Session/Conversations/ConversationViewModel.h @@ -91,6 +91,24 @@ typedef NS_ENUM(NSUInteger, ConversationUpdateItemType) { #pragma mark - +// Always load up to n messages when user arrives. +// +// The smaller this number is, the faster the conversation can display. +// To test, shrink you accessibility font as much as possible, then count how many 1-line system info messages (our +// shortest cells) can fit on screen at a time on an iPhoneX +// +// PERF: we could do less messages on shorter (older, slower) devices +// PERF: we could cache the cell height, since some messages will be much taller. +static const int kYapDatabasePageSize = 250; + +// Never show more than n messages in conversation view when user arrives. +static const int kConversationInitialMaxRangeSize = 250; + +// Never show more than n messages in conversation view at a time. +static const int kYapDatabaseRangeMaxLength = 250; + +#pragma mark - + @interface ConversationViewModel : NSObject @property (nonatomic, readonly) ConversationViewState *viewState; diff --git a/Session/Conversations/ConversationViewModel.m b/Session/Conversations/ConversationViewModel.m index 2b8952cca..86ad1f5e7 100644 --- a/Session/Conversations/ConversationViewModel.m +++ b/Session/Conversations/ConversationViewModel.m @@ -162,24 +162,6 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - -// Always load up to n messages when user arrives. -// -// The smaller this number is, the faster the conversation can display. -// To test, shrink you accessibility font as much as possible, then count how many 1-line system info messages (our -// shortest cells) can fit on screen at a time on an iPhoneX -// -// PERF: we could do less messages on shorter (older, slower) devices -// PERF: we could cache the cell height, since some messages will be much taller. -static const int kYapDatabasePageSize = 25000; - -// Never show more than n messages in conversation view when user arrives. -static const int kConversationInitialMaxRangeSize = 25000; - -// Never show more than n messages in conversation view at a time. -static const int kYapDatabaseRangeMaxLength = 25000; - -#pragma mark - - @interface ConversationViewModel () @property (nonatomic, weak) id delegate; diff --git a/SignalUtilitiesKit/Utilities/ThreadUtil.m b/SignalUtilitiesKit/Utilities/ThreadUtil.m index 62a5963fe..4922fc4f5 100644 --- a/SignalUtilitiesKit/Utilities/ThreadUtil.m +++ b/SignalUtilitiesKit/Utilities/ThreadUtil.m @@ -198,6 +198,14 @@ NS_ASSUME_NONNULL_BEGIN visibleUnseenMessageCount++; interactionAfterUnreadIndicator = interaction; + + if (visibleUnseenMessageCount + 1 >= maxRangeSize) { + // If there are more unseen messages than can be displayed in the + // messages view, show the unread indicator at the top of the + // displayed messages. + *stop = YES; + hasMoreUnseenMessages = YES; + } }]; if (!interactionAfterUnreadIndicator) { From 72807c52b7890ee3cb2ee33e2ba9eacd38ea86ff Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 19 Apr 2021 09:38:47 +1000 Subject: [PATCH 08/16] fix open group message timestamp --- SessionMessagingKit/Messages/Signal/TSInteraction.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index d71496f1b..15415de82 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -170,7 +170,9 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)timestampForUI { if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { - return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; + if (((TSIncomingMessage *) self).serverTimestamp) + return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; + return ((TSIncomingMessage *) self).receivedAtTimestamp; } return _timestamp; } @@ -182,7 +184,7 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (NSDate *)receivedAtDate { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { return [NSDate ows_dateWithMillisecondsSince1970:((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue]; } return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp]; From 7a593862c942e1bcbe68e352d1ad8c452945fa83 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 19 Apr 2021 09:55:30 +1000 Subject: [PATCH 09/16] minor fix --- SessionMessagingKit/Messages/Signal/TSInteraction.m | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index 15415de82..f27563cea 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -169,10 +169,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)timestampForUI { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { - if (((TSIncomingMessage *) self).serverTimestamp) - return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; - return ((TSIncomingMessage *) self).receivedAtTimestamp; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { + return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; } return _timestamp; } @@ -184,9 +182,6 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (NSDate *)receivedAtDate { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { - return [NSDate ows_dateWithMillisecondsSince1970:((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue]; - } return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp]; } @@ -227,7 +222,7 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)sortId { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; } return self.timestamp; From d360353c17209f38f97072023200d5400e639547 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 19 Apr 2021 10:22:12 +1000 Subject: [PATCH 10/16] fix open group message sort id --- SessionMessagingKit/Messages/Signal/TSInteraction.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index f27563cea..ad5648f98 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -222,8 +222,13 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)sortId { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { - return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { + if (((TSIncomingMessage *) self).serverTimestamp != nil) { + return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; + } + // For messages that don't have a serverTimestamp, it is the same to sort by the receivedAtTimestamp, + // since in the open group poller we sort messages by their server timestamp. + return ((TSIncomingMessage *) self).receivedAtTimestamp; } return self.timestamp; } From f2fb8a57dcf1b400494e29668f63890c827a7c76 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 19 Apr 2021 10:43:43 +1000 Subject: [PATCH 11/16] fix incorrect scrolling for link previews --- Session/Conversations/ConversationVC.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 61824915d..961e3186d 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -181,7 +181,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat addOrRemoveBlockedBanner() // Notifications let notificationCenter = NotificationCenter.default - notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillShowNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) + notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillChangeFrameNotification(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil) notificationCenter.addObserver(self, selector: #selector(handleKeyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) notificationCenter.addObserver(self, selector: #selector(handleAudioDidFinishPlayingNotification(_:)), name: .SNAudioDidFinishPlaying, object: nil) notificationCenter.addObserver(self, selector: #selector(addOrRemoveBlockedBanner), name: NSNotification.Name(rawValue: kNSNotificationName_BlockListDidChange), object: nil) @@ -289,7 +289,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat } } - @objc func handleKeyboardWillShowNotification(_ notification: Notification) { + @objc func handleKeyboardWillChangeFrameNotification(_ notification: Notification) { guard let newHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.size.height else { return } if (newHeight > 0 && baselineKeyboardHeight == 0) { baselineKeyboardHeight = newHeight @@ -300,8 +300,8 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat scrollButton.pin(.bottom, to: .bottom, of: view, withInset: -(newHeight + 16)) // + 16 to match the bottom inset of the table view didConstrainScrollButton = true } - let newContentOffsetY = self.messagesTableView.contentOffset.y + min(lastPageTop, 0) + newHeight - self.messagesTableView.keyboardHeight - self.messagesTableView.contentOffset.y = max(self.messagesTableView.contentOffset.y, newContentOffsetY) + let newContentOffsetY = max(self.messagesTableView.contentOffset.y + min(lastPageTop, 0) + newHeight - self.messagesTableView.keyboardHeight, 0.0) + self.messagesTableView.contentOffset.y = newContentOffsetY self.messagesTableView.keyboardHeight = newHeight self.scrollButton.alpha = self.getScrollButtonOpacity() } From d897952ce0941e46cac924224382967b385ee937 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 19 Apr 2021 11:36:05 +1000 Subject: [PATCH 12/16] use sent timestamp instead of received timestamp for sorting and UI --- .../Message Cells/VisibleMessageCell.swift | 2 +- .../MediaGalleryViewController.swift | 2 +- .../Messages/Signal/TSInteraction.h | 2 ++ .../Messages/Signal/TSInteraction.m | 15 ++++++++------- .../Messaging/ThreadViewModel.swift | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index e1b94861e..c60c0d191 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -286,7 +286,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate { dateBreakLabel.font = .boldSystemFont(ofSize: Values.verySmallFontSize) dateBreakLabel.textColor = Colors.text dateBreakLabel.textAlignment = .center - let date = viewItem.interaction.receivedAtDate() + let date = viewItem.interaction.dateForUI() let description = DateUtil.formatDate(forConversationDateBreaks: date) dateBreakLabel.text = description headerView.addSubview(dateBreakLabel) diff --git a/Session/Media Viewing & Editing/MediaGalleryViewController.swift b/Session/Media Viewing & Editing/MediaGalleryViewController.swift index 973acfad6..093289508 100644 --- a/Session/Media Viewing & Editing/MediaGalleryViewController.swift +++ b/Session/Media Viewing & Editing/MediaGalleryViewController.swift @@ -120,7 +120,7 @@ public struct GalleryDate: Hashable, Comparable, Equatable { let month: Int init(message: TSMessage) { - let date = message.receivedAtDate() + let date = message.dateForUI() self.year = Calendar.current.component(.year, from: date) self.month = Calendar.current.component(.month, from: date) diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.h b/SessionMessagingKit/Messages/Signal/TSInteraction.h index 1d67d12c0..7cdef9db1 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.h +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.h @@ -43,6 +43,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value); - (uint64_t)timestampForUI; +- (NSDate *)dateForUI; + - (NSDate *)receivedAtDate; - (OWSInteractionType)interactionType; diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index ad5648f98..a1bf68e0c 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -180,8 +180,14 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) return self.timestamp; } +- (NSDate *)dateForUI +{ + return [NSDate ows_dateWithMillisecondsSince1970:self.timestampForUI]; +} + - (NSDate *)receivedAtDate { + // This is only used for sorting threads return [NSDate ows_dateWithMillisecondsSince1970:self.receivedAtTimestamp]; } @@ -222,13 +228,8 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)sortId { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage) { - if (((TSIncomingMessage *) self).serverTimestamp != nil) { - return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; - } - // For messages that don't have a serverTimestamp, it is the same to sort by the receivedAtTimestamp, - // since in the open group poller we sort messages by their server timestamp. - return ((TSIncomingMessage *) self).receivedAtTimestamp; + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { + return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; } return self.timestamp; } diff --git a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift index 16f8fa16a..a164f96fb 100644 --- a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift +++ b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift @@ -32,7 +32,7 @@ public class ThreadViewModel: NSObject { self.lastMessageText = thread.lastMessageText(transaction: transaction) let lastInteraction = thread.lastInteractionForInbox(transaction: transaction) self.lastMessageForInbox = lastInteraction - self.lastMessageDate = lastInteraction?.receivedAtDate() ?? thread.creationDate + self.lastMessageDate = lastInteraction?.dateForUI() ?? thread.creationDate if let contactThread = thread as? TSContactThread { self.contactIdentifier = contactThread.contactIdentifier() From 709c0f1463d9832bbdb9de9bfd45f30143e66bf0 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 19 Apr 2021 14:56:58 +1000 Subject: [PATCH 13/16] Add documentation --- .../Messages/Signal/TSInteraction.m | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/SessionMessagingKit/Messages/Signal/TSInteraction.m b/SessionMessagingKit/Messages/Signal/TSInteraction.m index a1bf68e0c..a23a23ab6 100644 --- a/SessionMessagingKit/Messages/Signal/TSInteraction.m +++ b/SessionMessagingKit/Messages/Signal/TSInteraction.m @@ -169,8 +169,11 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)timestampForUI { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { - return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; + // We always want to show the sent timestamp. In the case of one-on-one, closed group and V2 open group messages we get + // this from the protobuf. In the case of V1 open group messages we get it from the envelope in which the message is + // wrapped, which gets parsed to `serverTimestamp` in that case. + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage && ((TSIncomingMessage *)self).serverTimestamp != nil) { + return ((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue; } return _timestamp; } @@ -199,7 +202,7 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) // In open groups messages should be sorted by server timestamp. `sortId` represents the order in which messages // were processed. Since in the open group poller we sort messages by their server timestamp, sorting by `sortId` is // effectively the same as sorting by server timestamp. - // sortId == serverTimestamp for open group messages. + // sortId == serverTimestamp (the sent timestamp) for open group messages. // sortId == timestamp (the sent timestamp) for one-to-one and closed group messages. sortId1 = self.sortId; sortId2 = other.sortId; @@ -228,8 +231,11 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) - (uint64_t)sortId { - if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *) self).isOpenGroupMessage && ((TSIncomingMessage *) self).serverTimestamp != nil) { - return ((TSIncomingMessage *) self).serverTimestamp.unsignedLongLongValue; + // We always want to sort on the sent timestamp. In the case of one-on-one, closed group and V2 open group messages we get + // this from the protobuf. In the case of V1 open group messages we get it from the envelope in which the message is + // wrapped, which gets parsed to `serverTimestamp` in that case. + if ([self isKindOfClass:TSIncomingMessage.class] && ((TSIncomingMessage *)self).isOpenGroupMessage && ((TSIncomingMessage *)self).serverTimestamp != nil) { + return ((TSIncomingMessage *)self).serverTimestamp.unsignedLongLongValue; } return self.timestamp; } From 766c35186960eb91c3f0d1e4f1019a912147c9de Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 19 Apr 2021 15:09:00 +1000 Subject: [PATCH 14/16] Update version number --- Session.xcodeproj/project.pbxproj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 1404940ab..49ce0d8b5 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -5241,7 +5241,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 215; + CURRENT_PROJECT_VERSION = 216; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5262,7 +5262,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.6; + MARKETING_VERSION = 1.9.7; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5310,7 +5310,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 215; + CURRENT_PROJECT_VERSION = 216; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5336,7 +5336,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.6; + MARKETING_VERSION = 1.9.7; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5371,7 +5371,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 215; + CURRENT_PROJECT_VERSION = 216; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5390,7 +5390,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.6; + MARKETING_VERSION = 1.9.7; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -5441,7 +5441,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 215; + CURRENT_PROJECT_VERSION = 216; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5465,7 +5465,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.6; + MARKETING_VERSION = 1.9.7; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -6326,7 +6326,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 215; + CURRENT_PROJECT_VERSION = 216; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6362,7 +6362,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.9.6; + MARKETING_VERSION = 1.9.7; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; @@ -6394,7 +6394,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 215; + CURRENT_PROJECT_VERSION = 216; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6430,7 +6430,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.9.6; + MARKETING_VERSION = 1.9.7; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; From 4c822f7e550db1d7dbf6771b18820d86dad22d45 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 20 Apr 2021 15:12:14 +1000 Subject: [PATCH 15/16] fix the conversation screen doesn't update the messages from PN immediately. --- Session/Conversations/ConversationViewModel.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Session/Conversations/ConversationViewModel.m b/Session/Conversations/ConversationViewModel.m index 86ad1f5e7..590e91d15 100644 --- a/Session/Conversations/ConversationViewModel.m +++ b/Session/Conversations/ConversationViewModel.m @@ -196,6 +196,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) NSArray> *persistedViewItems; @property (nonatomic) NSArray *unsavedOutgoingMessages; +@property (nonatomic) BOOL hasUiDatabaseUpdatedExternally; + @end #pragma mark - @@ -551,9 +553,14 @@ NS_ASSUME_NONNULL_BEGIN - (void)uiDatabaseDidUpdateExternally:(NSNotification *)notification { OWSAssertIsOnMainThread(); - // External database modifications (e.g. changes from another process such as the SAE) // are "flushed" using touchDbAsync when the app re-enters the foreground. + // NSE will trigger this when we receive a new message from remote PN, + // the touchDbAsync will trigger uiDatabaseDidUpdate but with a notification + // that does NOT include the recent update from NSE. + // This flag let the uiDatabaseDidUpdate know it needs to expect more update + // than those in the notification. + _hasUiDatabaseUpdatedExternally = true; } - (void)uiDatabaseWillUpdate:(NSNotification *)notification @@ -571,10 +578,12 @@ NS_ASSUME_NONNULL_BEGIN YapDatabaseAutoViewConnection *messageDatabaseView = [self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName]; OWSAssertDebug([messageDatabaseView isKindOfClass:[YapDatabaseAutoViewConnection class]]); - if (![messageDatabaseView hasChangesForGroup:self.thread.uniqueId inNotifications:notifications]) { + if (![messageDatabaseView hasChangesForGroup:self.thread.uniqueId inNotifications:notifications] && !_hasUiDatabaseUpdatedExternally) { [self.delegate conversationViewModelDidUpdate:ConversationUpdate.minorUpdate]; return; } + + _hasUiDatabaseUpdatedExternally = false; __block ConversationMessageMappingDiff *_Nullable diff = nil; [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { From 091cb61d239f14ef3da509614b897f80fe749220 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 21 Apr 2021 08:50:23 +1000 Subject: [PATCH 16/16] Clean & update version number --- Session.xcodeproj/project.pbxproj | 24 +++++++++---------- Session/Conversations/ConversationViewModel.m | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 49ce0d8b5..56f3fc499 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -5241,7 +5241,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 216; + CURRENT_PROJECT_VERSION = 217; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5262,7 +5262,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.7; + MARKETING_VERSION = 1.9.8; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5310,7 +5310,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 216; + CURRENT_PROJECT_VERSION = 217; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5336,7 +5336,7 @@ INFOPLIST_FILE = SessionShareExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.7; + MARKETING_VERSION = 1.9.8; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -5371,7 +5371,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 216; + CURRENT_PROJECT_VERSION = 217; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5390,7 +5390,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.7; + MARKETING_VERSION = 1.9.8; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -5441,7 +5441,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 216; + CURRENT_PROJECT_VERSION = 217; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5465,7 +5465,7 @@ INFOPLIST_FILE = SessionNotificationServiceExtension/Meta/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.9.7; + MARKETING_VERSION = 1.9.8; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -6326,7 +6326,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 216; + CURRENT_PROJECT_VERSION = 217; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6362,7 +6362,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.9.7; + MARKETING_VERSION = 1.9.8; OTHER_LDFLAGS = "$(inherited)"; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; @@ -6394,7 +6394,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 216; + CURRENT_PROJECT_VERSION = 217; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6430,7 +6430,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.9.7; + MARKETING_VERSION = 1.9.8; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; diff --git a/Session/Conversations/ConversationViewModel.m b/Session/Conversations/ConversationViewModel.m index 590e91d15..59651fa06 100644 --- a/Session/Conversations/ConversationViewModel.m +++ b/Session/Conversations/ConversationViewModel.m @@ -555,11 +555,11 @@ NS_ASSUME_NONNULL_BEGIN OWSAssertIsOnMainThread(); // External database modifications (e.g. changes from another process such as the SAE) // are "flushed" using touchDbAsync when the app re-enters the foreground. - // NSE will trigger this when we receive a new message from remote PN, - // the touchDbAsync will trigger uiDatabaseDidUpdate but with a notification - // that does NOT include the recent update from NSE. - // This flag let the uiDatabaseDidUpdate know it needs to expect more update - // than those in the notification. + // + // The NSE will trigger this when we receive a new message through a remote notification. + // In this scenario, touchDbAsync will trigger uiDatabaseDidUpdate, but with a notification + // that does NOT include the recent update from NSE. This flag lets uiDatabaseDidUpdate + // know it needs to expect more updates than those in the notification. _hasUiDatabaseUpdatedExternally = true; } @@ -578,7 +578,7 @@ NS_ASSUME_NONNULL_BEGIN YapDatabaseAutoViewConnection *messageDatabaseView = [self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName]; OWSAssertDebug([messageDatabaseView isKindOfClass:[YapDatabaseAutoViewConnection class]]); - if (![messageDatabaseView hasChangesForGroup:self.thread.uniqueId inNotifications:notifications] && !_hasUiDatabaseUpdatedExternally) { + if (![messageDatabaseView hasChangesForGroup:self.thread.uniqueId inNotifications:notifications] && !self.hasUiDatabaseUpdatedExternally) { [self.delegate conversationViewModelDidUpdate:ConversationUpdate.minorUpdate]; return; }