Merge pull request 'fix accept block' (#288) from fixAcceptBlock into trunk
continuous-integration/drone/push Build is passing Details

Reviewed-on: #288
Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
Dan Ballard 2022-01-06 23:06:56 +00:00
commit 5c6765b565
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() val conversation = a.getInt("conversation").toLong()
Cwtch.blockContact(profile, conversation) Cwtch.blockContact(profile, conversation)
} }
"UnblockContact" -> {
val profile = (a.get("ProfileOnion") as? String) ?: ""
val conversation = a.getInt("conversation").toLong()
Cwtch.unblockContact(profile, conversation)
}
"SendMessage" -> { "SendMessage" -> {
val profile = (a.get("ProfileOnion") as? String) ?: "" val profile = (a.get("ProfileOnion") as? String) ?: ""
val conversation = a.getInt("conversation").toLong() val conversation = a.getInt("conversation").toLong()

View File

@ -32,6 +32,8 @@ abstract class Cwtch {
void AcceptContact(String profileOnion, int contactHandle); void AcceptContact(String profileOnion, int contactHandle);
// ignore: non_constant_identifier_names // ignore: non_constant_identifier_names
void BlockContact(String profileOnion, int contactHandle); void BlockContact(String profileOnion, int contactHandle);
// ignore: non_constant_identifier_names
void UnblockContact(String profileOnion, int contactHandle);
// ignore: non_constant_identifier_names // ignore: non_constant_identifier_names
Future<dynamic> GetMessage(String profile, int handle, int index); 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"); profileCN.add(data["Identity"], data["name"], data["picture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["tag"] != "v1-defaultPassword");
break; break;
case "ContactCreated": case "ContactCreated":
EnvironmentConfig.debugLog("NewServer $data"); EnvironmentConfig.debugLog("ContactCreated $data");
profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState( profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(
data["ProfileOnion"], data["ProfileOnion"],
int.parse(data["ConversationID"]), int.parse(data["ConversationID"]),
@ -58,7 +59,8 @@ class CwtchNotifier {
nickname: data["nick"], nickname: data["nick"],
status: data["status"], status: data["status"],
imagePath: data["picture"], imagePath: data["picture"],
authorization: stringToContactAuthorization(data["authorization"]), blocked: data["blocked"] == "true",
accepted: data["accepted"] == "true",
savePeerHistory: data["saveConversationHistory"] == null ? "DeleteHistoryConfirmed" : data["saveConversationHistory"], savePeerHistory: data["saveConversationHistory"] == null ? "DeleteHistoryConfirmed" : data["saveConversationHistory"],
numMessages: int.parse(data["numMessages"]), numMessages: int.parse(data["numMessages"]),
numUnread: int.parse(data["unread"]), numUnread: int.parse(data["unread"]),
@ -94,7 +96,8 @@ class CwtchNotifier {
} }
if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(data["ConversationID"])) == null) { 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"], 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"], imagePath: data["PicturePath"],
nickname: data["GroupName"], nickname: data["GroupName"],
status: status, status: status,
@ -127,10 +130,6 @@ class CwtchNotifier {
if (data["ConnectionState"] != null) { if (data["ConnectionState"] != null) {
contact.status = data["ConnectionState"]; 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(); profileCN.getProfile(data["ProfileOnion"])?.contactList.resort();
} }
break; break;
@ -289,7 +288,8 @@ class CwtchNotifier {
if (profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(groupInvite["GroupID"]) == null) { if (profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(groupInvite["GroupID"]) == null) {
var identifier = int.parse(data["ConversationID"]); var identifier = int.parse(data["ConversationID"]);
profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], identifier, groupInvite["GroupID"], 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"], imagePath: data["PicturePath"],
nickname: groupInvite["GroupName"], nickname: groupInvite["GroupName"],
server: groupInvite["ServerHost"], server: groupInvite["ServerHost"],

View File

@ -342,6 +342,17 @@ class CwtchFfi implements Cwtch {
malloc.free(u1); 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 @override
// ignore: non_constant_identifier_names // ignore: non_constant_identifier_names
void SendMessage(String profileOnion, int contactHandle, String message) { void SendMessage(String profileOnion, int contactHandle, String message) {

View File

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

View File

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

View File

@ -209,7 +209,7 @@ class _AddContactViewState extends State<AddContactView> {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: serverInfo.onion, value: serverInfo.onion,
child: Text( child: Text(
serverInfo.description, serverInfo.description.isNotEmpty ? serverInfo.description : serverInfo.onion,
overflow: TextOverflow.ellipsis, 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)), title: Text(AppLocalizations.of(context)!.blockBtn, style: TextStyle(color: settings.current().mainTextColor)),
value: Provider.of<ContactInfoState>(context).isBlocked, value: Provider.of<ContactInfoState>(context).isBlocked,
onChanged: (bool blocked) { onChanged: (bool blocked) {
// Save local blocked status Provider.of<ContactInfoState>(context, listen: false).blocked = blocked;
if (blocked) {
Provider.of<ContactInfoState>(context, listen: false).authorization = ContactAuthorization.blocked;
} else {
Provider.of<ContactInfoState>(context, listen: false).authorization = ContactAuthorization.unknown;
}
// Save New peer authorization
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion; var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
var identifier = Provider.of<ContactInfoState>(context, listen: false).identifier;
var onion = Provider.of<ContactInfoState>(context, listen: false).onion;
Provider.of<ContactInfoState>(context, listen: false).nickname = ctrlrNick.text;
if (blocked) { if (blocked) {
final setPeerAttribute = { Provider.of<FlwtchState>(context, listen: false).cwtch.BlockContact(profileOnion, identifier);
"EventType": "UpdatePeerAuthorization",
"Data": {"RemotePeer": onion, "Authorization": "blocked"},
};
final setPeerAttributeJson = jsonEncode(setPeerAttribute);
Provider.of<FlwtchState>(context, listen: false).cwtch.SendProfileEvent(profileOnion, setPeerAttributeJson);
} else { } else {
final setPeerAttribute = { Provider.of<FlwtchState>(context, listen: false).cwtch.UnblockContact(profileOnion, identifier);
"EventType": "UpdatePeerAuthorization",
"Data": {"RemotePeer": onion, "Authorization": "authorized"},
};
final setPeerAttributeJson = jsonEncode(setPeerAttribute);
Provider.of<FlwtchState>(context, listen: false).cwtch.SendProfileEvent(profileOnion, setPeerAttributeJson);
} }
}, },
activeTrackColor: settings.theme.defaultButtonColor, activeTrackColor: settings.theme.defaultButtonColor,

View File

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