mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 12:28:24 +00:00
Fix closed group multi device message sending
This commit is contained in:
parent
f015339fc5
commit
7d5114b595
@ -154,7 +154,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
|
||||
if (filterAddress != null) targets = Collections.singletonList(Address.fromSerialized(filterAddress));
|
||||
else if (!existingNetworkFailures.isEmpty()) targets = Stream.of(existingNetworkFailures).map(NetworkFailure::getAddress).toList();
|
||||
else targets = getGroupMessageRecipients(message.getRecipient().getAddress().toGroupString(), messageId);
|
||||
else targets = ClosedGroupsProtocol.getDestinations(message.getRecipient().getAddress().toGroupString(), context).get();
|
||||
|
||||
List<SendMessageResult> results = deliver(message, targets);
|
||||
List<NetworkFailure> networkFailures = Stream.of(results).filter(SendMessageResult::isNetworkFailure).map(result -> new NetworkFailure(Address.fromSerialized(result.getAddress().getNumber()))).toList();
|
||||
@ -205,7 +205,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
database.markAsSentFailed(messageId);
|
||||
notifyMediaMessageDeliveryFailed(context, messageId);
|
||||
}
|
||||
} catch (UntrustedIdentityException | UndeliverableMessageException e) {
|
||||
} catch (Exception e) {
|
||||
warn(TAG, e);
|
||||
database.markAsSentFailed(messageId);
|
||||
notifyMediaMessageDeliveryFailed(context, messageId);
|
||||
@ -231,7 +231,9 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
Address address = message.getRecipient().getAddress();
|
||||
if (address.isRSSFeed()) {
|
||||
List<SendMessageResult> results = new ArrayList<>();
|
||||
for (Address destination : destinations) results.add(SendMessageResult.networkFailure(new SignalServiceAddress(destination.toPhoneString())));
|
||||
for (Address destination : destinations) {
|
||||
results.add(SendMessageResult.networkFailure(new SignalServiceAddress(destination.toPhoneString())));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -263,7 +265,6 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
SignalServiceDataMessage groupDataMessage = SignalServiceDataMessage.newBuilder()
|
||||
.withTimestamp(message.getSentTimeMillis())
|
||||
.withExpiration(message.getRecipient().getExpireMessages())
|
||||
.withBody(message.getBody())
|
||||
.asGroupMessage(group)
|
||||
.build();
|
||||
|
||||
@ -288,10 +289,6 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
}
|
||||
}
|
||||
|
||||
private @NonNull List<Address> getGroupMessageRecipients(String groupId, long messageId) {
|
||||
return ClosedGroupsProtocol.getDestinations(groupId, context);
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<PushGroupSendJob> {
|
||||
@Override
|
||||
public @NonNull PushGroupSendJob create(@NonNull Parameters parameters, @NonNull org.thoughtcrime.securesms.jobmanager.Data data) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.thoughtcrime.securesms.loki.protocol
|
||||
|
||||
import android.content.Context
|
||||
import nl.komponents.kovenant.Promise
|
||||
import nl.komponents.kovenant.functional.map
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
@ -14,6 +16,7 @@ import org.whispersystems.libsignal.SignalProtocolAddress
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI
|
||||
import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol
|
||||
import java.util.*
|
||||
|
||||
@ -38,27 +41,29 @@ object ClosedGroupsProtocol {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDestinations(groupID: String, context: Context): List<Address> {
|
||||
if (GroupUtil.isRSSFeed(groupID)) { return listOf() }
|
||||
fun getDestinations(groupID: String, context: Context): Promise<List<Address>, Exception> {
|
||||
if (GroupUtil.isRSSFeed(groupID)) { return Promise.of(listOf()) }
|
||||
if (GroupUtil.isOpenGroup(groupID)) {
|
||||
val result = mutableListOf<Address>()
|
||||
result.add(Address.fromSerialized(groupID))
|
||||
return result
|
||||
return Promise.of(result)
|
||||
} else {
|
||||
// A closed group's members should never include slave devices
|
||||
val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupID, false)
|
||||
val destinations = members.flatMap { member ->
|
||||
MultiDeviceProtocol.shared.getAllLinkedDevices(member.address.serialize()).map { Address.fromSerialized(it) }
|
||||
}.toMutableSet()
|
||||
val userMasterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
|
||||
if (userMasterPublicKey != null && destinations.contains(Address.fromSerialized(userMasterPublicKey))) {
|
||||
destinations.remove(Address.fromSerialized(userMasterPublicKey))
|
||||
return LokiFileServerAPI.shared.getDeviceLinks(members.map { it.address.serialize() }.toSet()).map {
|
||||
val result = members.flatMap { member ->
|
||||
MultiDeviceProtocol.shared.getAllLinkedDevices(member.address.serialize()).map { Address.fromSerialized(it) }
|
||||
}.toMutableSet()
|
||||
val userMasterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
|
||||
if (userMasterPublicKey != null && result.contains(Address.fromSerialized(userMasterPublicKey))) {
|
||||
result.remove(Address.fromSerialized(userMasterPublicKey))
|
||||
}
|
||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
if (userPublicKey != null && result.contains(Address.fromSerialized(userPublicKey))) {
|
||||
result.remove(Address.fromSerialized(userPublicKey))
|
||||
}
|
||||
result.toList()
|
||||
}
|
||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
if (userPublicKey != null && destinations.contains(Address.fromSerialized(userPublicKey))) {
|
||||
destinations.remove(Address.fromSerialized(userPublicKey))
|
||||
}
|
||||
return destinations.toList()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user