Merge pull request 'Fix Reconnect Woes + DeleteProfile on Android' (#206) from beta_fixes into trunk
continuous-integration/drone/push Build is passing Details

Reviewed-on: #206
This commit is contained in:
erinn 2021-06-23 15:02:47 -07:00
commit c4203477de
9 changed files with 58 additions and 16 deletions

View File

@ -1 +1 @@
v0.0.2-99-gc864bcc-2021-06-22-00-52
v0.0.2-104-gc1b7e4c-2021-06-22-23-59

View File

@ -181,8 +181,8 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
}
"DeleteProfile" -> {
val profile = (a.get("ProfileOnion") as? String) ?: ""
val groupHandle = (a.get("pass") as? String) ?: ""
Cwtch.deleteProfile(profile, groupHandle)
val pass = (a.get("pass") as? String) ?: ""
Cwtch.deleteProfile(profile, pass)
}
"LeaveConversation" -> {
val profile = (a.get("ProfileOnion") as? String) ?: ""

View File

@ -142,6 +142,14 @@ class MainActivity: FlutterActivity() {
myReceiver = MyBroadcastReceiver(mc)
LocalBroadcastManager.getInstance(applicationContext).registerReceiver(myReceiver!!, filter)
}
// ReconnectCwtchForeground which will resync counters and settings...
// We need to do this here because after a "pause" flutter is still running
// but we might have lost sync with the background process...
Log.i("MainActivity.kt", "Call ReconnectCwtchForeground")
val data: Data = Data.Builder().putString(FlwtchWorker.KEY_METHOD, "ReconnectCwtchForeground").putString(FlwtchWorker.KEY_ARGS, "{}").build()
val workRequest = OneTimeWorkRequestBuilder<FlwtchWorker>().setInputData(data).build()
WorkManager.getInstance(applicationContext).enqueue(workRequest)
}
override fun onStop() {

View File

@ -37,8 +37,7 @@ class CwtchNotifier {
appState.SetAppError(data["Error"]);
break;
case "NewPeer":
profileCN.add(ProfileInfoState(
onion: data["Identity"], nickname: data["name"], imagePath: data["picture"], contactsJson: data["ContactsJson"], serversJson: data["ServerList"], online: data["Online"] == "true"));
profileCN.add(data["Identity"], data["name"], data["picture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true");
break;
case "PeerCreated":
profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(

View File

@ -83,7 +83,7 @@ class CwtchGomobile implements Cwtch {
// ignore: non_constant_identifier_names
void DeleteProfile(String onion, String pass) {
cwtchPlatform.invokeMethod("DeleteProfile", {"onion": onion, "pass": pass});
cwtchPlatform.invokeMethod("DeleteProfile", {"ProfileOnion": onion, "pass": pass});
}
// ignore: non_constant_identifier_names

View File

@ -38,13 +38,13 @@ class ProfileListState extends ChangeNotifier {
List<ProfileInfoState> _profiles = [];
int get num => _profiles.length;
void addAll(Iterable<ProfileInfoState> newProfiles) {
_profiles.addAll(newProfiles);
notifyListeners();
}
void add(ProfileInfoState newProfile) {
_profiles.add(newProfile);
void add(String onion, String name, String picture, String contactsJson, String serverJson, bool online) {
var idx = _profiles.indexWhere((element) => element.onion == onion);
if (idx == -1) {
_profiles.add(ProfileInfoState(onion: onion, nickname: name, imagePath: picture, contactsJson: contactsJson, serversJson: serverJson, online: online));
} else {
_profiles[idx].updateFrom(onion, name, picture, contactsJson, serverJson, online);
}
notifyListeners();
}
@ -261,6 +261,41 @@ class ProfileInfoState extends ChangeNotifier {
super.dispose();
print("profileinfostate.dispose()");
}
void updateFrom(String onion, String name, String picture, String contactsJson, String serverJson, bool online) {
this._nickname = name;
this._imagePath = picture;
this._online = online;
this.replaceServers(serverJson);
if (contactsJson != null && contactsJson != "" && contactsJson != "null") {
List<dynamic> contacts = jsonDecode(contactsJson);
contacts.forEach((contact) {
var profileContact = this._contacts.getContact(contact["onion"]);
if (profileContact != null) {
profileContact.status = contact["status"];
profileContact.totalMessages = contact["numMessages"];
profileContact.lastMessageTime = DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"]));
} else {
this._contacts.add(ContactInfoState(
this.onion,
contact["onion"],
nickname: contact["name"],
status: contact["status"],
imagePath: contact["picture"],
isBlocked: contact["authorization"] == "blocked",
isInvitation: contact["authorization"] == "unknown",
savePeerHistory: contact["saveConversationHistory"],
numMessages: contact["numMessages"],
numUnread: contact["numUnread"],
isGroup: contact["isGroup"],
server: contact["groupServer"],
lastMessageTime: DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])),
));
}
});
}
}
}
class ContactInfoState extends ChangeNotifier {

View File

@ -20,7 +20,7 @@ class Settings extends ChangeNotifier {
bool experimentsEnabled = false;
HashMap<String, bool> experiments = HashMap.identity();
late bool blockUnknownConnections;
bool blockUnknownConnections = false;
/// Set the dark theme.
void setDark() {

View File

@ -55,7 +55,7 @@ class _TorStatusView extends State<TorStatusView> {
ListTile(
title: Text(AppLocalizations.of(context)!.torVersion),
subtitle: Text(torStatus.version),
),
),
]))));
});
});

View File

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+13
version: 1.0.0+14
environment:
sdk: ">=2.12.0 <3.0.0"