]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/RemoteDeleteCommand.java
1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
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
;
16 import java
.util
.List
;
18 public class RemoteDeleteCommand
implements DbusCommand
{
21 public void attachToSubparser(final Subparser subparser
) {
22 subparser
.help("Remotely delete a previously sent message.");
23 subparser
.addArgument("-t", "--target-timestamp")
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("*");
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");
36 final var noRecipients
= recipients
== null || recipients
.isEmpty();
37 if (noRecipients
&& groupIdString
== null) {
38 throw new UserErrorException("No recipients given");
40 if (!noRecipients
&& groupIdString
!= null) {
41 throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
44 final long targetTimestamp
= ns
.getLong("target_timestamp");
46 final var writer
= new PlainTextWriterImpl(System
.out
);
48 byte[] groupId
= null;
49 if (groupIdString
!= null) {
51 groupId
= Util
.decodeGroupId(groupIdString
).serialize();
52 } catch (GroupIdFormatException e
) {
53 throw new UserErrorException("Invalid group id: " + e
.getMessage());
59 if (groupId
!= null) {
60 timestamp
= signal
.sendGroupRemoteDeleteMessage(targetTimestamp
, groupId
);
62 timestamp
= signal
.sendRemoteDeleteMessage(targetTimestamp
, recipients
);
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());