mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Add support for blocking contacts and accounts (#260)
* Add blockContact and unblockContact subcommands * Send blocked status in contacts sync * Use only one method for blocking and unblocking * Add blocking/unblocking for groups * Prevent blocked messages from being printed * Print blocked property in listContacts and listGroups commands * Handle BlockedListMessages * Store blocked state from incoming contact and group sync messages * Minor changes and corrections * Add block and unblock commands to man file (and also fix some headings of commands)
This commit is contained in:
parent
7f9379f78b
commit
8b9640ba14
11 changed files with 255 additions and 20 deletions
52
src/main/java/org/asamk/signal/commands/UnblockCommand.java
Normal file
52
src/main/java/org/asamk/signal/commands/UnblockCommand.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
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 {
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.addArgument("contact")
|
||||
.help("Contact number")
|
||||
.nargs("*");
|
||||
subparser.addArgument("-g", "--group")
|
||||
.help("Group ID")
|
||||
.nargs("*");
|
||||
subparser.help("Unblock the given contacts or groups (messages will be received again)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
for (String groupIdString : ns.<String>getList("group")) {
|
||||
try {
|
||||
byte[] groupId = Util.decodeGroupId(groupIdString);
|
||||
m.setGroupBlocked(groupId, false);
|
||||
} catch (GroupIdFormatException | GroupNotFoundException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue