Java Code Examples for org.whispersystems.signalservice.api.messages.SignalServiceDataMessage#getTimestamp()
The following examples show how to use
org.whispersystems.signalservice.api.messages.SignalServiceDataMessage#getTimestamp() .
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 |
/** * Send a message to a group. * * @param recipients The group members. * @param message The group message. * @throws IOException */ public List<SendMessageResult> sendMessage(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccessPair>> unidentifiedAccess, boolean isRecipientUpdate, SignalServiceDataMessage message) throws IOException, UntrustedIdentityException { byte[] content = createMessageContent(message); long timestamp = message.getTimestamp(); List<SendMessageResult> results = sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false); boolean needsSyncInResults = false; for (SendMessageResult result : results) { if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) { needsSyncInResults = true; break; } } if (needsSyncInResults || isMultiDevice.get()) { byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.<SignalServiceAddress>absent(), timestamp, results, isRecipientUpdate); sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false); } return results; }
Example 2
Source File: PushProcessMessageJob.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private void handleReaction(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message) { SignalServiceDataMessage.Reaction reaction = message.getReaction().get(); Recipient targetAuthor = Recipient.externalPush(context, reaction.getTargetAuthor()); MessageRecord targetMessage = DatabaseFactory.getMmsSmsDatabase(context).getMessageFor(reaction.getTargetSentTimestamp(), targetAuthor.getId()); if (targetMessage != null && !targetMessage.isRemoteDelete()) { Recipient reactionAuthor = Recipient.externalPush(context, content.getSender()); MessagingDatabase db = targetMessage.isMms() ? DatabaseFactory.getMmsDatabase(context) : DatabaseFactory.getSmsDatabase(context); if (reaction.isRemove()) { db.deleteReaction(targetMessage.getId(), reactionAuthor.getId()); ApplicationDependencies.getMessageNotifier().updateNotification(context); } else { ReactionRecord reactionRecord = new ReactionRecord(reaction.getEmoji(), reactionAuthor.getId(), message.getTimestamp(), System.currentTimeMillis()); db.addReaction(targetMessage.getId(), reactionRecord); ApplicationDependencies.getMessageNotifier().updateNotification(context, targetMessage.getThreadId(), false); } } else if (targetMessage != null) { Log.w(TAG, "[handleReaction] Found a matching message, but it's flagged as remotely deleted. timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId()); } else { Log.w(TAG, "[handleReaction] Could not find matching message! timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId()); ApplicationDependencies.getEarlyMessageCache().store(targetAuthor.getId(), reaction.getTargetSentTimestamp(), content); } }
Example 3
Source File: PushDecryptJob.java From bcm-android with GNU General Public License v3.0 | 6 votes |
private void handleEndSessionMessage(@NonNull SignalServiceProtos.Envelope envelope, @NonNull SignalServiceDataMessage message) { ALog.i(TAG, "handleEndSessionMessage"); PrivateChatRepo chatRepo = repository.getChatRepo(); IncomingTextMessage incomingTextMessage = new IncomingTextMessage(Address.from(accountContext, envelope.getSource()), envelope.getSourceDevice(), message.getTimestamp(), "", Optional.absent(), 0); long threadId; IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage); kotlin.Pair<Long, Long> insertResult = chatRepo.insertIncomingTextMessage(incomingEndSessionMessage); if (insertResult.getSecond() > 0) threadId = insertResult.getFirst(); else threadId = 0L; if (threadId > 0L) { SessionStore sessionStore = new TextSecureSessionStore(context, accountContext); sessionStore.deleteAllSessions(envelope.getSource()); SecurityEvent.broadcastSecurityUpdateEvent(context); } }
Example 4
Source File: PushDecryptJob.java From bcm-android with GNU General Public License v3.0 | 6 votes |
private void handleExpirationUpdate(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceProtos.Envelope envelope, @NonNull SignalServiceDataMessage message) { ALog.i(TAG, "handleExpirationUpdate"); PrivateChatRepo chatRepo = repository.getChatRepo(); Recipient recipient = getMessageDestination(envelope, message); IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, Address.from(accountContext, envelope.getSource()), message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000, true, Optional.fromNullable(envelope.getRelay()), Optional.absent(), message.getGroupInfo(), Optional.absent()); chatRepo.insertIncomingMediaMessage(masterSecret.getMasterSecret().get(), mediaMessage); repository.getRecipientRepo().setExpireTime(recipient, message.getExpiresInSeconds()); }
Example 5
Source File: SignalServiceMessageSender.java From libsignal-service-java with GNU General Public License v3.0 | 6 votes |
/** * Send a message to a group. * * @param recipients The group members. * @param message The group message. * @throws IOException */ public List<SendMessageResult> sendMessage(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccessPair>> unidentifiedAccess, boolean isRecipientUpdate, SignalServiceDataMessage message) throws IOException, UntrustedIdentityException { byte[] content = createMessageContent(message); long timestamp = message.getTimestamp(); List<SendMessageResult> results = sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false); boolean needsSyncInResults = false; for (SendMessageResult result : results) { if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) { needsSyncInResults = true; break; } } if (needsSyncInResults || isMultiDevice.get()) { byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.<SignalServiceAddress>absent(), timestamp, results, isRecipientUpdate); sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false); } return results; }
Example 6
Source File: Manager.java From signal-cli with GNU General Public License v3.0 | 6 votes |
private SendMessageResult sendSelfMessage(SignalServiceDataMessage message) throws IOException { SignalServiceMessageSender messageSender = getMessageSender(); SignalServiceAddress recipient = account.getSelfAddress(); final Optional<UnidentifiedAccessPair> unidentifiedAccess = getAccessFor(recipient); SentTranscriptMessage transcript = new SentTranscriptMessage(Optional.of(recipient), message.getTimestamp(), message, message.getExpiresInSeconds(), Collections.singletonMap(recipient, unidentifiedAccess.isPresent()), false); SignalServiceSyncMessage syncMessage = SignalServiceSyncMessage.forSentTranscript(transcript); try { messageSender.sendMessage(syncMessage, unidentifiedAccess); return SendMessageResult.success(recipient, unidentifiedAccess.isPresent(), false); } catch (UntrustedIdentityException e) { account.getSignalProtocolStore().saveIdentity(resolveSignalServiceAddress(e.getIdentifier()), e.getIdentityKey(), TrustLevel.UNTRUSTED); return SendMessageResult.identityFailure(recipient, e.getIdentityKey()); } }
Example 7
Source File: JsonDataMessage.java From signal-cli with GNU General Public License v3.0 | 6 votes |
JsonDataMessage(SignalServiceDataMessage dataMessage) { this.timestamp = dataMessage.getTimestamp(); if (dataMessage.getGroupContext().isPresent() && dataMessage.getGroupContext().get().getGroupV1().isPresent()) { SignalServiceGroup groupInfo = dataMessage.getGroupContext().get().getGroupV1().get(); this.groupInfo = new JsonGroupInfo(groupInfo); } if (dataMessage.getBody().isPresent()) { this.message = dataMessage.getBody().get(); } this.expiresInSeconds = dataMessage.getExpiresInSeconds(); if (dataMessage.getAttachments().isPresent()) { this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size()); for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) { this.attachments.add(new JsonAttachment(attachment)); } } else { this.attachments = new ArrayList<>(); } }
Example 8
Source File: SignalServiceMessageSender.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
/** * Send a message to a single recipient. * * @param recipient The message's destination. * @param message The message. * @throws UntrustedIdentityException * @throws IOException */ public SendMessageResult sendMessage(SignalServiceAddress recipient, Optional<UnidentifiedAccessPair> unidentifiedAccess, SignalServiceDataMessage message) throws UntrustedIdentityException, IOException { byte[] content = createMessageContent(message); long timestamp = message.getTimestamp(); SendMessageResult result = sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false); if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) { byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.of(recipient), timestamp, Collections.singletonList(result), false); sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false); } if (message.isEndSession()) { if (recipient.getUuid().isPresent()) { store.deleteAllSessions(recipient.getUuid().get().toString()); } if (recipient.getNumber().isPresent()) { store.deleteAllSessions(recipient.getNumber().get()); } if (eventListener.isPresent()) { eventListener.get().onSecurityEvent(recipient); } } return result; }
Example 9
Source File: PushSendJob.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
protected SignalServiceSyncMessage buildSelfSendSyncMessage(@NonNull Context context, @NonNull SignalServiceDataMessage message, Optional<UnidentifiedAccessPair> syncAccess) { SignalServiceAddress localAddress = new SignalServiceAddress(TextSecurePreferences.getLocalUuid(context), TextSecurePreferences.getLocalNumber(context)); SentTranscriptMessage transcript = new SentTranscriptMessage(Optional.of(localAddress), message.getTimestamp(), message, message.getExpiresInSeconds(), Collections.singletonMap(localAddress, syncAccess.isPresent()), false); return SignalServiceSyncMessage.forSentTranscript(transcript); }
Example 10
Source File: PushDecryptJob.java From bcm-android with GNU General Public License v3.0 | 5 votes |
private void handleTextMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceProtos.Envelope envelope, @NonNull SignalServiceDataMessage message) { ALog.i(TAG, "handleTextMessage"); PrivateChatRepo chatRepo = repository.getChatRepo(); String body = message.getBody().isPresent() ? message.getBody().get() : ""; Recipient recipient = getMessageDestination(envelope, message); if (message.getExpiresInSeconds() != recipient.getExpireMessages()) { handleExpirationUpdate(masterSecret, envelope, message); } if (recipient.getAddress().isIndividual()) { AmePushProcess.INSTANCE.processPush(accountContext, new AmePushProcess.BcmData(new AmePushProcess.BcmNotify(AmePushProcess.CHAT_NOTIFY, 0, new AmePushProcess.ChatNotifyData(recipient.getAddress().serialize()), null, null, null, null))); } long expiresIn = 0; if (recipient.getExpireMessages() > 0) { expiresIn = recipient.getExpireMessages() * 1000; } else if (AmeConfigure.INSTANCE.isOutgoingAutoDelete()) { expiresIn = message.getExpiresInSeconds() * 1000; } IncomingTextMessage textMessage = new IncomingTextMessage(Address.from(accountContext, envelope.getSource()), envelope.getSourceDevice(), message.getTimestamp(), body, message.getGroupInfo(), expiresIn); textMessage = new IncomingEncryptedMessage(textMessage, body); chatRepo.insertIncomingTextMessage(textMessage); }
Example 11
Source File: JsonDataMessage.java From signald with GNU General Public License v3.0 | 5 votes |
JsonDataMessage(SignalServiceDataMessage dataMessage, String username) throws IOException, NoSuchAccountException { this.timestamp = dataMessage.getTimestamp(); if (dataMessage.getGroupInfo().isPresent()) { this.groupInfo = new JsonGroupInfo(dataMessage.getGroupInfo().get(), username); } if (dataMessage.getBody().isPresent()) { this.message = dataMessage.getBody().get(); } this.expiresInSeconds = dataMessage.getExpiresInSeconds(); if (dataMessage.getAttachments().isPresent()) { this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size()); for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) { this.attachments.add(new JsonAttachment(attachment, username)); } } else { this.attachments = new ArrayList<>(); } if(dataMessage.getQuote().isPresent()) { this.quote = dataMessage.getQuote().get(); } if(dataMessage.getPreviews().isPresent()) { previews = new ArrayList<JsonPreview>(); for(SignalServiceDataMessage.Preview p : dataMessage.getPreviews().get()) { previews.add(new JsonPreview(p, username)); } } if(dataMessage.getSticker().isPresent()) { this.sticker = new JsonSticker(dataMessage.getSticker().get(), username); } }
Example 12
Source File: SignalServiceMessageSender.java From libsignal-service-java with GNU General Public License v3.0 | 5 votes |
/** * Send a message to a single recipient. * * @param recipient The message's destination. * @param message The message. * @throws UntrustedIdentityException * @throws IOException */ public SendMessageResult sendMessage(SignalServiceAddress recipient, Optional<UnidentifiedAccessPair> unidentifiedAccess, SignalServiceDataMessage message) throws UntrustedIdentityException, IOException { byte[] content = createMessageContent(message); long timestamp = message.getTimestamp(); SendMessageResult result = sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, content, false); if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) { byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, Optional.of(recipient), timestamp, Collections.singletonList(result), false); sendMessage(localAddress, Optional.<UnidentifiedAccess>absent(), timestamp, syncMessage, false); } if (message.isEndSession()) { if (recipient.getUuid().isPresent()) { store.deleteAllSessions(recipient.getUuid().get().toString()); } if (recipient.getNumber().isPresent()) { store.deleteAllSessions(recipient.getNumber().get()); } if (eventListener.isPresent()) { eventListener.get().onSecurityEvent(recipient); } } return result; }
Example 13
Source File: PushProcessMessageJob.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void handleMediaMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws StorageFailedException, BadGroupIdException { notifyTypingStoppedFromIncomingMessage(getMessageDestination(content, message), content.getSender(), content.getSenderDevice()); Optional<InsertResult> insertResult; MmsDatabase database = DatabaseFactory.getMmsDatabase(context); database.beginTransaction(); try { Optional<QuoteModel> quote = getValidatedQuote(message.getQuote()); Optional<List<Contact>> sharedContacts = getContacts(message.getSharedContacts()); Optional<List<LinkPreview>> linkPreviews = getLinkPreviews(message.getPreviews(), message.getBody().or("")); Optional<Attachment> sticker = getStickerAttachment(message.getSticker()); IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Recipient.externalPush(context, content.getSender()).getId(), message.getTimestamp(), content.getServerTimestamp(), -1, message.getExpiresInSeconds() * 1000L, false, message.isViewOnce(), content.isNeedsReceipt(), message.getBody(), message.getGroupContext(), message.getAttachments(), quote, sharedContacts, linkPreviews, sticker); insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1); if (insertResult.isPresent()) { List<DatabaseAttachment> allAttachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId()); List<DatabaseAttachment> stickerAttachments = Stream.of(allAttachments).filter(Attachment::isSticker).toList(); List<DatabaseAttachment> attachments = Stream.of(allAttachments).filterNot(Attachment::isSticker).toList(); forceStickerDownloadIfNecessary(stickerAttachments); for (DatabaseAttachment attachment : attachments) { ApplicationDependencies.getJobManager().add(new AttachmentDownloadJob(insertResult.get().getMessageId(), attachment.getAttachmentId(), false)); } if (smsMessageId.isPresent()) { DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); } database.setTransactionSuccessful(); } } catch (MmsException e) { throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice()); } finally { database.endTransaction(); } if (insertResult.isPresent()) { ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId()); if (message.isViewOnce()) { ApplicationContext.getInstance(context).getViewOnceMessageManager().scheduleIfNecessary(); } } }
Example 14
Source File: PushProcessMessageJob.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void handleTextMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId, @NonNull Optional<GroupId> groupId) throws StorageFailedException, BadGroupIdException { SmsDatabase database = DatabaseFactory.getSmsDatabase(context); String body = message.getBody().isPresent() ? message.getBody().get() : ""; Recipient recipient = getMessageDestination(content, message); if (message.getExpiresInSeconds() != recipient.getExpireMessages()) { handleExpirationUpdate(content, message, Optional.absent(), groupId); } Long threadId; if (smsMessageId.isPresent() && !message.getGroupContext().isPresent()) { threadId = database.updateBundleMessageBody(smsMessageId.get(), body).second; } else { notifyTypingStoppedFromIncomingMessage(recipient, content.getSender(), content.getSenderDevice()); IncomingTextMessage textMessage = new IncomingTextMessage(Recipient.externalPush(context, content.getSender()).getId(), content.getSenderDevice(), message.getTimestamp(), content.getServerTimestamp(), body, groupId, message.getExpiresInSeconds() * 1000L, content.isNeedsReceipt()); textMessage = new IncomingEncryptedMessage(textMessage, body); Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage); if (insertResult.isPresent()) threadId = insertResult.get().getThreadId(); else threadId = null; if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get()); } if (threadId != null) { ApplicationDependencies.getMessageNotifier().updateNotification(context, threadId); } }
Example 15
Source File: PushDecryptJob.java From bcm-android with GNU General Public License v3.0 | 4 votes |
private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceProtos.Envelope envelope, @NonNull SignalServiceDataMessage message) { ALog.i(TAG, "handleMediaMessage"); PrivateChatRepo chatRepo = repository.getChatRepo(); Recipient recipient = getMessageDestination(envelope, message); long expiresIn = 0; if (recipient.getExpireMessages() > 0) { expiresIn = recipient.getExpireMessages() * 1000; } if (AmeConfigure.INSTANCE.isOutgoingAutoDelete()) { expiresIn = message.getExpiresInSeconds() * 1000; } IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, Address.from(accountContext, envelope.getSource()), message.getTimestamp(), -1, expiresIn, false, Optional.fromNullable(envelope.getRelay()), message.getBody(), message.getGroupInfo(), message.getAttachments()); if (message.getExpiresInSeconds() != recipient.getExpireMessages()) { handleExpirationUpdate(masterSecret, envelope, message); } if (recipient.getAddress().isIndividual()) { AmePushProcess.INSTANCE.processPush(accountContext, new AmePushProcess.BcmData(new AmePushProcess.BcmNotify(AmePushProcess.CHAT_NOTIFY, 0, new AmePushProcess.ChatNotifyData(recipient.getAddress().serialize()), null, null, null, null))); } kotlin.Pair<Long, Long> insertResult = chatRepo.insertIncomingMediaMessage(masterSecret.getMasterSecret().get(), mediaMessage); List<AttachmentRecord> attachments = repository.getAttachmentRepo().getAttachments(insertResult.getSecond()); JobManager manager = AmeModuleCenter.INSTANCE.accountJobMgr(accountContext); if (manager != null) { for (AttachmentRecord attachment : attachments) { manager.add(new AttachmentDownloadJob(context, accountContext, insertResult.getSecond(), attachment.getId(), attachment.getUniqueId(), false)); if (!masterSecret.getMasterSecret().isPresent()) { manager.add(new AttachmentFileNameJob(context, accountContext, masterSecret.getAsymmetricMasterSecret().get(), attachment, mediaMessage)); } } } }