Java Code Examples for org.whispersystems.signalservice.api.messages.SignalServiceContent#getSenderDevice()
The following examples show how to use
org.whispersystems.signalservice.api.messages.SignalServiceContent#getSenderDevice() .
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 | 5 votes |
private void handleEndSessionMessage(@NonNull SignalServiceContent content, @NonNull Optional<Long> smsMessageId) { SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); IncomingTextMessage incomingTextMessage = new IncomingTextMessage(Recipient.externalPush(context, content.getSender()).getId(), content.getSenderDevice(), content.getTimestamp(), content.getServerTimestamp(), "", Optional.absent(), 0, content.isNeedsReceipt()); Long threadId; if (!smsMessageId.isPresent()) { IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage); Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(incomingEndSessionMessage); if (insertResult.isPresent()) threadId = insertResult.get().getThreadId(); else threadId = null; } else { smsDatabase.markAsEndSession(smsMessageId.get()); threadId = smsDatabase.getThreadIdForMessage(smsMessageId.get()); } if (threadId != null) { SessionStore sessionStore = new TextSecureSessionStore(context); sessionStore.deleteAllSessions(content.getSender().getIdentifier()); SecurityEvent.broadcastSecurityUpdateEvent(context); ApplicationDependencies.getMessageNotifier().updateNotification(context, threadId); } }
Example 2
Source File: JsonMessageEnvelope.java From signal-cli with GNU General Public License v3.0 | 5 votes |
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content) { if (!envelope.isUnidentifiedSender() && envelope.hasSource()) { SignalServiceAddress source = envelope.getSourceAddress(); this.source = source.getNumber().get(); this.relay = source.getRelay().isPresent() ? source.getRelay().get() : null; } this.sourceDevice = envelope.getSourceDevice(); this.timestamp = envelope.getTimestamp(); this.isReceipt = envelope.isReceipt(); if (content != null) { if (envelope.isUnidentifiedSender()) { this.source = content.getSender().getNumber().get(); this.sourceDevice = content.getSenderDevice(); } if (content.getDataMessage().isPresent()) { this.dataMessage = new JsonDataMessage(content.getDataMessage().get()); } if (content.getSyncMessage().isPresent()) { this.syncMessage = new JsonSyncMessage(content.getSyncMessage().get()); } if (content.getCallMessage().isPresent()) { this.callMessage = new JsonCallMessage(content.getCallMessage().get()); } if (content.getReceiptMessage().isPresent()) { this.receiptMessage = new JsonReceiptMessage(content.getReceiptMessage().get()); } } }
Example 3
Source File: GroupV1MessageProcessor.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private static @Nullable Long storeMessage(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, @NonNull GroupContext storage, boolean outgoing) { if (group.getAvatar().isPresent()) { ApplicationDependencies.getJobManager() .add(new AvatarGroupsV1DownloadJob(GroupId.v1orThrow(group.getGroupId()))); } try { if (outgoing) { MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context); RecipientId recipientId = DatabaseFactory.getRecipientDatabase(context).getOrInsertFromGroupId(GroupId.v1orThrow(group.getGroupId())); Recipient recipient = Recipient.resolved(recipientId); OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(recipient, storage, null, content.getTimestamp(), 0, false, null, Collections.emptyList(), Collections.emptyList()); long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient); long messageId = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null); mmsDatabase.markAsSent(messageId, true); return threadId; } else { SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); String body = Base64.encodeBytes(storage.toByteArray()); IncomingTextMessage incoming = new IncomingTextMessage(Recipient.externalPush(context, content.getSender()).getId(), content.getSenderDevice(), content.getTimestamp(), content.getServerTimestamp(), body, Optional.of(GroupId.v1orThrow(group.getGroupId())), 0, content.isNeedsReceipt()); IncomingGroupUpdateMessage groupMessage = new IncomingGroupUpdateMessage(incoming, storage, body); Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(groupMessage); if (insertResult.isPresent()) { ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId()); return insertResult.get().getThreadId(); } else { return null; } } } catch (MmsException e) { Log.w(TAG, e); } return null; }
Example 4
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 5
Source File: PushProcessMessageJob.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void handleSynchronizeSentMessage(@NonNull SignalServiceContent content, @NonNull SentTranscriptMessage message) throws StorageFailedException, BadGroupIdException, VerificationFailedException, IOException, InvalidGroupStateException { try { GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context); Long threadId = null; if (message.isRecipientUpdate()) { handleGroupRecipientUpdate(message); } else if (message.getMessage().isEndSession()) { threadId = handleSynchronizeSentEndSessionMessage(message); } else if (message.getMessage().isGroupV1Update()) { threadId = GroupV1MessageProcessor.process(context, content, message.getMessage(), true); } else if (message.getMessage().isExpirationUpdate()) { threadId = handleSynchronizeSentExpirationUpdate(message); } else if (message.getMessage().getReaction().isPresent()) { handleReaction(content, message.getMessage()); threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(getSyncMessageDestination(message)); threadId = threadId != -1 ? threadId : null; } else if (message.getMessage().getRemoteDelete().isPresent()) { handleRemoteDelete(content, message.getMessage()); } else if (message.getMessage().getAttachments().isPresent() || message.getMessage().getQuote().isPresent() || message.getMessage().getPreviews().isPresent() || message.getMessage().getSticker().isPresent() || message.getMessage().isViewOnce()) { threadId = handleSynchronizeSentMediaMessage(message); } else { threadId = handleSynchronizeSentTextMessage(message); } if (message.getMessage().getGroupContext().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.idFromGroupContext(message.getMessage().getGroupContext().get()))) { handleUnknownGroupMessage(content, message.getMessage().getGroupContext().get()); } if (message.getMessage().getProfileKey().isPresent()) { Recipient recipient = getSyncMessageDestination(message); if (recipient != null && !recipient.isSystemContact() && !recipient.isProfileSharing()) { DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient.getId(), true); } } if (threadId != null) { DatabaseFactory.getThreadDatabase(context).setRead(threadId, true); ApplicationDependencies.getMessageNotifier().updateNotification(context); } ApplicationDependencies.getMessageNotifier().setLastDesktopActivityTimestamp(message.getTimestamp()); } catch (MmsException e) { throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice()); } }
Example 6
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 7
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); } }