Fix inspections

This commit is contained in:
AsamK 2023-10-17 20:00:47 +02:00
parent d51dd7ae57
commit fc2e9bbfae
27 changed files with 158 additions and 158 deletions

View file

@ -138,9 +138,9 @@ public interface Signal extends DBusInterface {
DBusPath getDevice(long deviceId);
public DBusPath getIdentity(String number);
DBusPath getIdentity(String number);
public List<StructIdentity> listIdentities();
List<StructIdentity> listIdentities();
List<StructDevice> listDevices() throws Error.Failure;
@ -497,13 +497,13 @@ public interface Signal extends DBusInterface {
class StructDevice extends Struct {
@Position(0)
DBusPath objectPath;
final DBusPath objectPath;
@Position(1)
Long id;
final Long id;
@Position(2)
String name;
final String name;
public StructDevice(final DBusPath objectPath, final Long id, final String name) {
this.objectPath = objectPath;
@ -542,13 +542,13 @@ public interface Signal extends DBusInterface {
class StructGroup extends Struct {
@Position(0)
DBusPath objectPath;
final DBusPath objectPath;
@Position(1)
byte[] id;
final byte[] id;
@Position(2)
String name;
final String name;
public StructGroup(final DBusPath objectPath, final byte[] id, final String name) {
this.objectPath = objectPath;
@ -610,13 +610,13 @@ public interface Signal extends DBusInterface {
class StructIdentity extends Struct {
@Position(0)
DBusPath objectPath;
final DBusPath objectPath;
@Position(1)
String uuid;
final String uuid;
@Position(2)
String number;
final String number;
public StructIdentity(final DBusPath objectPath, final String uuid, final String number) {
this.objectPath = objectPath;

View file

@ -165,20 +165,7 @@ public class App {
return;
}
Set<String> accounts;
try {
accounts = signalAccountFiles.getAllLocalAccountNumbers();
} catch (IOException e) {
throw new IOErrorException("Failed to load local accounts file", e);
}
if (accounts.size() == 0) {
throw new UserErrorException("No local users found, you first need to register or link an account");
} else if (accounts.size() > 1) {
throw new UserErrorException(
"Multiple users found, you need to specify an account (phone number) with -a");
}
account = accounts.stream().findFirst().get();
account = getAccountIfOnlyOne(signalAccountFiles);
} else if (!Manager.isValidNumber(account, null)) {
throw new UserErrorException("Invalid account (phone number), make sure you include the country code.");
}
@ -196,6 +183,21 @@ public class App {
throw new UserErrorException("Command only works in multi-account mode");
}
private static String getAccountIfOnlyOne(final SignalAccountFiles signalAccountFiles) throws IOErrorException, UserErrorException {
Set<String> accounts;
try {
accounts = signalAccountFiles.getAllLocalAccountNumbers();
} catch (IOException e) {
throw new IOErrorException("Failed to load local accounts file", e);
}
if (accounts.isEmpty()) {
throw new UserErrorException("No local users found, you first need to register or link an account");
} else if (accounts.size() > 1) {
throw new UserErrorException("Multiple users found, you need to specify an account (phone number) with -a");
}
return accounts.stream().findFirst().get();
}
private OutputWriter getOutputWriter(final Command command) throws UserErrorException {
final var outputTypeInput = ns.<OutputType>get("output");
final var outputType = outputTypeInput == null ? command.getSupportedOutputTypes()
@ -274,8 +276,6 @@ public class App {
) throws CommandException {
try (var m = loadManager(account, signalAccountFiles)) {
commandHandler.handleLocalCommand(command, m);
} catch (IOException e) {
logger.warn("Cleanup failed", e);
}
}

View file

@ -10,8 +10,6 @@ import org.asamk.signal.manager.api.SendMessageResults;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;
import java.io.IOException;
import static org.asamk.signal.util.SendMessageResultUtils.outputResult;
public class SendReceiptCommand implements JsonRpcLocalCommand {
@ -45,19 +43,14 @@ public class SendReceiptCommand implements JsonRpcLocalCommand {
final var targetTimestamps = ns.<Long>getList("target-timestamp");
final var type = ns.getString("type");
try {
final SendMessageResults results;
if (type == null || "read".equals(type)) {
results = m.sendReadReceipt(recipient, targetTimestamps);
} else if ("viewed".equals(type)) {
results = m.sendViewedReceipt(recipient, targetTimestamps);
} else {
throw new UserErrorException("Unknown receipt type: " + type);
}
outputResult(outputWriter, results);
} catch (IOException e) {
throw new UserErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
.getSimpleName() + ")");
final SendMessageResults results;
if (type == null || "read".equals(type)) {
results = m.sendReadReceipt(recipient, targetTimestamps);
} else if ("viewed".equals(type)) {
results = m.sendViewedReceipt(recipient, targetTimestamps);
} else {
throw new UserErrorException("Unknown receipt type: " + type);
}
outputResult(outputWriter, results);
}
}

View file

@ -4,14 +4,12 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
import org.asamk.signal.output.OutputWriter;
import java.io.IOException;
import java.util.Optional;
public class UpdateConfigurationCommand implements JsonRpcLocalCommand {
@ -51,8 +49,6 @@ public class UpdateConfigurationCommand implements JsonRpcLocalCommand {
Optional.ofNullable(unidentifiedDeliveryIndicators),
Optional.ofNullable(typingIndicators),
Optional.ofNullable(linkPreviews)));
} catch (IOException e) {
throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
} catch (NotPrimaryDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
}

View file

@ -136,7 +136,7 @@ public class DbusManagerImpl implements Manager {
}
@Override
public void updateConfiguration(Configuration newConfiguration) throws IOException {
public void updateConfiguration(Configuration newConfiguration) {
final var configuration = getRemoteObject(new DBusPath(signal.getObjectPath() + "/Configuration"),
Signal.Configuration.class);
newConfiguration.readReceipts()

View file

@ -351,26 +351,16 @@ public class DbusSignalImpl implements Signal {
public void sendReadReceipt(
final String recipient, final List<Long> messageIds
) throws Error.Failure, Error.UntrustedIdentity {
try {
final var results = m.sendReadReceipt(getSingleRecipientIdentifier(recipient, m.getSelfNumber()),
messageIds);
checkSendMessageResults(results);
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
final var results = m.sendReadReceipt(getSingleRecipientIdentifier(recipient, m.getSelfNumber()), messageIds);
checkSendMessageResults(results);
}
@Override
public void sendViewedReceipt(
final String recipient, final List<Long> messageIds
) throws Error.Failure, Error.UntrustedIdentity {
try {
final var results = m.sendViewedReceipt(getSingleRecipientIdentifier(recipient, m.getSelfNumber()),
messageIds);
checkSendMessageResults(results);
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
final var results = m.sendViewedReceipt(getSingleRecipientIdentifier(recipient, m.getSelfNumber()), messageIds);
checkSendMessageResults(results);
}
@Override
@ -532,8 +522,6 @@ public class DbusSignalImpl implements Signal {
m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name, "");
} catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new Error.Failure("Contact is not registered.");
} catch (UnregisteredRecipientException e) {
throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
@ -1238,8 +1226,6 @@ public class DbusSignalImpl implements Signal {
Optional.ofNullable(unidentifiedDeliveryIndicators),
Optional.ofNullable(typingIndicators),
Optional.ofNullable(linkPreviews)));
} catch (IOException e) {
throw new Error.Failure("UpdateAccount error: " + e.getMessage());
} catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
}