Search in sources :

Example 31 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class SmsDatabase method insertMessageOutbox.

@Override
public long insertMessageOutbox(long threadId, OutgoingTextMessage message, boolean forceSms, long date, InsertListener insertListener) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    long type = Types.BASE_SENDING_TYPE;
    if (message.isKeyExchange())
        type |= Types.KEY_EXCHANGE_BIT;
    else if (message.isSecureMessage())
        type |= (Types.SECURE_MESSAGE_BIT | Types.PUSH_MESSAGE_BIT);
    else if (message.isEndSession())
        type |= Types.END_SESSION_BIT;
    if (forceSms)
        type |= Types.MESSAGE_FORCE_SMS_BIT;
    if (message.isIdentityVerified())
        type |= Types.KEY_EXCHANGE_IDENTITY_VERIFIED_BIT;
    else if (message.isIdentityDefault())
        type |= Types.KEY_EXCHANGE_IDENTITY_DEFAULT_BIT;
    RecipientId recipientId = message.getRecipient().getId();
    Map<RecipientId, EarlyReceiptCache.Receipt> earlyDeliveryReceipts = earlyDeliveryReceiptCache.remove(date);
    ContentValues contentValues = new ContentValues(6);
    contentValues.put(RECIPIENT_ID, recipientId.serialize());
    contentValues.put(THREAD_ID, threadId);
    contentValues.put(BODY, message.getMessageBody());
    contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
    contentValues.put(DATE_SENT, date);
    contentValues.put(READ, 1);
    contentValues.put(TYPE, type);
    contentValues.put(SUBSCRIPTION_ID, message.getSubscriptionId());
    contentValues.put(EXPIRES_IN, message.getExpiresIn());
    contentValues.put(DELIVERY_RECEIPT_COUNT, Stream.of(earlyDeliveryReceipts.values()).mapToLong(EarlyReceiptCache.Receipt::getCount).sum());
    contentValues.put(RECEIPT_TIMESTAMP, Stream.of(earlyDeliveryReceipts.values()).mapToLong(EarlyReceiptCache.Receipt::getTimestamp).max().orElse(-1));
    long messageId = db.insert(TABLE_NAME, null, contentValues);
    if (insertListener != null) {
        insertListener.onComplete();
    }
    if (!message.isIdentityVerified() && !message.isIdentityDefault()) {
        SignalDatabase.threads().setLastScrolled(threadId, 0);
        SignalDatabase.threads().setLastSeenSilently(threadId);
    }
    SignalDatabase.threads().setHasSentSilently(threadId, true);
    ApplicationDependencies.getDatabaseObserver().notifyMessageInsertObservers(threadId, new MessageId(messageId, false));
    if (!message.isIdentityVerified() && !message.isIdentityDefault()) {
        TrimThreadJob.enqueueAsync(threadId);
    }
    return messageId;
}
Also used : ContentValues(android.content.ContentValues) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 32 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class ThreadDatabase method deleteConversation.

public void deleteConversation(long threadId) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    RecipientId recipientIdForThreadId = getRecipientIdForThreadId(threadId);
    db.beginTransaction();
    try {
        SignalDatabase.sms().deleteThread(threadId);
        SignalDatabase.mms().deleteThread(threadId);
        SignalDatabase.drafts().clearDrafts(threadId);
        db.delete(TABLE_NAME, ID_WHERE, new String[] { threadId + "" });
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyConversationListListeners();
    notifyConversationListeners(threadId);
    ConversationUtil.clearShortcuts(context, Collections.singleton(recipientIdForThreadId));
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId)

Example 33 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class ThreadDatabase method getAllThreadRecipients.

@NonNull
public Set<RecipientId> getAllThreadRecipients() {
    SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
    Set<RecipientId> ids = new HashSet<>();
    try (Cursor cursor = db.query(TABLE_NAME, new String[] { RECIPIENT_ID }, null, null, null, null, null)) {
        while (cursor.moveToNext()) {
            ids.add(RecipientId.from(CursorUtil.requireString(cursor, RECIPIENT_ID)));
        }
    }
    return ids;
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) NonNull(androidx.annotation.NonNull)

Example 34 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class ThreadDatabase method getExtrasFor.

