Accept session request if it was sent by a member of our group or if it was sent by one of our friends.

This commit is contained in:
Mikunj 2020-02-03 10:52:15 +11:00
parent d5420de0b7
commit 353f456ae2
2 changed files with 33 additions and 6 deletions

View File

@ -160,6 +160,23 @@ public class GroupDatabase extends Database {
return recipients;
}
public boolean signalGroupsHaveMember(String hexEncodedPublicKey) {
try {
Address address = Address.fromSerialized(hexEncodedPublicKey);
Reader reader = DatabaseFactory.getGroupDatabase(context).getGroups();
GroupRecord record;
while ((record = reader.getNext()) != null) {
if (record.isSignalGroup() && record.members.contains(address)) {
return true;
}
}
return false;
} catch (Exception e) {
return false;
}
}
public void create(@NonNull String groupId, @Nullable String title, @NonNull List<Address> members,
@Nullable SignalServiceAttachmentPointer avatar, @Nullable String relay, @Nullable List<Address> admins)
{
@ -476,6 +493,8 @@ public class GroupDatabase extends Database {
public boolean isRSSFeed() { return Address.fromSerialized(id).isRSSFeed(); }
public boolean isSignalGroup() { return Address.fromSerialized(id).isSignalGroup(); }
public String getUrl() { return url; }
public List<Address> getAdmins() { return admins; }

View File

@ -1228,12 +1228,20 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
private void handleSessionRequestIfNeeded(@NonNull SignalServiceContent content) {
if (content.isFriendRequest() && isSessionRequest(content)) {
// TODO: Check if member is in one of our private groups
boolean isInOneOfOurGroups = false;
if (isInOneOfOurGroups) {
// Check if the session request from a member in one of our groups or our friend
LokiStorageAPI.shared.getPrimaryDevicePublicKey(content.getSender()).success(primaryDevicePublicKey -> {
String sender = primaryDevicePublicKey != null ? primaryDevicePublicKey : content.getSender();
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(Recipient.from(context, Address.fromSerialized(sender), false));
LokiThreadFriendRequestStatus threadFriendRequestStatus = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadID);
boolean isOurFriend = threadFriendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS;
boolean isInOneOfOurGroups = DatabaseFactory.getGroupDatabase(context).signalGroupsHaveMember(sender);
boolean shouldAcceptSessionRequest = isOurFriend || isInOneOfOurGroups;
if (shouldAcceptSessionRequest) {
// Send a background message to acknowledge session request
MessageSender.sendBackgroundMessage(context, content.getSender());
}
return Unit.INSTANCE;
});
}
}