mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 04:20:38 +00:00
Minor changes and corrections
This commit is contained in:
parent
20f9f2b26d
commit
98aedcb3f3
4 changed files with 33 additions and 9 deletions
|
@ -6,6 +6,7 @@ import org.freedesktop.dbus.DBusInterface;
|
||||||
import org.freedesktop.dbus.DBusSignal;
|
import org.freedesktop.dbus.DBusSignal;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||||
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -24,7 +25,7 @@ public interface Signal extends DBusInterface {
|
||||||
|
|
||||||
void setContactName(String number, String name);
|
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;
|
void setGroupBlocked(byte[] groupId, boolean blocked) throws GroupNotFoundException;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.asamk.signal.GroupIdFormatException;
|
||||||
import org.asamk.signal.GroupNotFoundException;
|
import org.asamk.signal.GroupNotFoundException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
public class BlockCommand implements LocalCommand {
|
public class BlockCommand implements LocalCommand {
|
||||||
|
|
||||||
|
@ -28,10 +29,14 @@ public class BlockCommand implements LocalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String contact_number : ns.<String>getList("contact")) {
|
for (String contact_number : ns.<String>getList("contact")) {
|
||||||
m.setContactBlocked(contact_number, true);
|
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")) {
|
for (String groupIdString : ns.<String>getList("group")) {
|
||||||
try {
|
try {
|
||||||
byte[] groupId = Util.decodeGroupId(groupIdString);
|
byte[] groupId = Util.decodeGroupId(groupIdString);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.asamk.signal.GroupIdFormatException;
|
||||||
import org.asamk.signal.GroupNotFoundException;
|
import org.asamk.signal.GroupNotFoundException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
public class UnblockCommand implements LocalCommand {
|
public class UnblockCommand implements LocalCommand {
|
||||||
|
|
||||||
|
@ -28,10 +29,14 @@ public class UnblockCommand implements LocalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String contact_number : ns.<String>getList("contact")) {
|
for (String contact_number : ns.<String>getList("contact")) {
|
||||||
m.setContactBlocked(contact_number, false);
|
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")) {
|
for (String groupIdString : ns.<String>getList("group")) {
|
||||||
try {
|
try {
|
||||||
byte[] groupId = Util.decodeGroupId(groupIdString);
|
byte[] groupId = Util.decodeGroupId(groupIdString);
|
||||||
|
|
|
@ -688,7 +688,8 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
ContactInfo contact = account.getContactStore().getContact(number);
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
contact = new ContactInfo();
|
contact = new ContactInfo();
|
||||||
|
@ -1207,7 +1208,14 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMessageBlocked(SignalServiceEnvelope envelope, SignalServiceContent content) {
|
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());
|
ContactInfo sourceContact = getContact(source.getNumber().get());
|
||||||
if (sourceContact != null && sourceContact.blocked) {
|
if (sourceContact != null && sourceContact.blocked) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1313,8 +1321,13 @@ public class Manager implements Signal {
|
||||||
if (syncMessage.getBlockedList().isPresent()) {
|
if (syncMessage.getBlockedList().isPresent()) {
|
||||||
final BlockedListMessage blockedListMessage = syncMessage.getBlockedList().get();
|
final BlockedListMessage blockedListMessage = syncMessage.getBlockedList().get();
|
||||||
for (SignalServiceAddress address : blockedListMessage.getAddresses()) {
|
for (SignalServiceAddress address : blockedListMessage.getAddresses()) {
|
||||||
if (address.getNumber().isPresent())
|
if (address.getNumber().isPresent()) {
|
||||||
setContactBlocked(address.getNumber().get(), true);
|
try {
|
||||||
|
setContactBlocked(address.getNumber().get(), true);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (byte[] groupId : blockedListMessage.getGroupIds()) {
|
for (byte[] groupId : blockedListMessage.getGroupIds()) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue