From 6180b881724c04539905740bb24fe78aafa3523f Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 10 Dec 2021 15:37:08 -0800 Subject: [PATCH] port to new cwtch storage API --- lib/model.dart | 2 +- lib/models/profileservers.dart | 3 ++- lib/views/profileserversview.dart | 13 +++++++++++-- lib/views/remoteserverview.dart | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/model.dart b/lib/model.dart index 9435dc3f..82246ee0 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -292,7 +292,7 @@ class ProfileInfoState extends ChangeNotifier { List servers = jsonDecode(serversJson); this._servers.replace(servers.map((server) { // TODO Keys... - return RemoteServerInfoState(onion: server["onion"], description: server["description"], status: server["status"]); + return RemoteServerInfoState(onion: server["onion"], identifier: server["identifier"], description: server["description"], status: server["status"]); })); this._contacts.contacts.forEach((contact) { diff --git a/lib/models/profileservers.dart b/lib/models/profileservers.dart index cdf103f3..5f422538 100644 --- a/lib/models/profileservers.dart +++ b/lib/models/profileservers.dart @@ -67,11 +67,12 @@ class ProfileServerListState extends ChangeNotifier { class RemoteServerInfoState extends ChangeNotifier { final String onion; + final int identifier; String status; String description; List _groups = []; - RemoteServerInfoState({required this.onion, required this.description, required this.status}); + RemoteServerInfoState({required this.onion, required this.identifier, required this.description, required this.status}); void updateDescription(String newDescription) { this.description = newDescription; diff --git a/lib/views/profileserversview.dart b/lib/views/profileserversview.dart index 7822ff96..37337c54 100644 --- a/lib/views/profileserversview.dart +++ b/lib/views/profileserversview.dart @@ -118,8 +118,17 @@ class _ProfileServersView extends State { // Wait 500ms and hope the server is imported and add it's description in the UI and as an attribute Future.delayed(const Duration(milliseconds: 500), () { var profile = Provider.of(context); - profile.serverList.getServer(serverHandle)?.updateDescription(serverDesc); - Provider.of(context, listen: false).cwtch.SetContactAttribute(profile.onion, serverHandle, "local.server.description", serverDesc); + if (profile.serverList.getServer(serverHandle) != null) { + profile.serverList.getServer(serverHandle)?.updateDescription( + serverDesc); + + Provider + .of(context, listen: false) + .cwtch + .SetConversationAttribute(profile.onion, profile.serverList + .getServer(serverHandle) + !.identifier, "server.description", serverDesc); + } }); Navigator.of(context).pop(); }); diff --git a/lib/views/remoteserverview.dart b/lib/views/remoteserverview.dart index e194da05..bc940807 100644 --- a/lib/views/remoteserverview.dart +++ b/lib/views/remoteserverview.dart @@ -84,7 +84,7 @@ class _RemoteServerViewState extends State { labelText: AppLocalizations.of(context)!.fieldDescriptionLabel, icon: Icon(Icons.save), onPressed: () { - Provider.of(context, listen: false).cwtch.SetContactAttribute(profile.onion, serverInfoState.onion, "local.server.description", ctrlrDesc.text); + Provider.of(context, listen: false).cwtch.SetConversationAttribute(profile.onion, serverInfoState.identifier, "server.description", ctrlrDesc.text); serverInfoState.updateDescription(ctrlrDesc.text); }, ),