diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 5716366..aa4e0c5 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -23,13 +23,38 @@ class CwtchNotifier { profileCN.add(ProfileInfoState( onion: data["Identity"], nickname: data["name"], - imagePath: data["picture"])); + 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) {//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"], + onion: data["RemotePeer"], + nickname: data["nick"], + status: data["ConnectionState"], + )); + } else { + contact.status = data["ConnectionState"]; + } break; case "UpdateGlobalSettings": settings.handleUpdate(jsonDecode(data["Data"])); break; default: - print("unhandled gomobile appbus event: ${type}"); + print("unhandled event: $type"); } } } diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index a0b759e..b69fb4c 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -56,7 +56,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 4372a20..5713c1c 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -69,87 +69,84 @@ 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; - - 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; @@ -170,6 +167,8 @@ class ProfileInfoState extends ChangeNotifier { notifyListeners(); } + ContactListState get contactList => this._contacts; + @override void dispose() { super.dispose(); @@ -229,6 +228,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 d054489..58f60e2 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -14,27 +14,6 @@ class ContactsView extends StatefulWidget { } class _ContactsViewState extends State { - _ContactsViewState(); - // Map _contacts = new HashMap(); - - // @override - // void didChangeDependencies() { - // super.didChangeDependencies(); - // - // Provider.of(context).onions.forEach((contact) { - // _contacts.putIfAbsent(contact.onion, () => ContactModel(contact); - // }); - // .cwtch.GetContacts(widget.profile.onion).then((jsonContacts) { - // print("got contact: $jsonContacts"); - // setState(() { - // List contacts = jsonDecode(jsonContacts); - // contacts.forEach((onion) { - // _contacts.putIfAbsent(onion['onion'], () => ContactModel(onion: onion['onion'], nickname: onion['name'], status: onion['status'])); - // }); - // }); - // }); - // } - @override Widget build(BuildContext context) { return Scaffold( @@ -61,26 +40,11 @@ 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 ListView(children: divided); - }, - ); + 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 bc2363a..30f6b8b 100644 --- a/lib/views/profilemgrview.dart +++ b/lib/views/profilemgrview.dart @@ -50,7 +50,7 @@ class _ProfileMgrViewState extends State { } void _testChangingContactInfo() { - Provider.of(context, listen: false).notifyListeners(); + Provider.of(context, listen:false).profiles.first.nickname = "yay!"; } void _pushGlobalSettings() { @@ -116,7 +116,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 e5b28d1..3dbcb65 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -20,19 +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 diff --git a/lib/widgets/profilerow.dart b/lib/widgets/profilerow.dart index b6e2682..6130399 100644 --- a/lib/widgets/profilerow.dart +++ b/lib/widgets/profilerow.dart @@ -80,11 +80,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(), 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"