mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
parent
609ebf024b
commit
7e223dc228
6 changed files with 144 additions and 2 deletions
|
@ -4,9 +4,10 @@
|
||||||
**Attention**: Now requires native libsignal-client version 0.8.1
|
**Attention**: Now requires native libsignal-client version 0.8.1
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Added new parameters to `updateGroup` for group v2 features:
|
- New parameters to `updateGroup` for group v2 features:
|
||||||
`--remove-member`, `--admin`, `--remove-admin`, `--reset-link`, `--link`, `--set-permission-add-member`, `--set-permission-edit-details`, `--expiration`
|
`--remove-member`, `--admin`, `--remove-admin`, `--reset-link`, `--link`, `--set-permission-add-member`, `--set-permission-edit-details`, `--expiration`
|
||||||
- Added new `--delete` parameter to `quitGroup`, to delete the local group data
|
- New `--delete` parameter for `quitGroup`, to delete the local group data
|
||||||
|
- New 'sendTyping' command to send typing indicators
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Prevent last admin of a group from leaving the group
|
- Prevent last admin of a group from leaving the group
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.asamk.signal.manager;
|
package org.asamk.signal.manager;
|
||||||
|
|
||||||
import org.asamk.signal.manager.api.Device;
|
import org.asamk.signal.manager.api.Device;
|
||||||
|
import org.asamk.signal.manager.api.TypingAction;
|
||||||
import org.asamk.signal.manager.config.ServiceConfig;
|
import org.asamk.signal.manager.config.ServiceConfig;
|
||||||
import org.asamk.signal.manager.config.ServiceEnvironment;
|
import org.asamk.signal.manager.config.ServiceEnvironment;
|
||||||
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
|
||||||
|
@ -106,6 +107,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
|
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContact;
|
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContact;
|
||||||
|
@ -1597,6 +1599,40 @@ public class Manager implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendTypingMessage(
|
||||||
|
TypingAction action, Set<String> recipients
|
||||||
|
) throws IOException, UntrustedIdentityException, InvalidNumberException {
|
||||||
|
sendTypingMessageInternal(action, getSignalServiceAddresses(recipients));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendTypingMessageInternal(
|
||||||
|
TypingAction action, Set<RecipientId> recipientIds
|
||||||
|
) throws IOException, UntrustedIdentityException {
|
||||||
|
final var timestamp = System.currentTimeMillis();
|
||||||
|
var message = new SignalServiceTypingMessage(action.toSignalService(), timestamp, Optional.absent());
|
||||||
|
var messageSender = createMessageSender();
|
||||||
|
for (var recipientId : recipientIds) {
|
||||||
|
final var address = resolveSignalServiceAddress(recipientId);
|
||||||
|
messageSender.sendTyping(address, unidentifiedAccessHelper.getAccessFor(recipientId), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendGroupTypingMessage(
|
||||||
|
TypingAction action, GroupId groupId
|
||||||
|
) throws IOException, NotAGroupMemberException, GroupNotFoundException {
|
||||||
|
final var timestamp = System.currentTimeMillis();
|
||||||
|
final var g = getGroupForSending(groupId);
|
||||||
|
final var message = new SignalServiceTypingMessage(action.toSignalService(),
|
||||||
|
timestamp,
|
||||||
|
Optional.of(groupId.serialize()));
|
||||||
|
final var messageSender = createMessageSender();
|
||||||
|
final var recipientIdList = new ArrayList<>(g.getMembersWithout(account.getSelfRecipientId()));
|
||||||
|
final var addresses = recipientIdList.stream()
|
||||||
|
.map(this::resolveSignalServiceAddress)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
messageSender.sendTyping(addresses, unidentifiedAccessHelper.getAccessFor(recipientIdList), message, null);
|
||||||
|
}
|
||||||
|
|
||||||
private Pair<Long, List<SendMessageResult>> sendMessage(
|
private Pair<Long, List<SendMessageResult>> sendMessage(
|
||||||
SignalServiceDataMessage.Builder messageBuilder, Set<RecipientId> recipientIds
|
SignalServiceDataMessage.Builder messageBuilder, Set<RecipientId> recipientIds
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.asamk.signal.manager.api;
|
||||||
|
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
|
||||||
|
|
||||||
|
public enum TypingAction {
|
||||||
|
START,
|
||||||
|
STOP;
|
||||||
|
|
||||||
|
public SignalServiceTypingMessage.Action toSignalService() {
|
||||||
|
switch (this) {
|
||||||
|
case START:
|
||||||
|
return SignalServiceTypingMessage.Action.STARTED;
|
||||||
|
case STOP:
|
||||||
|
return SignalServiceTypingMessage.Action.STOPPED;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Invalid typing action " + this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -199,6 +199,20 @@ Specify the timestamp of the message to which to react.
|
||||||
*-r*, *--remove*::
|
*-r*, *--remove*::
|
||||||
Remove a reaction.
|
Remove a reaction.
|
||||||
|
|
||||||
|
=== sendTyping
|
||||||
|
|
||||||
|
Send typing message to trigger a typing indicator for the recipient.
|
||||||
|
Indicator will be shown for 15seconds unless a typing STOP message is sent first.
|
||||||
|
|
||||||
|
RECIPIENT::
|
||||||
|
Specify the recipients’ phone number.
|
||||||
|
|
||||||
|
*-g* GROUP, *--group* GROUP::
|
||||||
|
Specify the recipient group ID in base64 encoding.
|
||||||
|
|
||||||
|
*-s*, *--stop*::
|
||||||
|
Send a typing STOP message.
|
||||||
|
|
||||||
=== remoteDelete
|
=== remoteDelete
|
||||||
|
|
||||||
Remotely delete a previously sent message.
|
Remotely delete a previously sent message.
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class Commands {
|
||||||
addCommand("sendContacts", new SendContactsCommand());
|
addCommand("sendContacts", new SendContactsCommand());
|
||||||
addCommand("sendReaction", new SendReactionCommand());
|
addCommand("sendReaction", new SendReactionCommand());
|
||||||
addCommand("sendSyncRequest", new SendSyncRequestCommand());
|
addCommand("sendSyncRequest", new SendSyncRequestCommand());
|
||||||
|
addCommand("sendTyping", new SendTypingCommand());
|
||||||
addCommand("setPin", new SetPinCommand());
|
addCommand("setPin", new SetPinCommand());
|
||||||
addCommand("trust", new TrustCommand());
|
addCommand("trust", new TrustCommand());
|
||||||
addCommand("unblock", new UnblockCommand());
|
addCommand("unblock", new UnblockCommand());
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package org.asamk.signal.commands;
|
||||||
|
|
||||||
|
import net.sourceforge.argparse4j.impl.Arguments;
|
||||||
|
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.UserErrorException;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.api.TypingAction;
|
||||||
|
import org.asamk.signal.manager.groups.GroupId;
|
||||||
|
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||||
|
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||||
|
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||||
|
import org.asamk.signal.util.Util;
|
||||||
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class SendTypingCommand implements LocalCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
|
subparser.help(
|
||||||
|
"Send typing message to trigger a typing indicator for the recipient. Indicator will be shown for 15seconds unless a typing STOP message is sent first.");
|
||||||
|
subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
|
||||||
|
subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
|
||||||
|
subparser.addArgument("-s", "--stop").help("Send a typing STOP message.").action(Arguments.storeTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
|
||||||
|
final var recipients = ns.<String>getList("recipient");
|
||||||
|
final var groupIdString = ns.getString("group");
|
||||||
|
|
||||||
|
final var noRecipients = recipients == null || recipients.isEmpty();
|
||||||
|
if (noRecipients && groupIdString == null) {
|
||||||
|
throw new UserErrorException("No recipients given");
|
||||||
|
}
|
||||||
|
if (!noRecipients && groupIdString != null) {
|
||||||
|
throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
|
||||||
|
}
|
||||||
|
|
||||||
|
final var action = ns.getBoolean("stop") ? TypingAction.STOP : TypingAction.START;
|
||||||
|
|
||||||
|
GroupId groupId = null;
|
||||||
|
if (groupIdString != null) {
|
||||||
|
try {
|
||||||
|
groupId = Util.decodeGroupId(groupIdString);
|
||||||
|
} catch (GroupIdFormatException e) {
|
||||||
|
throw new UserErrorException("Invalid group id: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (groupId != null) {
|
||||||
|
m.sendGroupTypingMessage(action, groupId);
|
||||||
|
} else {
|
||||||
|
m.sendTypingMessage(action, new HashSet<>(recipients));
|
||||||
|
}
|
||||||
|
} catch (IOException | UntrustedIdentityException e) {
|
||||||
|
throw new UserErrorException("Failed to send message: " + e.getMessage());
|
||||||
|
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||||
|
throw new UserErrorException("Failed to send to group: " + e.getMessage());
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new UserErrorException("Invalid number: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue