Merge branch '1632-allow-resharing-shareable' into 'master'

Allow sharer to re-share a shareable again after leaving

Closes #1632

See merge request briar/briar!1169
This commit is contained in:
akwizgran
2019-10-14 14:29:38 +00:00
2 changed files with 56 additions and 4 deletions

View File

@@ -496,9 +496,11 @@ abstract class ProtocolEngineImpl<S extends Shareable>
txn.attach(e);
// Stop sharing the shareable with the contact
setShareableVisibility(txn, s, INVISIBLE);
// Send a LEAVE message, so the other party doesn't hang in LOCAL_LEFT
Message sent = sendLeaveMessage(txn, s);
// Move to the next state
return new Session(START, s.getContactGroupId(), s.getShareableId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
sent.getId(), m.getId(), sent.getTimestamp(),
s.getInviteTimestamp());
}

View File

@@ -234,6 +234,23 @@ public class ForumSharingIntegrationTest
// forum can be shared again
Contact c1 = contactManager0.getContact(contactId1From0);
assertTrue(forumSharingManager0.canBeShared(forum.getId(), c1));
// sharer un-subscribes from forum
forumManager0.removeForum(forum);
// send a new invitation again after re-adding the forum
db0.transaction(false, txn -> forumManager0.addForum(txn, forum));
forumSharingManager0.sendInvitation(forum.getId(), contactId1From0,
null, clock.currentTimeMillis());
// reset listener state for new request
listener1.requestReceived = false;
listener1.requestContactId = null;
// sync only 1 request message to make sure there wasn't an abort
sync0To1(1, true);
eventWaiter.await(TIMEOUT, 1);
assertRequestReceived(listener1, contactId0From1);
}
@Test
@@ -288,9 +305,16 @@ public class ForumSharingIntegrationTest
// forum can be shared again by sharer
assertTrue(forumSharingManager0
.canBeShared(forum.getId(), contact1From0));
// invitee that left can not share again
// invitee that left can not yet share again
assertFalse(forumSharingManager1
.canBeShared(forum.getId(), contact0From1));
// sharer responds with leave message
sync0To1(1, true);
// invitee that left can now share again
assertTrue(forumSharingManager1
.canBeShared(forum.getId(), contact0From1));
}
@Test
@@ -344,8 +368,31 @@ public class ForumSharingIntegrationTest
// sharer no longer gets forum shared by invitee
assertFalse(forumSharingManager1.getSharedWith(forum.getId())
.contains(contact0));
// forum can be shared again
// forum can be re-shared by invitee now
assertTrue(forumSharingManager1.canBeShared(forum.getId(), c0));
// invitee responds with LEAVE message
sync1To0(1, true);
// sharer can share forum again as well now
assertTrue(forumSharingManager0.canBeShared(forum.getId(), c1));
// invitee also un-subscribes forum without effect
forumManager1.removeForum(forum);
// send a new invitation again after re-adding the forum
db0.transaction(false, txn -> forumManager0.addForum(txn, forum));
forumSharingManager0.sendInvitation(forum.getId(), contactId1From0,
null, clock.currentTimeMillis());
// reset listener state for new request
listener1.requestReceived = false;
listener1.requestContactId = null;
// sync request message
sync0To1(1, true);
eventWaiter.await(TIMEOUT, 1);
assertRequestReceived(listener1, contactId0From1);
}
@Test
@@ -856,10 +903,13 @@ public class ForumSharingIntegrationTest
assertEquals(0, getMessages0From1().size());
assertGroupCount(messageTracker1, g0From1, 0, 0);
// both leave forum and send LEAVE message
// sharer leaves forum and sends LEAVE message
forumManager0.removeForum(forum);
sync0To1(1, true);
// invitee responds with LEAVE message
sync1To0(1, true);
// sending invitation is possible again
forumSharingManager1.sendInvitation(forum.getId(), contactId0From1,
null, clock.currentTimeMillis());