use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by WhisperSystems.
the class DirectoryHelper method notifyNewUsers.
private static void notifyNewUsers(@NonNull Context context, @NonNull Collection<RecipientId> newUsers) {
if (!SignalStore.settings().isNotifyWhenContactJoinsSignal())
return;
for (RecipientId newUser : newUsers) {
Recipient recipient = Recipient.resolved(newUser);
if (!recipient.isSelf() && recipient.hasAUserSetDisplayName(context) && !hasSession(recipient.getId())) {
IncomingJoinedMessage message = new IncomingJoinedMessage(recipient.getId());
Optional<InsertResult> insertResult = SignalDatabase.sms().insertMessageInbox(message);
if (insertResult.isPresent()) {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if (hour >= 9 && hour < 23) {
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId(), true);
} else {
Log.i(TAG, "Not notifying of a new user due to the time of day. (Hour: " + hour + ")");
}
}
}
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by WhisperSystems.
the class SmsReceiveJob method onRun.
@Override
public void onRun() throws MigrationPendingException, RetryLaterException {
Optional<IncomingTextMessage> message = assembleMessageFragments(pdus, subscriptionId);
if (SignalStore.account().getE164() == null) {
Log.i(TAG, "Received an SMS before we're registered...");
if (message.isPresent()) {
Optional<String> token = VerificationCodeParser.parse(message.get().getMessageBody());
if (token.isPresent()) {
Log.i(TAG, "Received something that looks like a registration SMS. Posting a notification and broadcast.");
NotificationManager manager = ServiceUtil.getNotificationManager(context);
Notification notification = buildPreRegistrationNotification(context, message.get());
manager.notify(NotificationIds.PRE_REGISTRATION_SMS, notification);
Intent smsRetrieverIntent = buildSmsRetrieverIntent(message.get());
context.sendBroadcast(smsRetrieverIntent);
return;
} else {
Log.w(TAG, "Received an SMS before registration is complete. We'll try again later.");
throw new RetryLaterException();
}
} else {
Log.w(TAG, "Received an SMS before registration is complete, but couldn't assemble the message anyway. Ignoring.");
return;
}
}
if (message.isPresent() && !isBlocked(message.get())) {
Optional<InsertResult> insertResult = storeMessage(message.get());
if (insertResult.isPresent()) {
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
}
} else if (message.isPresent()) {
Log.w(TAG, "*** Received blocked SMS, ignoring...");
} else {
Log.w(TAG, "*** Failed to assemble message fragments!");
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method handleMediaMessage.
@Nullable
private MessageId handleMediaMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId, @NonNull Recipient senderRecipient, @NonNull Recipient threadRecipient, long receivedTime) throws StorageFailedException {
log(message.getTimestamp(), "Media message.");
notifyTypingStoppedFromIncomingMessage(senderRecipient, threadRecipient, content.getSenderDevice());
Optional<InsertResult> insertResult;
MessageDatabase database = SignalDatabase.mms();
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<List<Mention>> mentions = getMentions(message.getMentions());
Optional<Attachment> sticker = getStickerAttachment(message.getSticker());
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(senderRecipient.getId(), message.getTimestamp(), content.getServerReceivedTimestamp(), receivedTime, -1, TimeUnit.SECONDS.toMillis(message.getExpiresInSeconds()), false, message.isViewOnce(), content.isNeedsReceipt(), message.getBody(), message.getGroupContext(), message.getAttachments(), quote, sharedContacts, linkPreviews, mentions, sticker, content.getServerUuid());
insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1);
if (insertResult.isPresent()) {
if (smsMessageId.isPresent()) {
SignalDatabase.sms().deleteMessage(smsMessageId.get());
}
database.setTransactionSuccessful();
}
} catch (MmsException e) {
throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice());
} finally {
database.endTransaction();
}
if (insertResult.isPresent()) {
List<DatabaseAttachment> allAttachments = SignalDatabase.attachments().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(insertResult.get().getMessageId(), stickerAttachments);
for (DatabaseAttachment attachment : attachments) {
ApplicationDependencies.getJobManager().add(new AttachmentDownloadJob(insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
}
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
TrimThreadJob.enqueueAsync(insertResult.get().getThreadId());
if (message.isViewOnce()) {
ApplicationDependencies.getViewOnceMessageManager().scheduleIfNecessary();
}
return new MessageId(insertResult.get().getMessageId(), true);
} else {
return null;
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method handleEndSessionMessage.
@Nullable
private MessageId handleEndSessionMessage(@NonNull SignalServiceContent content, @NonNull Optional<Long> smsMessageId, @NonNull Recipient senderRecipient) {
log(content.getTimestamp(), "End session message.");
MessageDatabase smsDatabase = SignalDatabase.sms();
IncomingTextMessage incomingTextMessage = new IncomingTextMessage(senderRecipient.getId(), content.getSenderDevice(), content.getTimestamp(), content.getServerReceivedTimestamp(), System.currentTimeMillis(), "", Optional.absent(), 0, content.isNeedsReceipt(), content.getServerUuid());
Optional<InsertResult> insertResult;
if (!smsMessageId.isPresent()) {
IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
insertResult = smsDatabase.insertMessageInbox(incomingEndSessionMessage);
} else {
smsDatabase.markAsEndSession(smsMessageId.get());
insertResult = Optional.of(new InsertResult(smsMessageId.get(), smsDatabase.getThreadIdForMessage(smsMessageId.get())));
}
if (insertResult.isPresent()) {
ApplicationDependencies.getProtocolStore().aci().deleteAllSessions(content.getSender().getIdentifier());
SecurityEvent.broadcastSecurityUpdateEvent(context);
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
return new MessageId(insertResult.get().getMessageId(), true);
} else {
return null;
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase.InsertResult in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method handleCorruptMessage.
private void handleCorruptMessage(@NonNull String sender, int senderDevice, long timestamp, @NonNull Optional<Long> smsMessageId) {
log(timestamp, "Corrupt message.");
MessageDatabase smsDatabase = SignalDatabase.sms();
if (!smsMessageId.isPresent()) {
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
if (insertResult.isPresent()) {
smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId());
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
}
} else {
smsDatabase.markAsDecryptFailed(smsMessageId.get());
}
}
Aggregations