Minor changes and corrections

This commit is contained in:
Daniel Schäufele 2020-01-22 01:20:00 +01:00
parent 20f9f2b26d
commit 98aedcb3f3
4 changed files with 33 additions and 9 deletions

View file

@ -6,6 +6,7 @@ import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.exceptions.DBusException;
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.io.IOException;
import java.util.List;
@ -24,7 +25,7 @@ public interface Signal extends DBusInterface {
void setContactName(String number, String name);
void setContactBlocked(String number, boolean blocked);
void setContactBlocked(String number, boolean blocked) throws InvalidNumberException;
void setGroupBlocked(byte[] groupId, boolean blocked) throws GroupNotFoundException;

View file

@ -6,6 +6,7 @@ import org.asamk.signal.GroupIdFormatException;
import org.asamk.signal.GroupNotFoundException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
public class BlockCommand implements LocalCommand {
@ -28,10 +29,14 @@ public class BlockCommand implements LocalCommand {
}
for (String contact_number : ns.<String>getList("contact")) {
try {
m.setContactBlocked(contact_number, true);
} catch (InvalidNumberException e) {
System.err.println(e.getMessage());
}
}
if(ns.<String>getList("group") != null) {
if (ns.<String>getList("group") != null) {
for (String groupIdString : ns.<String>getList("group")) {
try {
byte[] groupId = Util.decodeGroupId(groupIdString);

View file

@ -6,6 +6,7 @@ import org.asamk.signal.GroupIdFormatException;
import org.asamk.signal.GroupNotFoundException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
public class UnblockCommand implements LocalCommand {
@ -28,10 +29,14 @@ public class UnblockCommand implements LocalCommand {
}
for (String contact_number : ns.<String>getList("contact")) {
try {
m.setContactBlocked(contact_number, false);
} catch (InvalidNumberException e) {
System.err.println(e.getMessage());
}
}
if(ns.<String>getList("group") != null) {
if (ns.<String>getList("group") != null) {
for (String groupIdString : ns.<String>getList("group")) {
try {
byte[] groupId = Util.decodeGroupId(groupIdString);

View file

@ -688,7 +688,8 @@ public class Manager implements Signal {
}
@Override
public void setContactBlocked(String number, boolean blocked) {
public void setContactBlocked(String number, boolean blocked) throws InvalidNumberException {
number = Utils.canonicalizeNumber(number, username);
ContactInfo contact = account.getContactStore().getContact(number);
if (contact == null) {
contact = new ContactInfo();
@ -1207,7 +1208,14 @@ public class Manager implements Signal {
}
private boolean isMessageBlocked(SignalServiceEnvelope envelope, SignalServiceContent content) {
SignalServiceAddress source = envelope.getSourceAddress();
SignalServiceAddress source;
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
source = envelope.getSourceAddress();
} else if (content != null) {
source = content.getSender();
} else {
return false;
}
ContactInfo sourceContact = getContact(source.getNumber().get());
if (sourceContact != null && sourceContact.blocked) {
return true;
@ -1313,8 +1321,13 @@ public class Manager implements Signal {
if (syncMessage.getBlockedList().isPresent()) {
final BlockedListMessage blockedListMessage = syncMessage.getBlockedList().get();
for (SignalServiceAddress address : blockedListMessage.getAddresses()) {
if (address.getNumber().isPresent())
if (address.getNumber().isPresent()) {
try {
setContactBlocked(address.getNumber().get(), true);
} catch (InvalidNumberException e) {
e.printStackTrace();
}
}
}
for (byte[] groupId : blockedListMessage.getGroupIds()) {
try {