diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt index c83491a5..f6429989 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt @@ -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"); diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt index 204b7d01..d2eafd73 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt @@ -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 diff --git a/lib/cwtch/cwtch.dart b/lib/cwtch/cwtch.dart index 811e8abd..1cc06e22 100644 --- a/lib/cwtch/cwtch.dart +++ b/lib/cwtch/cwtch.dart @@ -154,6 +154,6 @@ abstract class Cwtch { // ignore: non_constant_identifier_names Future SearchConversations(String profile, String pattern); void DeleteServerInfo(String profile, String handle); - + void PublishServerUpdate(String onion); Future ConfigureConnections(String onion, bool listen, bool peers, bool servers); } diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index e66bbdcd..f4776e0e 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -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": diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 3b9a8535..ec0f9197 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -1111,4 +1111,14 @@ class CwtchFfi implements Cwtch { malloc.free(utf8profile); return; } + + @override + void PublishServerUpdate(String profile) { + var publishServerUpdate = library.lookup>("c_PublishServerUpdate"); + // ignore: non_constant_identifier_names + final PublishServerUpdate = publishServerUpdate.asFunction(); + final utf8profile = profile.toNativeUtf8(); + PublishServerUpdate(utf8profile, utf8profile.length); + malloc.free(utf8profile); + } } diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index 476cf7c7..ffc8f736 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -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}); + } + } diff --git a/lib/models/contactlist.dart b/lib/models/contactlist.dart index 99bd398f..0ec9ef45 100644 --- a/lib/models/contactlist.dart +++ b/lib/models/contactlist.dart @@ -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(); diff --git a/lib/views/globalsettingsview.dart b/lib/views/globalsettingsview.dart index 136d52c1..4910c5df 100644 --- a/lib/views/globalsettingsview.dart +++ b/lib/views/globalsettingsview.dart @@ -573,8 +573,8 @@ class _GlobalSettingsViewState extends State { 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: [ Padding( padding: EdgeInsets.fromLTRB(24.0 + 10.0 + (appIcon.size ?? 24.0), 16.0, 0.0, 0.0),