Simplify methods to populate missing UUIDs
We no longer need `isBlocking`, and we can always consider errors.
This commit is contained in:
parent
358c884bce
commit
72c4dcff51
@ -55,7 +55,7 @@ public extension DebugUIStress {
|
||||
for member in members {
|
||||
Logger.verbose("Candidate member: \(member)")
|
||||
}
|
||||
return GroupManager.tryToEnableGroupsV2(for: members, isBlocking: true, ignoreErrors: true)
|
||||
return GroupManager.tryToEnableGroupsV2(for: members)
|
||||
}.then { () -> Promise<TSGroupThread> in
|
||||
guard GroupManager.defaultGroupsVersion == .V2 else {
|
||||
throw OWSAssertionError("Groups v2 not enabled.")
|
||||
@ -118,7 +118,7 @@ public extension DebugUIStress {
|
||||
for member in membersToAdd {
|
||||
Logger.verbose("Candidate member: \(member)")
|
||||
}
|
||||
return GroupManager.tryToEnableGroupsV2(for: Array(membersToAdd), isBlocking: true, ignoreErrors: true)
|
||||
return GroupManager.tryToEnableGroupsV2(for: Array(membersToAdd))
|
||||
}.then { () -> Promise<TSGroupThread> in
|
||||
let uuidsToAdd: [UUID] = try {
|
||||
let validMembersToAdd: [SignalServiceAddress]
|
||||
|
||||
@ -162,7 +162,7 @@ extension BaseGroupMemberViewController: MemberViewDelegate {
|
||||
// Recipient already supports groups v2.
|
||||
return AnyPromise(Promise.value(()))
|
||||
}
|
||||
return AnyPromise(tryToEnableGroupsV2ForAddress(address, isBlocking: true, ignoreErrors: false))
|
||||
return AnyPromise(tryToEnableGroupsV2ForAddress(address))
|
||||
}
|
||||
|
||||
private func doesRecipientSupportGroupsV2(_ recipient: PickedRecipient) -> Bool {
|
||||
@ -173,8 +173,8 @@ extension BaseGroupMemberViewController: MemberViewDelegate {
|
||||
return GroupManager.doesUserSupportGroupsV2(address: address)
|
||||
}
|
||||
|
||||
func tryToEnableGroupsV2ForAddress(_ address: SignalServiceAddress, isBlocking: Bool, ignoreErrors: Bool) -> Promise<Void> {
|
||||
GroupManager.tryToEnableGroupsV2(for: [address], isBlocking: isBlocking, ignoreErrors: ignoreErrors)
|
||||
func tryToEnableGroupsV2ForAddress(_ address: SignalServiceAddress) -> Promise<Void> {
|
||||
GroupManager.tryToEnableGroupsV2(for: [address])
|
||||
}
|
||||
|
||||
public func memberViewNoUuidSubtitleForRecipient(_ recipient: PickedRecipient) -> String? {
|
||||
|
||||
@ -1194,49 +1194,22 @@ public class GroupManager: NSObject {
|
||||
|
||||
// MARK: - UUIDs
|
||||
|
||||
public static func tryToEnableGroupsV2(for addresses: [SignalServiceAddress],
|
||||
isBlocking: Bool,
|
||||
ignoreErrors: Bool) -> Promise<Void> {
|
||||
let promise = tryToEnableGroupsV2(for: addresses, isBlocking: isBlocking)
|
||||
if ignoreErrors {
|
||||
return promise.recover { error in
|
||||
Logger.warn("Error: \(error).")
|
||||
}
|
||||
} else {
|
||||
return promise
|
||||
}
|
||||
}
|
||||
|
||||
private static func tryToEnableGroupsV2(for addresses: [SignalServiceAddress],
|
||||
isBlocking: Bool) -> Promise<Void> {
|
||||
public static func tryToEnableGroupsV2(for addresses: [SignalServiceAddress]) -> Promise<Void> {
|
||||
return firstly { () -> Promise<Void> in
|
||||
for address in addresses {
|
||||
let phoneNumbersWithoutUuids = try addresses.compactMap { address -> String? in
|
||||
guard address.isValid else {
|
||||
throw OWSAssertionError("Invalid address: \(address).")
|
||||
}
|
||||
guard address.uuid == nil else {
|
||||
return nil
|
||||
}
|
||||
return address.phoneNumber
|
||||
}
|
||||
guard phoneNumbersWithoutUuids.count > 0 else {
|
||||
return Promise.value(())
|
||||
}
|
||||
return Promise.value(())
|
||||
}.then(on: .global()) { _ -> Promise<Void> in
|
||||
return self.tryToFillInMissingUuids(for: addresses, isBlocking: isBlocking)
|
||||
}
|
||||
}
|
||||
|
||||
public static func tryToFillInMissingUuids(for addresses: [SignalServiceAddress],
|
||||
isBlocking: Bool) -> Promise<Void> {
|
||||
|
||||
let phoneNumbersWithoutUuids = addresses.filter { $0.uuid == nil }.compactMap { $0.phoneNumber }
|
||||
guard phoneNumbersWithoutUuids.count > 0 else {
|
||||
return Promise.value(())
|
||||
}
|
||||
|
||||
if isBlocking {
|
||||
// Block on the outcome.
|
||||
let discoveryTask = ContactDiscoveryTask(phoneNumbers: Set(phoneNumbersWithoutUuids))
|
||||
return discoveryTask.perform(at: .userInitiated).asVoid()
|
||||
} else {
|
||||
// This will throttle, de-bounce, etc.
|
||||
self.bulkUUIDLookup.lookupUuids(phoneNumbers: phoneNumbersWithoutUuids)
|
||||
return Promise.value(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user