@Nullable
private Extra getExtrasFor(@NonNull MessageRecord record) {
    Recipient threadRecipient = record.isOutgoing() ? record.getRecipient() : getRecipientForThreadId(record.getThreadId());
    boolean messageRequestAccepted = RecipientUtil.isMessageRequestAccepted(context, record.getThreadId(), threadRecipient);
    RecipientId individualRecipientId = record.getIndividualRecipient().getId();
    // noinspection ConstantConditions
    if (!messageRequestAccepted && threadRecipient != null) {
        if (threadRecipient.isPushGroup()) {
            if (threadRecipient.isPushV2Group()) {
                MessageRecord.InviteAddState inviteAddState = record.getGv2AddInviteState();
                if (inviteAddState != null) {
                    RecipientId from = RecipientId.from(ACI.from(inviteAddState.getAddedOrInvitedBy()), null);
                    if (inviteAddState.isInvited()) {
                        Log.i(TAG, "GV2 invite message request from " + from);
                        return Extra.forGroupV2invite(from, individualRecipientId);
                    } else {
                        Log.i(TAG, "GV2 message request from " + from);
                        return Extra.forGroupMessageRequest(from, individualRecipientId);
                    }
                }
                Log.w(TAG, "Falling back to unknown message request state for GV2 message");
                return Extra.forMessageRequest(individualRecipientId);
            } else {
                RecipientId recipientId = SignalDatabase.mmsSms().getGroupAddedBy(record.getThreadId());
                if (recipientId != null) {
                    return Extra.forGroupMessageRequest(recipientId, individualRecipientId);
                }
            }
        }
        return Extra.forMessageRequest(individualRecipientId);
    }
    if (record.isRemoteDelete()) {
        return Extra.forRemoteDelete(individualRecipientId);
    } else if (record.isViewOnce()) {
        return Extra.forViewOnce(individualRecipientId);
    } else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getStickerSlide() != null) {
        StickerSlide slide = Objects.requireNonNull(((MmsMessageRecord) record).getSlideDeck().getStickerSlide());
        return Extra.forSticker(slide.getEmoji(), individualRecipientId);
    } else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getSlides().size() > 1) {
        return Extra.forAlbum(individualRecipientId);
    }
    if (threadRecipient != null && threadRecipient.isGroup()) {
        return Extra.forDefault(individualRecipientId);
    }
    return null;
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Nullable(androidx.annotation.Nullable)

Example 35 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class ThreadDatabase method setForcedUnread.

public void setForcedUnread(@NonNull Collection<Long> threadIds) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    List<RecipientId> recipientIds = Collections.emptyList();
    db.beginTransaction();
    try {
        SqlUtil.Query query = SqlUtil.buildCollectionQuery(ID, threadIds);
        ContentValues contentValues = new ContentValues();
        contentValues.put(READ, ReadStatus.FORCED_UNREAD.serialize());
        db.update(TABLE_NAME, contentValues, query.getWhere(), query.getWhereArgs());
        recipientIds = getRecipientIdsForThreadIds(threadIds);
        SignalDatabase.recipients().markNeedsSyncWithoutRefresh(recipientIds);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        for (RecipientId id : recipientIds) {
            Recipient.live(id).refresh();
        }
        StorageSyncHelper.scheduleSyncForDataChange();
        notifyConversationListListeners();
    }
}
Also used : ContentValues(android.content.ContentValues) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SqlUtil(org.thoughtcrime.securesms.util.SqlUtil)

Aggregations

RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)154 NonNull (androidx.annotation.NonNull)70 Recipient (org.thoughtcrime.securesms.recipients.Recipient)70 List (java.util.List)34 ArrayList (java.util.ArrayList)33 Nullable (androidx.annotation.Nullable)32 Context (android.content.Context)31 Log (org.signal.core.util.logging.Log)31 IOException (java.io.IOException)30 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)29 WorkerThread (androidx.annotation.WorkerThread)28 Stream (com.annimon.stream.Stream)27 LinkedList (java.util.LinkedList)25 ContentValues (android.content.ContentValues)24 Cursor (android.database.Cursor)24 Collections (java.util.Collections)24 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)24 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)23 Optional (org.whispersystems.libsignal.util.guava.Optional)22 HashSet (java.util.HashSet)21