mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Cleanup Recipient.externalPush to use RecipientId cache.
This commit is contained in:
@@ -303,7 +303,7 @@ open class MessageContentProcessorV2(private val context: Context) {
|
||||
open fun process(envelope: Envelope, content: Content, metadata: EnvelopeMetadata, serverDeliveredTimestamp: Long, processingEarlyContent: Boolean = false) {
|
||||
val stopwatch = Stopwatch("process-content")
|
||||
|
||||
val senderRecipient = Recipient.resolved(RecipientId.from(SignalServiceAddress(metadata.sourceServiceId, metadata.sourceE164)))
|
||||
val senderRecipient = Recipient.externalPush(SignalServiceAddress(metadata.sourceServiceId, metadata.sourceE164))
|
||||
|
||||
handleMessage(senderRecipient, envelope, content, metadata, serverDeliveredTimestamp, processingEarlyContent, stopwatch)
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.StringUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.zkgroup.profiles.ExpiringProfileKeyCredential;
|
||||
@@ -271,8 +269,7 @@ public class Recipient {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
RecipientTable db = SignalDatabase.recipients();
|
||||
RecipientId recipientId = db.getAndPossiblyMerge(serviceId, e164);
|
||||
RecipientId recipientId = RecipientId.from(new SignalServiceAddress(serviceId, e164));
|
||||
|
||||
Recipient resolved = resolved(recipientId);
|
||||
|
||||
@@ -282,7 +279,7 @@ public class Recipient {
|
||||
|
||||
if (!resolved.isRegistered() && serviceId != null) {
|
||||
Log.w(TAG, "External push was locally marked unregistered. Marking as registered.");
|
||||
db.markRegistered(recipientId, serviceId);
|
||||
SignalDatabase.recipients().markRegistered(recipientId, serviceId);
|
||||
} else if (!resolved.isRegistered()) {
|
||||
Log.w(TAG, "External push was locally marked unregistered, but we don't have an ACI, so we can't do anything.", new Throwable());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.thoughtcrime.securesms.recipients;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
@@ -13,6 +12,7 @@ import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.DatabaseId;
|
||||
import org.signal.core.util.LongSerializer;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.util.DelimiterUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
@@ -21,7 +21,6 @@ import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -94,9 +93,8 @@ public class RecipientId implements Parcelable, Comparable<RecipientId>, Databas
|
||||
RecipientId recipientId = RecipientIdCache.INSTANCE.get(serviceId, e164);
|
||||
|
||||
if (recipientId == null) {
|
||||
Recipient recipient = Recipient.externalPush(serviceId, e164);
|
||||
RecipientIdCache.INSTANCE.put(recipient);
|
||||
recipientId = recipient.getId();
|
||||
recipientId = SignalDatabase.recipients().getAndPossiblyMerge(serviceId, e164);
|
||||
RecipientIdCache.INSTANCE.put(recipientId, e164, serviceId);
|
||||
}
|
||||
|
||||
return recipientId;
|
||||
|
||||
@@ -32,18 +32,22 @@ final class RecipientIdCache {
|
||||
};
|
||||
}
|
||||
|
||||
synchronized void put(@NonNull RecipientId recipientId, @Nullable String e164, @Nullable ServiceId serviceId) {
|
||||
if (e164 != null) {
|
||||
ids.put(e164, recipientId);
|
||||
}
|
||||
|
||||
if (serviceId != null) {
|
||||
ids.put(serviceId, recipientId);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void put(@NonNull Recipient recipient) {
|
||||
RecipientId recipientId = recipient.getId();
|
||||
Optional<String> e164 = recipient.getE164();
|
||||
Optional<ServiceId> serviceId = recipient.getServiceId();
|
||||
|
||||
if (e164.isPresent()) {
|
||||
ids.put(e164.get(), recipientId);
|
||||
}
|
||||
|
||||
if (serviceId.isPresent()) {
|
||||
ids.put(serviceId.get(), recipientId);
|
||||
}
|
||||
put(recipientId, e164.orElse(null), serviceId.orElse(null));
|
||||
}
|
||||
|
||||
synchronized @Nullable RecipientId get(@Nullable ServiceId serviceId, @Nullable String e164) {
|
||||
|
||||
Reference in New Issue
Block a user