package org.asamk.signal.manager;
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.ServiceEnvironment;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.SignalSessionLock;
+import org.whispersystems.signalservice.api.crypto.ContentHint;
import org.whispersystems.signalservice.api.crypto.SignalServiceCipher;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
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.ContactsMessage;
import org.whispersystems.signalservice.api.messages.multidevice.DeviceContact;
private void sendSyncMessage(SignalServiceSyncMessage message) throws IOException, UntrustedIdentityException {
var messageSender = createMessageSender();
- messageSender.sendMessage(message, unidentifiedAccessHelper.getAccessForSync());
+ messageSender.sendSyncMessage(message, unidentifiedAccessHelper.getAccessForSync());
}
private Set<RecipientId> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException {
}
}
+ 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(
SignalServiceDataMessage.Builder messageBuilder, Set<RecipientId> recipientIds
) throws IOException {
final var addresses = recipientIdList.stream()
.map(this::resolveSignalServiceAddress)
.collect(Collectors.toList());
- var result = messageSender.sendMessage(addresses,
+ var result = messageSender.sendDataMessage(addresses,
unidentifiedAccessHelper.getAccessFor(recipientIdList),
isRecipientUpdate,
+ ContentHint.DEFAULT,
message);
for (var r : result) {
try {
var startTime = System.currentTimeMillis();
- messageSender.sendMessage(syncMessage, unidentifiedAccess);
+ messageSender.sendSyncMessage(syncMessage, unidentifiedAccess);
return SendMessageResult.success(recipient,
unidentifiedAccess.isPresent(),
false,
final var address = resolveSignalServiceAddress(recipientId);
try {
try {
- return messageSender.sendMessage(address, unidentifiedAccessHelper.getAccessFor(recipientId), message);
+ return messageSender.sendDataMessage(address,
+ unidentifiedAccessHelper.getAccessFor(recipientId),
+ ContentHint.DEFAULT,
+ message);
} catch (UnregisteredUserException e) {
final var newRecipientId = refreshRegisteredUser(recipientId);
- return messageSender.sendMessage(resolveSignalServiceAddress(newRecipientId),
+ return messageSender.sendDataMessage(resolveSignalServiceAddress(newRecipientId),
unidentifiedAccessHelper.getAccessFor(newRecipientId),
+ ContentHint.DEFAULT,
message);
}
} catch (UntrustedIdentityException e) {