Search in sources :

Example 41 with Pair

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

the class MmsDatabase method setTimestampRead.

@Override
@NonNull
MmsSmsDatabase.TimestampReadResult setTimestampRead(SyncMessageId messageId, long proposedExpireStarted, @NonNull Map<Long, Long> threadToLatestRead) {
    SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
    List<Pair<Long, Long>> expiring = new LinkedList<>();
    String[] projection = new String[] { ID, THREAD_ID, MESSAGE_BOX, EXPIRES_IN, EXPIRE_STARTED, RECIPIENT_ID };
    String query = DATE_SENT + " = ?";
    String[] args = SqlUtil.buildArgs(messageId.getTimetamp());
    List<Long> threads = new LinkedList<>();
    try (Cursor cursor = database.query(TABLE_NAME, projection, query, args, null, null, null)) {
        while (cursor.moveToNext()) {
            RecipientId theirRecipientId = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(RECIPIENT_ID)));
            RecipientId ourRecipientId = messageId.getRecipientId();
            if (ourRecipientId.equals(theirRecipientId) || Recipient.resolved(theirRecipientId).isGroup() || ourRecipientId.equals(Recipient.self().getId())) {
                long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
                long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
                long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRES_IN));
                long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRE_STARTED));
                expireStarted = expireStarted > 0 ? Math.min(proposedExpireStarted, expireStarted) : proposedExpireStarted;
                ContentValues values = new ContentValues();
                values.put(READ, 1);
                values.put(REACTIONS_UNREAD, 0);
                values.put(REACTIONS_LAST_SEEN, System.currentTimeMillis());
                if (expiresIn > 0) {
                    values.put(EXPIRE_STARTED, expireStarted);
                    expiring.add(new Pair<>(id, expiresIn));
                }
                database.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(id));
                threads.add(threadId);
                Long latest = threadToLatestRead.get(threadId);
                threadToLatestRead.put(threadId, (latest != null) ? Math.max(latest, messageId.getTimetamp()) : messageId.getTimetamp());
            }
        }
    }
    return new MmsSmsDatabase.TimestampReadResult(expiring, threads);
}
Also used : ContentValues(android.content.ContentValues) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) Pair(org.whispersystems.libsignal.util.Pair) NonNull(androidx.annotation.NonNull)

Example 42 with Pair

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

the class MmsSmsDatabase method getGroupAddedBy.

@NonNull
private Pair<RecipientId, Long> getGroupAddedBy(long threadId, long lastQuitChecked) {
    MessageDatabase mmsDatabase = SignalDatabase.mms();
    MessageDatabase smsDatabase = SignalDatabase.sms();
    long latestQuit = mmsDatabase.getLatestGroupQuitTimestamp(threadId, lastQuitChecked);
    RecipientId id = smsDatabase.getOldestGroupUpdateSender(threadId, latestQuit);
    return new Pair<>(id, latestQuit);
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Pair(org.whispersystems.libsignal.util.Pair) NonNull(androidx.annotation.NonNull)

Example 43 with Pair

use of org.whispersystems.libsignal.util.Pair in project libsignal-service-java by signalapp.

the class PushServiceSocket method getContactDiscoveryRemoteAttestation.

public Pair<RemoteAttestationResponse, List<String>> getContactDiscoveryRemoteAttestation(String authorization, RemoteAttestationRequest request, String mrenclave) throws IOException {
    Response response = makeContactDiscoveryRequest(authorization, new LinkedList<String>(), "/v1/attestation/" + mrenclave, "PUT", JsonUtil.toJson(request));
    ResponseBody body = response.body();
    List<String> rawCookies = response.headers("Set-Cookie");
    List<String> cookies = new LinkedList<>();
    for (String cookie : rawCookies) {
        cookies.add(cookie.split(";")[0]);
    }
    if (body != null) {
        return new Pair<>(JsonUtil.fromJson(body.string(), RemoteAttestationResponse.class), cookies);
    } else {
        throw new NonSuccessfulResponseCodeException("Empty response!");
    }
}
Also used : RemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) Response(okhttp3.Response) RemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) LinkedList(java.util.LinkedList) ResponseBody(okhttp3.ResponseBody) Pair(org.whispersystems.libsignal.util.Pair)

Example 44 with Pair

use of org.whispersystems.libsignal.util.Pair in project libsignal-service-java by signalapp.

the class WebSocketConnection method sendRequest.

public synchronized Future<Pair<Integer, String>> sendRequest(WebSocketRequestMessage request) throws IOException {
    if (client == null || !connected)
        throw new IOException("No connection!");
    WebSocketMessage message = WebSocketMessage.newBuilder().setType(WebSocketMessage.Type.REQUEST).setRequest(request).build();
    SettableFuture<Pair<Integer, String>> future = new SettableFuture<>();
    outgoingRequests.put(request.getId(), future);
    if (!client.send(ByteString.of(message.toByteArray()))) {
        throw new IOException("Write failed!");
    }
    return future;
}
Also used : SettableFuture(org.whispersystems.signalservice.internal.util.concurrent.SettableFuture) IOException(java.io.IOException) WebSocketMessage(org.whispersystems.signalservice.internal.websocket.WebSocketProtos.WebSocketMessage) Pair(org.whispersystems.libsignal.util.Pair)

Example 45 with Pair

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

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