fetch GSEs if needed before end group

This commit is contained in:
kate-signal 2026-03-31 15:13:59 -04:00 committed by GitHub
parent e3e41f5aec
commit 0b841b2328
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 31 deletions

View File

@ -654,8 +654,10 @@ class ConversationSettingsViewController: OWSTableViewController2, BadgeCollecti
showEndGroupConfirmation(title: nil, description: finalConfirmationDescription, action: {
Task { @MainActor in
do {
try await ModalActivityIndicatorViewController.presentAndPropagateResult(from: self) {
try await GroupManager.terminateGroup(groupModel: groupModelV2)
try await ModalActivityIndicatorViewController.presentAndPropagateResult(from: self) { [weak self] in
guard let self else { return }
guard let groupThread = thread as? TSGroupThread else { return }
try await GroupManager.terminateGroup(groupModel: groupModelV2, threadId: groupThread.sqliteRowId!)
}
self.reloadThreadAndUpdateContent()
} catch {

View File

@ -656,12 +656,40 @@ public class GroupManager: NSObject {
// MARK: - Group Terminate
public static func terminateGroup(groupModel: TSGroupModelV2) async throws {
public static func terminateGroup(groupModel: TSGroupModelV2, threadId: Int64) async throws {
try await refreshGroupSendEndorsementsIfNeeded(threadId: threadId, groupModel: groupModel)
try await updateGroupV2(groupModel: groupModel, description: "Terminate group") { groupChangeSet in
groupChangeSet.setShouldTerminateGroup()
}
}
static func refreshGroupSendEndorsementsIfNeeded(
threadId: TSGroupThread.RowId,
groupModel: TSGroupModelV2,
) async throws {
// If we're not a full member, we can't fetch credentials.
guard groupModel.groupMembership.isLocalUserFullMember else {
return
}
guard !groupModel.isTerminated else {
return
}
let groupSendEndorsementStore = DependenciesBridge.shared.groupSendEndorsementStore
let combinedEndorsement = SSKEnvironment.shared.databaseStorageRef.read { tx in
return try? groupSendEndorsementStore.fetchCombinedEndorsement(groupThreadId: threadId, tx: tx)
}
// If we have recent-ish credentials, we don't need to refresh.
guard GroupSendEndorsements.willExpireSoon(expirationDate: combinedEndorsement?.expiration) else {
return
}
let secretParams = try groupModel.secretParams()
let groupId = try secretParams.getPublicParams().getGroupIdentifier()
Logger.info("Refreshing GSEs before leaving \(groupId)")
// Otherwise, try to refresh the credentials to use them when leaving.
try await SSKEnvironment.shared.groupV2UpdatesRef.refreshGroup(secretParams: secretParams)
}
// MARK: - Removed from Group or Invite Revoked
public static func handleNotInGroup(groupId: GroupIdentifier) async {

View File

@ -68,7 +68,7 @@ private class LocalUserLeaveGroupJobRunner: JobRunner {
}
do {
try await refreshGroupSendEndorsementsIfNeeded(threadId: groupThread.sqliteRowId!, groupModel: groupModel)
try await GroupManager.refreshGroupSendEndorsementsIfNeeded(threadId: groupThread.sqliteRowId!, groupModel: groupModel)
} catch where !error.isNetworkFailureOrTimeout {
Logger.warn("Tried and failed to refresh credentials; continuing anyways because credentials aren't required; error: \(error)")
}
@ -92,33 +92,6 @@ private class LocalUserLeaveGroupJobRunner: JobRunner {
return sendPromises
}
private func refreshGroupSendEndorsementsIfNeeded(
threadId: TSGroupThread.RowId,
groupModel: TSGroupModelV2,
) async throws {
// If we're not a full member, we can't fetch credentials.
guard groupModel.groupMembership.isLocalUserFullMember else {
return
}
guard !groupModel.isTerminated else {
return
}
let groupSendEndorsementStore = DependenciesBridge.shared.groupSendEndorsementStore
let combinedEndorsement = SSKEnvironment.shared.databaseStorageRef.read { tx in
return try? groupSendEndorsementStore.fetchCombinedEndorsement(groupThreadId: threadId, tx: tx)
}
// If we have recent-ish credentials, we don't need to refresh.
guard GroupSendEndorsements.willExpireSoon(expirationDate: combinedEndorsement?.expiration) else {
return
}
let secretParams = try groupModel.secretParams()
let groupId = try secretParams.getPublicParams().getGroupIdentifier()
Logger.info("Refreshing GSEs before leaving \(groupId)")
// Otherwise, try to refresh the credentials to use them when leaving.
try await SSKEnvironment.shared.groupV2UpdatesRef.refreshGroup(secretParams: secretParams)
}
}
public class LocalUserLeaveGroupJobQueue {