Search in sources :

Example 21 with ThreadDatabase

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

the class MessageSender method sendMediaBroadcast.

public static void sendMediaBroadcast(@NonNull Context context, @NonNull List<OutgoingSecureMediaMessage> messages, @NonNull Collection<PreUploadResult> preUploadResults) {
    Log.i(TAG, "Sending media broadcast to " + Stream.of(messages).map(m -> m.getRecipient().getId()).toList());
    Preconditions.checkArgument(messages.size() > 0, "No messages!");
    Preconditions.checkArgument(Stream.of(messages).allMatch(m -> m.getAttachments().isEmpty()), "Messages can't have attachments! They should be pre-uploaded.");
    JobManager jobManager = ApplicationDependencies.getJobManager();
    AttachmentDatabase attachmentDatabase = SignalDatabase.attachments();
    MessageDatabase mmsDatabase = SignalDatabase.mms();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    List<AttachmentId> preUploadAttachmentIds = Stream.of(preUploadResults).map(PreUploadResult::getAttachmentId).toList();
    List<String> preUploadJobIds = Stream.of(preUploadResults).map(PreUploadResult::getJobIds).flatMap(Stream::of).toList();
    List<Long> messageIds = new ArrayList<>(messages.size());
    List<String> messageDependsOnIds = new ArrayList<>(preUploadJobIds);
    mmsDatabase.beginTransaction();
    try {
        OutgoingSecureMediaMessage primaryMessage = messages.get(0);
        long primaryThreadId = threadDatabase.getOrCreateThreadIdFor(primaryMessage.getRecipient(), primaryMessage.getDistributionType());
        long primaryMessageId = mmsDatabase.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, primaryMessage.getRecipient(), primaryMessage, primaryThreadId), primaryThreadId, false, null);
        attachmentDatabase.updateMessageId(preUploadAttachmentIds, primaryMessageId);
        messageIds.add(primaryMessageId);
        if (messages.size() > 0) {
            List<OutgoingSecureMediaMessage> secondaryMessages = messages.subList(1, messages.size());
            List<List<AttachmentId>> attachmentCopies = new ArrayList<>();
            List<DatabaseAttachment> preUploadAttachments = Stream.of(preUploadAttachmentIds).map(attachmentDatabase::getAttachment).toList();
            for (int i = 0; i < preUploadAttachmentIds.size(); i++) {
                attachmentCopies.add(new ArrayList<>(messages.size()));
            }
            for (OutgoingSecureMediaMessage secondaryMessage : secondaryMessages) {
                long allocatedThreadId = threadDatabase.getOrCreateThreadIdFor(secondaryMessage.getRecipient(), secondaryMessage.getDistributionType());
                long messageId = mmsDatabase.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, secondaryMessage.getRecipient(), secondaryMessage, allocatedThreadId), allocatedThreadId, false, null);
                List<AttachmentId> attachmentIds = new ArrayList<>(preUploadAttachmentIds.size());
                for (int i = 0; i < preUploadAttachments.size(); i++) {
                    AttachmentId attachmentId = attachmentDatabase.insertAttachmentForPreUpload(preUploadAttachments.get(i)).getAttachmentId();
                    attachmentCopies.get(i).add(attachmentId);
                    attachmentIds.add(attachmentId);
                }
                attachmentDatabase.updateMessageId(attachmentIds, messageId);
                messageIds.add(messageId);
            }
            for (int i = 0; i < attachmentCopies.size(); i++) {
                Job copyJob = new AttachmentCopyJob(preUploadAttachmentIds.get(i), attachmentCopies.get(i));
                jobManager.add(copyJob, preUploadJobIds);
                messageDependsOnIds.add(copyJob.getId());
            }
        }
        for (int i = 0; i < messageIds.size(); i++) {
            long messageId = messageIds.get(i);
            OutgoingSecureMediaMessage message = messages.get(i);
            Recipient recipient = message.getRecipient();
            if (isLocalSelfSend(context, recipient, false)) {
                sendLocalMediaSelf(context, messageId);
            } else if (isGroupPushSend(recipient)) {
                jobManager.add(new PushGroupSendJob(messageId, recipient.getId(), null, true), messageDependsOnIds, recipient.getId().toQueueKey());
            } else {
                jobManager.add(new PushMediaSendJob(messageId, recipient, true), messageDependsOnIds, recipient.getId().toQueueKey());
            }
        }
        onMessageSent();
        mmsDatabase.setTransactionSuccessful();
    } catch (MmsException e) {
        Log.w(TAG, "Failed to send messages.", e);
    } finally {
        mmsDatabase.endTransaction();
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Arrays(java.util.Arrays) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Preconditions(org.whispersystems.libsignal.util.guava.Preconditions) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ParcelUtil(org.thoughtcrime.securesms.util.ParcelUtil) ReactionSendJob(org.thoughtcrime.securesms.jobs.ReactionSendJob) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Job(org.thoughtcrime.securesms.jobmanager.Job) ResumableUploadSpecJob(org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) Attachment(org.thoughtcrime.securesms.attachments.Attachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob) Context(android.content.Context) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) Stream(com.annimon.stream.Stream) DirectoryHelper(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) WorkerThread(androidx.annotation.WorkerThread) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) Parcel(android.os.Parcel) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) ArrayList(java.util.ArrayList) RemoteDeleteSendJob(org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) AttachmentUploadJob(org.thoughtcrime.securesms.jobs.AttachmentUploadJob) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) EventBus(org.greenrobot.eventbus.EventBus) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) LinkedList(java.util.LinkedList) Parcelable(android.os.Parcelable) MessageId(org.thoughtcrime.securesms.database.model.MessageId) Contact(org.thoughtcrime.securesms.contactshare.Contact) MmsException(org.thoughtcrime.securesms.mms.MmsException) IOException(java.io.IOException) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Collections(java.util.Collections) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) ArrayList(java.util.ArrayList) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MmsException(org.thoughtcrime.securesms.mms.MmsException) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) AttachmentMarkUploadedJob(org.thoughtcrime.securesms.jobs.AttachmentMarkUploadedJob) ReactionSendJob(org.thoughtcrime.securesms.jobs.ReactionSendJob) PushMediaSendJob(org.thoughtcrime.securesms.jobs.PushMediaSendJob) Job(org.thoughtcrime.securesms.jobmanager.Job) ResumableUploadSpecJob(org.thoughtcrime.securesms.jobs.ResumableUploadSpecJob) PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) AttachmentCompressionJob(org.thoughtcrime.securesms.jobs.AttachmentCompressionJob) ProfileKeySendJob(org.thoughtcrime.securesms.jobs.ProfileKeySendJob) RemoteDeleteSendJob(org.thoughtcrime.securesms.jobs.RemoteDeleteSendJob) MmsSendJob(org.thoughtcrime.securesms.jobs.MmsSendJob) AttachmentUploadJob(org.thoughtcrime.securesms.jobs.AttachmentUploadJob) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) AttachmentCopyJob(org.thoughtcrime.securesms.jobs.AttachmentCopyJob) SmsSendJob(org.thoughtcrime.securesms.jobs.SmsSendJob) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)

