Search in sources :

Example 16 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method handleProfileKey.

private void handleProfileKey(@NonNull SignalServiceContent content, @NonNull byte[] messageProfileKeyBytes, @NonNull Recipient senderRecipient) {
    RecipientDatabase database = SignalDatabase.recipients();
    ProfileKey messageProfileKey = ProfileKeyUtil.profileKeyOrNull(messageProfileKeyBytes);
    if (senderRecipient.isSelf()) {
        if (!Objects.equals(ProfileKeyUtil.getSelfProfileKey(), messageProfileKey)) {
            warn(content.getTimestamp(), "Saw a sync message whose profile key doesn't match our records. Scheduling a storage sync to check.");
            StorageSyncHelper.scheduleSyncForDataChange();
        }
    } else if (messageProfileKey != null) {
        if (database.setProfileKey(senderRecipient.getId(), messageProfileKey)) {
            log(content.getTimestamp(), "Profile key on message from " + senderRecipient.getId() + " didn't match our local store. It has been updated.");
            ApplicationDependencies.getJobManager().add(RetrieveProfileJob.forRecipient(senderRecipient.getId()));
        }
    } else {
        warn(String.valueOf(content.getTimestamp()), "Ignored invalid profile key seen in message");
    }
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 17 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by WhisperSystems.

the class MessageRequestRepository method acceptMessageRequest.

void acceptMessageRequest(@NonNull LiveRecipient liveRecipient, long threadId, @NonNull Runnable onMessageRequestAccepted, @NonNull GroupChangeErrorCallback error) {
    executor.execute(() -> {
        if (liveRecipient.get().isPushV2Group()) {
            try {
                Log.i(TAG, "GV2 accepting invite");
                GroupManager.acceptInvite(context, liveRecipient.get().requireGroupId().requireV2());
                RecipientDatabase recipientDatabase = SignalDatabase.recipients();
                recipientDatabase.setProfileSharing(liveRecipient.getId(), true);
                onMessageRequestAccepted.run();
            } catch (GroupChangeException | IOException e) {
                Log.w(TAG, e);
                error.onError(GroupChangeFailureReason.fromException(e));
            }
        } else {
            RecipientDatabase recipientDatabase = SignalDatabase.recipients();
            recipientDatabase.setProfileSharing(liveRecipient.getId(), true);
            MessageSender.sendProfileKey(context, threadId);
            List<MessageDatabase.MarkedMessageInfo> messageIds = SignalDatabase.threads().setEntireThreadRead(threadId);
            ApplicationDependencies.getMessageNotifier().updateNotification(context);
            MarkReadReceiver.process(context, messageIds);
            List<MessageDatabase.MarkedMessageInfo> viewedInfos = SignalDatabase.mms().getViewedIncomingMessages(threadId);
            SendViewedReceiptJob.enqueue(threadId, liveRecipient.getId(), viewedInfos);
            if (TextSecurePreferences.isMultiDevice(context)) {
                ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forAccept(liveRecipient.getId()));
            }
            onMessageRequestAccepted.run();
        }
    });
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) GroupChangeException(org.thoughtcrime.securesms.groups.GroupChangeException) IOException(java.io.IOException)

Example 18 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by WhisperSystems.

the class InviteReminderRepository method setHasSeenFirstInviteReminder.

@Override
public void setHasSeenFirstInviteReminder(Recipient recipient) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    recipientDatabase.setSeenFirstInviteReminder(recipient.getId());
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase)

Example 19 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by WhisperSystems.

the class InsightsRepository method getInsecureRecipients.

@Override
public void getInsecureRecipients(@NonNull Consumer<List<Recipient>> insecureRecipientsConsumer) {
    SimpleTask.run(() -> {
        RecipientDatabase recipientDatabase = SignalDatabase.recipients();
        List<RecipientId> unregisteredRecipients = recipientDatabase.getUninvitedRecipientsForInsights();
        return Stream.of(unregisteredRecipients).map(Recipient::resolved).toList();
    }, insecureRecipientsConsumer::accept);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId)

Example 20 with RecipientDatabase

use of org.thoughtcrime.securesms.database.RecipientDatabase in project Signal-Android by WhisperSystems.

the class InsightsRepository method sendSmsInvite.

@Override
public void sendSmsInvite(@NonNull Recipient recipient, Runnable onSmsMessageSent) {
    SimpleTask.run(() -> {
        Recipient resolved = recipient.resolve();
        int subscriptionId = resolved.getDefaultSubscriptionId().or(-1);
        String message = context.getString(R.string.InviteActivity_lets_switch_to_signal, context.getString(R.string.install_url));
        MessageSender.send(context, new OutgoingTextMessage(resolved, message, subscriptionId), -1L, true, null, null);
        RecipientDatabase database = SignalDatabase.recipients();
        database.setHasSentInvite(recipient.getId());
        return null;
    }, v -> onSmsMessageSent.run());
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Aggregations

RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)72 Recipient (org.thoughtcrime.securesms.recipients.Recipient)32 WorkerThread (androidx.annotation.WorkerThread)30 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)20 NonNull (androidx.annotation.NonNull)18 IOException (java.io.IOException)14 Nullable (androidx.annotation.Nullable)10 ArrayList (java.util.ArrayList)10 Log (org.signal.core.util.logging.Log)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ACI (org.whispersystems.signalservice.api.push.ACI)10 Context (android.content.Context)8 Stream (com.annimon.stream.Stream)8 Collections (java.util.Collections)8 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)8 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)8 Optional (org.whispersystems.libsignal.util.guava.Optional)8 HashSet (java.util.HashSet)7