use of org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage in project libsignal-service-java by signalapp.
the class SignalServiceCipher method createTypingMessage.
private SignalServiceTypingMessage createTypingMessage(Metadata metadata, TypingMessage content) throws ProtocolInvalidMessageException {
SignalServiceTypingMessage.Action action;
if (content.getAction() == TypingMessage.Action.STARTED)
action = SignalServiceTypingMessage.Action.STARTED;
else if (content.getAction() == TypingMessage.Action.STOPPED)
action = SignalServiceTypingMessage.Action.STOPPED;
else
action = SignalServiceTypingMessage.Action.UNKNOWN;
if (content.hasTimestamp() && content.getTimestamp() != metadata.getTimestamp()) {
throw new ProtocolInvalidMessageException(new InvalidMessageException("Timestamps don't match: " + content.getTimestamp() + " vs " + metadata.getTimestamp()), metadata.getSender().getIdentifier(), metadata.getSenderDevice());
}
return new SignalServiceTypingMessage(action, content.getTimestamp(), content.hasGroupId() ? Optional.of(content.getGroupId().toByteArray()) : Optional.<byte[]>absent());
}
use of org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage in project Signal-Android by signalapp.
the class TypingSendJob method onRun.
@Override
public void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
if (!TextSecurePreferences.isTypingIndicatorsEnabled(context)) {
return;
}
Log.d(TAG, "Sending typing " + (typing ? "started" : "stopped") + " for thread " + threadId);
Recipient recipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
if (recipient == null) {
Log.w(TAG, "Tried to send a typing indicator to a non-existent thread.");
return;
}
if (recipient.isBlocked()) {
Log.w(TAG, "Not sending typing indicators to blocked recipients.");
return;
}
if (recipient.isSelf()) {
Log.w(TAG, "Not sending typing indicators to self.");
return;
}
if (recipient.isPushV1Group() || recipient.isMmsGroup()) {
Log.w(TAG, "Not sending typing indicators to unsupported groups.");
return;
}
if (!recipient.isRegistered() || recipient.isForceSmsSelection()) {
Log.w(TAG, "Not sending typing indicators to non-Signal recipients.");
return;
}
List<Recipient> recipients = Collections.singletonList(recipient);
Optional<byte[]> groupId = Optional.absent();
if (recipient.isGroup()) {
recipients = SignalDatabase.groups().getGroupMembers(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
groupId = Optional.of(recipient.requireGroupId().getDecodedId());
}
recipients = RecipientUtil.getEligibleForSending(Stream.of(recipients).map(Recipient::resolve).filter(r -> !r.isBlocked()).toList());
SignalServiceTypingMessage typingMessage = new SignalServiceTypingMessage(typing ? Action.STARTED : Action.STOPPED, System.currentTimeMillis(), groupId);
try {
GroupSendUtil.sendTypingMessage(context, recipient.getGroupId().transform(GroupId::requireV2).orNull(), recipients, typingMessage, this::isCanceled);
} catch (CancelationException e) {
Log.w(TAG, "Canceled during send!");
}
}
use of org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage in project Signal-Android by WhisperSystems.
the class TypingSendJob method onRun.
@Override
public void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
if (!TextSecurePreferences.isTypingIndicatorsEnabled(context)) {
return;
}
Log.d(TAG, "Sending typing " + (typing ? "started" : "stopped") + " for thread " + threadId);
Recipient recipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
if (recipient == null) {
Log.w(TAG, "Tried to send a typing indicator to a non-existent thread.");
return;
}
if (recipient.isBlocked()) {
Log.w(TAG, "Not sending typing indicators to blocked recipients.");
return;
}
if (recipient.isSelf()) {
Log.w(TAG, "Not sending typing indicators to self.");
return;
}
if (recipient.isPushV1Group() || recipient.isMmsGroup()) {
Log.w(TAG, "Not sending typing indicators to unsupported groups.");
return;
}
if (!recipient.isRegistered() || recipient.isForceSmsSelection()) {
Log.w(TAG, "Not sending typing indicators to non-Signal recipients.");
return;
}
List<Recipient> recipients = Collections.singletonList(recipient);
Optional<byte[]> groupId = Optional.absent();
if (recipient.isGroup()) {
recipients = SignalDatabase.groups().getGroupMembers(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
groupId = Optional.of(recipient.requireGroupId().getDecodedId());
}
recipients = RecipientUtil.getEligibleForSending(Stream.of(recipients).map(Recipient::resolve).filter(r -> !r.isBlocked()).toList());
SignalServiceTypingMessage typingMessage = new SignalServiceTypingMessage(typing ? Action.STARTED : Action.STOPPED, System.currentTimeMillis(), groupId);
try {
GroupSendUtil.sendTypingMessage(context, recipient.getGroupId().transform(GroupId::requireV2).orNull(), recipients, typingMessage, this::isCanceled);
} catch (CancelationException e) {
Log.w(TAG, "Canceled during send!");
}
}
Aggregations