mirror of
https://github.com/aljazceru/signal-cli.git
synced 2025-12-24 17:44:22 +01:00
Extract ContactHelper and IncomingMessageHandler
This commit is contained in:
@@ -5,6 +5,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.OutputWriter;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||
@@ -13,6 +14,8 @@ import org.asamk.signal.util.CommandUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BlockCommand implements JsonRpcLocalCommand {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(BlockCommand.class);
|
||||
@@ -39,6 +42,8 @@ public class BlockCommand implements JsonRpcLocalCommand {
|
||||
m.setContactBlocked(contact, true);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||
} catch (IOException e) {
|
||||
throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +54,8 @@ public class BlockCommand implements JsonRpcLocalCommand {
|
||||
m.setGroupBlocked(groupId, true);
|
||||
} catch (GroupNotFoundException e) {
|
||||
logger.warn("Group not found {}: {}", groupId.toBase64(), e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.OutputWriter;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||
@@ -13,6 +14,8 @@ import org.asamk.signal.util.CommandUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnblockCommand implements JsonRpcLocalCommand {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(UnblockCommand.class);
|
||||
@@ -38,6 +41,8 @@ public class UnblockCommand implements JsonRpcLocalCommand {
|
||||
m.setContactBlocked(contactNumber, false);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new UserErrorException("This command doesn't work on linked devices.");
|
||||
} catch (IOException e) {
|
||||
throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +52,8 @@ public class UnblockCommand implements JsonRpcLocalCommand {
|
||||
m.setGroupBlocked(groupId, false);
|
||||
} catch (GroupNotFoundException e) {
|
||||
logger.warn("Unknown group id: {}", groupId);
|
||||
} catch (IOException e) {
|
||||
throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,6 +253,8 @@ public class DbusSignalImpl implements Signal {
|
||||
m.setContactBlocked(getSingleRecipientIdentifier(number, m.getUsername()), blocked);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +264,8 @@ public class DbusSignalImpl implements Signal {
|
||||
m.setGroupBlocked(getGroupId(groupId), blocked);
|
||||
} catch (GroupNotFoundException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user