From a6b63c827ef6658439a399e917659a49143d493d Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 10 Aug 2020 15:49:51 +1000 Subject: [PATCH 01/12] =?UTF-8?q?fix=20aaptions=20with=20just=201=20charac?= =?UTF-8?q?ter=20aren=E2=80=99t=20displayed=20when=20opening=20the=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Signal/src/views/CaptionView.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Signal/src/views/CaptionView.swift b/Signal/src/views/CaptionView.swift index 1624b09b7..8db43a089 100644 --- a/Signal/src/views/CaptionView.swift +++ b/Signal/src/views/CaptionView.swift @@ -27,13 +27,13 @@ public class CaptionContainerView: UIView { } func updatePagerTransition(ratioComplete: CGFloat) { - if let currentText = self.currentText, currentText.count > 1 { + if let currentText = self.currentText, currentText.count > 0 { currentCaptionView.alpha = 1 - ratioComplete } else { currentCaptionView.alpha = 0 } - if let pendingText = self.pendingText, pendingText.count > 1 { + if let pendingText = self.pendingText, pendingText.count > 0 { pendingCaptionView.alpha = ratioComplete } else { pendingCaptionView.alpha = 0 @@ -48,6 +48,8 @@ public class CaptionContainerView: UIView { self.currentCaptionView = self.pendingCaptionView self.pendingCaptionView = oldCaptionView self.pendingText = nil + self.currentCaptionView.alpha = 1 + self.pendingCaptionView.alpha = 0 } // MARK: Initializers From 5c53c31fec2fa8ea0bdc73c5df0bb4f177fc2616 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 11 Aug 2020 11:48:11 +1000 Subject: [PATCH 02/12] fix display name not shown when a Desktop contact change Disappearing message in a conversation --- SignalServiceKit/src/Messages/OWSMessageManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 492ef2ea9..ecdb75eb6 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1061,7 +1061,7 @@ NS_ASSUME_NONNULL_BEGIN } OWSAssertDebug(disappearingMessagesConfiguration); [disappearingMessagesConfiguration saveWithTransaction:transaction]; - NSString *name = [dataMessage.profile displayName] ?: [self.contactsManager displayNameForPhoneIdentifier:envelope.source transaction:transaction]; + NSString *name = [dataMessage.profile displayName] ?: [SSKEnvironment.shared.profileManager profileNameForRecipientWithID:envelope.source transaction:transaction] ?: envelope.source; // MJK TODO - safe to remove senderTimestamp OWSDisappearingConfigurationUpdateInfoMessage *message = From 2d747af959cbf36265fb1fc940459c79714932a6 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 11 Aug 2020 13:36:19 +1000 Subject: [PATCH 03/12] fix Session reset confirmation message not displayed --- Pods | 2 +- .../Session Management/LokiSessionResetImplementation.swift | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Pods b/Pods index 71f54b041..d626be8f6 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 71f54b041ff9b9a77fecea805aa42ac536392c40 +Subproject commit d626be8f621bad9ed9d04d4370cbbb23cc438746 diff --git a/SignalServiceKit/src/Loki/Protocol/Session Management/LokiSessionResetImplementation.swift b/SignalServiceKit/src/Loki/Protocol/Session Management/LokiSessionResetImplementation.swift index e6aef07fc..844ba8659 100644 --- a/SignalServiceKit/src/Loki/Protocol/Session Management/LokiSessionResetImplementation.swift +++ b/SignalServiceKit/src/Loki/Protocol/Session Management/LokiSessionResetImplementation.swift @@ -47,10 +47,6 @@ public class LokiSessionResetImplementation : NSObject, SessionResetProtocol { Logger.debug("[Loki] A new session was adopted but the thread couldn't be found for: \(recipientID).") return } - // If the current user initiated the reset then send back a null message to acknowledge the completion of the session reset - if thread.sessionResetStatus == .initiated { - SessionManagementProtocol.sendNullMessage(to: recipientID, in: transaction) - } // Notify the user let infoMessage = TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: thread, messageType: .typeLokiSessionResetDone) infoMessage.save(with: transaction) From 005324953d3ad0b7ccce7fa9b5c5145880e48ec6 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 11 Aug 2020 15:48:31 +1000 Subject: [PATCH 04/12] =?UTF-8?q?fix=20Avatar=20not=20displayed=20on=20the?= =?UTF-8?q?=20contact=E2=80=99s=20device?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SignalMessaging/profiles/OWSProfileManager.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 8e3bd5f46..25c0dedb9 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -935,8 +935,9 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); NSData *groupId = groupThread.groupModel.groupId; return [self isGroupIdInProfileWhitelist:groupId]; } else { - NSString *recipientId = thread.contactIdentifier; - return [self isUserInProfileWhitelist:recipientId]; +// NSString *recipientId = thread.contactIdentifier; +// return [self isUserInProfileWhitelist:recipientId]; + return true; } } From d7ae441ee5c65945e7a1eea2fda11f1713e9cdb7 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 11 Aug 2020 16:01:43 +1000 Subject: [PATCH 05/12] fix when in Settings, tapping notification won't lead to conversation view --- Signal/src/Loki/View Controllers/HomeVC.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Signal/src/Loki/View Controllers/HomeVC.swift b/Signal/src/Loki/View Controllers/HomeVC.swift index 07f5dd51f..8d63bbf1d 100644 --- a/Signal/src/Loki/View Controllers/HomeVC.swift +++ b/Signal/src/Loki/View Controllers/HomeVC.swift @@ -383,6 +383,9 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol @objc func show(_ thread: TSThread, with action: ConversationViewAction, highlightedMessageID: String?, animated: Bool) { DispatchMainThreadSafe { + if let presentedVC = self.presentedViewController { + presentedVC.dismiss(animated: false, completion: nil) + } let conversationVC = ConversationViewController() conversationVC.configure(for: thread, action: action, focusMessageId: highlightedMessageID) self.navigationController?.setViewControllers([ self, conversationVC ], animated: true) From 417afbbcb98df4e601fc4a5e9570728aeb576f36 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 12 Aug 2020 15:35:19 +1000 Subject: [PATCH 06/12] fix duplicated message shown in open groups --- .../src/Loki/API/Open Groups/PublicChatPoller.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SignalServiceKit/src/Loki/API/Open Groups/PublicChatPoller.swift b/SignalServiceKit/src/Loki/API/Open Groups/PublicChatPoller.swift index d60046331..3e4efc7e1 100644 --- a/SignalServiceKit/src/Loki/API/Open Groups/PublicChatPoller.swift +++ b/SignalServiceKit/src/Loki/API/Open Groups/PublicChatPoller.swift @@ -8,6 +8,7 @@ public final class PublicChatPoller : NSObject { private var pollForModeratorsTimer: Timer? = nil private var pollForDisplayNamesTimer: Timer? = nil private var hasStarted = false + private var isPolling = false // MARK: Settings private let pollForNewMessagesInterval: TimeInterval = 4 @@ -54,9 +55,12 @@ public final class PublicChatPoller : NSObject { } public func pollForNewMessages() -> Promise { + guard !self.isPolling else { return Promise.value(()) } + self.isPolling = true let publicChat = self.publicChat let userPublicKey = getUserHexEncodedPublicKey() return PublicChatAPI.getMessages(for: publicChat.channel, on: publicChat.server).done(on: DispatchQueue.global(qos: .default)) { messages in + self.isPolling = false let uniquePublicKeys = Set(messages.map { $0.senderPublicKey }) func proceed() { let storage = OWSPrimaryStorage.shared() From 74a49ab46dfa3de498ecaf2a0b3049e980375eae Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 12 Aug 2020 16:26:15 +1000 Subject: [PATCH 07/12] fix muted label not disappear after the end of the set period --- Signal/src/Loki/Components/ConversationTitleView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/src/Loki/Components/ConversationTitleView.swift b/Signal/src/Loki/Components/ConversationTitleView.swift index 79f3f6d35..6de074a79 100644 --- a/Signal/src/Loki/Components/ConversationTitleView.swift +++ b/Signal/src/Loki/Components/ConversationTitleView.swift @@ -167,7 +167,7 @@ final class ConversationTitleView : UIView { case .messageFailed: self.subtitleLabel.text = NSLocalizedString("Message failed to send", comment: "") case nil: let subtitle = NSMutableAttributedString() - if let muteEndDate = self.thread.mutedUntilDate { + if let muteEndDate = self.thread.mutedUntilDate, self.thread.isMuted { subtitle.append(NSAttributedString(string: "\u{e067} ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.unimportant ])) let dateFormatter = DateFormatter() dateFormatter.locale = Locale.current From aced49a5af913da629a4cb1d0bcb387b70452d94 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Wed, 12 Aug 2020 17:10:41 +1000 Subject: [PATCH 08/12] fix ID displayed instead of username when a member leaves the group --- SignalServiceKit/src/Messages/OWSMessageManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index ecdb75eb6..1679e5b80 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1352,7 +1352,7 @@ NS_ASSUME_NONNULL_BEGIN oldGroupThread.groupModel.groupMemberIds = [newMemberIds.allObjects mutableCopy]; [oldGroupThread saveWithTransaction:transaction]; - NSString *nameString = + NSString *nameString = [SSKEnvironment.shared.profileManager profileNameForRecipientWithID:senderMasterPublicKey transaction:transaction] ?: [self.contactsManager displayNameForPhoneIdentifier:senderMasterPublicKey transaction:transaction]; NSString *updateGroupInfo = [NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""), nameString]; From 86bb60258cde3ab9dadec34da6e02124f3769d66 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Thu, 13 Aug 2020 10:59:54 +1000 Subject: [PATCH 09/12] fix link previews --- SignalServiceKit/src/Messages/OWSMessageSender.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 018facd99..0eec0f8c3 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -377,7 +377,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; // // So we're using YDB behavior to ensure this invariant, which is a bit // unorthodox. - if (message.attachmentIds.count > 0) { + if (message.allAttachmentIds.count > 0) { [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [allAttachmentIds addObjectsFromArray:[OutgoingMessagePreparer prepareMessageForSending:message transaction:transaction]]; } error:nil]; From 0d8b861df1bfb0ff63b802b29d513158b09c9999 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Thu, 13 Aug 2020 15:08:26 +1000 Subject: [PATCH 10/12] show disappearing message settings for closed groups --- .../OWSConversationSettingsViewController.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index fa2c105f1..9443e0db4 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -185,6 +185,11 @@ const CGFloat kIconViewLength = 24; return [self.thread isKindOfClass:[TSGroupThread class]]; } +- (BOOL)isOpenGroupChat +{ + return [self isGroupThread] && ![self isPrivateGroupChat]; +} + -(BOOL)isPrivateGroupChat { if (self.isGroupThread) { @@ -500,7 +505,7 @@ const CGFloat kIconViewLength = 24; * ======= */ - if (!self.thread.isGroupThread) { + if (![self isOpenGroupChat]) { [mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ UITableViewCell *cell = [OWSTableItem newCell]; @@ -536,7 +541,14 @@ const CGFloat kIconViewLength = 24; [topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom]; UILabel *subtitleLabel = [UILabel new]; - subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"When enabled, messages between you and %@ will disappear after they have been seen.", ""), [LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:self.thread.contactIdentifier]]; + NSString *threadName; + // TODO: Modify the text content + if (self.thread.isGroupThread) { + threadName = @"the group"; + } else { + threadName = [LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:self.thread.contactIdentifier]; + } + subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"When enabled, messages between you and %@ will disappear after they have been seen.", ""), threadName]; subtitleLabel.textColor = LKColors.text; subtitleLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize]; subtitleLabel.numberOfLines = 0; From 09a68ebfd8a6728ddcb139869e5170b2cf356a03 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Fri, 14 Aug 2020 13:34:57 +1000 Subject: [PATCH 11/12] fix race condition in highlight mentions --- .../src/UserInterface/Notifications/AppNotifications.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Signal/src/UserInterface/Notifications/AppNotifications.swift b/Signal/src/UserInterface/Notifications/AppNotifications.swift index bd74ea59f..29b44b0c0 100644 --- a/Signal/src/UserInterface/Notifications/AppNotifications.swift +++ b/Signal/src/UserInterface/Notifications/AppNotifications.swift @@ -357,7 +357,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { // it must be escaped. // see https://developer.apple.com/documentation/uikit/uilocalnotification/1616646-alertbody // for more details. - let messageText = MentionUtilities.highlightMentions(in: DisplayableText.filterNotificationText(rawMessageText)!, threadID: thread.uniqueId!) + let messageText = DisplayableText.filterNotificationText(rawMessageText) let senderName = OWSUserProfile.fetch(uniqueId: incomingMessage.authorId, transaction: transaction)?.profileName ?? contactsManager.displayName(forPhoneIdentifier: incomingMessage.authorId) @@ -383,7 +383,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { } } - let notificationBody: String? + var notificationBody: String? switch previewType { case .noNameNoPreview, .nameNoPreview: notificationBody = NotificationStrings.incomingMessageBody @@ -413,6 +413,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { ] DispatchQueue.main.async { + notificationBody = MentionUtilities.highlightMentions(in: notificationBody!, threadID: thread.uniqueId!) let sound = self.requestSound(thread: thread) self.adaptee.notify(category: category, title: notificationTitle, From 8d44115195bced2dae5b322ee84144ab7afa7648 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Mon, 17 Aug 2020 14:34:47 +1000 Subject: [PATCH 12/12] fix invalid auth token handling with onion request --- .../Loki/View Controllers/JoinPublicChatVC.swift | 2 +- SignalServiceKit/src/Loki/API/DotNetAPI.swift | 14 -------------- .../Loki/API/Onion Requests/OnionRequestAPI.swift | 4 ++-- .../src/Loki/API/Open Groups/PublicChatAPI.swift | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift b/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift index bcff10242..0099344a0 100644 --- a/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift +++ b/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift @@ -156,7 +156,7 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie self?.dismiss(animated: true, completion: nil) // Dismiss the loader var title = "Couldn't Join" var message = "" - if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 { + if case OnionRequestAPI.Error.httpRequestFailedAtTargetSnode(statusCode: let statusCode, json: _) = error, statusCode == 401 || statusCode == 403 { title = "Unauthorized" message = "Please ask the open group operator to add you to the group." } diff --git a/SignalServiceKit/src/Loki/API/DotNetAPI.swift b/SignalServiceKit/src/Loki/API/DotNetAPI.swift index 696a35fe7..643338995 100644 --- a/SignalServiceKit/src/Loki/API/DotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/DotNetAPI.swift @@ -187,17 +187,3 @@ public class DotNetAPI : NSObject { } } } - -// MARK: Error Handling -internal extension Promise { - - internal func handlingInvalidAuthTokenIfNeeded(for server: String) -> Promise { - return recover2 { error -> Promise in - if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 { - print("[Loki] Auth token for: \(server) expired; dropping it.") - DotNetAPI.removeAuthToken(for: server) - } - throw error - } - } -} diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index b96eddd53..ea4883dd9 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -26,7 +26,7 @@ public enum OnionRequestAPI { } // MARK: Error - internal enum Error : LocalizedError { + public enum Error : LocalizedError { case httpRequestFailedAtTargetSnode(statusCode: UInt, json: JSON) case insufficientSnodes case invalidURL @@ -35,7 +35,7 @@ public enum OnionRequestAPI { case snodePublicKeySetMissing case unsupportedSnodeVersion(String) - internal var errorDescription: String? { + public var errorDescription: String? { switch self { case .httpRequestFailedAtTargetSnode(let statusCode): return "HTTP request failed at target snode with status code: \(statusCode)." case .insufficientSnodes: return "Couldn't find enough snodes to build a path." diff --git a/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift b/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift index b41ea757c..dd3226e84 100644 --- a/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift +++ b/SignalServiceKit/src/Loki/API/Open Groups/PublicChatAPI.swift @@ -523,3 +523,17 @@ public final class PublicChatAPI : DotNetAPI { return moderators[server]?[channel]?.contains(hexEncodedPublicString) ?? false } } + +// MARK: Error Handling +internal extension Promise { + + internal func handlingInvalidAuthTokenIfNeeded(for server: String) -> Promise { + return recover2 { error -> Promise in + if case OnionRequestAPI.Error.httpRequestFailedAtTargetSnode(let statusCode, _) = error, statusCode == 401 || statusCode == 403 { + print("[Loki] Auth token for: \(server) expired; dropping it.") + PublicChatAPI.removeAuthToken(for: server) + } + throw error + } + } +}