From 221eabc49679c9cb8b511c2562c5320f99f5b718 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 16 Jul 2021 13:27:27 +1000 Subject: [PATCH 1/5] fix scroll to button not always works --- Session/Conversations/ConversationVC+Interaction.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 795cc80ae..23b17d9ee 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -18,7 +18,10 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc } func handleScrollToBottomButtonTapped() { - scrollToBottom(isAnimated: true) + // The tableview's content size will be calculated by the estimated height of cells, + // so the result may be inaccurate before all the cells are loaded. + // Use this scroll to the last row instead. + messagesTableView.scrollToRow(at: IndexPath(row: viewItems.count-1, section: 0), at: .top, animated: true) } // MARK: Blocking From 4fad67484f1ee160ee6da5965cf3ed323b074532 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 20 Jul 2021 11:22:56 +1000 Subject: [PATCH 2/5] fix incorrect unread position --- Session/Conversations/ConversationVC.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 2b61c9b1f..de7b29ae3 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -223,7 +223,9 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat unreadCount = self.thread.unreadMessageCount(transaction: transaction) } DispatchQueue.main.async { - if unreadCount > 0, let viewItem = self.viewItems[ifValid: self.viewItems.count - Int(unreadCount)], let interactionID = viewItem.interaction.uniqueId { + let unreadIndicatorIndex = self.viewModel.viewState.unreadIndicatorIndex?.intValue ?? (self.viewItems.count - self.unreadViewItems.count) + print("Ryan Test: \(unreadIndicatorIndex)") + if unreadCount > 0, let viewItem = self.viewItems[ifValid: unreadIndicatorIndex], let interactionID = viewItem.interaction.uniqueId { self.scrollToInteraction(with: interactionID, position: .top, isAnimated: false) self.unreadCountView.alpha = self.scrollButton.alpha } else { From fcca7f3076f61da701d46c87c6bd519353fbf4e7 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 20 Jul 2021 11:42:22 +1000 Subject: [PATCH 3/5] clean --- Session/Conversations/ConversationVC.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index de7b29ae3..45cf5b7ce 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -224,7 +224,6 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat } DispatchQueue.main.async { let unreadIndicatorIndex = self.viewModel.viewState.unreadIndicatorIndex?.intValue ?? (self.viewItems.count - self.unreadViewItems.count) - print("Ryan Test: \(unreadIndicatorIndex)") if unreadCount > 0, let viewItem = self.viewItems[ifValid: unreadIndicatorIndex], let interactionID = viewItem.interaction.uniqueId { self.scrollToInteraction(with: interactionID, position: .top, isAnimated: false) self.unreadCountView.alpha = self.scrollButton.alpha From bd7e9b5943a9ff779e4c66e1ede0aca4eaa189d9 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 20 Jul 2021 11:46:02 +1000 Subject: [PATCH 4/5] add comment --- Session/Conversations/ConversationVC.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 45cf5b7ce..baa5ec147 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -222,6 +222,10 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat Storage.read { transaction in unreadCount = self.thread.unreadMessageCount(transaction: transaction) } + // When the unread message count is more than the number of a page of viewItems, + // the screen will scroll to bottom instead of the correct first unread message. + // The unreadIndicatorIndex is calculated during loading the viewItems, it is + // supposed to be accurate. DispatchQueue.main.async { let unreadIndicatorIndex = self.viewModel.viewState.unreadIndicatorIndex?.intValue ?? (self.viewItems.count - self.unreadViewItems.count) if unreadCount > 0, let viewItem = self.viewItems[ifValid: unreadIndicatorIndex], let interactionID = viewItem.interaction.uniqueId { From 69dea7548696fa4f1c82c98c420089d4b1b33c89 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 20 Jul 2021 14:06:23 +1000 Subject: [PATCH 5/5] potentially fix the conversation stuck at unread --- SessionMessagingKit/Jobs/AttachmentDownloadJob.swift | 5 +++++ SessionMessagingKit/Messages/Signal/TSIncomingMessage.m | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift b/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift index 980582e83..f7a281b20 100644 --- a/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift +++ b/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift @@ -86,6 +86,11 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject self.handlePermanentFailure(error: error) } else if let error = error as? OnionRequestAPI.Error, case .httpRequestFailedAtDestination(let statusCode, _, _) = error, statusCode == 400 { + // Otherwise, the attachment will show a state of downloading forever, + // and the message won't be able to be marked as read. + storage.write(with: { transaction in + storage.setAttachmentState(to: .failed, for: pointer, associatedWith: self.tsMessageID, using: transaction) + }, completion: { }) // This usually indicates a file that has expired on the server, so there's no need to retry. self.handlePermanentFailure(error: error) } else { diff --git a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m index cdf88f736..6d5d17ab7 100644 --- a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m @@ -147,6 +147,11 @@ NS_ASSUME_NONNULL_BEGIN BOOL areAllAttachmentsDownloaded = YES; for (NSString *attachmentId in self.attachmentIds) { TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction]; + // If the attachment download is failed, we can mark this message as read. + // Otherwise, this message will never be marked as read. + if ([attachment isKindOfClass:[TSAttachmentPointer class]] && ((TSAttachmentPointer *)attachment).state == TSAttachmentPointerStateFailed) { + continue; + } areAllAttachmentsDownloaded = areAllAttachmentsDownloaded && attachment.isDownloaded; if (!areAllAttachmentsDownloaded) break; }