Rework accept/block data flow to map to new storage; fix add group server list falls back to onion when no description
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Dan Ballard 2022-01-06 16:54:25 -05:00
parent 90e3cd203d
commit 5e485b6327
11 changed files with 65 additions and 61 deletions

View File

@ -1 +1 @@
2021-12-20-18-47-v1.5.2
2022-01-06-17-13-v1.5.3

View File

@ -1 +1 @@
2021-12-20-23-47-v1.5.2
2022-01-06-22-13-v1.5.3

View File

@ -225,6 +225,11 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
val conversation = a.getInt("conversation").toLong()
Cwtch.blockContact(profile, conversation)
}
"UnblockContact" -> {
val profile = (a.get("ProfileOnion") as? String) ?: ""
val conversation = a.getInt("conversation").toLong()
Cwtch.unblockContact(profile, conversation)
}
"SendMessage" -> {
val profile = (a.get("ProfileOnion") as? String) ?: ""
val conversation = a.getInt("conversation").toLong()

View File

@ -32,6 +32,8 @@ abstract class Cwtch {
void AcceptContact(String profileOnion, int contactHandle);
// ignore: non_constant_identifier_names
void BlockContact(String profileOnion, int contactHandle);
// ignore: non_constant_identifier_names
void UnblockContact(String profileOnion, int contactHandle);
// ignore: non_constant_identifier_names
Future<dynamic> GetMessage(String profile, int handle, int index);

View File

@ -50,7 +50,8 @@ class CwtchNotifier {
profileCN.add(data["Identity"], data["name"], data["picture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["tag"] != "v1-defaultPassword");
break;
case "ContactCreated":
EnvironmentConfig.debugLog("NewServer $data");
EnvironmentConfig.debugLog("ContactCreated $data");
profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(
data["ProfileOnion"],
int.parse(data["ConversationID"]),
@ -58,7 +59,8 @@ class CwtchNotifier {
nickname: data["nick"],
status: data["status"],
imagePath: data["picture"],
authorization: stringToContactAuthorization(data["authorization"]),
blocked: data["blocked"] == "true",
accepted: data["accepted"] == "true",
savePeerHistory: data["saveConversationHistory"] == null ? "DeleteHistoryConfirmed" : data["saveConversationHistory"],
numMessages: int.parse(data["numMessages"]),
numUnread: int.parse(data["unread"]),
@ -94,7 +96,8 @@ class CwtchNotifier {
}
if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(data["ConversationID"])) == null) {
profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], int.parse(data["ConversationID"]), data["GroupID"],
authorization: ContactAuthorization.approved,
blocked: data["blocked"] == "true",
accepted: data["accepted"] == "true",
imagePath: data["PicturePath"],
nickname: data["GroupName"],
status: status,
@ -127,10 +130,6 @@ class CwtchNotifier {
if (data["ConnectionState"] != null) {
contact.status = data["ConnectionState"];
}
if (data["authorization"] != null) {
contact.authorization = stringToContactAuthorization(data["authorization"]);
}
// contact.[status/isBlocked] might change the list's sort order
profileCN.getProfile(data["ProfileOnion"])?.contactList.resort();
}
break;
@ -289,7 +288,8 @@ class CwtchNotifier {
if (profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(groupInvite["GroupID"]) == null) {
var identifier = int.parse(data["ConversationID"]);
profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], identifier, groupInvite["GroupID"],
authorization: ContactAuthorization.approved,
blocked: data["blocked"] == "true",
accepted: data["accepted"] == "true",
imagePath: data["PicturePath"],
nickname: groupInvite["GroupName"],
server: groupInvite["ServerHost"],

View File

@ -342,6 +342,17 @@ class CwtchFfi implements Cwtch {
malloc.free(u1);
}
@override
// ignore: non_constant_identifier_names
void UnblockContact(String profileOnion, int contactHandle) {
var unblockContact = library.lookup<NativeFunction<string_int_to_void_function>>("c_UnblockContact");
// ignore: non_constant_identifier_names
final UnblockContact = unblockContact.asFunction<VoidFromStringIntFn>();
final u1 = profileOnion.toNativeUtf8();
UnblockContact(u1, u1.length, contactHandle);
malloc.free(u1);
}
@override
// ignore: non_constant_identifier_names
void SendMessage(String profileOnion, int contactHandle, String message) {

View File

@ -111,7 +111,7 @@ class CwtchGomobile implements Cwtch {
@override
// ignore: non_constant_identifier_names
void AcceptContact(String profileOnion, int conversation) {
cwtchPlatform.invokeMethod("AcceptContact", {"ProfileOnion": profileOnion, "conversation": conversation});
cwtchPlatform.invokeMethod("AcceptConversation", {"ProfileOnion": profileOnion, "conversation": conversation});
}
@override
@ -120,6 +120,12 @@ class CwtchGomobile implements Cwtch {
cwtchPlatform.invokeMethod("BlockContact", {"ProfileOnion": profileOnion, "conversation": conversation});
}
@override
// ignore: non_constant_identifier_names
void UnblockContact(String profileOnion, int conversation) {
cwtchPlatform.invokeMethod("UnblockContact", {"ProfileOnion": profileOnion, "conversation": conversation});
}
@override
// ignore: non_constant_identifier_names
void SendMessage(String profileOnion, int conversation, String message) {
@ -207,7 +213,7 @@ class CwtchGomobile implements Cwtch {
@override
// ignore: non_constant_identifier_names
void SetConversationAttribute(String profile, int conversation, String key, String val) {
cwtchPlatform.invokeMethod("SetContactAttribute", {"ProfileOnion": profile, "conversation": conversation, "Key": key, "Val": val});
cwtchPlatform.invokeMethod("SetConversationAttribute", {"ProfileOnion": profile, "conversation": conversation, "Key": key, "Val": val});
}
@override

View File

@ -286,7 +286,8 @@ class ProfileInfoState extends ChangeNotifier {
nickname: contact["name"],
status: contact["status"],
imagePath: contact["picture"],
authorization: stringToContactAuthorization(contact["authorization"]),
accepted: contact["accepted"],
blocked: contact["blocked"],
savePeerHistory: contact["saveConversationHistory"],
numMessages: contact["numMessages"],
numUnread: contact["numUnread"],
@ -382,10 +383,11 @@ class ProfileInfoState extends ChangeNotifier {
if (contactsJson != null && contactsJson != "" && contactsJson != "null") {
List<dynamic> contacts = jsonDecode(contactsJson);
contacts.forEach((contact) {
var profileContact = this._contacts.getContact(contact["onion"]);
var profileContact = this._contacts.getContact(contact["identifier"]);
if (profileContact != null) {
profileContact.status = contact["status"];
profileContact.totalMessages = contact["numMessages"];
profileContact.unreadMessages = contact["numUnread"];
profileContact.lastMessageTime = DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"]));
} else {
this._contacts.add(ContactInfoState(
@ -395,7 +397,8 @@ class ProfileInfoState extends ChangeNotifier {
nickname: contact["name"],
status: contact["status"],
imagePath: contact["picture"],
authorization: stringToContactAuthorization(contact["authorization"]),
accepted: contact["accepted"],
blocked: contact["blocked"],
savePeerHistory: contact["saveConversationHistory"],
numMessages: contact["numMessages"],
numUnread: contact["numUnread"],
@ -406,6 +409,7 @@ class ProfileInfoState extends ChangeNotifier {
}
});
}
this._contacts.resort();
}
void downloadInit(String fileKey, int numChunks) {
@ -534,19 +538,6 @@ String prettyBytes(int bytes) {
}
}
enum ContactAuthorization { unknown, approved, blocked }
ContactAuthorization stringToContactAuthorization(String authStr) {
switch (authStr) {
case "approved":
return ContactAuthorization.approved;
case "blocked":
return ContactAuthorization.blocked;
default:
return ContactAuthorization.unknown;
}
}
class MessageCache {
final MessageMetadata metadata;
final String wrapper;
@ -559,7 +550,8 @@ class ContactInfoState extends ChangeNotifier {
final String onion;
late String _nickname;
late ContactAuthorization _authorization;
late bool _accepted;
late bool _blocked;
late String _status;
late String _imagePath;
late String _savePeerHistory;
@ -579,7 +571,8 @@ class ContactInfoState extends ChangeNotifier {
ContactInfoState(this.profileOnion, this.identifier, this.onion,
{nickname = "",
isGroup = false,
authorization = ContactAuthorization.unknown,
accepted = false,
blocked = false,
status = "",
imagePath = "",
savePeerHistory = "DeleteHistoryConfirmed",
@ -590,7 +583,8 @@ class ContactInfoState extends ChangeNotifier {
archived = false}) {
this._nickname = nickname;
this._isGroup = isGroup;
this._authorization = authorization;
this._accepted = accepted;
this._blocked = blocked;
this._status = status;
this._imagePath = imagePath;
this._totalMessages = numMessages;
@ -633,13 +627,17 @@ class ContactInfoState extends ChangeNotifier {
notifyListeners();
}
bool get isBlocked => this._authorization == ContactAuthorization.blocked;
bool get isBlocked => this._blocked;
bool get isInvitation => this._authorization == ContactAuthorization.unknown;
bool get isInvitation => !this._blocked && !this._accepted;
ContactAuthorization get authorization => this._authorization;
set authorization(ContactAuthorization newAuth) {
this._authorization = newAuth;
set accepted(bool newVal) {
this._accepted = newVal;
notifyListeners();
}
set blocked(bool newVal) {
this._blocked = newVal;
notifyListeners();
}

View File

@ -209,7 +209,7 @@ class _AddContactViewState extends State<AddContactView> {
return DropdownMenuItem<String>(
value: serverInfo.onion,
child: Text(
serverInfo.description,
serverInfo.description.isNotEmpty ? serverInfo.description : serverInfo.onion,
overflow: TextOverflow.ellipsis,
),
);

View File

@ -108,33 +108,15 @@ class _PeerSettingsViewState extends State<PeerSettingsView> {
title: Text(AppLocalizations.of(context)!.blockBtn, style: TextStyle(color: settings.current().mainTextColor)),
value: Provider.of<ContactInfoState>(context).isBlocked,
onChanged: (bool blocked) {
// Save local blocked status
if (blocked) {
Provider.of<ContactInfoState>(context, listen: false).authorization = ContactAuthorization.blocked;
} else {
Provider.of<ContactInfoState>(context, listen: false).authorization = ContactAuthorization.unknown;
}
Provider.of<ContactInfoState>(context, listen: false).blocked = blocked;
// Save New peer authorization
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
var onion = Provider.of<ContactInfoState>(context, listen: false).onion;
Provider.of<ContactInfoState>(context, listen: false).nickname = ctrlrNick.text;
var identifier = Provider.of<ContactInfoState>(context, listen: false).identifier;
if (blocked) {
final setPeerAttribute = {
"EventType": "UpdatePeerAuthorization",
"Data": {"RemotePeer": onion, "Authorization": "blocked"},
};
final setPeerAttributeJson = jsonEncode(setPeerAttribute);
Provider.of<FlwtchState>(context, listen: false).cwtch.SendProfileEvent(profileOnion, setPeerAttributeJson);
Provider.of<FlwtchState>(context, listen: false).cwtch.BlockContact(profileOnion, identifier);
} else {
final setPeerAttribute = {
"EventType": "UpdatePeerAuthorization",
"Data": {"RemotePeer": onion, "Authorization": "authorized"},
};
final setPeerAttributeJson = jsonEncode(setPeerAttribute);
Provider.of<FlwtchState>(context, listen: false).cwtch.SendProfileEvent(profileOnion, setPeerAttributeJson);
Provider.of<FlwtchState>(context, listen: false).cwtch.UnblockContact(profileOnion, identifier);
}
},
activeTrackColor: settings.theme.defaultButtonColor,

View File

@ -111,14 +111,14 @@ class _ContactRowState extends State<ContactRow> {
}
void _btnApprove() {
// Update the UI
Provider.of<ContactInfoState>(context, listen: false).authorization = ContactAuthorization.approved;
Provider.of<ContactInfoState>(context, listen: false).accepted = true;
Provider.of<FlwtchState>(context, listen: false)
.cwtch
.AcceptContact(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier);
}
void _btnReject() {
Provider.of<ContactInfoState>(context, listen: false).blocked = true;
ContactInfoState contact = Provider.of<ContactInfoState>(context, listen: false);
if (contact.isGroup == true) {
// FIXME This flow is incrorect. Groups never just show up on the contact list anymore