Do not create PeerSession for groups we created

This needs a CreatorSession which gets created on-demand.
This commit is contained in:
Torsten Grote
2021-01-14 14:02:00 -03:00
parent 2ddb7b5b64
commit c4c70f5ac2
6 changed files with 51 additions and 7 deletions

View File

@@ -109,6 +109,11 @@ public interface PrivateGroupManager {
Collection<PrivateGroup> getPrivateGroups(Transaction txn) Collection<PrivateGroup> getPrivateGroups(Transaction txn)
throws DbException; throws DbException;
/**
* Returns true if the private group with the given ID was created by us.
*/
boolean isOurPrivateGroup(Transaction txn, GroupId g) throws DbException;
/** /**
* Returns the text of the private group message with the given ID. * Returns the text of the private group message with the given ID.
*/ */

View File

@@ -286,6 +286,14 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
return privateGroups; return privateGroups;
} }
@Override
public boolean isOurPrivateGroup(Transaction txn, GroupId g)
throws DbException {
PrivateGroup group = getPrivateGroup(txn, g);
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
return localAuthor.getId().equals(group.getCreator().getId());
}
@Override @Override
public Collection<PrivateGroup> getPrivateGroups() throws DbException { public Collection<PrivateGroup> getPrivateGroups() throws DbException {
return db.transactionWithResult(true, this::getPrivateGroups); return db.transactionWithResult(true, this::getPrivateGroups);

View File

@@ -126,11 +126,15 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
db.setGroupVisibility(txn, c.getId(), g.getId(), client); db.setGroupVisibility(txn, c.getId(), g.getId(), client);
// Attach the contact ID to the group // Attach the contact ID to the group
clientHelper.setContactId(txn, g.getId(), c.getId()); clientHelper.setContactId(txn, g.getId(), c.getId());
// If the contact belongs to any private groups, create a peer session // If the contact belongs to any private groups (we didn't create),
// create a peer session
for (Group pg : db.getGroups(txn, PrivateGroupManager.CLIENT_ID, for (Group pg : db.getGroups(txn, PrivateGroupManager.CLIENT_ID,
PrivateGroupManager.MAJOR_VERSION)) { PrivateGroupManager.MAJOR_VERSION)) {
if (privateGroupManager.isMember(txn, pg.getId(), c.getAuthor())) if (privateGroupManager.isMember(txn, pg.getId(), c.getAuthor())) {
addingMember(txn, pg.getId(), c); if (!privateGroupManager.isOurPrivateGroup(txn, pg.getId())) {
addingMember(txn, pg.getId(), c);
}
}
} }
} }

View File

@@ -709,6 +709,30 @@ public class GroupInvitationIntegrationTest
assertTrue(deleteMessages0From1(emptySet()).allDeleted()); assertTrue(deleteMessages0From1(emptySet()).allDeleted());
} }
@Test
public void testInvitationAfterReAddingContacts() throws Exception {
// sync invitation and response back
sendInvitation(c0.getClock().currentTimeMillis(), null);
sync0To1(1, true);
groupInvitationManager1
.respondToInvitation(contactId0From1, privateGroup, true);
sync1To0(1, true);
// sync group join messages
sync0To1(2, true); // + one invitation protocol join message
sync1To0(1, true);
assertFalse(groupInvitationManager0
.isInvitationAllowed(contact1From0, privateGroup.getId()));
// re-add contacts
removeAllContacts();
addDefaultContacts();
assertTrue(groupInvitationManager0
.isInvitationAllowed(contact1From0, privateGroup.getId()));
}
private Collection<ConversationMessageHeader> getMessages1From0() private Collection<ConversationMessageHeader> getMessages1From0()
throws DbException { throws DbException {
return db0.transactionWithResult(true, txn -> groupInvitationManager0 return db0.transactionWithResult(true, txn -> groupInvitationManager0

View File

@@ -196,6 +196,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(privateGroupManager).isMember(txn, privateGroup.getId(), oneOf(privateGroupManager).isMember(txn, privateGroup.getId(),
c.getAuthor()); c.getAuthor());
will(returnValue(true)); will(returnValue(true));
oneOf(privateGroupManager)
.isOurPrivateGroup(txn, privateGroup.getId());
will(returnValue(false));
}}); }});
expectAddingMember(privateGroup.getId(), c); expectAddingMember(privateGroup.getId(), c);
} }

View File

@@ -523,10 +523,10 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
contactManager0.removeContact(contactId2From0); contactManager0.removeContact(contactId2From0);
contactManager1.removeContact(contactId0From1); contactManager1.removeContact(contactId0From1);
contactManager2.removeContact(contactId0From2); contactManager2.removeContact(contactId0From2);
assertNotNull(contactId2From1); if (contactId2From1 != null)
contactManager1.removeContact(contactId2From1); contactManager1.removeContact(contactId2From1);
assertNotNull(contactId1From2); if (contactId1From2 != null)
contactManager2.removeContact(contactId1From2); contactManager2.removeContact(contactId1From2);
} }
protected void setAutoDeleteTimer(BriarIntegrationTestComponent component, protected void setAutoDeleteTimer(BriarIntegrationTestComponent component,