Create and Leave Groups / Conversations Pane Cleanup
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
b35ddd145f
commit
0136795107
|
@ -178,6 +178,17 @@ class MainActivity: FlutterActivity() {
|
|||
val value = (call.argument("value") as? String) ?: "";
|
||||
Cwtch.setGroupAttribute(profile, groupHandle, key, value);
|
||||
}
|
||||
"CreateGroup" -> {
|
||||
val profile = (call.argument("ProfileOnion") as? String) ?: "";
|
||||
val server = (call.argument("server") as? String) ?: "";
|
||||
val groupName = (call.argument("groupname") as? String) ?: "";
|
||||
Cwtch.createGroup(profile, server, groupName);
|
||||
}
|
||||
"LeaveGroup" -> {
|
||||
val profile = (call.argument("ProfileOnion") as? String) ?: "";
|
||||
val groupHandle = (call.argument("groupHandle") as? String) ?: "";
|
||||
Cwtch.leaveGroup(profile, groupHandle);
|
||||
}
|
||||
"RejectInvite" -> {
|
||||
val profile = (call.argument("ProfileOnion") as? String) ?: "";
|
||||
val groupHandle = (call.argument("groupHandle") as? String) ?: "";
|
||||
|
|
|
@ -44,6 +44,11 @@ abstract class Cwtch {
|
|||
// ignore: non_constant_identifier_names
|
||||
void SendInvitation(String profile, String handle, String target);
|
||||
|
||||
// ignore: non_constant_identifier_names
|
||||
void CreateGroup(String profile, String server, String groupName);
|
||||
// ignore: non_constant_identifier_names
|
||||
void LeaveGroup(String profile, String groupID);
|
||||
|
||||
// ignore: non_constant_identifier_names
|
||||
void ImportBundle(String profile, String bundle);
|
||||
// ignore: non_constant_identifier_names
|
||||
|
|
|
@ -48,6 +48,16 @@ class CwtchNotifier {
|
|||
lastMessageTime: DateTime.now(), //show at the top of the contact list even if no messages yet
|
||||
));
|
||||
break;
|
||||
case "GroupCreated":
|
||||
if (profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"]) == null) {
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.add(ContactInfoState(data["ProfileOnion"], data["GroupID"],
|
||||
isInvitation: false, imagePath: data["PicturePath"], nickname: data["GroupName"], server: data["GroupServer"], isGroup: true, lastMessageTime: DateTime.now()));
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["GroupID"], DateTime.now());
|
||||
}
|
||||
break;
|
||||
case "DeleteGroup":
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.removeContact(data["GroupID"]);
|
||||
break;
|
||||
case "PeerStateChange":
|
||||
ContactInfoState? contact = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]);
|
||||
if (contact != null) {
|
||||
|
@ -144,7 +154,7 @@ class CwtchNotifier {
|
|||
if (data["Key"] == "public.name") {
|
||||
profileCN.getProfile(data["ProfileOnion"]).nickname = data["Data"];
|
||||
} else {
|
||||
print("unhandled set attribute event: $type");
|
||||
print("unhandled set attribute event: $type $data");
|
||||
}
|
||||
break;
|
||||
case "NetworkError":
|
||||
|
@ -186,9 +196,17 @@ class CwtchNotifier {
|
|||
});
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.resort();
|
||||
break;
|
||||
|
||||
case "SetGroupAttribute":
|
||||
if (data["Key"] == "local.name") {
|
||||
if (profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"]) != null) {
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["GroupID"])!.nickname = data["Data"];
|
||||
}
|
||||
} else {
|
||||
print("unhandled set group attribute event: $type $data");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
print("unhandled event: $type");
|
||||
print("unhandled event: $type $data");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -356,4 +356,26 @@ class CwtchFfi implements Cwtch {
|
|||
final u2 = groupHandle.toNativeUtf8();
|
||||
RejectInvite(u1, u1.length, u2, u2.length);
|
||||
}
|
||||
|
||||
@override
|
||||
void CreateGroup(String profileOnion, String server, String groupName) {
|
||||
var createGroup = library.lookup<NativeFunction<void_from_string_string_string_function>>("c_CreateGroup");
|
||||
// ignore: non_constant_identifier_names
|
||||
final CreateGroup = createGroup.asFunction<VoidFromStringStringStringFn>();
|
||||
final u1 = profileOnion.toNativeUtf8();
|
||||
final u2 = server.toNativeUtf8();
|
||||
final u3 = groupName.toNativeUtf8();
|
||||
CreateGroup(u1, u1.length, u2, u2.length, u3, u3.length);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: non_constant_identifier_names
|
||||
void LeaveGroup(String profileOnion, String groupHandle) {
|
||||
var leaveGroup = library.lookup<NativeFunction<string_string_to_void_function>>("c_LeaveGroup");
|
||||
// ignore: non_constant_identifier_names
|
||||
final RejectInvite = leaveGroup.asFunction<VoidFromStringStringFn>();
|
||||
final u1 = profileOnion.toNativeUtf8();
|
||||
final u2 = groupHandle.toNativeUtf8();
|
||||
RejectInvite(u1, u1.length, u2, u2.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,4 +172,15 @@ class CwtchGomobile implements Cwtch {
|
|||
void RejectInvite(String profileOnion, String groupHandle) {
|
||||
cwtchPlatform.invokeMethod("RejectInvite", {"ProfileOnion": profileOnion, "handle": groupHandle});
|
||||
}
|
||||
|
||||
@override
|
||||
void CreateGroup(String profileOnion, String server, String groupName) {
|
||||
cwtchPlatform.invokeMethod("CreateGroup", {"ProfileOnion": profileOnion, "server": server, "groupName": groupName});
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: non_constant_identifier_names
|
||||
void LeaveGroup(String profileOnion, String groupHandle) {
|
||||
cwtchPlatform.invokeMethod("LeaveGroup", {"ProfileOnion": profileOnion, "handle": groupHandle});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,6 +122,13 @@ class ContactListState extends ChangeNotifier {
|
|||
int idx = _contacts.indexWhere((element) => element.onion == onion);
|
||||
return idx >= 0 ? _contacts[idx] : null;
|
||||
}
|
||||
|
||||
void removeContact(String onion) {
|
||||
int idx = _contacts.indexWhere((element) => element.onion == onion);
|
||||
if (idx >= 0) {
|
||||
_contacts.removeAt(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileInfoState extends ChangeNotifier {
|
||||
|
|
|
@ -1383,6 +1383,7 @@ ThemeData mkThemeData(Settings opaque) {
|
|||
)),
|
||||
),
|
||||
),
|
||||
tabBarTheme: TabBarTheme(indicator: UnderlineTabIndicator(borderSide: BorderSide(color: opaque.current().defaultButtonActiveColor()))),
|
||||
dialogTheme: DialogTheme(
|
||||
backgroundColor: opaque.current().backgroundPaneColor(),
|
||||
titleTextStyle: TextStyle(color: opaque.current().mainTextColor()),
|
||||
|
|
|
@ -26,7 +26,6 @@ class AddContactView extends StatefulWidget {
|
|||
class _AddContactViewState extends State<AddContactView> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _createGroupFormKey = GlobalKey<FormState>();
|
||||
final _joinGroupFormKey = GlobalKey<FormState>();
|
||||
final ctrlrOnion = TextEditingController(text: "");
|
||||
final ctrlrContact = TextEditingController(text: "");
|
||||
final ctrlrGroupName = TextEditingController(text: "");
|
||||
|
@ -34,6 +33,11 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// if we haven't picked a server yet, pick the first one in the list...
|
||||
if (server.isEmpty) {
|
||||
server = Provider.of<ProfileInfoState>(context).serverList.servers.first.onion;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.titleManageContacts),
|
||||
|
@ -49,12 +53,17 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
bool groupsEnabled = Provider.of<Settings>(context).experimentsEnabled && Provider.of<Settings>(context).experiments[TapirGroupsExperiment]!;
|
||||
return Consumer<ErrorHandler>(builder: (context, globalErrorHandler, child) {
|
||||
return DefaultTabController(
|
||||
length: groupsEnabled ? 4 : 1,
|
||||
length: groupsEnabled ? 2 : 1,
|
||||
child: Column(children: [
|
||||
(groupsEnabled ? getTabBarWithGroups() : getTabBarWithAddPeerOnly()),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
children: (groupsEnabled ? [addPeerTab(), manageServersTab(), addGroupTab(), joinGroupTab()] : [addPeerTab()]),
|
||||
children: (groupsEnabled
|
||||
? [
|
||||
addPeerTab(),
|
||||
addGroupTab(),
|
||||
]
|
||||
: [addPeerTab()]),
|
||||
)),
|
||||
]));
|
||||
});
|
||||
|
@ -84,11 +93,10 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
tabs: [
|
||||
Tab(
|
||||
icon: Icon(Icons.person_add_rounded),
|
||||
text: AppLocalizations.of(context)!.addPeer,
|
||||
text: AppLocalizations.of(context)!.tooltipAddContact,
|
||||
),
|
||||
Tab(icon: Icon(Icons.backup), text: AppLocalizations.of(context)!.titleManageServers),
|
||||
//Tab(icon: Icon(Icons.backup), text: AppLocalizations.of(context)!.titleManageServers),
|
||||
Tab(icon: Icon(Icons.group), text: AppLocalizations.of(context)!.createGroup),
|
||||
Tab(icon: Icon(Icons.group_add), text: AppLocalizations.of(context)!.joinGroup),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -133,18 +141,13 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
} else if (globalErrorHandler.explicitAddContactSuccess) {}
|
||||
return null;
|
||||
},
|
||||
onChanged: (String peerAddr) async {
|
||||
onChanged: (String importBundle) async {
|
||||
var profileOnion = Provider.of<ProfileInfoState>(context, listen: false).onion;
|
||||
final setPeerAttribute = {
|
||||
"EventType": "AddContact",
|
||||
"Data": {"ImportString": peerAddr},
|
||||
};
|
||||
final setPeerAttributeJson = jsonEncode(setPeerAttribute);
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.SendProfileEvent(profileOnion, setPeerAttributeJson);
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.ImportBundle(profileOnion, importBundle);
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (globalErrorHandler.explicitAddContactSuccess) {
|
||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + peerAddr));
|
||||
if (globalErrorHandler.importBundleSuccess) {
|
||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + importBundle));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
@ -162,11 +165,6 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
return Text("You need to add a server before you can create a group.");
|
||||
}
|
||||
|
||||
// if we haven't picked a server yet, pick the first one in the list...
|
||||
if (server.isEmpty) {
|
||||
server = Provider.of<ProfileInfoState>(context).serverList.servers.first.onion;
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.all(30),
|
||||
padding: EdgeInsets.all(20),
|
||||
|
@ -182,14 +180,20 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
height: 20,
|
||||
),
|
||||
DropdownButton(
|
||||
onChanged: (newServer) {
|
||||
server = newServer.toString();
|
||||
onChanged: (String? newServer) {
|
||||
setState(() {
|
||||
server = newServer!;
|
||||
});
|
||||
},
|
||||
isExpanded: true, // magic property
|
||||
value: server,
|
||||
items: Provider.of<ProfileInfoState>(context).serverList.servers.map<DropdownMenuItem<String>>((ServerInfoState serverInfo) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: serverInfo.onion,
|
||||
child: Text(serverInfo.onion),
|
||||
child: Text(
|
||||
serverInfo.onion,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
SizedBox(
|
||||
|
@ -209,54 +213,21 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
height: 20,
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
var profileOnion = Provider.of<ProfileInfoState>(context, listen: false).onion;
|
||||
Provider.of<FlwtchState>(context, 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);
|
||||
});
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.createGroupBtn),
|
||||
),
|
||||
],
|
||||
)));
|
||||
}
|
||||
|
||||
/// TODO Join Group Pane
|
||||
Widget joinGroupTab() {
|
||||
return Container(
|
||||
margin: EdgeInsets.all(30),
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Form(
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
key: _joinGroupFormKey,
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
CwtchLabel(label: AppLocalizations.of(context)!.joinGroupTab),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
CwtchTextField(
|
||||
controller: ctrlrContact,
|
||||
validator: (value) {
|
||||
if (value == "") {
|
||||
return null;
|
||||
}
|
||||
if (globalErrorHandler.importBundleError) {
|
||||
return AppLocalizations.of(context)!.invalidImportString;
|
||||
} else if (globalErrorHandler.importBundleSuccess) {}
|
||||
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);
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (globalErrorHandler.importBundleSuccess) {
|
||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.successfullAddedContact + importBundle));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
},
|
||||
labelText: '',
|
||||
)
|
||||
])));
|
||||
}
|
||||
|
||||
/// TODO Manage Servers Tab
|
||||
Widget manageServersTab() {
|
||||
final tiles = Provider.of<ProfileInfoState>(context).serverList.servers.map((ServerInfoState server) {
|
||||
|
|
|
@ -129,6 +129,21 @@ class _GroupSettingsViewState extends State<GroupSettingsView> {
|
|||
),
|
||||
// TODO
|
||||
]),
|
||||
|
||||
Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.end, children: [
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Tooltip(
|
||||
message: AppLocalizations.of(context)!.rejectGroupBtn,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
showAlertDialog(context);
|
||||
},
|
||||
icon: Icon(Icons.delete),
|
||||
label: Text(AppLocalizations.of(context)!.deleteBtn),
|
||||
))
|
||||
])
|
||||
])))));
|
||||
});
|
||||
});
|
||||
|
@ -139,4 +154,44 @@ class _GroupSettingsViewState extends State<GroupSettingsView> {
|
|||
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedClipboardNotification));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
showAlertDialog(BuildContext context) {
|
||||
// set up the buttons
|
||||
Widget cancelButton = TextButton(
|
||||
child: Text("Cancel"),
|
||||
style: ButtonStyle(padding: MaterialStateProperty.all(EdgeInsets.all(20))),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // dismiss dialog
|
||||
},
|
||||
);
|
||||
Widget continueButton = TextButton(
|
||||
style: ButtonStyle(padding: MaterialStateProperty.all(EdgeInsets.all(20))),
|
||||
child: Text(AppLocalizations.of(context)!.deleteProfileConfirmBtn),
|
||||
onPressed: () {
|
||||
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
|
||||
var handle = Provider.of<ContactInfoState>(context, listen: false).onion;
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.LeaveGroup(profileOnion, handle);
|
||||
Future.delayed(Duration(milliseconds: 500), () {
|
||||
Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text(AppLocalizations.of(context)!.deleteProfileConfirmBtn),
|
||||
actions: [
|
||||
cancelButton,
|
||||
continueButton,
|
||||
],
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ class _ProfileRowState extends State<ProfileRow> {
|
|||
void _pushContactList(ProfileInfoState profile, bool includeDoublePane) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
settings: RouteSettings(name: "conversations"),
|
||||
builder: (BuildContext buildcontext) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
|
|
Loading…
Reference in New Issue