From 185f6ab269a49ad817c9721626ea862c63bf7b9a Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 22 Jul 2022 15:20:18 +1000 Subject: [PATCH 01/15] remove text from quote protobuf --- Podfile.lock | 2 +- .../Message Cells/Content Views/QuoteView.swift | 1 - Session/Meta/Translations/en.lproj/Localizable.strings | 1 + SessionMessagingKit/Database/Models/Quote.swift | 5 +---- .../Messages/Visible Messages/VisibleMessage+Quote.swift | 1 - 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 70045a1da..bab1ae426 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -232,4 +232,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 6ab902a81a379cc2c0a9a92c334c78d413190338 -COCOAPODS: 1.11.3 +COCOAPODS: 1.11.2 diff --git a/Session/Conversations/Message Cells/Content Views/QuoteView.swift b/Session/Conversations/Message Cells/Content Views/QuoteView.swift index 2a47a91d9..b6558ab0c 100644 --- a/Session/Conversations/Message Cells/Content Views/QuoteView.swift +++ b/Session/Conversations/Message Cells/Content Views/QuoteView.swift @@ -186,7 +186,6 @@ final class QuoteView: UIView { } }() let bodyLabel = UILabel() - bodyLabel.numberOfLines = 0 bodyLabel.lineBreakMode = .byTruncatingTail let isOutgoing = (direction == .outgoing) diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 70292f244..956dc193d 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/SessionMessagingKit/Database/Models/Quote.swift b/SessionMessagingKit/Database/Models/Quote.swift index 9ac83853c..faa8bee1a 100644 --- a/SessionMessagingKit/Database/Models/Quote.swift +++ b/SessionMessagingKit/Database/Models/Quote.swift @@ -100,11 +100,8 @@ public extension Quote { if let quotedInteraction: Interaction = quotedInteraction, quotedInteraction.body?.isEmpty == false { self.body = quotedInteraction.body } - else if let body: String = quoteProto.text, !body.isEmpty { - self.body = body - } else { - self.body = nil + self.body = "QUOTED_MESSAGE_NOT_FOUND".localized() } // We only use the first attachment diff --git a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift index fdd50732c..2c30d72d0 100644 --- a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift +++ b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift @@ -44,7 +44,6 @@ public extension VisibleMessage { return nil } let quoteProto = SNProtoDataMessageQuote.builder(id: timestamp, author: publicKey) - if let text = text { quoteProto.setText(text) } addAttachmentsIfNeeded(db, to: quoteProto) do { return try quoteProto.build() From cf961d173dd599499c0f5bcfc85a745b51a41933 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 25 Jul 2022 15:04:55 +1000 Subject: [PATCH 02/15] add text back for smooth migration --- .../Messages/Visible Messages/VisibleMessage+Quote.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift index 2c30d72d0..fdd50732c 100644 --- a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift +++ b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage+Quote.swift @@ -44,6 +44,7 @@ public extension VisibleMessage { return nil } let quoteProto = SNProtoDataMessageQuote.builder(id: timestamp, author: publicKey) + if let text = text { quoteProto.setText(text) } addAttachmentsIfNeeded(db, to: quoteProto) do { return try quoteProto.build() From 6b4dba0908dda4c64a72a1214258c190a1e49ec1 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 25 Jul 2022 16:10:53 +1000 Subject: [PATCH 03/15] redo quote from proto --- SessionMessagingKit/Database/Models/Quote.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SessionMessagingKit/Database/Models/Quote.swift b/SessionMessagingKit/Database/Models/Quote.swift index faa8bee1a..2e7a3ce83 100644 --- a/SessionMessagingKit/Database/Models/Quote.swift +++ b/SessionMessagingKit/Database/Models/Quote.swift @@ -97,11 +97,20 @@ public extension Quote { .filter(Interaction.Columns.timestampMs == Double(quoteProto.id)) .fetchOne(db) + guard quotedInteraction != nil else { + self.body = "QUOTED_MESSAGE_NOT_FOUND".localized() + self.attachmentId = nil + return + } + if let quotedInteraction: Interaction = quotedInteraction, quotedInteraction.body?.isEmpty == false { self.body = quotedInteraction.body } + else if let body: String = quoteProto.text, !body.isEmpty { + self.body = body + } else { - self.body = "QUOTED_MESSAGE_NOT_FOUND".localized() + self.body = nil } // We only use the first attachment From 83b40915a161a093e5d2bef0d20cb0f00a674a74 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 26 Jul 2022 16:23:54 +1000 Subject: [PATCH 04/15] remove quote content when original message is removed --- .../ConversationVC+Interaction.swift | 21 +++++++++++++++++++ .../Database/Models/Quote.swift | 15 +++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 33dfce0fb..0d272ee29 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1075,6 +1075,13 @@ extension ConversationVC: .done { _ in // Delete the interaction (and associated data) from the database Storage.shared.writeAsync { db in + try Quote + .updateBeforeQuotedInterationDeletion( + db, + timestampMs: cellViewModel.timestampMs, + authorId: cellViewModel.authorId + ) + _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) @@ -1155,6 +1162,13 @@ extension ConversationVC: // For incoming interactions or interactions with no serverHash just delete them locally guard cellViewModel.variant == .standardOutgoing, let serverHash: String = serverHash else { Storage.shared.writeAsync { db in + try Quote + .updateBeforeQuotedInterationDeletion( + db, + timestampMs: cellViewModel.timestampMs, + authorId: cellViewModel.authorId + ) + _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) @@ -1178,6 +1192,13 @@ extension ConversationVC: let alertVC = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet) alertVC.addAction(UIAlertAction(title: "delete_message_for_me".localized(), style: .destructive) { [weak self] _ in Storage.shared.writeAsync { db in + try Quote + .updateBeforeQuotedInterationDeletion( + db, + timestampMs: cellViewModel.timestampMs, + authorId: cellViewModel.authorId + ) + _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) diff --git a/SessionMessagingKit/Database/Models/Quote.swift b/SessionMessagingKit/Database/Models/Quote.swift index 2e7a3ce83..b6ba5b39f 100644 --- a/SessionMessagingKit/Database/Models/Quote.swift +++ b/SessionMessagingKit/Database/Models/Quote.swift @@ -76,6 +76,21 @@ public struct Quote: Codable, Equatable, Hashable, FetchableRecord, PersistableR } } +public extension Quote { + /// This method updates the all Quotes before the quoted interation is deleted + /// + static func updateBeforeQuotedInterationDeletion(_ db: Database, timestampMs: Int64, authorId: String) throws { + try Quote + .filter(Columns.authorId == authorId) + .filter(Columns.timestampMs == timestampMs) + .updateAll( + db, + Columns.body.set(to: "QUOTED_MESSAGE_NOT_FOUND".localized()), + Columns.attachmentId.set(to: nil) + ) + } +} + // MARK: - Protobuf public extension Quote { From 170ac8a498a170cc9d0be0626013bed6bbf3c4ad Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 27 Jul 2022 10:47:50 +1000 Subject: [PATCH 05/15] add observer to refresh UI when quoted message is deleted --- Session/Conversations/ConversationViewModel.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Session/Conversations/ConversationViewModel.swift b/Session/Conversations/ConversationViewModel.swift index 28bf921a7..45966586c 100644 --- a/Session/Conversations/ConversationViewModel.swift +++ b/Session/Conversations/ConversationViewModel.swift @@ -192,6 +192,16 @@ public class ConversationViewModel: OWSAudioPlayerDelegate { return SQL("LEFT JOIN \(Profile.self) ON \(profile[.id]) = \(interaction[.authorId])") }() + ), + PagedData.ObservedChanges( + table: Quote.self, + columns: [.body], + joinToPagedType: { + let interaction: TypedTableAlias = TypedTableAlias() + let quote: TypedTableAlias = TypedTableAlias() + + return SQL("LEFT JOIN \(Quote.self) ON \(quote[.interactionId]) = \(interaction[.id])") + }() ) ], filterSQL: MessageViewModel.filterSQL(threadId: threadId), From 4d66d3fea52d61c30dd5b4b314cf9aecf262c0f1 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 27 Jul 2022 10:48:34 +1000 Subject: [PATCH 06/15] observe attachment change as well --- Session/Conversations/ConversationViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Session/Conversations/ConversationViewModel.swift b/Session/Conversations/ConversationViewModel.swift index 45966586c..9261160a9 100644 --- a/Session/Conversations/ConversationViewModel.swift +++ b/Session/Conversations/ConversationViewModel.swift @@ -195,7 +195,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate { ), PagedData.ObservedChanges( table: Quote.self, - columns: [.body], + columns: [.body, .attachmentId], joinToPagedType: { let interaction: TypedTableAlias = TypedTableAlias() let quote: TypedTableAlias = TypedTableAlias() From 01be564649c49f118de72c9cff4e95ccd8501ea5 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 11 Aug 2022 09:31:52 +1000 Subject: [PATCH 07/15] tweak: add localised strings --- Session/Meta/Translations/de.lproj/Localizable.strings | 1 + Session/Meta/Translations/es.lproj/Localizable.strings | 1 + Session/Meta/Translations/fa.lproj/Localizable.strings | 1 + Session/Meta/Translations/fi.lproj/Localizable.strings | 1 + Session/Meta/Translations/fr.lproj/Localizable.strings | 1 + Session/Meta/Translations/hi.lproj/Localizable.strings | 1 + Session/Meta/Translations/hr.lproj/Localizable.strings | 1 + Session/Meta/Translations/id-ID.lproj/Localizable.strings | 1 + Session/Meta/Translations/it.lproj/Localizable.strings | 1 + Session/Meta/Translations/ja.lproj/Localizable.strings | 1 + Session/Meta/Translations/nl.lproj/Localizable.strings | 1 + Session/Meta/Translations/pl.lproj/Localizable.strings | 1 + Session/Meta/Translations/pt_BR.lproj/Localizable.strings | 1 + Session/Meta/Translations/ru.lproj/Localizable.strings | 1 + Session/Meta/Translations/si.lproj/Localizable.strings | 1 + Session/Meta/Translations/sk.lproj/Localizable.strings | 1 + Session/Meta/Translations/sv.lproj/Localizable.strings | 1 + Session/Meta/Translations/th.lproj/Localizable.strings | 1 + Session/Meta/Translations/vi-VN.lproj/Localizable.strings | 1 + Session/Meta/Translations/zh-Hant.lproj/Localizable.strings | 1 + Session/Meta/Translations/zh_CN.lproj/Localizable.strings | 1 + 21 files changed, 21 insertions(+) diff --git a/Session/Meta/Translations/de.lproj/Localizable.strings b/Session/Meta/Translations/de.lproj/Localizable.strings index d12868e54..362bdfe99 100644 --- a/Session/Meta/Translations/de.lproj/Localizable.strings +++ b/Session/Meta/Translations/de.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/es.lproj/Localizable.strings b/Session/Meta/Translations/es.lproj/Localizable.strings index e5d4f9d44..7be87ea63 100644 --- a/Session/Meta/Translations/es.lproj/Localizable.strings +++ b/Session/Meta/Translations/es.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/fa.lproj/Localizable.strings b/Session/Meta/Translations/fa.lproj/Localizable.strings index f333f1b70..82a4cade7 100644 --- a/Session/Meta/Translations/fa.lproj/Localizable.strings +++ b/Session/Meta/Translations/fa.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/fi.lproj/Localizable.strings b/Session/Meta/Translations/fi.lproj/Localizable.strings index b9e9b8267..6bc45479a 100644 --- a/Session/Meta/Translations/fi.lproj/Localizable.strings +++ b/Session/Meta/Translations/fi.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/fr.lproj/Localizable.strings b/Session/Meta/Translations/fr.lproj/Localizable.strings index f99011932..0b74fd37f 100644 --- a/Session/Meta/Translations/fr.lproj/Localizable.strings +++ b/Session/Meta/Translations/fr.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/hi.lproj/Localizable.strings b/Session/Meta/Translations/hi.lproj/Localizable.strings index eca955776..09b10b985 100644 --- a/Session/Meta/Translations/hi.lproj/Localizable.strings +++ b/Session/Meta/Translations/hi.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/hr.lproj/Localizable.strings b/Session/Meta/Translations/hr.lproj/Localizable.strings index bb4556500..3784a354a 100644 --- a/Session/Meta/Translations/hr.lproj/Localizable.strings +++ b/Session/Meta/Translations/hr.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/id-ID.lproj/Localizable.strings b/Session/Meta/Translations/id-ID.lproj/Localizable.strings index 6322bf9f2..806d7a49a 100644 --- a/Session/Meta/Translations/id-ID.lproj/Localizable.strings +++ b/Session/Meta/Translations/id-ID.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/it.lproj/Localizable.strings b/Session/Meta/Translations/it.lproj/Localizable.strings index eedf2137b..1ea6f9a9e 100644 --- a/Session/Meta/Translations/it.lproj/Localizable.strings +++ b/Session/Meta/Translations/it.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/ja.lproj/Localizable.strings b/Session/Meta/Translations/ja.lproj/Localizable.strings index 253f72de8..46b75b828 100644 --- a/Session/Meta/Translations/ja.lproj/Localizable.strings +++ b/Session/Meta/Translations/ja.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/nl.lproj/Localizable.strings b/Session/Meta/Translations/nl.lproj/Localizable.strings index d58ebff00..c2ae093ef 100644 --- a/Session/Meta/Translations/nl.lproj/Localizable.strings +++ b/Session/Meta/Translations/nl.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/pl.lproj/Localizable.strings b/Session/Meta/Translations/pl.lproj/Localizable.strings index 5a08f7e35..5b19b879f 100644 --- a/Session/Meta/Translations/pl.lproj/Localizable.strings +++ b/Session/Meta/Translations/pl.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings index a848b7587..7a2526795 100644 --- a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings +++ b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/ru.lproj/Localizable.strings b/Session/Meta/Translations/ru.lproj/Localizable.strings index a3984387e..527e65051 100644 --- a/Session/Meta/Translations/ru.lproj/Localizable.strings +++ b/Session/Meta/Translations/ru.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/si.lproj/Localizable.strings b/Session/Meta/Translations/si.lproj/Localizable.strings index cacf3f5d1..57015b6c1 100644 --- a/Session/Meta/Translations/si.lproj/Localizable.strings +++ b/Session/Meta/Translations/si.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/sk.lproj/Localizable.strings b/Session/Meta/Translations/sk.lproj/Localizable.strings index 102514ede..8a7eb4c2e 100644 --- a/Session/Meta/Translations/sk.lproj/Localizable.strings +++ b/Session/Meta/Translations/sk.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/sv.lproj/Localizable.strings b/Session/Meta/Translations/sv.lproj/Localizable.strings index da8933ad7..9e621af4d 100644 --- a/Session/Meta/Translations/sv.lproj/Localizable.strings +++ b/Session/Meta/Translations/sv.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/th.lproj/Localizable.strings b/Session/Meta/Translations/th.lproj/Localizable.strings index b8f6e41ac..09abc064d 100644 --- a/Session/Meta/Translations/th.lproj/Localizable.strings +++ b/Session/Meta/Translations/th.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings index fd93b1f63..45fd11a4e 100644 --- a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings +++ b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings index f936369d4..f8880e793 100644 --- a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; diff --git a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings index 9145c3fe8..ccccec0c5 100644 --- a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings @@ -684,3 +684,4 @@ "SEND_FAILED_NOTIFICATION_BODY" = "Your message failed to send."; "INVALID_SESSION_ID_MESSAGE" = "Please check the Session ID and try again."; "INVALID_RECOVERY_PHRASE_MESSAGE" = "Please check the Recovery Phrase and try again."; +"QUOTED_MESSAGE_NOT_FOUND" = "Original message not found."; From 51a0093ceb40ce52ea739b8f00de310dd479c4e8 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 11 Aug 2022 09:36:52 +1000 Subject: [PATCH 08/15] update cocoapods --- Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile.lock b/Podfile.lock index 5e750d933..37f4ac9c5 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -244,4 +244,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: f0857369c4831b2e5c1946345e76e493f3286805 -COCOAPODS: 1.11.2 +COCOAPODS: 1.11.3 From bedf3ab44b2dd07456d9a347464615d6c47208b5 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 11 Aug 2022 14:41:08 +1000 Subject: [PATCH 09/15] WIP: select quote body from original interaction --- .../Database/Models/Quote.swift | 54 +------------------ .../Shared Models/MessageViewModel.swift | 12 ++++- 2 files changed, 13 insertions(+), 53 deletions(-) diff --git a/SessionMessagingKit/Database/Models/Quote.swift b/SessionMessagingKit/Database/Models/Quote.swift index ae4526d60..f24ae3e4f 100644 --- a/SessionMessagingKit/Database/Models/Quote.swift +++ b/SessionMessagingKit/Database/Models/Quote.swift @@ -104,57 +104,7 @@ public extension Quote { self.interactionId = interactionId self.timestampMs = Int64(quoteProto.id) self.authorId = quoteProto.author - - // Prefer to generate the text snippet locally if available. - let quotedInteraction: Interaction? = try? thread - .interactions - .filter(Interaction.Columns.authorId == quoteProto.author) - .filter(Interaction.Columns.timestampMs == Double(quoteProto.id)) - .fetchOne(db) - - guard quotedInteraction != nil else { - self.body = "QUOTED_MESSAGE_NOT_FOUND".localized() - self.attachmentId = nil - return - } - - if let quotedInteraction: Interaction = quotedInteraction, quotedInteraction.body?.isEmpty == false { - self.body = quotedInteraction.body - } - else if let body: String = quoteProto.text, !body.isEmpty { - self.body = body - } - else { - self.body = nil - } - - // We only use the first attachment - if let attachment = quoteProto.attachments.first(where: { $0.thumbnail != nil })?.thumbnail { - self.attachmentId = try quotedInteraction - .map { quotedInteraction -> Attachment? in - // If the quotedInteraction has an attachment then try clone it - if let attachment: Attachment = try? quotedInteraction.attachments.fetchOne(db) { - return attachment.cloneAsQuoteThumbnail() - } - - // Otherwise if the quotedInteraction has a link preview, try clone that - return try? quotedInteraction.linkPreview - .fetchOne(db)? - .attachment - .fetchOne(db)? - .cloneAsQuoteThumbnail() - } - .defaulting(to: Attachment(proto: attachment)) - .inserted(db) - .id - } - else { - self.attachmentId = nil - } - - // Make sure the quote is valid before completing - if self.body == nil && self.attachmentId == nil { - return nil - } + self.body = nil + self.attachmentId = nil } } diff --git a/SessionMessagingKit/Shared Models/MessageViewModel.swift b/SessionMessagingKit/Shared Models/MessageViewModel.swift index bad4cb96e..69b28faff 100644 --- a/SessionMessagingKit/Shared Models/MessageViewModel.swift +++ b/SessionMessagingKit/Shared Models/MessageViewModel.swift @@ -656,7 +656,17 @@ public extension MessageViewModel { LEFT JOIN \(DisappearingMessagesConfiguration.self) ON \(disappearingMessagesConfig[.threadId]) = \(interaction[.threadId]) LEFT JOIN \(OpenGroup.self) ON \(openGroup[.threadId]) = \(interaction[.threadId]) LEFT JOIN \(Profile.self) ON \(profile[.id]) = \(interaction[.authorId]) - LEFT JOIN \(Quote.self) ON \(quote[.interactionId]) = \(interaction[.id]) + LEFT JOIN ( + SELECT \(quote[.interactionId]), + \(quote[.authorId]), + \(quote[.timestampMs]), + FROM \(Quote.self) + LEFT JOIN ( + SELECT \(interaction[.authorId]), + \(interaction[.timestampMs]), + \(interaction[.body]) + ) + ) AS \(ViewModel.quoteKey) ON \(quote[.interactionId]) = \(interaction[.id]) LEFT JOIN \(Attachment.self) AS \(ViewModel.quoteAttachmentKey) ON \(ViewModel.quoteAttachmentKey).\(attachmentIdColumnLiteral) = \(quote[.attachmentId]) LEFT JOIN \(LinkPreview.self) ON ( \(linkPreview[.url]) = \(interaction[.linkPreviewUrl]) AND From 8ba7f927d8a4eb6d97cec895556dad043673a3ae Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 11 Aug 2022 16:44:22 +1000 Subject: [PATCH 10/15] feat: deal with quoted text --- .../Conversations/Message Cells/VisibleMessageCell.swift | 2 +- SessionMessagingKit/Shared Models/MessageViewModel.swift | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index ccb099d8e..e3450b4ad 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -457,7 +457,7 @@ final class VisibleMessageCell: MessageCell, UITextViewDelegate, BodyTextViewDel let quoteView: QuoteView = QuoteView( for: .regular, authorId: quote.authorId, - quotedText: quote.body, + quotedText: quote.body ?? "QUOTED_MESSAGE_NOT_FOUND".localized(), threadVariant: cellViewModel.threadVariant, currentUserPublicKey: cellViewModel.currentUserPublicKey, currentUserBlindedPublicKey: cellViewModel.currentUserBlindedPublicKey, diff --git a/SessionMessagingKit/Shared Models/MessageViewModel.swift b/SessionMessagingKit/Shared Models/MessageViewModel.swift index 69b28faff..753c50078 100644 --- a/SessionMessagingKit/Shared Models/MessageViewModel.swift +++ b/SessionMessagingKit/Shared Models/MessageViewModel.swift @@ -660,11 +660,12 @@ public extension MessageViewModel { SELECT \(quote[.interactionId]), \(quote[.authorId]), \(quote[.timestampMs]), + \(interaction[.body]) AS \(Quote.Columns.body), + \(quote[.attachmentId]) FROM \(Quote.self) - LEFT JOIN ( - SELECT \(interaction[.authorId]), - \(interaction[.timestampMs]), - \(interaction[.body]) + LEFT JOIN \(Interaction.self) ON ( + \(quote[.authorId]) = \(interaction[.authorId]) AND + \(quote[.timestampMs]) = \(interaction[.timestampMs]) ) ) AS \(ViewModel.quoteKey) ON \(quote[.interactionId]) = \(interaction[.id]) LEFT JOIN \(Attachment.self) AS \(ViewModel.quoteAttachmentKey) ON \(ViewModel.quoteAttachmentKey).\(attachmentIdColumnLiteral) = \(quote[.attachmentId]) From 229e8376e5eccb9e036f0630df5b9c379c23d5e7 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 11 Aug 2022 17:15:56 +1000 Subject: [PATCH 11/15] WIP: observe quote update --- .../ConversationVC+Interaction.swift | 21 ------------------- .../Database/Models/Quote.swift | 15 ------------- 2 files changed, 36 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 27209404c..caef86415 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1077,13 +1077,6 @@ extension ConversationVC: .done { _ in // Delete the interaction (and associated data) from the database Storage.shared.writeAsync { db in - try Quote - .updateBeforeQuotedInterationDeletion( - db, - timestampMs: cellViewModel.timestampMs, - authorId: cellViewModel.authorId - ) - _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) @@ -1164,13 +1157,6 @@ extension ConversationVC: // For incoming interactions or interactions with no serverHash just delete them locally guard cellViewModel.variant == .standardOutgoing, let serverHash: String = serverHash else { Storage.shared.writeAsync { db in - try Quote - .updateBeforeQuotedInterationDeletion( - db, - timestampMs: cellViewModel.timestampMs, - authorId: cellViewModel.authorId - ) - _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) @@ -1194,13 +1180,6 @@ extension ConversationVC: let alertVC = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet) alertVC.addAction(UIAlertAction(title: "delete_message_for_me".localized(), style: .destructive) { [weak self] _ in Storage.shared.writeAsync { db in - try Quote - .updateBeforeQuotedInterationDeletion( - db, - timestampMs: cellViewModel.timestampMs, - authorId: cellViewModel.authorId - ) - _ = try Interaction .filter(id: cellViewModel.id) .deleteAll(db) diff --git a/SessionMessagingKit/Database/Models/Quote.swift b/SessionMessagingKit/Database/Models/Quote.swift index f24ae3e4f..af92ee454 100644 --- a/SessionMessagingKit/Database/Models/Quote.swift +++ b/SessionMessagingKit/Database/Models/Quote.swift @@ -76,21 +76,6 @@ public struct Quote: Codable, Equatable, Hashable, FetchableRecord, PersistableR } } -public extension Quote { - /// This method updates the all Quotes before the quoted interation is deleted - /// - static func updateBeforeQuotedInterationDeletion(_ db: Database, timestampMs: Int64, authorId: String) throws { - try Quote - .filter(Columns.authorId == authorId) - .filter(Columns.timestampMs == timestampMs) - .updateAll( - db, - Columns.body.set(to: "QUOTED_MESSAGE_NOT_FOUND".localized()), - Columns.attachmentId.set(to: nil) - ) - } -} - // MARK: - Protobuf public extension Quote { From 6565c3fe73b5dad9695d5ae20c5360045c3ec578 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 12 Aug 2022 11:46:28 +1000 Subject: [PATCH 12/15] feat: quotes refer to original attachments. --- SessionMessagingKit/Shared Models/MessageViewModel.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SessionMessagingKit/Shared Models/MessageViewModel.swift b/SessionMessagingKit/Shared Models/MessageViewModel.swift index 753c50078..367e645e8 100644 --- a/SessionMessagingKit/Shared Models/MessageViewModel.swift +++ b/SessionMessagingKit/Shared Models/MessageViewModel.swift @@ -584,6 +584,7 @@ public extension MessageViewModel { let disappearingMessagesConfig: TypedTableAlias = TypedTableAlias() let profile: TypedTableAlias = TypedTableAlias() let quote: TypedTableAlias = TypedTableAlias() + let interactionAttachment: TypedTableAlias = TypedTableAlias() let linkPreview: TypedTableAlias = TypedTableAlias() let threadProfileTableLiteral: SQL = SQL(stringLiteral: "threadProfile") @@ -661,12 +662,13 @@ public extension MessageViewModel { \(quote[.authorId]), \(quote[.timestampMs]), \(interaction[.body]) AS \(Quote.Columns.body), - \(quote[.attachmentId]) + \(interactionAttachment[.attachmentId]) AS \(Quote.Columns.attachmentId) FROM \(Quote.self) LEFT JOIN \(Interaction.self) ON ( \(quote[.authorId]) = \(interaction[.authorId]) AND \(quote[.timestampMs]) = \(interaction[.timestampMs]) ) + LEFT JOIN \(InteractionAttachment.self) ON \(interaction[.id]) = \(interactionAttachment[.interactionId]) ) AS \(ViewModel.quoteKey) ON \(quote[.interactionId]) = \(interaction[.id]) LEFT JOIN \(Attachment.self) AS \(ViewModel.quoteAttachmentKey) ON \(ViewModel.quoteAttachmentKey).\(attachmentIdColumnLiteral) = \(quote[.attachmentId]) LEFT JOIN \(LinkPreview.self) ON ( From 98c5c996fc57ac5a9af6346de7edbde1ad4f9274 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Tue, 11 Oct 2022 16:37:48 +1100 Subject: [PATCH 13/15] clean --- Session/Conversations/ConversationViewModel.swift | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Session/Conversations/ConversationViewModel.swift b/Session/Conversations/ConversationViewModel.swift index ed3e3b262..48a81fbd1 100644 --- a/Session/Conversations/ConversationViewModel.swift +++ b/Session/Conversations/ConversationViewModel.swift @@ -197,16 +197,6 @@ public class ConversationViewModel: OWSAudioPlayerDelegate { return SQL("LEFT JOIN \(Profile.self) ON \(profile[.id]) = \(interaction[.authorId])") }() - ), - PagedData.ObservedChanges( - table: Quote.self, - columns: [.body, .attachmentId], - joinToPagedType: { - let interaction: TypedTableAlias = TypedTableAlias() - let quote: TypedTableAlias = TypedTableAlias() - - return SQL("LEFT JOIN \(Quote.self) ON \(quote[.interactionId]) = \(interaction[.id])") - }() ) ], joinSQL: MessageViewModel.optimisedJoinSQL, From 7cbdca672edd190dfd0bce81d184f990807c53f2 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Wed, 9 Nov 2022 11:07:13 +1100 Subject: [PATCH 14/15] Fixed a bug where copying the open group url wasn't working correctly --- .../ConversationVC+Interaction.swift | 5 ++ .../Settings/ThreadSettingsViewModel.swift | 43 ++++++++++++--- .../Database/Models/OpenGroup.swift | 52 ++----------------- .../ConfigurationMessage+Convenience.swift | 8 ++- .../SessionThreadViewModel.swift | 9 ++++ .../Open Groups/Models/OpenGroupSpec.swift | 26 ++++++++++ 6 files changed, 86 insertions(+), 57 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index bb70bea7f..afd586d78 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1578,6 +1578,11 @@ extension ConversationVC: case .typingIndicator, .dateHeader: break case .textOnlyMessage: + if cellViewModel.body == nil, let linkPreview: LinkPreview = cellViewModel.linkPreview { + UIPasteboard.general.string = linkPreview.url + return + } + UIPasteboard.general.string = cellViewModel.body case .audio, .genericAttachment, .mediaMessage: diff --git a/Session/Conversations/Settings/ThreadSettingsViewModel.swift b/Session/Conversations/Settings/ThreadSettingsViewModel.swift index e771e26fb..fe23f06f8 100644 --- a/Session/Conversations/Settings/ThreadSettingsViewModel.swift +++ b/Session/Conversations/Settings/ThreadSettingsViewModel.swift @@ -241,7 +241,24 @@ class ThreadSettingsViewModel: SessionTableViewModel) { - let threadId: String = self.threadId + private func addUsersToOpenGoup(threadViewModel: SessionThreadViewModel, selectedUsers: Set) { + guard + let name: String = threadViewModel.openGroupName, + let server: String = threadViewModel.openGroupServer, + let roomToken: String = threadViewModel.openGroupRoomToken, + let publicKey: String = threadViewModel.openGroupPublicKey + else { return } dependencies.storage.writeAsync { db in - guard let openGroup: OpenGroup = try OpenGroup.fetchOne(db, id: threadId) else { return } - - let urlString: String = "\(openGroup.server)/\(openGroup.roomToken)?public_key=\(openGroup.publicKey)" + let urlString: String = OpenGroup.urlFor( + server: server, + roomToken: roomToken, + publicKey: publicKey + ) try selectedUsers.forEach { userId in let thread: SessionThread = try SessionThread.fetchOrCreate(db, id: userId, variant: .contact) @@ -575,7 +602,7 @@ class ThreadSettingsViewModel: SessionTableViewModel String { + return "\(server)/\(roomToken)?public_key=\(publicKey)" + } } extension OpenGroup: CustomStringConvertible, CustomDebugStringConvertible { @@ -243,51 +247,3 @@ extension OpenGroup: CustomStringConvertible, CustomDebugStringConvertible { ].joined(separator: ", ") } } - -// MARK: - Objective-C Support - -// TODO: Remove this when possible - -@objc(SMKOpenGroup) -public class SMKOpenGroup: NSObject { - @objc(inviteUsers:toOpenGroupFor:) - public static func invite(selectedUsers: Set, openGroupThreadId: String) { - Storage.shared.write { db in - guard let openGroup: OpenGroup = try OpenGroup.fetchOne(db, id: openGroupThreadId) else { return } - - let urlString: String = "\(openGroup.server)/\(openGroup.roomToken)?public_key=\(openGroup.publicKey)" - - try selectedUsers.forEach { userId in - let thread: SessionThread = try SessionThread.fetchOrCreate(db, id: userId, variant: .contact) - - try LinkPreview( - url: urlString, - variant: .openGroupInvitation, - title: openGroup.name - ) - .save(db) - - let interaction: Interaction = try Interaction( - threadId: thread.id, - authorId: userId, - variant: .standardOutgoing, - timestampMs: Int64(floor(Date().timeIntervalSince1970 * 1000)), - expiresInSeconds: try? DisappearingMessagesConfiguration - .select(.durationSeconds) - .filter(id: userId) - .filter(DisappearingMessagesConfiguration.Columns.isEnabled == true) - .asRequest(of: TimeInterval.self) - .fetchOne(db), - linkPreviewUrl: urlString - ) - .inserted(db) - - try MessageSender.send( - db, - interaction: interaction, - in: thread - ) - } - } - } -} diff --git a/SessionMessagingKit/Messages/Control Messages/ConfigurationMessage+Convenience.swift b/SessionMessagingKit/Messages/Control Messages/ConfigurationMessage+Convenience.swift index a2d7bf096..72289c200 100644 --- a/SessionMessagingKit/Messages/Control Messages/ConfigurationMessage+Convenience.swift +++ b/SessionMessagingKit/Messages/Control Messages/ConfigurationMessage+Convenience.swift @@ -42,7 +42,13 @@ extension ConfigurationMessage { .filter(OpenGroup.Columns.roomToken != "") .filter(OpenGroup.Columns.isActive) .fetchAll(db) - .map { "\($0.server)/\($0.roomToken)?public_key=\($0.publicKey)" } + .map { openGroup in + OpenGroup.urlFor( + server: openGroup.server, + roomToken: openGroup.roomToken, + publicKey: openGroup.publicKey + ) + } .asSet() let contacts: Set = try Contact .filter(Contact.Columns.id != currentUserProfile.id) diff --git a/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift b/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift index 2280a8542..616b7c15a 100644 --- a/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift +++ b/SessionMessagingKit/Shared Models/SessionThreadViewModel.swift @@ -43,6 +43,7 @@ public struct SessionThreadViewModel: FetchableRecordWithRowId, Decodable, Equat public static let openGroupNameKey: SQL = SQL(stringLiteral: CodingKeys.openGroupName.stringValue) public static let openGroupServerKey: SQL = SQL(stringLiteral: CodingKeys.openGroupServer.stringValue) public static let openGroupRoomTokenKey: SQL = SQL(stringLiteral: CodingKeys.openGroupRoomToken.stringValue) + public static let openGroupPublicKeyKey: SQL = SQL(stringLiteral: CodingKeys.openGroupPublicKey.stringValue) public static let openGroupProfilePictureDataKey: SQL = SQL(stringLiteral: CodingKeys.openGroupProfilePictureData.stringValue) public static let openGroupUserCountKey: SQL = SQL(stringLiteral: CodingKeys.openGroupUserCount.stringValue) public static let openGroupPermissionsKey: SQL = SQL(stringLiteral: CodingKeys.openGroupPermissions.stringValue) @@ -117,6 +118,7 @@ public struct SessionThreadViewModel: FetchableRecordWithRowId, Decodable, Equat public let openGroupName: String? public let openGroupServer: String? public let openGroupRoomToken: String? + public let openGroupPublicKey: String? public let openGroupProfilePictureData: Data? private let openGroupUserCount: Int? private let openGroupPermissions: OpenGroup.Permissions? @@ -274,6 +276,7 @@ public extension SessionThreadViewModel { self.openGroupName = nil self.openGroupServer = nil self.openGroupRoomToken = nil + self.openGroupPublicKey = nil self.openGroupProfilePictureData = nil self.openGroupUserCount = nil self.openGroupPermissions = nil @@ -334,6 +337,7 @@ public extension SessionThreadViewModel { openGroupName: self.openGroupName, openGroupServer: self.openGroupServer, openGroupRoomToken: self.openGroupRoomToken, + openGroupPublicKey: self.openGroupPublicKey, openGroupProfilePictureData: self.openGroupProfilePictureData, openGroupUserCount: self.openGroupUserCount, openGroupPermissions: self.openGroupPermissions, @@ -387,6 +391,7 @@ public extension SessionThreadViewModel { openGroupName: self.openGroupName, openGroupServer: self.openGroupServer, openGroupRoomToken: self.openGroupRoomToken, + openGroupPublicKey: self.openGroupPublicKey, openGroupProfilePictureData: self.openGroupProfilePictureData, openGroupUserCount: self.openGroupUserCount, openGroupPermissions: self.openGroupPermissions, @@ -753,6 +758,7 @@ public extension SessionThreadViewModel { \(openGroup[.name]) AS \(ViewModel.openGroupNameKey), \(openGroup[.server]) AS \(ViewModel.openGroupServerKey), \(openGroup[.roomToken]) AS \(ViewModel.openGroupRoomTokenKey), + \(openGroup[.publicKey]) AS \(ViewModel.openGroupPublicKeyKey), \(openGroup[.userCount]) AS \(ViewModel.openGroupUserCountKey), \(openGroup[.permissions]) AS \(ViewModel.openGroupPermissionsKey), @@ -847,6 +853,9 @@ public extension SessionThreadViewModel { \(closedGroup[.name]) AS \(ViewModel.closedGroupNameKey), (\(groupMember[.profileId]) IS NOT NULL) AS \(ViewModel.currentUserIsClosedGroupMemberKey), \(openGroup[.name]) AS \(ViewModel.openGroupNameKey), + \(openGroup[.server]) AS \(ViewModel.openGroupServerKey), + \(openGroup[.roomToken]) AS \(ViewModel.openGroupRoomTokenKey), + \(openGroup[.publicKey]) AS \(ViewModel.openGroupPublicKeyKey), \(openGroup[.imageData]) AS \(ViewModel.openGroupProfilePictureDataKey), \(SQL("\(userPublicKey)")) AS \(ViewModel.currentUserPublicKeyKey) diff --git a/SessionMessagingKitTests/Open Groups/Models/OpenGroupSpec.swift b/SessionMessagingKitTests/Open Groups/Models/OpenGroupSpec.swift index b6083b47a..5225a130a 100644 --- a/SessionMessagingKitTests/Open Groups/Models/OpenGroupSpec.swift +++ b/SessionMessagingKitTests/Open Groups/Models/OpenGroupSpec.swift @@ -79,6 +79,32 @@ class OpenGroupSpec: QuickSpec { .to(equal("OpenGroup(server: \"server\", roomToken: \"room\", id: \"server.room\", publicKey: \"1234\", isActive: true, name: \"name\", roomDescription: null, imageId: null, userCount: 0, infoUpdates: 0, sequenceNumber: 0, inboxLatestMessageId: 0, outboxLatestMessageId: 0, pollFailureCount: 0, permissions: ---)")) } } + + context("when generating an id") { + it("generates correctly") { + expect(OpenGroup.idFor(roomToken: "room", server: "server")).to(equal("server.room")) + } + + it("converts the server to lowercase") { + expect(OpenGroup.idFor(roomToken: "room", server: "SeRVeR")).to(equal("server.room")) + } + + it("maintains the casing of the roomToken") { + expect(OpenGroup.idFor(roomToken: "RoOM", server: "server")).to(equal("server.RoOM")) + } + } + + context("when generating a url") { + it("generates the url correctly") { + expect(OpenGroup.urlFor(server: "server", roomToken: "room", publicKey: "key")) + .to(equal("server/room?public_key=key")) + } + + it("maintains the casing provided") { + expect(OpenGroup.urlFor(server: "SeRVer", roomToken: "RoOM", publicKey: "KEy")) + .to(equal("SeRVer/RoOM?public_key=KEy")) + } + } } } } From e808f385e8bb0e0d1493d54bc549a00edd93eebd Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 10 Nov 2022 15:54:02 +1100 Subject: [PATCH 15/15] Fixed a crash which could occur in global search --- SessionUtilitiesKit/Database/Utilities/Database+Utilities.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SessionUtilitiesKit/Database/Utilities/Database+Utilities.swift b/SessionUtilitiesKit/Database/Utilities/Database+Utilities.swift index d736dfc35..b8e849c74 100644 --- a/SessionUtilitiesKit/Database/Utilities/Database+Utilities.swift +++ b/SessionUtilitiesKit/Database/Utilities/Database+Utilities.swift @@ -32,6 +32,8 @@ public extension Database { } func interrupt() { + guard sqliteConnection != nil else { return } + sqlite3_interrupt(sqliteConnection) } }