Search in sources :

Example 1 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by signalapp.

the class ThreadDatabase method getLastSeenAndHasSent.

public Pair<Long, Boolean> getLastSeenAndHasSent(long threadId) {
    SQLiteDatabase db = databaseHelper.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, new String[] { LAST_SEEN, HAS_SENT }, ID_WHERE, new String[] { String.valueOf(threadId) }, null, null, null);
    try {
        if (cursor != null && cursor.moveToFirst()) {
            return new Pair<>(cursor.getLong(0), cursor.getLong(1) == 1);
        }
        return new Pair<>(-1L, false);
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) Pair(org.whispersystems.libsignal.util.Pair)

Example 2 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by WhisperSystems.

the class MmsDatabase method insertMessageInbox.

public Pair<Long, Long> insertMessageInbox(@NonNull NotificationInd notification, int subscriptionId) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    long threadId = getThreadIdFor(notification);
    ContentValues contentValues = new ContentValues();
    ContentValuesBuilder contentBuilder = new ContentValuesBuilder(contentValues);
    Log.i(TAG, "Message received type: " + notification.getMessageType());
    contentBuilder.add(CONTENT_LOCATION, notification.getContentLocation());
    contentBuilder.add(DATE_SENT, System.currentTimeMillis());
    contentBuilder.add(EXPIRY, notification.getExpiry());
    contentBuilder.add(MESSAGE_SIZE, notification.getMessageSize());
    contentBuilder.add(TRANSACTION_ID, notification.getTransactionId());
    contentBuilder.add(MESSAGE_TYPE, notification.getMessageType());
    if (notification.getFrom() != null) {
        Recipient recipient = Recipient.external(context, Util.toIsoString(notification.getFrom().getTextString()));
        contentValues.put(RECIPIENT_ID, recipient.getId().serialize());
    } else {
        contentValues.put(RECIPIENT_ID, RecipientId.UNKNOWN.serialize());
    }
    contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE);
    contentValues.put(THREAD_ID, threadId);
    contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
    contentValues.put(DATE_RECEIVED, generatePduCompatTimestamp(System.currentTimeMillis()));
    contentValues.put(READ, Util.isDefaultSmsProvider(context) ? 0 : 1);
    contentValues.put(SUBSCRIPTION_ID, subscriptionId);
    if (!contentValues.containsKey(DATE_SENT))
        contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
    long messageId = db.insert(TABLE_NAME, null, contentValues);
    return new Pair<>(messageId, threadId);
}
Also used : ContentValues(android.content.ContentValues) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Pair(org.whispersystems.libsignal.util.Pair)

Example 3 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by WhisperSystems.

the class MmsDatabase method getOldestUnreadMentionDetails.

@Override
@Nullable
public Pair<RecipientId, Long> getOldestUnreadMentionDetails(long threadId) {
    SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
    String[] projection = new String[] { RECIPIENT_ID, DATE_RECEIVED };
    String selection = THREAD_ID + " = ? AND " + READ + " = 0 AND " + MENTIONS_SELF + " = 1";
    String[] args = SqlUtil.buildArgs(threadId);
    try (Cursor cursor = database.query(TABLE_NAME, projection, selection, args, null, null, DATE_RECEIVED + " ASC", "1")) {
        if (cursor != null && cursor.moveToFirst()) {
            return new Pair<>(RecipientId.from(CursorUtil.requireString(cursor, RECIPIENT_ID)), CursorUtil.requireLong(cursor, DATE_RECEIVED));
        }
    }
    return null;
}
Also used : Cursor(android.database.Cursor) Pair(org.whispersystems.libsignal.util.Pair) Nullable(androidx.annotation.Nullable)

Example 4 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by WhisperSystems.

the class MmsSmsDatabase method setTimestampRead.

public void setTimestampRead(@NonNull Recipient senderRecipient, @NonNull List<ReadMessage> readMessages, long proposedExpireStarted, @NonNull Map<Long, Long> threadToLatestRead) {
    SQLiteDatabase db = getWritableDatabase();
    List<Pair<Long, Long>> expiringText = new LinkedList<>();
    List<Pair<Long, Long>> expiringMedia = new LinkedList<>();
    Set<Long> updatedThreads = new HashSet<>();
    db.beginTransaction();
    try {
        for (ReadMessage readMessage : readMessages) {
            TimestampReadResult textResult = SignalDatabase.sms().setTimestampRead(new SyncMessageId(senderRecipient.getId(), readMessage.getTimestamp()), proposedExpireStarted, threadToLatestRead);
            TimestampReadResult mediaResult = SignalDatabase.mms().setTimestampRead(new SyncMessageId(senderRecipient.getId(), readMessage.getTimestamp()), proposedExpireStarted, threadToLatestRead);
            expiringText.addAll(textResult.expiring);
            expiringMedia.addAll(mediaResult.expiring);
            updatedThreads.addAll(textResult.threads);
            updatedThreads.addAll(mediaResult.threads);
        }
        for (long threadId : updatedThreads) {
            SignalDatabase.threads().updateReadState(threadId);
            SignalDatabase.threads().setLastSeen(threadId);
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    for (Pair<Long, Long> expiringMessage : expiringText) {
        ApplicationDependencies.getExpiringMessageManager().scheduleDeletion(expiringMessage.first(), false, proposedExpireStarted, expiringMessage.second());
    }
    for (Pair<Long, Long> expiringMessage : expiringMedia) {
        ApplicationDependencies.getExpiringMessageManager().scheduleDeletion(expiringMessage.first(), true, proposedExpireStarted, expiringMessage.second());
    }
    for (long threadId : updatedThreads) {
        notifyConversationListeners(threadId);
    }
}
Also used : ReadMessage(org.whispersystems.signalservice.api.messages.multidevice.ReadMessage) SyncMessageId(org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId) LinkedList(java.util.LinkedList) Pair(org.whispersystems.libsignal.util.Pair) HashSet(java.util.HashSet)

Example 5 with Pair

use of org.whispersystems.libsignal.util.Pair in project Signal-Android by WhisperSystems.

the class WebSocketConnection method createTlsSocketFactory.

private Pair<SSLSocketFactory, X509TrustManager> createTlsSocketFactory(TrustStore trustStore) {
    try {
        SSLContext context = SSLContext.getInstance("TLS");
        TrustManager[] trustManagers = BlacklistingTrustManager.createFor(trustStore);
        context.init(null, trustManagers, null);
        return new Pair<>(context.getSocketFactory(), (X509TrustManager) trustManagers[0]);
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new AssertionError(e);
    }
}
Also used : SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) BlacklistingTrustManager(org.whispersystems.signalservice.internal.util.BlacklistingTrustManager) Pair(org.whispersystems.libsignal.util.Pair)

Aggregations

Pair (org.whispersystems.libsignal.util.Pair)49 NonNull (androidx.annotation.NonNull)26 List (java.util.List)18 LinkedList (java.util.LinkedList)15 Context (android.content.Context)14 Stream (com.annimon.stream.Stream)14 IOException (java.io.IOException)14 Recipient (org.thoughtcrime.securesms.recipients.Recipient)14 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)14 Nullable (androidx.annotation.Nullable)12 SpannableString (android.text.SpannableString)10 TextUtils (android.text.TextUtils)10 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 Cursor (android.database.Cursor)9 ContentValues (android.content.ContentValues)8 HashSet (java.util.HashSet)8 Locale (java.util.Locale)8 Set (java.util.Set)8 Log (org.signal.core.util.logging.Log)8