Java Code Examples for org.whispersystems.signalservice.api.messages.SignalServiceDataMessage#getExpiresInSeconds()
The following examples show how to use
org.whispersystems.signalservice.api.messages.SignalServiceDataMessage#getExpiresInSeconds() .
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: PushProcessMessageJob.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private void handleGroupV1Message(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId, @NonNull GroupId.V1 groupId) throws StorageFailedException, BadGroupIdException { GroupV1MessageProcessor.process(context, content, message, false); if (message.getExpiresInSeconds() != 0 && message.getExpiresInSeconds() != getMessageDestination(content, message).getExpireMessages()) { handleExpirationUpdate(content, message, Optional.absent(), Optional.of(groupId)); } if (smsMessageId.isPresent()) { DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); } }
Example 2
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 3
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 4
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 5
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 6
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 7
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 8
Source File: PushProcessMessageJob.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void handleExpirationUpdate(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId, @NonNull Optional<GroupId> groupId) throws StorageFailedException, BadGroupIdException { if (groupId.isPresent() && groupId.get().isV2()) { Log.w(TAG, "Expiration update received for GV2. Ignoring."); return; } int expiresInSeconds = message.getExpiresInSeconds(); Optional<SignalServiceGroupContext> groupContext = message.getGroupContext(); Recipient recipient = getMessageDestination(content, groupContext); if (recipient.getExpireMessages() == expiresInSeconds) { Log.i(TAG, "No change in message expiry for group. Ignoring."); return; } try { MmsDatabase database = DatabaseFactory.getMmsDatabase(context); Recipient sender = Recipient.externalPush(context, content.getSender()); IncomingMediaMessage mediaMessage = new IncomingMediaMessage(sender.getId(), content.getTimestamp(), content.getServerTimestamp(), -1, expiresInSeconds * 1000L, true, false, content.isNeedsReceipt(), Optional.absent(), groupContext, Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()); database.insertSecureDecryptedMessageInbox(mediaMessage, -1); DatabaseFactory.getRecipientDatabase(context).setExpireMessages(recipient.getId(), expiresInSeconds); if (smsMessageId.isPresent()) { DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); } } catch (MmsException e) { throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice()); } }
Example 9
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 10
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 11
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)); } } } }