Merge branch 'feature/updated-user-config-handling' of https://github.com/mpretty-cyro/session-ios into disappearing-message-redesign

pull/941/head
ryanzhao 1 year ago
commit 5b9944d668

@ -188,7 +188,7 @@ final class NukeDataModal: Modal {
.subscribe(on: DispatchQueue.global(qos: .default))
.flatMap { results in
SnodeAPI
.deleteAllMessages()
.deleteAllMessages(namespace: .all)
.map { results.reduce($0) { result, next in result.updated(with: next) } }
.eraseToAnyPublisher()
}

@ -166,6 +166,7 @@ enum _013_SessionUtilChanges: Migration {
.notNull()
t.column(.timestampMs, .integer)
.notNull()
.defaults(to: 0)
t.primaryKey([.variant, .publicKey])
}

@ -78,8 +78,11 @@ extension MessageReceiver {
changeTimestampMs: Int64(sentTimestamp)
)
else {
// If the closed group already exists then store the encryption keys (just in case - there can be
// some weird edge-cases where we don't have keys we need if we don't store them)
// If the closed group already exists then store the encryption keys (since the config only stores
// the latest key we won't be able to decrypt older messages if we were added to the group within
// the last two weeks and the key has been rotated - unfortunately if the user was added more than
// two weeks ago and the keys were rotated within the last two weeks then we won't be able to decrypt
// messages received before the key rotation)
let groupPublicKey: String = publicKeyAsData.toHexString()
let receivedTimestamp: TimeInterval = (TimeInterval(SnodeAPI.currentOffsetTimestampMs()) / 1000)
let newKeyPair: ClosedGroupKeyPair = ClosedGroupKeyPair(

@ -3,6 +3,7 @@
import UIKit
import GRDB
import SessionUIKit
import SessionSnodeKit
import SessionUtil
import SessionUtilitiesKit
@ -72,7 +73,7 @@ internal extension SessionUtil {
conf: conf,
for: variant,
publicKey: publicKey,
timestampMs: Int64(Date().timeIntervalSince1970 * 1000)
timestampMs: SnodeAPI.currentOffsetTimestampMs()
)?.save(db)
return config_needs_push(conf)
@ -342,21 +343,30 @@ public extension SessionUtil {
// FIXME: Remove this once `useSharedUtilForUserConfig` is permanent
guard SessionUtil.userConfigsEnabled(db) else { return true }
let userPublicKey: String = getUserHexEncodedPublicKey()
let configVariant: ConfigDump.Variant = {
switch threadVariant {
case .contact: return .contacts
case .contact: return (threadId == userPublicKey ? .userProfile : .contacts)
case .legacyGroup, .group, .community: return .userGroups
}
}()
return SessionUtil
.config(for: configVariant, publicKey: getUserHexEncodedPublicKey())
.config(for: configVariant, publicKey: userPublicKey)
.wrappedValue
.map { conf in
var cThreadId: [CChar] = threadId.cArray.nullTerminated()
switch threadVariant {
case .contact:
// The 'Note to Self' conversation is stored in the 'userProfile' config
guard threadId != userPublicKey else {
return (
!visibleOnly ||
SessionUtil.shouldBeVisible(priority: user_profile_get_nts_priority(conf))
)
}
var contact: contacts_contact = contacts_contact()
guard contacts_get(conf, &contact, &cThreadId) else { return false }

@ -13,12 +13,12 @@ extension SnodeAPI {
///
/// **Note:** If omitted when sending the request, messages are deleted from the default namespace
/// only (namespace 0)
let namespace: SnodeAPI.Namespace?
let namespace: SnodeAPI.Namespace
// MARK: - Init
public init(
namespace: SnodeAPI.Namespace?,
namespace: SnodeAPI.Namespace,
pubkey: String,
timestampMs: UInt64,
ed25519PublicKey: [UInt8],
@ -39,11 +39,10 @@ extension SnodeAPI {
override public func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
// If no namespace is specified it defaults to the default namespace only (namespace
// 0), so instead in this case we want to explicitly delete from `all` namespaces
// The 'all' namespace should be sent through as `all` instead of a numerical value
switch namespace {
case .some(let namespace): try container.encode(namespace, forKey: .namespace)
case .none: try container.encode("all", forKey: .namespace)
case .all: try container.encode(namespace.verificationString, forKey: .namespace)
default: try container.encode(namespace, forKey: .namespace)
}
try super.encode(to: encoder)
@ -58,12 +57,7 @@ extension SnodeAPI {
/// The signature must be signed by the ed25519 pubkey in `pubkey` (omitting the leading prefix).
/// Must be base64 encoded for json requests; binary for OMQ requests.
let verificationBytes: [UInt8] = SnodeAPI.Endpoint.deleteAll.rawValue.bytes
.appending(
contentsOf: (namespace == nil ?
"all" :
namespace?.verificationString
)?.bytes
)
.appending(contentsOf: namespace.verificationString.bytes)
.appending(contentsOf: timestampMs.map { "\($0)" }?.data(using: .ascii)?.bytes)
guard

@ -939,7 +939,7 @@ public final class SnodeAPI {
/// Clears all the user's data from their swarm. Returns a dictionary of snode public key to deletion confirmation.
public static func deleteAllMessages(
namespace: SnodeAPI.Namespace? = nil,
namespace: SnodeAPI.Namespace,
using dependencies: SSKDependencies = SSKDependencies()
) -> AnyPublisher<[String: Bool], Error> {
guard let userED25519KeyPair = Identity.fetchUserEd25519KeyPair() else {
@ -987,7 +987,7 @@ public final class SnodeAPI {
/// Clears all the user's data from their swarm. Returns a dictionary of snode public key to deletion confirmation.
public static func deleteAllMessages(
beforeMs: UInt64,
namespace: SnodeAPI.Namespace? = nil,
namespace: SnodeAPI.Namespace,
using dependencies: SSKDependencies = SSKDependencies()
) -> AnyPublisher<[String: Bool], Error> {
guard let userED25519KeyPair = Identity.fetchUserEd25519KeyPair() else {

@ -14,6 +14,8 @@ public extension SnodeAPI {
case legacyClosedGroup = -10
case all = -9999990
// MARK: Variables
var requiresReadAuthentication: Bool {
@ -50,7 +52,7 @@ public extension SnodeAPI {
case .configUserProfile, .configContacts,
.configConvoInfoVolatile, .configUserGroups,
.configClosedGroupInfo:
.configClosedGroupInfo, .all:
return false
}
}
@ -58,6 +60,7 @@ public extension SnodeAPI {
var verificationString: String {
switch self {
case .`default`: return ""
case .all: return "all"
default: return "\(self.rawValue)"
}
}
@ -85,7 +88,7 @@ public extension SnodeAPI {
case .configUserProfile, .configContacts,
.configConvoInfoVolatile, .configUserGroups,
.configClosedGroupInfo:
.configClosedGroupInfo, .all:
return 1
}
}

Loading…
Cancel
Save