mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 10:28:27 +00:00
Send group messages to members and their secondary devices.
This commit is contained in:
parent
b6d2717286
commit
538cd39d00
@ -152,7 +152,9 @@ public class GroupDatabase extends Database {
|
|||||||
if (!includeSelf && Util.isOwnNumber(context, member))
|
if (!includeSelf && Util.isOwnNumber(context, member))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
recipients.add(Recipient.from(context, member, false));
|
if (member.isPhone()) {
|
||||||
|
recipients.add(Recipient.from(context, member, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return recipients;
|
return recipients;
|
||||||
|
@ -99,8 +99,7 @@ public class GroupMessageProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We should only create the group if we are part of the member list
|
// We should only create the group if we are part of the member list
|
||||||
String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
String hexEncodedPublicKey = getMasterHexEncodedPublicKey(context, TextSecurePreferences.getLocalNumber(context));
|
||||||
String hexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context);
|
|
||||||
if (members == null || !members.contains(Address.fromSerialized(hexEncodedPublicKey))) {
|
if (members == null || !members.contains(Address.fromSerialized(hexEncodedPublicKey))) {
|
||||||
Log.d("Loki - Group Message", "Received a group create message which doesn't include us in the member list. Ignoring.");
|
Log.d("Loki - Group Message", "Received a group create message which doesn't include us in the member list. Ignoring.");
|
||||||
return null;
|
return null;
|
||||||
@ -130,13 +129,7 @@ public class GroupMessageProcessor {
|
|||||||
|
|
||||||
// Only update group if admin sent the message
|
// Only update group if admin sent the message
|
||||||
if (group.getGroupType() == SignalServiceGroup.GroupType.SIGNAL) {
|
if (group.getGroupType() == SignalServiceGroup.GroupType.SIGNAL) {
|
||||||
String sender = content.getSender();
|
String hexEncodedPublicKey = getMasterHexEncodedPublicKey(context, content.getSender());
|
||||||
String hexEncodedPublicKey = sender;
|
|
||||||
try {
|
|
||||||
String primaryDevice = PromiseUtil.timeout(LokiStorageAPI.shared.getPrimaryDevicePublicKey(sender), 5000).get();
|
|
||||||
if (primaryDevice != null) { hexEncodedPublicKey = primaryDevice; }
|
|
||||||
} catch (Exception e) { }
|
|
||||||
|
|
||||||
if (!groupRecord.getAdmins().contains(Address.fromSerialized(hexEncodedPublicKey))) {
|
if (!groupRecord.getAdmins().contains(Address.fromSerialized(hexEncodedPublicKey))) {
|
||||||
Log.d("Loki - Group Message", "Received a group update message from a non-admin user for " + id +". Ignoring.");
|
Log.d("Loki - Group Message", "Received a group update message from a non-admin user for " + id +". Ignoring.");
|
||||||
return null;
|
return null;
|
||||||
@ -198,7 +191,10 @@ public class GroupMessageProcessor {
|
|||||||
@NonNull SignalServiceGroup group,
|
@NonNull SignalServiceGroup group,
|
||||||
@NonNull GroupRecord record)
|
@NonNull GroupRecord record)
|
||||||
{
|
{
|
||||||
if (record.getMembers().contains(Address.fromExternal(context, content.getSender()))) {
|
String hexEncodedPublicKey = getMasterHexEncodedPublicKey(context, content.getSender());
|
||||||
|
String ourPublicKey = getMasterHexEncodedPublicKey(context, TextSecurePreferences.getLocalNumber(context));
|
||||||
|
// If the requester is a group member and we are admin then we should send them the group update
|
||||||
|
if (record.getMembers().contains(Address.fromSerialized(hexEncodedPublicKey)) && record.getAdmins().contains(Address.fromSerialized(ourPublicKey))) {
|
||||||
ApplicationContext.getInstance(context)
|
ApplicationContext.getInstance(context)
|
||||||
.getJobManager()
|
.getJobManager()
|
||||||
.add(new PushGroupUpdateJob(content.getSender(), group.getGroupId()));
|
.add(new PushGroupUpdateJob(content.getSender(), group.getGroupId()));
|
||||||
@ -302,4 +298,15 @@ public class GroupMessageProcessor {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getMasterHexEncodedPublicKey(Context context, String hexEncodedPublicKey) {
|
||||||
|
String ourPublicKey = TextSecurePreferences.getLocalNumber(context);
|
||||||
|
try {
|
||||||
|
String masterHexEncodedPublicKey = hexEncodedPublicKey.equalsIgnoreCase(ourPublicKey)
|
||||||
|
? TextSecurePreferences.getMasterHexEncodedPublicKey(context)
|
||||||
|
: PromiseUtil.timeout(LokiStorageAPI.shared.getPrimaryDevicePublicKey(hexEncodedPublicKey), 5000).get();
|
||||||
|
return masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : hexEncodedPublicKey;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return hexEncodedPublicKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
|||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiPublicChat;
|
import org.whispersystems.signalservice.loki.api.LokiPublicChat;
|
||||||
|
import org.whispersystems.signalservice.loki.api.LokiStorageAPI;
|
||||||
|
import org.whispersystems.signalservice.loki.utilities.PromiseUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -313,7 +315,20 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
|||||||
if (!destinations.isEmpty()) return Stream.of(destinations).map(GroupReceiptInfo::getAddress).toList();
|
if (!destinations.isEmpty()) return Stream.of(destinations).map(GroupReceiptInfo::getAddress).toList();
|
||||||
|
|
||||||
List<Recipient> members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
|
List<Recipient> members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
|
||||||
return Stream.of(members).map(Recipient::getAddress).toList();
|
|
||||||
|
// Add secondary devices to the list
|
||||||
|
Set<Address> memberSet = Stream.of(members).map(Recipient::getAddress).collect(Collectors.toSet());
|
||||||
|
for (Recipient member : members) {
|
||||||
|
if (!member.getAddress().isPhone()) { continue; }
|
||||||
|
try {
|
||||||
|
List<String> secondaryDevices = PromiseUtil.timeout(LokiStorageAPI.shared.getSecondaryDevicePublicKeys(member.getAddress().serialize()), 5000).get();
|
||||||
|
memberSet.addAll(Stream.of(secondaryDevices).map(Address::fromSerialized).toList());
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Timed out, go to the next member
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LinkedList<>(memberSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user