From 25203387c727ab152051f403415358f8fc1835fe Mon Sep 17 00:00:00 2001 From: erinn Date: Fri, 12 Mar 2021 04:31:21 -0800 Subject: [PATCH 1/3] contact rewiring, merging trunk --- lib/cwtch/cwtchNotifier.dart | 32 +++++++++- lib/cwtch/ffi.dart | 7 ++- lib/cwtch/gomobile.dart | 1 - lib/model.dart | 109 ++++++++++++++++++++++------------ lib/views/contactsview.dart | 28 +++------ lib/views/profilemgrview.dart | 4 +- lib/widgets/contactrow.dart | 3 +- lib/widgets/profilerow.dart | 2 +- 8 files changed, 121 insertions(+), 65 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index d61c1f1..ca72bed 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -12,10 +12,38 @@ class CwtchNotifier { void handleMessage(String type, dynamic data) { switch (type) { case "NewPeer": - profileCN.add(ProfileInfoState(onion: data["Identity"], nickname: data["name"], imagePath: data["picture"])); + profileCN.add(ProfileInfoState( + onion: data["Identity"], + nickname: data["name"], + imagePath: data["picture"], + contactsJson: data["ContactsJson"], + )); + break; + case "PeerCreated": + print("xx peercreated"); + profileCN.getProfile(data["ProfileOnion"]).contactList.add(ContactInfoState( + profileOnion: data["ProfileOnion"], + onion: data["RemotePeer"], + nickname: data["nick"], + status: data["status"], + )); + break; + case "PeerStateChange": + ContactInfoState contact = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]); + if (contact == null) { + print("PSC -> adding "+data["ProfileOnion"]+" :: " + data["RemotePeer"]); + profileCN.getProfile(data["ProfileOnion"]).contactList.add(ContactInfoState( + profileOnion: data["ProfileOnion"], + onion: data["RemotePeer"], + nickname: data["nick"], + status: data["ConnectionState"], + )); + } else { + contact.status = data["ConnectionState"]; + } break; default: - print("unhandled gomobile appbus event: ${type}"); + print("unhandled event: $type"); } } } diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 3f8dd1c..779c1cc 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -78,7 +78,12 @@ class CwtchFfi implements Cwtch { cwtchIsolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort); _receivePort.listen((message) { var env = jsonDecode(message); - cwtchNotifier.handleMessage(env["EventType"], env["Data"]); + if (env["EventType"] != null) {//check if env["EventType"] exists + cwtchNotifier.handleMessage(env["EventType"], env["Data"]); + } else {//if not, use env["profile"] + env["Event"]["Data"]["ProfileOnion"] = env["Profile"]; + cwtchNotifier.handleMessage(env["Event"]["EventType"], env["Event"]["Data"]); + } }); } diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index 729fef1..bcdc304 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -54,7 +54,6 @@ class CwtchGomobile implements Cwtch { Future _handleAppbusEvent(MethodCall call) async { final String json = call.arguments; var obj = jsonDecode(json); - cwtchNotifier.handleMessage(call.method, obj); } diff --git a/lib/model.dart b/lib/model.dart index aa5162a..c26a8ba 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -64,78 +64,105 @@ class ChatMessage { /////////////////// class ProfileListState extends ChangeNotifier { - List _onions = []; - int get num => _onions.length; + List _profiles = []; + int get num => _profiles.length; - void addAll(Iterable newOnions) { - _onions.addAll(newOnions); + void addAll(Iterable newProfiles) { + _profiles.addAll(newProfiles); notifyListeners(); } - void add(ProfileInfoState newOnion) { - print("ProfileListState: adding " + newOnion.onion +" and notifying"); - _onions.add(newOnion); + void add(ProfileInfoState newProfile) { + print("ProfileListState: adding " + newProfile.onion +" and notifying"); + _profiles.add(newProfile); notifyListeners(); } - List get onions => _onions.sublist(0);//todo: copy?? dont want caller able to bypass changenotifier + List get profiles => _profiles.sublist(0);//todo: copy?? dont want caller able to bypass changenotifier + + ProfileInfoState getProfile(String onion) { + int idx = _profiles.indexWhere((element) => element.onion == onion); + return idx >= 0 ? _profiles[idx] : null; + } } class ContactListState extends ChangeNotifier { - List _onions = []; - int get num => _onions.length; + List _contacts = []; + int get num => _contacts.length; - ContactListState(Cwtch cwtch, String profileOnion) { - cwtch.GetContacts(profileOnion).then((jsonStr) { - if (jsonStr == null) return; + // ContactListState(Cwtch cwtch, String profileOnion) { + // cwtch.GetContacts(profileOnion).then((jsonStr) { + // if (jsonStr == null) return; + // + // print("contacts: " + jsonStr); + // List contacts = jsonDecode(jsonStr); + // contacts.forEach((c) { + // add(ContactInfoState( + // profileOnion: profileOnion, + // onion: c["onion"], + // nickname: c["name"], + // isGroup: false, + // isInvitation: false, + // isBlocked: false, + // status: c["status"], + // imagePath: "", + // )); + // }); + // }); + // } - print("contacts: " + jsonStr); - List contacts = jsonDecode(jsonStr); - contacts.forEach((c) { - add(ContactInfoState( - profileOnion: profileOnion, - onion: c["onion"], - nickname: c["name"], - isGroup: false, - isInvitation: false, - isBlocked: false, - status: c["status"], - imagePath: "", - )); - }); - }); - } - - void addAll(Iterable newOnions) { - _onions.addAll(newOnions); + void addAll(Iterable newContacts) { + _contacts.addAll(newContacts); notifyListeners(); } - void add(ContactInfoState newOnion) { - _onions.add(newOnion); + void add(ContactInfoState newContact) { + _contacts.add(newContact); notifyListeners(); } void updateUnreadMessages(String forOnion, int newVal) { - _onions.sort((ContactInfoState a, ContactInfoState b) { return b.unreadMessages - a.unreadMessages; }); + _contacts.sort((ContactInfoState a, ContactInfoState b) { return b.unreadMessages - a.unreadMessages; }); // if(changed) { notifyListeners(); //} } - List get onions => _onions.sublist(0);//todo: copy?? dont want caller able to bypass changenotifier + List get contacts => _contacts.sublist(0);//todo: copy?? dont want caller able to bypass changenotifier + + ContactInfoState getContact(String onion) { + int idx = _contacts.indexWhere((element) => element.onion == onion); + return idx >= 0 ? _contacts[idx] : null; + } } class ProfileInfoState extends ChangeNotifier { + ContactListState _contacts = ContactListState(); final String onion; String _nickname = ""; String _imagePath = ""; int _unreadMessages = 0; - ProfileInfoState({this.onion, nickname = "", imagePath = "", unreadMessages = 0,}){ + ProfileInfoState({this.onion, nickname = "", imagePath = "", unreadMessages = 0, contactsJson = "",}){ this._nickname = nickname; this._imagePath = imagePath; this._unreadMessages = unreadMessages; + + if (contactsJson != null && contactsJson != "" && contactsJson != "null") { + print("decoding " + contactsJson); + List contacts = jsonDecode(contactsJson); + this._contacts.addAll( + contacts.map((contact){ + return ContactInfoState( + profileOnion: this.onion, + onion: contact["onion"], + nickname: contact["name"], + status: contact["status"], + imagePath: contact["picture"], + ); + }) + ); + } } String get nickname => this._nickname; @@ -156,6 +183,8 @@ class ProfileInfoState extends ChangeNotifier { notifyListeners(); } + ContactListState get contactList => this._contacts; + @override void dispose() { super.dispose(); @@ -206,6 +235,12 @@ class ContactInfoState extends ChangeNotifier { this._unreadMessages = newVal; notifyListeners(); } + + get imagePath => this._imagePath; + set imagePath(String newVal) { + this._imagePath = newVal; + notifyListeners(); + } } ///////////// diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 41c9706..c9fdf04 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -54,26 +54,16 @@ class _ContactsViewState extends State { } Widget _buildContactList() { - return StreamBuilder( - stream: Provider.of(context).appStatus.contactEvents(), - builder: (BuildContext context, AsyncSnapshot snapshot) { - final tiles = Provider.of(context).onions.map( - (ContactInfoState contact) { - return ChangeNotifierProvider( - create: (context) => contact, - builder: (context, child) => ContactRow(), - ); - }, - ); - - final divided = ListTile.divideTiles( - context: context, - tiles: tiles, - ).toList(); - + // return StreamBuilder( + // stream: Provider.of(context).appStatus.contactEvents(), + // builder: (BuildContext context, AsyncSnapshot snapshot) { + final tiles = Provider.of(context).contacts.map((ContactInfoState contact) { + return ChangeNotifierProvider.value(value: contact, child: ContactRow()); + }); + final divided = ListTile.divideTiles(context: context, tiles: tiles, ).toList(); return ListView(children: divided); - }, - ); + // }, + // ); } void _pushAddContact() { diff --git a/lib/views/profilemgrview.dart b/lib/views/profilemgrview.dart index 599cff2..e9e177f 100644 --- a/lib/views/profilemgrview.dart +++ b/lib/views/profilemgrview.dart @@ -44,7 +44,7 @@ class _ProfileMgrViewState extends State { } void _testChangingContactInfo() { - Provider.of(context, listen:false).onions.first.nickname = "yay!"; + Provider.of(context, listen:false).profiles.first.nickname = "yay!"; } void _pushGlobalSettings() { @@ -109,7 +109,7 @@ class _ProfileMgrViewState extends State { } Widget _buildProfileManager() { - final tiles = Provider.of(context).onions.map( + final tiles = Provider.of(context).profiles.map( (ProfileInfoState profile) { return ChangeNotifierProvider.value( value: profile, diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index 29fe637..d123bea 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -20,8 +20,7 @@ class _ContactRowState extends State { width: 60, height: 60, child: ClipOval( - child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage("assets/profiles/001-centaur.png"), width:50,height:50,))), - //child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage(contact.imagePath), width:50,height:50,))), + child: SizedBox(width:60, height:60, child:Container(color:Colors.white, width: 60, height: 60, child: Image(image: AssetImage("assets/"+contact.imagePath), width:50,height:50,))), ), ), trailing: contact.isInvitation != null && contact.isInvitation ? Column(children:[Icon(Icons.favorite, color: Opaque.current().mainTextColor()),Icon(Icons.delete, color: Opaque.current().mainTextColor())]) : Text("99+"),//(nb: Icons.create is a pencil and we use it for "edit", not create) diff --git a/lib/widgets/profilerow.dart b/lib/widgets/profilerow.dart index 5e83ec8..2c19ae1 100644 --- a/lib/widgets/profilerow.dart +++ b/lib/widgets/profilerow.dart @@ -59,7 +59,7 @@ class _ProfileRowState extends State { return MultiProvider( providers: [ ChangeNotifierProvider.value(value: profile), - ChangeNotifierProvider(create: (_) => ContactListState(Provider.of(buildcontext).cwtch, profile.onion),), + ChangeNotifierProvider.value(value: profile.contactList), ], builder: (context, widget) => includeDoublePane ? DoubleColumnView() : ContactsView(), ); From 98d0e5647551a25b52fc081be66720087ae0990b Mon Sep 17 00:00:00 2001 From: erinn Date: Tue, 16 Mar 2021 15:51:21 -0700 Subject: [PATCH 2/3] move profileeventenvelope unwrapping to lcg --- lib/cwtch/cwtchNotifier.dart | 2 +- lib/cwtch/ffi.dart | 7 +------ linux/flutter/generated_plugin_registrant.cc | 2 ++ linux/flutter/generated_plugin_registrant.h | 2 ++ pubspec.lock | 19 ++++++------------- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 778e9a6..aa4e0c5 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -38,7 +38,7 @@ class CwtchNotifier { break; case "PeerStateChange": ContactInfoState contact = profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]); - if (contact == null) { + if (contact == null) {//todo: stopgap, as lc-g is supposed to handle this print("PSC -> adding "+data["ProfileOnion"]+" :: " + data["RemotePeer"]); profileCN.getProfile(data["ProfileOnion"]).contactList.add(ContactInfoState( profileOnion: data["ProfileOnion"], diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 46c920a..2e677e8 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -100,12 +100,7 @@ class CwtchFfi implements Cwtch { await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort); _receivePort.listen((message) { var env = jsonDecode(message); - if (env["EventType"] != null) {//check if env["EventType"] exists - cwtchNotifier.handleMessage(env["EventType"], env["Data"]); - } else {//if not, use env["profile"] - env["Event"]["Data"]["ProfileOnion"] = env["Profile"]; - cwtchNotifier.handleMessage(env["Event"]["EventType"], env["Event"]["Data"]); - } + cwtchNotifier.handleMessage(env["EventType"], env["Data"]); }); } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index d38195a..e71a16d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #include "generated_plugin_registrant.h" diff --git a/linux/flutter/generated_plugin_registrant.h b/linux/flutter/generated_plugin_registrant.h index 9bf7478..e0f0a47 100644 --- a/linux/flutter/generated_plugin_registrant.h +++ b/linux/flutter/generated_plugin_registrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_ diff --git a/pubspec.lock b/pubspec.lock index 20f4452..fb63563 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -115,7 +115,7 @@ packages: name: flutter_lokalise url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.4" flutter_test: dependency: "direct dev" description: flutter @@ -132,7 +132,7 @@ packages: name: freezed_annotation url: "https://pub.dartlang.org" source: hosted - version: "0.7.1" + version: "0.12.0" http: dependency: transitive description: @@ -195,7 +195,7 @@ packages: name: nested url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "1.0.0" package_info_plus: dependency: "direct main" description: @@ -286,7 +286,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.10.0" + version: "1.11.0" platform: dependency: transitive description: @@ -355,13 +355,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" - string_unescape: - dependency: transitive - description: - name: string_unescape - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.1" term_glyph: dependency: transitive description: @@ -396,7 +389,7 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.4" xdg_directories: dependency: transitive description: @@ -412,5 +405,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.12.0-259.9.beta <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.20.0" From 1ad7a607cf3c16792187a3df2867118c4652f7ab Mon Sep 17 00:00:00 2001 From: erinn Date: Tue, 16 Mar 2021 15:55:08 -0700 Subject: [PATCH 3/3] m. removing commented code --- lib/model.dart | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/lib/model.dart b/lib/model.dart index 0824f49..5713c1c 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -95,27 +95,6 @@ class ContactListState extends ChangeNotifier { List _contacts = []; int get num => _contacts.length; - // ContactListState(Cwtch cwtch, String profileOnion) { - // cwtch.GetContacts(profileOnion).then((jsonStr) { - // if (jsonStr == null) return; - // - // print("contacts: " + jsonStr); - // List contacts = jsonDecode(jsonStr); - // contacts.forEach((c) { - // add(ContactInfoState( - // profileOnion: profileOnion, - // onion: c["onion"], - // nickname: c["name"], - // isGroup: false, - // isInvitation: false, - // isBlocked: false, - // status: c["status"], - // imagePath: "", - // )); - // }); - // }); - // } - void addAll(Iterable newContacts) { _contacts.addAll(newContacts); notifyListeners();