Example 22 with ThreadDatabase

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

the class GroupManagerV1 method updateGroupTimer.

@WorkerThread
static void updateGroupTimer(@NonNull Context context, @NonNull GroupId.V1 groupId, int expirationTime) {
    RecipientDatabase recipientDatabase = SignalDatabase.recipients();
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    Recipient recipient = Recipient.externalGroupExact(context, groupId);
    long threadId = threadDatabase.getOrCreateThreadIdFor(recipient);
    recipientDatabase.setExpireMessages(recipient.getId(), expirationTime);
    OutgoingExpirationUpdateMessage outgoingMessage = new OutgoingExpirationUpdateMessage(recipient, System.currentTimeMillis(), expirationTime * 1000L);
    MessageSender.send(context, outgoingMessage, threadId, false, null, null);
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) WorkerThread(androidx.annotation.WorkerThread)

Example 23 with ThreadDatabase

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

the class ConversationListFragment method onItemSwiped.

@SuppressLint("StaticFieldLeak")
protected void onItemSwiped(long threadId, int unreadCount) {
    archiveDecoration.onArchiveStarted();
    itemAnimator.enable();
    new SnackbarAsyncTask<Long>(getViewLifecycleOwner().getLifecycle(), requireView(), getResources().getQuantityString(R.plurals.ConversationListFragment_conversations_archived, 1, 1), getString(R.string.ConversationListFragment_undo), getResources().getColor(R.color.amber_500), Snackbar.LENGTH_LONG, false) {

        private final ThreadDatabase threadDatabase = SignalDatabase.threads();

        private List<Long> pinnedThreadIds;

        @Override
        protected void executeAction(@Nullable Long parameter) {
            Context context = requireActivity();
            pinnedThreadIds = threadDatabase.getPinnedThreadIds();
            threadDatabase.archiveConversation(threadId);
            if (unreadCount > 0) {
                List<MarkedMessageInfo> messageIds = threadDatabase.setRead(threadId, false);
                ApplicationDependencies.getMessageNotifier().updateNotification(context);
                MarkReadReceiver.process(context, messageIds);
            }
        }

        @Override
        protected void reverseAction(@Nullable Long parameter) {
            Context context = requireActivity();
            threadDatabase.unarchiveConversation(threadId);
            threadDatabase.restorePins(pinnedThreadIds);
            if (unreadCount > 0) {
                threadDatabase.incrementUnread(threadId, unreadCount);
                ApplicationDependencies.getMessageNotifier().updateNotification(context);
            }
        }
    }.executeOnExecutor(SignalExecutors.BOUNDED, threadId);
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) List(java.util.List) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SuppressLint(android.annotation.SuppressLint)

