From 900a97bd8cc4f0f7f36ecba17aeacbc187193d70 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 27 Feb 2023 16:46:47 +1100 Subject: [PATCH 01/11] fix incorrect icon colour in draft quote --- .../Conversations/Message Cells/Content Views/QuoteView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Conversations/Message Cells/Content Views/QuoteView.swift b/Session/Conversations/Message Cells/Content Views/QuoteView.swift index 2ee2f9068..862b61427 100644 --- a/Session/Conversations/Message Cells/Content Views/QuoteView.swift +++ b/Session/Conversations/Message Cells/Content Views/QuoteView.swift @@ -144,7 +144,7 @@ final class QuoteView: UIView { .messageBubble_outgoingText : .messageBubble_incomingText ) - case .draft: return .messageBubble_outgoingText + case .draft: return .textPrimary } }() imageView.contentMode = .center From cd3c1ee043338d00a2e03a60701b52ef133c7395 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 27 Feb 2023 16:54:54 +1100 Subject: [PATCH 02/11] fix attachment description --- .../Message Cells/Content Views/QuoteView.swift | 7 ++----- SessionMessagingKit/Database/Models/Attachment.swift | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Session/Conversations/Message Cells/Content Views/QuoteView.swift b/Session/Conversations/Message Cells/Content Views/QuoteView.swift index 862b61427..fa5f9e931 100644 --- a/Session/Conversations/Message Cells/Content Views/QuoteView.swift +++ b/Session/Conversations/Message Cells/Content Views/QuoteView.swift @@ -156,10 +156,7 @@ final class QuoteView: UIView { mainStackView.addArrangedSubview(imageView) if (body ?? "").isEmpty { - body = (attachment.isImage ? - "Image" : - (isAudio ? "Audio" : "Document") - ) + body = attachment.shortDescription } // Generate the thumbnail if needed @@ -223,7 +220,7 @@ final class QuoteView: UIView { } .defaulting( to: attachment.map { - NSAttributedString(string: MIMETypeUtil.isAudio($0.contentType) ? "Audio" : "Document") + NSAttributedString(string: $0.shortDescription) } ) .defaulting(to: NSAttributedString(string: "Document")) diff --git a/SessionMessagingKit/Database/Models/Attachment.swift b/SessionMessagingKit/Database/Models/Attachment.swift index 72b8ff0c6..fc004c92e 100644 --- a/SessionMessagingKit/Database/Models/Attachment.swift +++ b/SessionMessagingKit/Database/Models/Attachment.swift @@ -787,6 +787,13 @@ extension Attachment { public var isText: Bool { MIMETypeUtil.isText(contentType) } public var isMicrosoftDoc: Bool { MIMETypeUtil.isMicrosoftDoc(contentType) } + public var shortDescription: String { + if isImage { return "Image" } + if isAudio { return "Audio" } + if isVideo { return "Video" } + return "Document" + } + public func readDataFromFile() throws -> Data? { guard let filePath: String = self.originalFilePath else { return nil From a0ba1484f5f33abcfdf3a0e37d3c7cbe105711ad Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 27 Feb 2023 17:16:38 +1100 Subject: [PATCH 03/11] fix an edge case of showing 'original message not found' incorrectly --- .../Conversations/Message Cells/Content Views/QuoteView.swift | 4 ++-- Session/Conversations/Message Cells/VisibleMessageCell.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Session/Conversations/Message Cells/Content Views/QuoteView.swift b/Session/Conversations/Message Cells/Content Views/QuoteView.swift index fa5f9e931..ebd726a1c 100644 --- a/Session/Conversations/Message Cells/Content Views/QuoteView.swift +++ b/Session/Conversations/Message Cells/Content Views/QuoteView.swift @@ -220,10 +220,10 @@ final class QuoteView: UIView { } .defaulting( to: attachment.map { - NSAttributedString(string: $0.shortDescription) + NSAttributedString(string: $0.shortDescription, attributes: [ .foregroundColor: textColor ]) } ) - .defaulting(to: NSAttributedString(string: "Document")) + .defaulting(to: NSAttributedString(string: "QUOTED_MESSAGE_NOT_FOUND".localized(), attributes: [ .foregroundColor: textColor ])) } // Label stack view diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index 94eb3d73e..591d3ade6 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -545,7 +545,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate { let quoteView: QuoteView = QuoteView( for: .regular, authorId: quote.authorId, - quotedText: quote.body ?? "QUOTED_MESSAGE_NOT_FOUND".localized(), + quotedText: quote.body, threadVariant: cellViewModel.threadVariant, currentUserPublicKey: cellViewModel.currentUserPublicKey, currentUserBlindedPublicKey: cellViewModel.currentUserBlindedPublicKey, From f8dc2ddfb8849ccac7ee411d85da37a9b66e9fac Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 28 Feb 2023 14:25:15 +1100 Subject: [PATCH 04/11] fix incorrect closed group leaving warning for members and admins --- .../Settings/ThreadSettingsViewModel.swift | 6 +++++- .../SessionThreadViewModel.swift | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Session/Conversations/Settings/ThreadSettingsViewModel.swift b/Session/Conversations/Settings/ThreadSettingsViewModel.swift index 25d35e095..21732ffda 100644 --- a/Session/Conversations/Settings/ThreadSettingsViewModel.swift +++ b/Session/Conversations/Settings/ThreadSettingsViewModel.swift @@ -206,6 +206,10 @@ class ThreadSettingsViewModel: SessionTableViewModel Date: Tue, 28 Feb 2023 15:02:36 +1100 Subject: [PATCH 05/11] fix an issue where a member leaving a group will make other member's group not working --- .../Message Handling/MessageReceiver+ClosedGroups.swift | 2 +- SessionMessagingKit/Shared Models/SessionThreadViewModel.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ClosedGroups.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ClosedGroups.swift index 669e46de0..5a5321554 100644 --- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ClosedGroups.swift +++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+ClosedGroups.swift @@ -420,7 +420,7 @@ extension MessageReceiver { // Delete the members to remove try GroupMember .filter(GroupMember.Columns.groupId == id) - .filter(updatedMemberIds.contains(GroupMember.Columns.profileId)) + .filter(membersToRemove.map{ $0.profileId }.contains(GroupMember.Columns.profileId)) .deleteAll(db) if didAdminLeave || sender == userPublicKey { diff --git a/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift b/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift index 0699a306e..02e614aeb 100644 --- a/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift +++ b/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift @@ -871,7 +871,7 @@ public extension SessionThreadViewModel { LEFT JOIN \(OpenGroup.self) ON \(openGroup[.threadId]) = \(thread[.id]) LEFT JOIN \(ClosedGroup.self) ON \(closedGroup[.threadId]) = \(thread[.id]) LEFT JOIN \(GroupMember.self) AS \(ViewModel.currentUserIsClosedGroupMemberKey) ON ( - \(SQL("\(ViewModel.currentUserIsClosedGroupMemberKey).\(groupMemberRoleColumnLiteral) = \(GroupMember.Role.standard)")) AND + \(SQL("\(ViewModel.currentUserIsClosedGroupMemberKey).\(groupMemberRoleColumnLiteral) != \(GroupMember.Role.zombie)")) AND \(ViewModel.currentUserIsClosedGroupMemberKey).\(groupMemberGroupIdColumnLiteral) = \(closedGroup[.threadId]) AND \(SQL("\(ViewModel.currentUserIsClosedGroupMemberKey).\(groupMemberProfileIdColumnLiteral) = \(userPublicKey)")) ) From 36ed8802bbd79dcbe95f0a911fa1be29cbf0667b Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 2 Mar 2023 16:17:58 +1100 Subject: [PATCH 06/11] don't include the attachment when quoted if the attachment is not downloaded --- SessionMessagingKit/Database/Models/Attachment.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SessionMessagingKit/Database/Models/Attachment.swift b/SessionMessagingKit/Database/Models/Attachment.swift index fc004c92e..c91686a17 100644 --- a/SessionMessagingKit/Database/Models/Attachment.swift +++ b/SessionMessagingKit/Database/Models/Attachment.swift @@ -885,13 +885,16 @@ extension Attachment { guard self.isValid, - self.isVisualMedia, let thumbnailPath: String = Attachment.originalFilePath( id: cloneId, mimeType: OWSMimeTypeImageJpeg, sourceFilename: thumbnailName ) else { + return nil + } + + guard self.isVisualMedia else { // Non-media files cannot have thumbnails but may be sent as quotes, in these cases we want // to create an attachment in an 'uploaded' state with a hard-coded file id so the messageSend // job doesn't try to upload the attachment (we include the original `serverId` as it's From 84ea821095270ad678c371beb13502c877e59ceb Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 2 Mar 2023 17:05:26 +1100 Subject: [PATCH 07/11] WIP: fix quote when retrying sending a message --- Session/Conversations/ConversationVC+Interaction.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 380c9c610..7ee51d86f 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1604,6 +1604,13 @@ extension ConversationVC: let thread: SessionThread = try SessionThread.fetchOne(db, id: threadId) else { return } + if + let quote = try? interaction.quote.fetchOne(db), + let quotedInteraction = try? quote.interaction.fetchOne(db) + { + + } + try MessageSender.send( db, interaction: interaction, From 3aacf27b798fe5927cde0afbcb842adcda148184 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 6 Mar 2023 14:33:24 +1100 Subject: [PATCH 08/11] regenerate the quoted attachment thumbnail when retrying to send the message --- .../ConversationVC+Interaction.swift | 10 ++++++++-- .../Database/Models/Attachment.swift | 5 +---- .../Database/Models/Quote.swift | 20 +++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 7ee51d86f..d94bf3199 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1606,9 +1606,15 @@ extension ConversationVC: if let quote = try? interaction.quote.fetchOne(db), - let quotedInteraction = try? quote.interaction.fetchOne(db) + let quotedAttachment = try? quote.attachment.fetchOne(db), + quotedAttachment.isVisualMedia, + quotedAttachment.downloadUrl == Attachment.nonMediaQuoteFileId, + let quotedInteraction = try? quote.originalInteraction.fetchOne(db) { - + let attachment = try? quotedInteraction.attachments.fetchAll(db).first + try quote.with( + attachmentId: attachment?.cloneAsQuoteThumbnail()?.inserted(db).id + ).update(db) } try MessageSender.send( diff --git a/SessionMessagingKit/Database/Models/Attachment.swift b/SessionMessagingKit/Database/Models/Attachment.swift index c91686a17..fc004c92e 100644 --- a/SessionMessagingKit/Database/Models/Attachment.swift +++ b/SessionMessagingKit/Database/Models/Attachment.swift @@ -885,16 +885,13 @@ extension Attachment { guard self.isValid, + self.isVisualMedia, let thumbnailPath: String = Attachment.originalFilePath( id: cloneId, mimeType: OWSMimeTypeImageJpeg, sourceFilename: thumbnailName ) else { - return nil - } - - guard self.isVisualMedia else { // Non-media files cannot have thumbnails but may be sent as quotes, in these cases we want // to create an attachment in an 'uploaded' state with a hard-coded file id so the messageSend // job doesn't try to upload the attachment (we include the original `serverId` as it's diff --git a/SessionMessagingKit/Database/Models/Quote.swift b/SessionMessagingKit/Database/Models/Quote.swift index af92ee454..1b702ecf1 100644 --- a/SessionMessagingKit/Database/Models/Quote.swift +++ b/SessionMessagingKit/Database/Models/Quote.swift @@ -76,6 +76,26 @@ public struct Quote: Codable, Equatable, Hashable, FetchableRecord, PersistableR } } +// MARK: - Mutation + +public extension Quote { + func with( + interactionId: Int64? = nil, + authorId: String? = nil, + timestampMs: Int64? = nil, + body: String? = nil, + attachmentId: String? = nil + ) -> Quote { + return Quote( + interactionId: interactionId ?? self.interactionId, + authorId: authorId ?? self.authorId, + timestampMs: timestampMs ?? self.timestampMs, + body: body ?? self.body, + attachmentId: attachmentId ?? self.attachmentId + ) + } +} + // MARK: - Protobuf public extension Quote { From 00d5d0815211d1295921e639f9444d7651d9b7b9 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 6 Mar 2023 15:31:04 +1100 Subject: [PATCH 09/11] fix retry action will end up with sending the same interaction twice --- Session/Conversations/ConversationVC+Interaction.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index d94bf3199..a8ca98c6d 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1617,6 +1617,10 @@ extension ConversationVC: ).update(db) } + // Remove message sending jobs for the same interaction in database + // Prevent the same message being sent twice + try Job.filter(Job.Columns.interactionId == interaction.id).deleteAll(db) + try MessageSender.send( db, interaction: interaction, From 779e199d7de35c6bcdcdec22a741aa1b4f6ed746 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 6 Mar 2023 15:53:26 +1100 Subject: [PATCH 10/11] update build number --- Session.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index d8fbdb833..42129e423 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -6040,7 +6040,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 394; + CURRENT_PROJECT_VERSION = 395; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -6113,7 +6113,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 394; + CURRENT_PROJECT_VERSION = 395; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -6179,7 +6179,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 394; + CURRENT_PROJECT_VERSION = 395; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -6253,7 +6253,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 394; + CURRENT_PROJECT_VERSION = 395; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; From 37962fa071981b245f1aa1f909709c62101c6978 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 6 Mar 2023 16:13:08 +1100 Subject: [PATCH 11/11] update build number --- Session.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 42129e423..95ecf73f0 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -7181,7 +7181,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 394; + CURRENT_PROJECT_VERSION = 395; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -7253,7 +7253,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 394; + CURRENT_PROJECT_VERSION = 395; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)",