Fix ConfigureConnections on Android, Expose PublishServerUpdate

This commit is contained in:
Sarah Jamie Lewis 2023-09-26 12:50:02 -07:00 committed by Gitea
parent f8ab1650c9
commit 92a42bb2f8
8 changed files with 47 additions and 6 deletions

View File

@ -93,7 +93,6 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
try {
val evt = MainActivity.AppbusEvent(Cwtch.getAppBusEvent())
// TODO replace this notification block with the NixNotification manager in dart as it has access to contact names and also needs less working around
if (evt.EventType == "NewMessageFromPeer" || evt.EventType == "NewMessageFromGroup") {
val data = JSONObject(evt.Data)
val handle = data.getString("RemotePeer");

View File

@ -255,6 +255,7 @@ class MainActivity: FlutterActivity() {
// the frontend calls Start every time it fires up, but we don't want to *actually* call Cwtch.Start()
// in case the ForegroundService is still running. in both cases, however, we *do* want to re-register
// the eventbus listener.
when (call.method) {
"Start" -> {
val uniqueTag = argmap["torPath"] ?: "nullEventBus"
@ -384,7 +385,11 @@ class MainActivity: FlutterActivity() {
result.success(Cwtch.deleteServerInfo(profile, handle))
return
}
"PublishServerUpdate" -> {
val profile: String = call.argument("ProfileOnion") ?: ""
result.success(Cwtch.publishServerUpdate(profile))
return
}
"PeerWithOnion" -> {
val profile: String = call.argument("ProfileOnion") ?: ""
val onion: String = call.argument("onion") ?: ""
@ -420,7 +425,7 @@ class MainActivity: FlutterActivity() {
Cwtch.activatePeerEngine(profile)
}
"ConfigureConnections" -> {
val profile: String = call.argument("profile") ?: ""
val profile: String = call.argument("ProfileOnion") ?: ""
val listen: Boolean = call.argument("listen") ?: false
val peers: Boolean = call.argument("peers") ?: false
val servers: Boolean = call.argument("servers") ?: false

View File

@ -154,6 +154,6 @@ abstract class Cwtch {
// ignore: non_constant_identifier_names
Future<String> SearchConversations(String profile, String pattern);
void DeleteServerInfo(String profile, String handle);
void PublishServerUpdate(String onion);
Future<void> ConfigureConnections(String onion, bool listen, bool peers, bool servers);
}

View File

@ -375,8 +375,13 @@ class CwtchNotifier {
status: status,
isGroup: true,
lastMessageTime: DateTime.now()));
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(identifier, DateTime.fromMillisecondsSinceEpoch(0));
}
// request a new server update...
// NOTE: In the future this should also update the TokenManagerInfo
// This is not currently communicated by ServerUpdateInfo (but it probably should be)git
flwtchState.cwtch.PublishServerUpdate(data["ProfileOnion"]);
}
break;
case "ServerStateChange":

View File

@ -1111,4 +1111,14 @@ class CwtchFfi implements Cwtch {
malloc.free(utf8profile);
return;
}
@override
void PublishServerUpdate(String profile) {
var publishServerUpdate = library.lookup<NativeFunction<string_to_void_function>>("c_PublishServerUpdate");
// ignore: non_constant_identifier_names
final PublishServerUpdate = publishServerUpdate.asFunction<StringFn>();
final utf8profile = profile.toNativeUtf8();
PublishServerUpdate(utf8profile, utf8profile.length);
malloc.free(utf8profile);
}
}

View File

@ -464,4 +464,10 @@ class CwtchGomobile implements Cwtch {
cwtchPlatform.invokeMethod("ConfigureConnections", {"ProfileOnion": profile, "listen": listen, "peers": peers, "servers": servers});
return;
}
@override
void PublishServerUpdate(String profile) {
cwtchPlatform.invokeMethod("PublishServerUpdate", {"ProfileOnion": profile});
}
}

View File

@ -1,3 +1,4 @@
import 'package:cwtch/config.dart';
import 'package:flutter/widgets.dart';
import 'contact.dart';
@ -40,6 +41,21 @@ class ContactListState extends ChangeNotifier {
void add(ContactInfoState newContact) {
_contacts.add(newContact);
if (newContact.isGroup) {
// Copy the current known antispam value for the server
// to the new contact. This lets us send messages straight away without
// waiting for another update (or restarting the peer)...
// Note for NEW servers we expect TokenServerInfo events to arrive after adding the group
// this flow is only for existing servers...
// FIXME: in Cwtch 1.14
// NOTE: This is a bit hacky. Ideally this information would be stored per
// Server not per Group, and creating a group would also trigger sharing
// this information...on the backend all the accounting is done correctly.
var otherGroups = servers?.getServer(newContact.server ?? "")?.groups;
if (otherGroups != null && otherGroups.isNotEmpty) {
EnvironmentConfig.debugLog("sharing antispam tickets to new group. FIXME: in Cwtch 1.14");
var antispamTickets = otherGroups[0].antispamTickets;
_contacts.last!.antispamTickets = antispamTickets;
}
servers?.addGroup(newContact);
}
resort();

View File

@ -573,8 +573,8 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
AboutListTile(
icon: appIcon,
applicationIcon: Padding(padding: EdgeInsets.all(5), child: Icon(CwtchIcons.cwtch_knott)),
applicationName: "Cwtch (Flutter UI)",
applicationLegalese: '\u{a9} 2021 Open Privacy Research Society',
applicationName: "Cwtch UI",
applicationLegalese: '\u{a9} 2021-2023 Open Privacy Research Society',
aboutBoxChildren: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(24.0 + 10.0 + (appIcon.size ?? 24.0), 16.0, 0.0, 0.0),