Added handling for "needs rekey" after the merge occurs

pull/941/head
Morgan Pretty 1 year ago
parent 476858401c
commit b22ec12989

@ -38,8 +38,6 @@ internal extension SessionUtil {
serverTimestampMs: Int64,
using dependencies: Dependencies
) throws {
typealias GroupData = (profileName: String, profilePictureUrl: String?, profilePictureKey: Data?)
guard config.needsDump(using: dependencies) else { return }
guard case .object(let conf) = config else { throw SessionUtilError.invalidConfigObject }

@ -14,11 +14,31 @@ public extension SessionUtil {
static var sizeSubaccountSignatureBytes: Int { 64 }
}
// MARK: - Group Info Handling
// MARK: - Group Keys Handling
internal extension SessionUtil {
/// `libSession` manages keys entirely so there is no need for a DB presence
static let columnsRelatedToGroupKeys: [ColumnExpression] = []
// MARK: - Incoming Changes
static func handleGroupKeysUpdate(
_ db: Database,
in config: Config?,
groupSessionId: SessionId,
using dependencies: Dependencies
) throws {
guard case .groupKeys(let conf, _, _) = config else { throw SessionUtilError.invalidConfigObject }
/// If two admins rekeyed for different member changes at the same time then there is a "key collision" and the "needs rekey" function
/// will return true to indicate that a 3rd `rekey` needs to be made to have a final set of keys which includes all members
///
/// **Note:** We don't check `needsDump` in this case because the local state _could_ be persisted yet still require a `rekey`
/// so we should rely solely on `groups_keys_needs_rekey`
guard groups_keys_needs_rekey(conf) else { return }
try rekey(db, groupSessionId: groupSessionId, using: dependencies)
}
}
// MARK: - Outgoing Changes

@ -12,7 +12,7 @@ public extension SessionUtil {
static var sizeMaxGroupMemberCount: Int { 100 }
}
// MARK: - Group Info Handling
// MARK: - Group Members Handling
internal extension SessionUtil {
static let columnsRelatedToGroupMembers: [ColumnExpression] = [

@ -481,7 +481,14 @@ public enum SessionUtil {
using: dependencies
)
case .groupKeys: break // No custom handling needed (libSession manages everything)
case .groupKeys:
try SessionUtil.handleGroupKeysUpdate(
db,
in: config,
groupSessionId: sessionId,
using: dependencies
)
case .invalid: SNLog("[libSession] Failed to process merge of invalid config namespace")
}

Loading…
Cancel
Save