mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Refactor set blocked methods to accept multiple recipientIds/groupIds
This commit is contained in:
parent
2d60f98e93
commit
53f47d42fc
6 changed files with 74 additions and 62 deletions
|
@ -47,6 +47,7 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -410,17 +411,21 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setContactBlocked(
|
||||
final RecipientIdentifier.Single recipient, final boolean blocked
|
||||
public void setContactsBlocked(
|
||||
final Collection<RecipientIdentifier.Single> recipients, final boolean blocked
|
||||
) throws NotMasterDeviceException, IOException {
|
||||
signal.setContactBlocked(recipient.getIdentifier(), blocked);
|
||||
for (final var recipient : recipients) {
|
||||
signal.setContactBlocked(recipient.getIdentifier(), blocked);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupBlocked(
|
||||
final GroupId groupId, final boolean blocked
|
||||
public void setGroupsBlocked(
|
||||
final Collection<GroupId> groupIds, final boolean blocked
|
||||
) throws GroupNotFoundException, IOException {
|
||||
setGroupProperty(groupId, "IsBlocked", blocked);
|
||||
for (final var groupId : groupIds) {
|
||||
setGroupProperty(groupId, "IsBlocked", blocked);
|
||||
}
|
||||
}
|
||||
|
||||
private void setGroupProperty(final GroupId groupId, final String propertyName, final boolean blocked) {
|
||||
|
|
|
@ -516,7 +516,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public void setContactBlocked(final String number, final boolean blocked) {
|
||||
try {
|
||||
m.setContactBlocked(getSingleRecipientIdentifier(number, m.getSelfNumber()), blocked);
|
||||
m.setContactsBlocked(List.of(getSingleRecipientIdentifier(number, m.getSelfNumber())), blocked);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (IOException e) {
|
||||
|
@ -529,7 +529,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public void setGroupBlocked(final byte[] groupId, final boolean blocked) {
|
||||
try {
|
||||
m.setGroupBlocked(getGroupId(groupId), blocked);
|
||||
m.setGroupsBlocked(List.of(getGroupId(groupId)), blocked);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (GroupNotFoundException e) {
|
||||
|
@ -1287,7 +1287,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
private void setIsBlocked(final boolean isBlocked) {
|
||||
try {
|
||||
m.setGroupBlocked(groupId, isBlocked);
|
||||
m.setGroupsBlocked(List.of(groupId), isBlocked);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (GroupNotFoundException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue