mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Do not create PeerSession for groups we created
This needs a CreatorSession which gets created on-demand.
This commit is contained in:
@@ -109,6 +109,11 @@ public interface PrivateGroupManager {
|
||||
Collection<PrivateGroup> getPrivateGroups(Transaction txn)
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -286,6 +286,14 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
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
|
||||
public Collection<PrivateGroup> getPrivateGroups() throws DbException {
|
||||
return db.transactionWithResult(true, this::getPrivateGroups);
|
||||
|
||||
@@ -126,11 +126,15 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||
// Attach the contact ID to the group
|
||||
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,
|
||||
PrivateGroupManager.MAJOR_VERSION)) {
|
||||
if (privateGroupManager.isMember(txn, pg.getId(), c.getAuthor()))
|
||||
addingMember(txn, pg.getId(), c);
|
||||
if (privateGroupManager.isMember(txn, pg.getId(), c.getAuthor())) {
|
||||
if (!privateGroupManager.isOurPrivateGroup(txn, pg.getId())) {
|
||||
addingMember(txn, pg.getId(), c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -709,6 +709,30 @@ public class GroupInvitationIntegrationTest
|
||||
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()
|
||||
throws DbException {
|
||||
return db0.transactionWithResult(true, txn -> groupInvitationManager0
|
||||
|
||||
@@ -196,6 +196,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(privateGroupManager).isMember(txn, privateGroup.getId(),
|
||||
c.getAuthor());
|
||||
will(returnValue(true));
|
||||
oneOf(privateGroupManager)
|
||||
.isOurPrivateGroup(txn, privateGroup.getId());
|
||||
will(returnValue(false));
|
||||
}});
|
||||
expectAddingMember(privateGroup.getId(), c);
|
||||
}
|
||||
|
||||
@@ -523,10 +523,10 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
contactManager0.removeContact(contactId2From0);
|
||||
contactManager1.removeContact(contactId0From1);
|
||||
contactManager2.removeContact(contactId0From2);
|
||||
assertNotNull(contactId2From1);
|
||||
contactManager1.removeContact(contactId2From1);
|
||||
assertNotNull(contactId1From2);
|
||||
contactManager2.removeContact(contactId1From2);
|
||||
if (contactId2From1 != null)
|
||||
contactManager1.removeContact(contactId2From1);
|
||||
if (contactId1From2 != null)
|
||||
contactManager2.removeContact(contactId1From2);
|
||||
}
|
||||
|
||||
protected void setAutoDeleteTimer(BriarIntegrationTestComponent component,
|
||||
|
||||
Reference in New Issue
Block a user