Dropping messages which shouldn't be processed without a thread

Removed an extra localised string value
This commit is contained in:
Morgan Pretty 2023-05-08 11:30:36 +10:00
parent a9afb2d1d1
commit 6685dc0572
7 changed files with 40 additions and 8 deletions

View File

@ -549,9 +549,10 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
if if
viewModel.threadData.threadIsNoteToSelf == false && viewModel.threadData.threadIsNoteToSelf == false &&
viewModel.threadData.threadShouldBeVisible == false && viewModel.threadData.threadShouldBeVisible == false &&
!SessionUtil.conversationVisibleInConfig( !SessionUtil.conversationInConfig(
threadId: threadId, threadId: threadId,
threadVariant: viewModel.threadData.threadVariant threadVariant: viewModel.threadData.threadVariant,
visibleOnly: true
) )
{ {
Storage.shared.writeAsync { db in Storage.shared.writeAsync { db in

View File

@ -407,7 +407,6 @@
"MESSAGE_REQUESTS_NOTIFICATION" = "شما درخواست پیام جدیدی دارید"; "MESSAGE_REQUESTS_NOTIFICATION" = "شما درخواست پیام جدیدی دارید";
"TXT_HIDE_TITLE" = "پنهان کردن"; "TXT_HIDE_TITLE" = "پنهان کردن";
"TXT_DELETE_ACCEPT" = "پذیرفتن"; "TXT_DELETE_ACCEPT" = "پذیرفتن";
"TXT_DECLINE_TITLE" = "رد کردن";
"TXT_BLOCK_USER_TITLE" = "مسدود کردن کاربر"; "TXT_BLOCK_USER_TITLE" = "مسدود کردن کاربر";
"ALERT_ERROR_TITLE" = "خطا"; "ALERT_ERROR_TITLE" = "خطا";
"modal_call_permission_request_title" = "دسترسی تلفن مورد نیاز است"; "modal_call_permission_request_title" = "دسترسی تلفن مورد نیاز است";

View File

@ -345,6 +345,8 @@ public class SessionCell: UITableViewCell {
titleTextField.textAlignment = (info.title?.textAlignment ?? .left) titleTextField.textAlignment = (info.title?.textAlignment ?? .left)
titleTextField.placeholder = info.title?.editingPlaceholder titleTextField.placeholder = info.title?.editingPlaceholder
titleTextField.isHidden = (info.title == nil) titleTextField.isHidden = (info.title == nil)
titleTextField.accessibilityIdentifier = info.accessibility?.identifier
titleTextField.accessibilityLabel = info.accessibility?.label
subtitleLabel.isUserInteractionEnabled = (info.subtitle?.interaction == .copy) subtitleLabel.isUserInteractionEnabled = (info.subtitle?.interaction == .copy)
subtitleLabel.font = info.subtitle?.font subtitleLabel.font = info.subtitle?.font
subtitleLabel.text = info.subtitle?.text subtitleLabel.text = info.subtitle?.text

View File

@ -163,6 +163,26 @@ public extension Message {
} }
} }
static func requiresExistingConversation(message: Message, threadVariant: SessionThread.Variant) -> Bool {
switch threadVariant {
case .contact, .community: return false
case .legacyGroup:
switch message {
case let controlMessage as ClosedGroupControlMessage:
switch controlMessage.kind {
case .new: return false
default: return true
}
default: return true
}
case .group:
return false
}
}
static func shouldSync(message: Message) -> Bool { static func shouldSync(message: Message) -> Bool {
switch message { switch message {
case is VisibleMessage: return true case is VisibleMessage: return true

View File

@ -20,13 +20,14 @@ public enum MessageReceiverError: LocalizedError {
case invalidGroupPublicKey case invalidGroupPublicKey
case noGroupKeyPair case noGroupKeyPair
case invalidSharedConfigMessageHandling case invalidSharedConfigMessageHandling
case requiredThreadNotInConfig
public var isRetryable: Bool { public var isRetryable: Bool {
switch self { switch self {
case .duplicateMessage, .duplicateMessageNewSnode, .duplicateControlMessage, case .duplicateMessage, .duplicateMessageNewSnode, .duplicateControlMessage,
.invalidMessage, .unknownMessage, .unknownEnvelopeType, .invalidSignature, .invalidMessage, .unknownMessage, .unknownEnvelopeType, .invalidSignature,
.noData, .senderBlocked, .noThread, .selfSend, .decryptionFailed, .noData, .senderBlocked, .noThread, .selfSend, .decryptionFailed,
.invalidSharedConfigMessageHandling: .invalidSharedConfigMessageHandling, .requiredThreadNotInConfig:
return false return false
default: return true default: return true
@ -54,7 +55,8 @@ public enum MessageReceiverError: LocalizedError {
case .invalidGroupPublicKey: return "Invalid group public key." case .invalidGroupPublicKey: return "Invalid group public key."
case .noGroupKeyPair: return "Missing group key pair." case .noGroupKeyPair: return "Missing group key pair."
case .invalidSharedConfigMessageHandling: return "Invalid handling of a shared config message" case .invalidSharedConfigMessageHandling: return "Invalid handling of a shared config message."
case .requiredThreadNotInConfig: return "Required thread not in config."
} }
} }
} }

View File

@ -185,6 +185,13 @@ public enum MessageReceiver {
associatedWithProto proto: SNProtoContent, associatedWithProto proto: SNProtoContent,
dependencies: SMKDependencies = SMKDependencies() dependencies: SMKDependencies = SMKDependencies()
) throws { ) throws {
// Check if the message requires an existing conversation (if it does and the conversation isn't in
// the config then the message will be dropped)
guard
!Message.requiresExistingConversation(message: message, threadVariant: threadVariant) ||
SessionUtil.conversationInConfig(threadId: threadId, threadVariant: threadVariant, visibleOnly: false)
else { throw MessageReceiverError.requiredThreadNotInConfig }
switch message { switch message {
case let message as ReadReceipt: case let message as ReadReceipt:
try MessageReceiver.handleReadReceipt( try MessageReceiver.handleReadReceipt(

View File

@ -298,9 +298,10 @@ internal extension SessionUtil {
// MARK: - External Outgoing Changes // MARK: - External Outgoing Changes
public extension SessionUtil { public extension SessionUtil {
static func conversationVisibleInConfig( static func conversationInConfig(
threadId: String, threadId: String,
threadVariant: SessionThread.Variant threadVariant: SessionThread.Variant,
visibleOnly: Bool
) -> Bool { ) -> Bool {
// FIXME: Remove this once `useSharedUtilForUserConfig` is permanent // FIXME: Remove this once `useSharedUtilForUserConfig` is permanent
guard SessionUtil.userConfigsEnabled else { return true } guard SessionUtil.userConfigsEnabled else { return true }
@ -327,7 +328,7 @@ public extension SessionUtil {
/// If the user opens a conversation with an existing contact but doesn't send them a message /// If the user opens a conversation with an existing contact but doesn't send them a message
/// then the one-to-one conversation should remain hidden so we want to delete the `SessionThread` /// then the one-to-one conversation should remain hidden so we want to delete the `SessionThread`
/// when leaving the conversation /// when leaving the conversation
return SessionUtil.shouldBeVisible(priority: contact.priority) return (!visibleOnly || SessionUtil.shouldBeVisible(priority: contact.priority))
case .community: case .community:
let maybeUrlInfo: OpenGroupUrlInfo? = Storage.shared let maybeUrlInfo: OpenGroupUrlInfo? = Storage.shared