Search in sources :

Example 16 with ThreadDatabase

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

the class DirectShareService method onGetChooserTargets.

@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    List<ChooserTarget> results = new LinkedList<>();
    ComponentName componentName = new ComponentName(this, ShareActivity.class);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
    Cursor cursor = threadDatabase.getDirectShareList();
    try {
        ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor);
        ThreadRecord record;
        while ((record = reader.getNext()) != null && results.size() < 10) {
            Recipient recipient = Recipient.from(this, record.getRecipient().getAddress(), false);
            String name = recipient.toShortString();
            Bitmap avatar;
            if (recipient.getContactPhoto() != null) {
                try {
                    avatar = GlideApp.with(this).asBitmap().load(recipient.getContactPhoto()).circleCrop().submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width)).get();
                } catch (InterruptedException | ExecutionException e) {
                    Log.w(TAG, e);
                    avatar = getFallbackDrawable(recipient);
                }
            } else {
                avatar = getFallbackDrawable(recipient);
            }
            Parcel parcel = Parcel.obtain();
            parcel.writeParcelable(recipient.getAddress(), 0);
            Bundle bundle = new Bundle();
            bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId());
            bundle.putByteArray(ShareActivity.EXTRA_ADDRESS_MARSHALLED, parcel.marshall());
            bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());
            bundle.setClassLoader(getClassLoader());
            results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
            parcel.recycle();
        }
        return results;
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : Parcel(android.os.Parcel) Bundle(android.os.Bundle) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) Bitmap(android.graphics.Bitmap) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with ThreadDatabase

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

the class ConversationActivity method saveDraft.

protected ListenableFuture<Long> saveDraft() {
    final SettableFuture<Long> future = new SettableFuture<>();
    if (this.recipient == null) {
        future.set(threadId);
        return future;
    }
    final Drafts drafts = getDraftsForCurrentState();
    final long thisThreadId = this.threadId;
    final int thisDistributionType = this.distributionType;
    new AsyncTask<Long, Void, Long>() {

        @Override
        protected Long doInBackground(Long... params) {
            ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(ConversationActivity.this);
            DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
            long threadId = params[0];
            if (drafts.size() > 0) {
                if (threadId == -1)
                    threadId = threadDatabase.getThreadIdFor(getRecipient(), thisDistributionType);
                draftDatabase.insertDrafts(threadId, drafts);
                threadDatabase.updateSnippet(threadId, drafts.getSnippet(ConversationActivity.this), drafts.getUriSnippet(), System.currentTimeMillis(), Types.BASE_DRAFT_TYPE, true);
            } else if (threadId > 0) {
                threadDatabase.update(threadId, false);
            }
            return threadId;
        }

        @Override
        protected void onPostExecute(Long result) {
            future.set(result);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, thisThreadId);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SuppressLint(android.annotation.SuppressLint) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts)

Example 18 with ThreadDatabase

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

the class ContactsCursorLoader method getRecentConversationsCursor.

private Cursor getRecentConversationsCursor(boolean groupsOnly) {
    ThreadDatabase threadDatabase = SignalDatabase.threads();
    MatrixCursor recentConversations = ContactsCursorRows.createMatrixCursor(RECENT_CONVERSATION_MAX);
    try (Cursor rawConversations = threadDatabase.getRecentConversationList(RECENT_CONVERSATION_MAX, flagSet(mode, DisplayMode.FLAG_INACTIVE_GROUPS), groupsOnly, hideGroupsV1(mode), !smsEnabled(mode))) {
        ThreadDatabase.Reader reader = threadDatabase.readerFor(rawConversations);
        ThreadRecord threadRecord;
        while ((threadRecord = reader.getNext()) != null) {
            recentConversations.addRow(ContactsCursorRows.forRecipient(getContext(), threadRecord.getRecipient()));
        }
    }
    return recentConversations;
}
Also used : ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) MatrixCursor(android.database.MatrixCursor) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor)

Example 19 with ThreadDatabase

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

the class TurnOffContactJoinedNotificationsActivity method handlePositiveAction.

private void handlePositiveAction(@NonNull DialogInterface dialog) {
    SimpleTask.run(getLifecycle(), () -> {
        ThreadDatabase threadDatabase = SignalDatabase.threads();
        List<MessageDatabase.MarkedMessageInfo> marked = threadDatabase.setRead(getIntent().getLongExtra(EXTRA_THREAD_ID, -1), false);
        MarkReadReceiver.process(this, marked);
        SignalStore.settings().setNotifyWhenContactJoinsSignal(false);
        ApplicationDependencies.getMessageNotifier().updateNotification(this);
        return null;
    }, unused -> {
        dialog.dismiss();
        finish();
    });
}
Also used : ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase)

Example 20 with ThreadDatabase

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

the class MessageSender method send.

public static long send(final Context context, final OutgoingMediaMessage message, final long threadId, final boolean forceSms, @Nullable final String metricId, final SmsDatabase.InsertListener insertListener) {
    Log.i(TAG, "Sending media message to " + message.getRecipient().getId() + ", thread: " + threadId);
    try {
        ThreadDatabase threadDatabase = SignalDatabase.threads();
        MessageDatabase database = SignalDatabase.mms();
        long allocatedThreadId = threadDatabase.getOrCreateValidThreadId(message.getRecipient(), threadId, message.getDistributionType());
        Recipient recipient = message.getRecipient();
        long messageId = database.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, recipient, message, allocatedThreadId), allocatedThreadId, forceSms, insertListener);
        if (message.getRecipient().isGroup() && message.getAttachments().isEmpty() && message.getLinkPreviews().isEmpty() && message.getSharedContacts().isEmpty()) {
            SignalLocalMetrics.GroupMessageSend.onInsertedIntoDatabase(messageId, metricId);
        } else {
            SignalLocalMetrics.GroupMessageSend.cancel(metricId);
        }
        sendMediaMessage(context, recipient, forceSms, messageId, Collections.emptyList());
        onMessageSent();
        threadDatabase.update(threadId, true);
        return allocatedThreadId;
    } catch (MmsException e) {
        Log.w(TAG, e);
        return threadId;
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) MmsException(org.thoughtcrime.securesms.mms.MmsException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) 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