mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Correctly update UI when an outgoing friend request is accepted from a secondary device.
This commit is contained in:
parent
9ea2a6c8e4
commit
10ec395915
@ -128,6 +128,7 @@ import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher;
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
||||
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.Database;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase;
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase.Draft;
|
||||
@ -245,6 +246,7 @@ import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -2187,8 +2189,22 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
@Override
|
||||
public void handleThreadFriendRequestStatusChanged(long threadID) {
|
||||
if (threadID != this.threadId) { return; }
|
||||
new Handler(getMainLooper()).post(this::updateInputPanel);
|
||||
Util.runOnMain(() -> {
|
||||
boolean shouldUpdateInputPanel = true;
|
||||
if (threadID != this.threadId) {
|
||||
Recipient threadRecipient = DatabaseFactory.getThreadDatabase(this).getRecipientForThreadId(threadID);
|
||||
if (threadRecipient != null && !threadRecipient.isGroupRecipient()) {
|
||||
// We should update our input if this thread is a part of the other threads device
|
||||
Set<String> devices = MultiDeviceUtilitiesKt.getAllDevicePublicKeys(threadRecipient.getAddress().serialize(), LokiStorageAPI.Companion.getShared());
|
||||
shouldUpdateInputPanel = devices.contains(recipient.getAddress().serialize());
|
||||
} else {
|
||||
shouldUpdateInputPanel = false;
|
||||
}
|
||||
}
|
||||
if (shouldUpdateInputPanel) {
|
||||
this.updateInputPanel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateInputPanel() {
|
||||
|
@ -1099,7 +1099,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
// it must be a friend request accepted message. Declining a friend request doesn't send a message.
|
||||
lokiThreadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS);
|
||||
// Update the last message if needed
|
||||
FriendRequestHandler.updateLastFriendRequestMessage(context, threadID, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
String primaryDevice = MultiDeviceUtilitiesKt.getPrimaryDevicePublicKey(pubKey);
|
||||
long primaryDeviceThreadID = primaryDevice == null ? threadID : DatabaseFactory.getThreadDatabase(context).getThreadIdFor(Recipient.from(context, Address.fromSerialized(primaryDevice), false));
|
||||
FriendRequestHandler.updateLastFriendRequestMessage(context, primaryDeviceThreadID, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
}
|
||||
|
||||
private void updateFriendRequestStatusIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message) {
|
||||
|
@ -41,15 +41,23 @@ fun getAllDeviceFriendRequestStatus(context: Context, hexEncodedPublicKey: Strin
|
||||
|
||||
fun getAllDevicePublicKeys(context: Context, hexEncodedPublicKey: String, storageAPI: LokiStorageAPI, block: (devicePublicKey: String, isFriend: Boolean, friendCount: Int) -> Unit) {
|
||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
storageAPI.getAllDevicePublicKeys(hexEncodedPublicKey).success { items ->
|
||||
val devices = items.toMutableSet()
|
||||
if (hexEncodedPublicKey != userHexEncodedPublicKey) {
|
||||
devices.remove(userHexEncodedPublicKey)
|
||||
}
|
||||
val friends = getFriendPublicKeys(context, devices)
|
||||
for (device in devices) {
|
||||
block(device, friends.contains(device), friends.count())
|
||||
}
|
||||
val devices = getAllDevicePublicKeys(hexEncodedPublicKey, storageAPI).toMutableSet()
|
||||
if (hexEncodedPublicKey != userHexEncodedPublicKey) {
|
||||
devices.remove(userHexEncodedPublicKey)
|
||||
}
|
||||
val friends = getFriendPublicKeys(context, devices)
|
||||
for (device in devices) {
|
||||
block(device, friends.contains(device), friends.count())
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllDevicePublicKeys(hexEncodedPublicKey: String, storageAPI: LokiStorageAPI): Set<String> {
|
||||
val future = SettableFuture<Set<String>>()
|
||||
storageAPI.getAllDevicePublicKeys(hexEncodedPublicKey).success { future.set(it) }.fail { future.setException(it) }
|
||||
return try {
|
||||
future.get()
|
||||
} catch (e: Exception) {
|
||||
setOf()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user