]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/RemoteDeleteCommand.java
Remove error handling for oracle unlimited crypto issue
[signal-cli] / src / main / java / org / asamk / signal / commands / RemoteDeleteCommand.java
1 package org.asamk.signal.commands;
2
3 import net.sourceforge.argparse4j.inf.Namespace;
4 import net.sourceforge.argparse4j.inf.Subparser;
5
6 import org.asamk.Signal;
7 import org.asamk.signal.PlainTextWriterImpl;
8 import org.asamk.signal.commands.exceptions.CommandException;
9 import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
10 import org.asamk.signal.commands.exceptions.UserErrorException;
11 import org.asamk.signal.manager.groups.GroupIdFormatException;
12 import org.asamk.signal.util.Util;
13 import org.freedesktop.dbus.errors.UnknownObject;
14 import org.freedesktop.dbus.exceptions.DBusExecutionException;
15
16 import java.util.List;
17
18 public class RemoteDeleteCommand implements DbusCommand {
19
20 @Override
21 public void attachToSubparser(final Subparser subparser) {
22 subparser.help("Remotely delete a previously sent message.");
23 subparser.addArgument("-t", "--target-timestamp")
24 .required(true)
25 .type(long.class)
26 .help("Specify the timestamp of the message to delete.");
27 subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
28 subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
29 }
30
31 @Override
32 public void handleCommand(final Namespace ns, final Signal signal) throws CommandException {
33 final List<String> recipients = ns.getList("recipient");
34 final var groupIdString = ns.getString("group");
35
36 final var noRecipients = recipients == null || recipients.isEmpty();
37 if (noRecipients && groupIdString == null) {
38 throw new UserErrorException("No recipients given");
39 }
40 if (!noRecipients && groupIdString != null) {
41 throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
42 }
43
44 final long targetTimestamp = ns.getLong("target_timestamp");
45
46 final var writer = new PlainTextWriterImpl(System.out);
47
48 byte[] groupId = null;
49 if (groupIdString != null) {
50 try {
51 groupId = Util.decodeGroupId(groupIdString).serialize();
52 } catch (GroupIdFormatException e) {
53 throw new UserErrorException("Invalid group id: " + e.getMessage());
54 }
55 }
56
57 try {
58 long timestamp;
59 if (groupId != null) {
60 timestamp = signal.sendGroupRemoteDeleteMessage(targetTimestamp, groupId);
61 } else {
62 timestamp = signal.sendRemoteDeleteMessage(targetTimestamp, recipients);
63 }
64 writer.println("{}", timestamp);
65 } catch (UnknownObject e) {
66 throw new UserErrorException("Failed to find dbus object, maybe missing the -u flag: " + e.getMessage());
67 } catch (Signal.Error.InvalidNumber e) {
68 throw new UserErrorException("Invalid number: " + e.getMessage());
69 } catch (Signal.Error.GroupNotFound e) {
70 throw new UserErrorException("Failed to send to group: " + e.getMessage());
71 } catch (DBusExecutionException e) {
72 throw new UnexpectedErrorException("Failed to send message: " + e.getMessage());
73 }
74 }
75 }