Use only one method for blocking and unblocking

This commit is contained in:
Daniel Schäufele 2020-01-06 23:14:14 +01:00
parent 3a3d9545ea
commit 5ab3152a40
4 changed files with 7 additions and 24 deletions

View file

@ -24,9 +24,7 @@ public interface Signal extends DBusInterface {
void setContactName(String number, String name); void setContactName(String number, String name);
void blockContact(String number); void setContactBlocked(String number, boolean blocked);
void unblockContact(String number);
List<byte[]> getGroupIds(); List<byte[]> getGroupIds();

View file

@ -22,7 +22,7 @@ public class BlockContactCommand implements LocalCommand {
String number = ns.getString("number"); String number = ns.getString("number");
m.blockContact(number); m.setContactBlocked(number, true);
return 0; return 0;
} }

View file

@ -22,7 +22,7 @@ public class UnblockContactCommand implements LocalCommand {
String number = ns.getString("number"); String number = ns.getString("number");
m.unblockContact(number); m.setContactBlocked(number, false);
return 0; return 0;
} }

View file

@ -687,31 +687,16 @@ public class Manager implements Signal {
} }
@Override @Override
public void blockContact(String number) { public void setContactBlocked(String number, boolean blocked) {
ContactInfo contact = account.getContactStore().getContact(number); ContactInfo contact = account.getContactStore().getContact(number);
if (contact == null) { if (contact == null) {
contact = new ContactInfo(); contact = new ContactInfo();
contact.number = number; contact.number = number;
System.err.println("Adding and blocking contact " + number); System.err.println("Adding and " + (blocked ? "blocking" : "unblocking") + " contact " + number);
} else { } else {
System.err.println("Blocking contact " + number); System.err.println((blocked ? "Blocking" : "Unblocking") + " contact " + number);
} }
contact.blocked = true; contact.blocked = blocked;
account.getContactStore().updateContact(contact);
account.save();
}
@Override
public void unblockContact(String number) {
ContactInfo contact = account.getContactStore().getContact(number);
if (contact == null) {
contact = new ContactInfo();
contact.number = number;
System.err.println("Adding and unblocking contact " + number);
} else {
System.err.println("Unblocking contact " + number);
}
contact.blocked = false;
account.getContactStore().updateContact(contact); account.getContactStore().updateContact(contact);
account.save(); account.save();
} }