Example 24 with ThreadDatabase

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

the class ConversationListFragment method handlePin.

private void handlePin(@NonNull Collection<Conversation> conversations) {
    final Set<Long> toPin = new LinkedHashSet<>(Stream.of(conversations).filterNot(conversation -> conversation.getThreadRecord().isPinned()).map(conversation -> conversation.getThreadRecord().getThreadId()).toList());
    if (toPin.size() + viewModel.getPinnedCount() > MAXIMUM_PINNED_CONVERSATIONS) {
        Snackbar.make(fab, getString(R.string.conversation_list__you_can_only_pin_up_to_d_chats, MAXIMUM_PINNED_CONVERSATIONS), Snackbar.LENGTH_LONG).setTextColor(Color.WHITE).show();
        endActionModeIfActive();
        return;
    }
    SimpleTask.run(SignalExecutors.BOUNDED, () -> {
        ThreadDatabase db = SignalDatabase.threads();
        db.pinConversations(toPin);
        return null;
    }, unused -> {
        endActionModeIfActive();
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NewConversationActivity(org.thoughtcrime.securesms.NewConversationActivity) Bundle(android.os.Bundle) PulsingFloatingActionButton(org.thoughtcrime.securesms.components.registration.PulsingFloatingActionButton) RecaptchaProofBottomSheetFragment(org.thoughtcrime.securesms.ratelimit.RecaptchaProofBottomSheetFragment) NonNull(androidx.annotation.NonNull) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ColorInt(androidx.annotation.ColorInt) Manifest(android.Manifest) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) TooltipCompat(androidx.appcompat.widget.TooltipCompat) SnapToTopDataObserver(org.thoughtcrime.securesms.util.SnapToTopDataObserver) Fragment(androidx.fragment.app.Fragment) Badge(org.thoughtcrime.securesms.badges.models.Badge) Canvas(android.graphics.Canvas) SimpleColorFilter(com.airbnb.lottie.SimpleColorFilter) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Megaphone(org.thoughtcrime.securesms.megaphone.Megaphone) ContextCompat(androidx.core.content.ContextCompat) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) ViewCompat(androidx.core.view.ViewCompat) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) Megaphones(org.thoughtcrime.securesms.megaphone.Megaphones) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) DimensionUnit(org.signal.core.util.DimensionUnit) IdRes(androidx.annotation.IdRes) Nullable(androidx.annotation.Nullable) SignalContextMenu(org.thoughtcrime.securesms.components.menu.SignalContextMenu) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) InsightsLauncher(org.thoughtcrime.securesms.insights.InsightsLauncher) UnexpectedSubscriptionCancellation(org.thoughtcrime.securesms.components.settings.app.subscription.errors.UnexpectedSubscriptionCancellation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) UnreadPayments(org.thoughtcrime.securesms.conversationlist.model.UnreadPayments) StickyHeaderDecoration(org.thoughtcrime.securesms.util.StickyHeaderDecoration) DialogFragment(androidx.fragment.app.DialogFragment) ServiceOutageReminder(org.thoughtcrime.securesms.components.reminder.ServiceOutageReminder) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) CantProcessSubscriptionPaymentBottomSheetDialogFragment(org.thoughtcrime.securesms.badges.self.expired.CantProcessSubscriptionPaymentBottomSheetDialogFragment) WorkerThread(androidx.annotation.WorkerThread) PaymentDetailsParcelable(org.thoughtcrime.securesms.payments.preferences.details.PaymentDetailsParcelable) MainFragment(org.thoughtcrime.securesms.MainFragment) ArrayList(java.util.ArrayList) ActionMenuView(androidx.appcompat.widget.ActionMenuView) ReminderView(org.thoughtcrime.securesms.components.reminder.ReminderView) KeyCachingService(org.thoughtcrime.securesms.service.KeyCachingService) WebSocketConnectionState(org.whispersystems.signalservice.api.websocket.WebSocketConnectionState) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) SignalProxyUtil(org.thoughtcrime.securesms.util.SignalProxyUtil) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) RatingManager(org.thoughtcrime.securesms.components.RatingManager) AppStartup(org.thoughtcrime.securesms.util.AppStartup) LinkedHashSet(java.util.LinkedHashSet) MainNavigator(org.thoughtcrime.securesms.MainNavigator) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ProgressDialog(android.app.ProgressDialog) Permissions(org.thoughtcrime.securesms.permissions.Permissions) UnreadPaymentsView(org.thoughtcrime.securesms.components.UnreadPaymentsView) PushRegistrationReminder(org.thoughtcrime.securesms.components.reminder.PushRegistrationReminder) Optional(org.whispersystems.libsignal.util.guava.Optional) Reminder(org.thoughtcrime.securesms.components.reminder.Reminder) BottomSheetUtil(org.thoughtcrime.securesms.util.BottomSheetUtil) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) SnackbarAsyncTask(org.thoughtcrime.securesms.util.task.SnackbarAsyncTask) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SignalBottomActionBar(org.thoughtcrime.securesms.components.menu.SignalBottomActionBar) ArgbEvaluatorCompat(com.google.android.material.animation.ArgbEvaluatorCompat) MessageSender(org.thoughtcrime.securesms.sms.MessageSender) NotificationProfileSelectionFragment(org.thoughtcrime.securesms.components.settings.app.notifications.manual.NotificationProfileSelectionFragment) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) PaymentDetailsFragmentArgs(org.thoughtcrime.securesms.payments.preferences.details.PaymentDetailsFragmentArgs) ConversationFragment(org.thoughtcrime.securesms.conversation.ConversationFragment) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) DrawableRes(androidx.annotation.DrawableRes) R(org.thoughtcrime.securesms.R) PlayStoreUtil(org.thoughtcrime.securesms.util.PlayStoreUtil) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) Locale(java.util.Locale) PluralsRes(androidx.annotation.PluralsRes) NotificationProfiles(org.thoughtcrime.securesms.notifications.profiles.NotificationProfiles) View(android.view.View) MegaphoneViewBuilder(org.thoughtcrime.securesms.megaphone.MegaphoneViewBuilder) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecyclerView(androidx.recyclerview.widget.RecyclerView) SignalExecutors(org.signal.core.util.concurrent.SignalExecutors) SearchToolbar(org.thoughtcrime.securesms.components.SearchToolbar) Conversation(org.thoughtcrime.securesms.conversationlist.model.Conversation) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) ExpiredBuildReminder(org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder) SearchResult(org.thoughtcrime.securesms.search.SearchResult) AsyncTask(android.os.AsyncTask) VoiceNotePlayerView(org.thoughtcrime.securesms.components.voice.VoiceNotePlayerView) Collection(java.util.Collection) UUID(java.util.UUID) ThreadMode(org.greenrobot.eventbus.ThreadMode) AvatarUtil(org.thoughtcrime.securesms.util.AvatarUtil) ExpiredBadgeBottomSheetDialogFragment(org.thoughtcrime.securesms.badges.self.expired.ExpiredBadgeBottomSheetDialogFragment) NotificationProfile(org.thoughtcrime.securesms.notifications.profiles.NotificationProfile) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) CreateKbsPinActivity(org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity) VoiceNoteMediaControllerOwner(org.thoughtcrime.securesms.components.voice.VoiceNoteMediaControllerOwner) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) TextView(android.widget.TextView) MarkReadReceiver(org.thoughtcrime.securesms.notifications.MarkReadReceiver) MessageResult(org.thoughtcrime.securesms.search.MessageResult) Toolbar(androidx.appcompat.widget.Toolbar) Snackbar(com.google.android.material.snackbar.Snackbar) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) DozeReminder(org.thoughtcrime.securesms.components.reminder.DozeReminder) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo) Context(android.content.Context) TopToastPopup(org.thoughtcrime.securesms.util.TopToastPopup) RESULT_OK(android.app.Activity.RESULT_OK) SignalLocalMetrics(org.thoughtcrime.securesms.util.SignalLocalMetrics) Intent(android.content.Intent) AppForegroundObserver(org.thoughtcrime.securesms.util.AppForegroundObserver) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) TooltipPopup(org.thoughtcrime.securesms.components.TooltipPopup) SuppressLint(android.annotation.SuppressLint) ActionItem(org.thoughtcrime.securesms.components.menu.ActionItem) OutdatedBuildReminder(org.thoughtcrime.securesms.components.reminder.OutdatedBuildReminder) POSITION_BELOW(org.thoughtcrime.securesms.components.TooltipPopup.POSITION_BELOW) EventBus(org.greenrobot.eventbus.EventBus) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) MegaphoneActionController(org.thoughtcrime.securesms.megaphone.MegaphoneActionController) Stub(org.thoughtcrime.securesms.util.views.Stub) LayoutInflater(android.view.LayoutInflater) MediaSelectionActivity(org.thoughtcrime.securesms.mediasend.v2.MediaSelectionActivity) PaymentsActivity(org.thoughtcrime.securesms.payments.preferences.PaymentsActivity) ActionMode(androidx.appcompat.view.ActionMode) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Color(android.graphics.Color) ServiceOutageDetectionJob(org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob) Subscribe(org.greenrobot.eventbus.Subscribe) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) ReminderUpdateEvent(org.thoughtcrime.securesms.events.ReminderUpdateEvent) MuteDialog(org.thoughtcrime.securesms.MuteDialog) Activity(android.app.Activity) Collections(java.util.Collections) Resources(android.content.res.Resources) UnauthorizedReminder(org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Example 25 with ThreadDatabase

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

the class MarkReadHelper method onViewsRevealed.

public void onViewsRevealed(long timestamp) {
    if (timestamp <= latestTimestamp || lifecycleOwner.getLifecycle().getCurrentState() != Lifecycle.State.RESUMED) {
        return;
    }
    latestTimestamp = timestamp;
    debouncer.publish(() -> {
        EXECUTOR.execute(() -> {
            ThreadDatabase threadDatabase = SignalDatabase.threads();
            List<MessageDatabase.MarkedMessageInfo> infos = threadDatabase.setReadSince(threadId, false, timestamp);
            Log.d(TAG, "Marking " + infos.size() + " messages as read.");
            ApplicationDependencies.getMessageNotifier().updateNotification(context);
            MarkReadReceiver.process(context, infos);
        });
    });
}
Also used : ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Aggregations

ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)29 Recipient (org.thoughtcrime.securesms.recipients.Recipient)14 ThreadRecord (org.thoughtcrime.securesms.database.model.ThreadRecord)7 ArrayList (java.util.ArrayList)6 SuppressLint (android.annotation.SuppressLint)5 Cursor (android.database.Cursor)5 WorkerThread (androidx.annotation.WorkerThread)5 Context (android.content.Context)4 MmsException (org.thoughtcrime.securesms.mms.MmsException)4 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)4 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 Bundle (android.os.Bundle)3 NonNull (androidx.annotation.NonNull)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 DraftDatabase (org.thoughtcrime.securesms.database.DraftDatabase)3 Drafts (org.thoughtcrime.securesms.database.DraftDatabase.Drafts)3 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)3 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)3 ComponentName (android.content.ComponentName)2