From 4db7dd5ca34dbf48022b101e60c6dc00ca3a59ea Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 27 Jul 2020 16:32:35 -0300 Subject: [PATCH] Refine scaffolding for testing gv2. --- .../AppSettings/AboutTableViewController.m | 9 +++++++++ .../AppSettings/TestingViewController.swift | 15 +++++++++++++++ .../ViewControllers/DebugUI/DebugUIGroupsV2.swift | 3 +++ ...onversationSettingsViewController+Header.swift | 9 ++++----- SignalServiceKit/src/Util/FeatureFlags.swift | 14 ++++++++++++++ .../src/groups/TSGroupModelBuilder.swift | 4 ++++ 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/AboutTableViewController.m b/Signal/src/ViewControllers/AppSettings/AboutTableViewController.m index 98ab7f36c9..4abb102360 100644 --- a/Signal/src/ViewControllers/AppSettings/AboutTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AboutTableViewController.m @@ -27,6 +27,11 @@ return SSKEnvironment.shared.tsAccountManager; } +- (OWSProfileManager *)profileManager +{ + return [OWSProfileManager sharedManager]; +} + #pragma mark - - (void)dealloc @@ -227,6 +232,10 @@ withString:@""]; [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Audio Category: %@", audioCategory]]]; + + NSData *localProfileKey = [self.profileManager localProfileKey].keyData; + [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Local Profile Key: %@", + localProfileKey.hexadecimalString]]]; } - (void)addGroupsV2memberStatusIndicators:(OWSTableContents *)contents diff --git a/Signal/src/ViewControllers/AppSettings/TestingViewController.swift b/Signal/src/ViewControllers/AppSettings/TestingViewController.swift index 25152f2bc4..56df3f2d65 100644 --- a/Signal/src/ViewControllers/AppSettings/TestingViewController.swift +++ b/Signal/src/ViewControllers/AppSettings/TestingViewController.swift @@ -56,6 +56,16 @@ class TestingViewController: OWSTableViewController { contents.addSection(section) } + do { + let section = OWSTableSection() + section.footerTitle = LocalizationNotNeeded("Client will not try to create v2 groups.") + section.add(OWSTableItem.switch(withText: LocalizationNotNeeded("Groups v2: Only create v1 groups"), + isOn: { DebugFlags.groupsV2onlyCreateV1Groups }, + target: self, + selector: #selector(didToggleGroupsV2onlyCreateV1Groups))) + contents.addSection(section) + } + self.contents = contents } @@ -73,4 +83,9 @@ class TestingViewController: OWSTableViewController { func didToggleGroupsV2corruptInvites(_ sender: UISwitch) { DebugFlags.groupsV2corruptInvites = sender.isOn } + + @objc + func didToggleGroupsV2onlyCreateV1Groups(_ sender: UISwitch) { + DebugFlags.groupsV2onlyCreateV1Groups = sender.isOn + } } diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIGroupsV2.swift b/Signal/src/ViewControllers/DebugUI/DebugUIGroupsV2.swift index 1fea812158..3339e98476 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIGroupsV2.swift +++ b/Signal/src/ViewControllers/DebugUI/DebugUIGroupsV2.swift @@ -149,6 +149,9 @@ class DebugUIGroupsV2: DebugUIPage { // V2 group members must have a uuid. allAddresses = allAddresses.filter { $0.uuid != nil } } + guard allAddresses.count >= 3 else { + return owsFailDebug("Not enough Signal users in your contacts.") + } let updaterAddress: SignalServiceAddress? if isAnonymousUpdate { updaterAddress = nil diff --git a/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController+Header.swift b/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController+Header.swift index 9f9bc9646f..27e0161008 100644 --- a/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController+Header.swift +++ b/Signal/src/ViewControllers/ThreadSettings/ConversationSettingsViewController+Header.swift @@ -255,12 +255,11 @@ extension ConversationSettingsViewController { // This will not appear in public builds. if DebugFlags.showProfileKeyAndUuidsIndicator { - let hasProfileKey = self.databaseStorage.uiRead { transaction in - self.profileManager.profileKeyData(for: recipientAddress, transaction: transaction) != nil + let profileKey = self.databaseStorage.uiRead { transaction in + self.profileManager.profileKeyData(for: recipientAddress, transaction: transaction) } - - let subtitle = "Has Profile Key: \(hasProfileKey)" - builder.addSubtitleLabel(attributedText: subtitle.asAttributedString) + let text = String(format: "Profile Key: %@", profileKey?.hexadecimalString ?? "Unknown") + builder.addSubtitleLabel(attributedText: text.asAttributedString) } builder.addLastSubviews() diff --git a/SignalServiceKit/src/Util/FeatureFlags.swift b/SignalServiceKit/src/Util/FeatureFlags.swift index 0d6c1130c0..c911c526ad 100644 --- a/SignalServiceKit/src/Util/FeatureFlags.swift +++ b/SignalServiceKit/src/Util/FeatureFlags.swift @@ -325,6 +325,20 @@ public class DebugFlags: BaseFlags { } } + private static let _groupsV2onlyCreateV1Groups = AtomicBool(false) + @objc + public static var groupsV2onlyCreateV1Groups: Bool { + get { + guard build.includes(.qa) else { + return false + } + return _groupsV2onlyCreateV1Groups.get() + } + set { + _groupsV2onlyCreateV1Groups.set(newValue) + } + } + @objc public static let groupsV2ignoreCorruptInvites = false diff --git a/SignalServiceKit/src/groups/TSGroupModelBuilder.swift b/SignalServiceKit/src/groups/TSGroupModelBuilder.swift index 5054bfacb6..222b53d2ef 100644 --- a/SignalServiceKit/src/groups/TSGroupModelBuilder.swift +++ b/SignalServiceKit/src/groups/TSGroupModelBuilder.swift @@ -152,6 +152,10 @@ public struct TSGroupModelBuilder { Logger.info("Creating v1 group due to feature flags.") return .V1 } + if DebugFlags.groupsV2onlyCreateV1Groups { + Logger.info("Creating v1 group due to debug flag.") + return .V1 + } let canUseV2 = GroupManager.canUseV2(for: members, transaction: transaction) if canUseV2 { Logger.info("Creating v2 group.")