Partially unbork accepting FRs sent by slave devices

This commit is contained in:
nielsandriesse 2020-05-25 12:30:58 +10:00
parent 92b4b81935
commit 40bc3bfda0
3 changed files with 15 additions and 6 deletions

View File

@ -1409,7 +1409,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
} else {
try {
// TODO: Burn this with fire when we can
PromiseUtilities.timeout(LokiFileServerAPI.shared.getDeviceLinks(publicKey, false), 4000).get();
PromiseUtilities.timeout(LokiFileServerAPI.shared.getDeviceLinks(publicKey, false), 6000).get();
String masterPublicKey = org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol.shared.getMasterDevice(publicKey);
if (masterPublicKey == null) {
masterPublicKey = publicKey;
@ -1441,7 +1441,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
} else {
try {
// TODO: Burn this with fire when we can
PromiseUtilities.timeout(LokiFileServerAPI.shared.getDeviceLinks(publicKey, false), 4000).get();
PromiseUtilities.timeout(LokiFileServerAPI.shared.getDeviceLinks(publicKey, false), 6000).get();
String masterPublicKey = org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol.shared.getMasterDevice(publicKey);
if (masterPublicKey == null) {
masterPublicKey = publicKey;

View File

@ -8,6 +8,7 @@ import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore
import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.loki.utilities.recipient
import org.thoughtcrime.securesms.loki.utilities.timeout
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.sms.MessageSender
import org.thoughtcrime.securesms.util.GroupUtil
@ -30,7 +31,7 @@ object ClosedGroupsProtocol {
if (!conversation.address.isClosedGroup || groupID == null) { return false }
// A closed group's members should never include slave devices
val senderPublicKey = content.sender
LokiFileServerAPI.shared.getDeviceLinks(senderPublicKey).get()
LokiFileServerAPI.shared.getDeviceLinks(senderPublicKey).timeout(6000).get()
val senderMasterPublicKey = MultiDeviceProtocol.shared.getMasterDevice(senderPublicKey)
val publicKeyToCheckFor = senderMasterPublicKey ?: senderPublicKey
val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupID, true)

View File

@ -224,9 +224,17 @@ object FriendRequestProtocol {
// friend request status is reset to NONE. Bob now sends Alice a friend request. Alice's thread's
// friend request status is reset to RECEIVED
lokiThreadDB.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.REQUEST_RECEIVED)
val lastMessageID = getLastMessageID(context, threadID)
if (lastMessageID != null) {
DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(lastMessageID, LokiMessageFriendRequestStatus.REQUEST_PENDING)
val masterPublicKey = MultiDeviceProtocol.shared.getMasterDevice(publicKey) ?: publicKey
val masterThreadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient(context, masterPublicKey))
val masterThreadLastMessageID = getLastMessageID(context, masterThreadID) // Messages get routed into the master thread
if (masterThreadLastMessageID != null) {
DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(masterThreadLastMessageID, LokiMessageFriendRequestStatus.REQUEST_PENDING)
} else {
// Device link fetching could fail, in which case the message could get routed into the slave thread
val slaveThreadLastMessageID = getLastMessageID(context, threadID)
if (slaveThreadLastMessageID != null) {
DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(slaveThreadLastMessageID, LokiMessageFriendRequestStatus.REQUEST_PENDING)
}
}
}
}