fetch GSEs if needed before end group
This commit is contained in:
parent
e3e41f5aec
commit
0b841b2328
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user