Add Hook into Add Contact Flow to better Gauge Intent
continuous-integration/drone/pr Build is passing Details

(This the future we can expand this, use this information to better guide people)
This commit is contained in:
Sarah Jamie Lewis 2022-04-12 12:14:47 -07:00
parent 987b80c92b
commit 0d1e7bb5a0
17 changed files with 139 additions and 62 deletions

View File

@ -1,6 +1,7 @@
{
"@@locale": "cy",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "da",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "de",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "el",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "en",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "es",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,8 +1,9 @@
{
"@@locale": "fr",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Activer la mise en forme de texte enrichi dans les messages affichés, par exemple **gras** et *italique*",
"formattingExperiment": "Mise en forme des messages",
"clickableLinksWarning": "L'ouverture de cette URL lancera une application en dehors de Cwtch et peut révéler des métadonnées ou compromettre la sécurité de Cwtch. N'ouvrez que les URLs de personnes en qui vous avez confiance. Êtes-vous sûr de vouloir continuer ?",
"clickableLinksCopy": "Copier l'URL",
"clickableLinkOpen": "Ouvrir l'URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "it",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "lb",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "no",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "pl",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "pt",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "ro",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -1,6 +1,7 @@
{
"@@locale": "ru",
"@@last_modified": "2022-04-06T22:31:33+02:00",
"@@last_modified": "2022-04-12T20:56:53+02:00",
"thisFeatureRequiresGroupExpermientsToBeEnabled": "This feature requires the Groups Experiment to be enabled in Settings",
"messageFormattingDescription": "Enable rich text formatting in displayed messages e.g. **bold** and *italic*",
"formattingExperiment": "Message Formatting",
"clickableLinkError": "Error encountered while attempting to open URL",

View File

@ -343,5 +343,4 @@ SOFTWARE.''');
See the License for the specific language governing permissions and
limitations under the License.
''');
}

View File

@ -21,6 +21,10 @@ import '../main.dart';
/// NOTE: This view makes use of the global Error Handler to receive events from the Cwtch Library (for validating
/// error states caused by incorrect import string or duplicate requests to add a specific contact)
class AddContactView extends StatefulWidget {
final newGroup;
const AddContactView({Key? key, this.newGroup}) : super(key: key);
@override
_AddContactViewState createState() => _AddContactViewState();
}
@ -52,9 +56,10 @@ class _AddContactViewState extends State<AddContactView> {
ctrlrOnion.text = Provider.of<ProfileInfoState>(context).onion;
/// We display a different number of tabs depending on the experiment setup
bool groupsEnabled = Provider.of<Settings>(context).isExperimentEnabled(TapirGroupsExperiment);
return Consumer<ErrorHandler>(builder: (context, globalErrorHandler, child) {
bool groupsEnabled = Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment);
return Consumer<ErrorHandler>(builder: (bcontext, globalErrorHandler, child) {
return DefaultTabController(
initialIndex: widget.newGroup && groupsEnabled ? 1 : 0,
length: groupsEnabled ? 2 : 1,
child: Column(children: [
(groupsEnabled ? getTabBarWithGroups() : getTabBarWithAddPeerOnly()),
@ -62,10 +67,10 @@ class _AddContactViewState extends State<AddContactView> {
child: TabBarView(
children: (groupsEnabled
? [
addPeerTab(),
addGroupTab(),
addPeerTab(bcontext),
addGroupTab(bcontext),
]
: [addPeerTab()]),
: [addPeerTab(bcontext)]),
)),
]));
});
@ -105,7 +110,7 @@ class _AddContactViewState extends State<AddContactView> {
/// The Add Peer Tab allows a peer to add a specific non-group peer to their contact lists
/// We also provide a convenient way to copy their onion.
Widget addPeerTab() {
Widget addPeerTab(bcontext) {
return Scrollbar(
child: SingleChildScrollView(
clipBehavior: Clip.antiAlias,
@ -152,18 +157,18 @@ class _AddContactViewState extends State<AddContactView> {
return null;
},
onChanged: (String importBundle) async {
var profileOnion = Provider.of<ProfileInfoState>(context, listen: false).onion;
Provider.of<FlwtchState>(context, listen: false).cwtch.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
var profileOnion = Provider.of<ProfileInfoState>(bcontext, listen: false).onion;
Provider.of<FlwtchState>(bcontext, listen: false).cwtch.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
Future.delayed(const Duration(milliseconds: 500), () {
if (globalErrorHandler.importBundleSuccess) {
// TODO: This isn't ideal, but because onChange can be fired during this future check
// and because the context can change after being popped we have this kind of double assertion...
// There is probably a better pattern to handle this...
if (AppLocalizations.of(context) != null) {
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + importBundle));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
Navigator.popUntil(context, (route) => route.settings.name == "conversations");
if (AppLocalizations.of(bcontext) != null) {
final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle));
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations");
}
}
});
@ -174,10 +179,10 @@ class _AddContactViewState extends State<AddContactView> {
}
/// TODO Add Group Pane
Widget addGroupTab() {
Widget addGroupTab(bcontext) {
// TODO We should replace with with a "Paste in Server Key Bundle"
if (Provider.of<ProfileInfoState>(context).serverList.servers.isEmpty) {
return Text(AppLocalizations.of(context)!.addServerFirst);
if (Provider.of<ProfileInfoState>(bcontext).serverList.servers.isEmpty) {
return Text(AppLocalizations.of(bcontext)!.addServerFirst);
}
return Scrollbar(
@ -205,11 +210,7 @@ class _AddContactViewState extends State<AddContactView> {
},
isExpanded: true, // magic property
value: server,
items: Provider.of<ProfileInfoState>(context)
.serverList
.servers
.where((serverInfo) => serverInfo.status == "Synced")
.map<DropdownMenuItem<String>>((RemoteServerInfoState serverInfo) {
items: Provider.of<ProfileInfoState>(bcontext).serverList.servers.map<DropdownMenuItem<String>>((RemoteServerInfoState serverInfo) {
return DropdownMenuItem<String>(
value: serverInfo.onion,
child: Text(
@ -221,13 +222,13 @@ class _AddContactViewState extends State<AddContactView> {
SizedBox(
height: 20,
),
CwtchLabel(label: AppLocalizations.of(context)!.groupNameLabel),
CwtchLabel(label: AppLocalizations.of(bcontext)!.groupNameLabel),
SizedBox(
height: 20,
),
CwtchTextField(
controller: ctrlrGroupName,
hintText: AppLocalizations.of(context)!.groupNameLabel,
hintText: AppLocalizations.of(bcontext)!.groupNameLabel,
onChanged: (newValue) {},
validator: (value) {},
),
@ -236,12 +237,12 @@ class _AddContactViewState extends State<AddContactView> {
),
ElevatedButton(
onPressed: () {
var profileOnion = Provider.of<ProfileInfoState>(context, listen: false).onion;
Provider.of<FlwtchState>(context, listen: false).cwtch.CreateGroup(profileOnion, server, ctrlrGroupName.text);
var profileOnion = Provider.of<ProfileInfoState>(bcontext, listen: false).onion;
Provider.of<FlwtchState>(bcontext, listen: false).cwtch.CreateGroup(profileOnion, server, ctrlrGroupName.text);
Future.delayed(const Duration(milliseconds: 500), () {
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + " " + ctrlrGroupName.text));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
Navigator.pop(context);
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
Navigator.pop(bcontext);
});
},
child: Text(AppLocalizations.of(context)!.createGroupBtn),
@ -249,20 +250,4 @@ class _AddContactViewState extends State<AddContactView> {
],
)))));
}
/// TODO Manage Servers Tab
Widget manageServersTab() {
final tiles = Provider.of<ProfileInfoState>(context).serverList.servers.map((RemoteServerInfoState server) {
return ChangeNotifierProvider<RemoteServerInfoState>.value(
value: server,
child: ListTile(
title: Text(server.onion),
));
});
final divided = ListTile.divideTiles(
context: context,
tiles: tiles,
).toList();
return ListView(children: divided);
}
}

View File

@ -128,7 +128,7 @@ class _ContactsViewState extends State<ContactsView> {
actions: getActions(context),
),
floatingActionButton: FloatingActionButton(
onPressed: _pushAddContact,
onPressed: _modalAddImportChoice,
tooltip: AppLocalizations.of(context)!.tooltipAddContact,
child: const Icon(CwtchIcons.person_add_alt_1_24px),
),
@ -204,14 +204,18 @@ class _ContactsViewState extends State<ContactsView> {
return RepaintBoundary(child: ListView(children: divided));
}
void _pushAddContact() {
void _pushAddContact(bool newGroup) {
// close modal
Navigator.popUntil(context, (route) => route.settings.name == "conversations");
// open add contact / create group pane
Navigator.of(context).push(MaterialPageRoute<void>(
builder: (BuildContext bcontext) {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context)),
],
child: AddContactView(),
child: AddContactView(newGroup: newGroup),
);
},
));
@ -228,4 +232,79 @@ class _ContactsViewState extends State<ContactsView> {
},
));
}
void _modalAddImportChoice() {
bool groupsEnabled = Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment);
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: RepaintBoundary(
child: Container(
height: 200, // bespoke value courtesy of the [TextField] docs
child: Center(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
Spacer(),
Expanded(
child: Tooltip(
message: AppLocalizations.of(context)!.tooltipAddContact,
child: ElevatedButton(
child: Text(AppLocalizations.of(context)!.addContact, semanticsLabel: AppLocalizations.of(context)!.addContact),
onPressed: () {
_pushAddContact(false);
},
))),
Spacer()
]),
SizedBox(
height: 20,
),
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
Spacer(),
Expanded(
child: Tooltip(
message: groupsEnabled ? AppLocalizations.of(context)!.addServerTooltip : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
child: ElevatedButton(
child: Text(AppLocalizations.of(context)!.addServerTitle, semanticsLabel: AppLocalizations.of(context)!.addServerTitle),
onPressed: groupsEnabled
? () {
_pushAddContact(false);
}
: null,
)),
),
Spacer()
]),
SizedBox(
height: 20,
),
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
Spacer(),
Expanded(
child: Tooltip(
message: groupsEnabled ? AppLocalizations.of(context)!.createGroupTitle : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
child: ElevatedButton(
child: Text(AppLocalizations.of(context)!.createGroupTitle, semanticsLabel: AppLocalizations.of(context)!.createGroupTitle),
onPressed: groupsEnabled
? () {
_pushAddContact(true);
}
: null,
))),
Spacer()
]),
],
))),
)));
});
}
}