org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage Java Examples
The following examples show how to use
org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalServiceMessageSender.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private byte[] createTypingContent(SignalServiceTypingMessage message) { Content.Builder container = Content.newBuilder(); TypingMessage.Builder builder = TypingMessage.newBuilder(); builder.setTimestamp(message.getTimestamp()); if (message.isTypingStarted()) builder.setAction(TypingMessage.Action.STARTED); else if (message.isTypingStopped()) builder.setAction(TypingMessage.Action.STOPPED); else throw new IllegalArgumentException("Unknown typing indicator"); if (message.getGroupId().isPresent()) { builder.setGroupId(ByteString.copyFrom(message.getGroupId().get())); } return container.setTypingMessage(builder).build().toByteArray(); }
Example #2
Source File: SignalServiceMessageSender.java From libsignal-service-java with GNU General Public License v3.0 | 6 votes |
private byte[] createTypingContent(SignalServiceTypingMessage message) { Content.Builder container = Content.newBuilder(); TypingMessage.Builder builder = TypingMessage.newBuilder(); builder.setTimestamp(message.getTimestamp()); if (message.isTypingStarted()) builder.setAction(TypingMessage.Action.STARTED); else if (message.isTypingStopped()) builder.setAction(TypingMessage.Action.STOPPED); else throw new IllegalArgumentException("Unknown typing indicator"); if (message.getGroupId().isPresent()) { builder.setGroupId(ByteString.copyFrom(message.getGroupId().get())); } return container.setTypingMessage(builder).build().toByteArray(); }
Example #3
Source File: SignalServiceCipher.java From libsignal-service-java with GNU General Public License v3.0 | 6 votes |
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()); }
Example #4
Source File: SignalServiceMessageSender.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
/** * Send a typing indicator. * * @param recipient The destination * @param message The typing indicator to deliver * @throws IOException * @throws UntrustedIdentityException */ public void sendTyping(SignalServiceAddress recipient, Optional<UnidentifiedAccessPair> unidentifiedAccess, SignalServiceTypingMessage message) throws IOException, UntrustedIdentityException { byte[] content = createTypingContent(message); sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true); }
Example #5
Source File: SignalServiceMessageSender.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void sendTyping(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccessPair>> unidentifiedAccess, SignalServiceTypingMessage message) throws IOException { byte[] content = createTypingContent(message); sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true); }
Example #6
Source File: PushProcessMessageJob.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private void handleTypingMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceTypingMessage typingMessage) throws BadGroupIdException { if (!TextSecurePreferences.isTypingIndicatorsEnabled(context)) { return; } Recipient author = Recipient.externalPush(context, content.getSender()); long threadId; if (typingMessage.getGroupId().isPresent()) { GroupId.Push groupId = GroupId.push(typingMessage.getGroupId().get()); if (!DatabaseFactory.getGroupDatabase(context).isCurrentMember(groupId, author.getId())) { Log.w(TAG, "Seen typing indicator for non-member"); return; } Recipient groupRecipient = Recipient.externalGroup(context, groupId); threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient); } else { threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(author); } if (threadId <= 0) { Log.w(TAG, "Couldn't find a matching thread for a typing message."); return; } if (typingMessage.isTypingStarted()) { Log.d(TAG, "Typing started on thread " + threadId); ApplicationContext.getInstance(context).getTypingStatusRepository().onTypingStarted(context,threadId, author, content.getSenderDevice()); } else { Log.d(TAG, "Typing stopped on thread " + threadId); ApplicationContext.getInstance(context).getTypingStatusRepository().onTypingStopped(context, threadId, author, content.getSenderDevice(), false); } }
Example #7
Source File: TypingSendJob.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public void onRun() throws Exception { if (!TextSecurePreferences.isTypingIndicatorsEnabled(context)) { return; } Log.d(TAG, "Sending typing " + (typing ? "started" : "stopped") + " for thread " + threadId); Recipient recipient = DatabaseFactory.getThreadDatabase(context).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."); } List<Recipient> recipients = Collections.singletonList(recipient); Optional<byte[]> groupId = Optional.absent(); if (recipient.isGroup()) { recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF); groupId = Optional.of(recipient.requireGroupId().getDecodedId()); } recipients = Stream.of(recipients).map(Recipient::resolve).toList(); SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender(); List<SignalServiceAddress> addresses = Stream.of(recipients).map(r -> RecipientUtil.toSignalServiceAddress(context, r)).toList(); List<Optional<UnidentifiedAccessPair>> unidentifiedAccess = Stream.of(recipients).map(r -> UnidentifiedAccessUtil.getAccessFor(context, r)).toList(); SignalServiceTypingMessage typingMessage = new SignalServiceTypingMessage(typing ? Action.STARTED : Action.STOPPED, System.currentTimeMillis(), groupId); messageSender.sendTyping(addresses, unidentifiedAccess, typingMessage); }
Example #8
Source File: JsonTypingMessage.java From signald with GNU General Public License v3.0 | 5 votes |
JsonTypingMessage(SignalServiceTypingMessage typingMessage) { action = typingMessage.getAction().name(); timestamp = typingMessage.getTimestamp(); if(typingMessage.getGroupId().isPresent()) { groupId = Base64.encodeBytes(typingMessage.getGroupId().get()); } }
Example #9
Source File: SignalServiceMessageSender.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
/** * Send a typing indicator. * * @param recipient The destination * @param message The typing indicator to deliver * @throws IOException * @throws UntrustedIdentityException */ public void sendTyping(SignalServiceAddress recipient, Optional<UnidentifiedAccessPair> unidentifiedAccess, SignalServiceTypingMessage message) throws IOException, UntrustedIdentityException { byte[] content = createTypingContent(message); sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true); }
Example #10
Source File: SignalServiceMessageSender.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
public void sendTyping(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccessPair>> unidentifiedAccess, SignalServiceTypingMessage message) throws IOException { byte[] content = createTypingContent(message); sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), message.getTimestamp(), content, true); }