Show all Forum Invitations, not only the first

This commit is contained in:
Torsten Grote
2016-07-07 13:43:35 -03:00
parent fa5304c145
commit c577efacbe
10 changed files with 72 additions and 64 deletions

View File

@@ -183,7 +183,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
assertTrue(listener0.responseReceived);
// forum was added successfully
assertEquals(0, forumSharingManager0.getAvailable().size());
assertEquals(0, forumSharingManager0.getInvited().size());
assertEquals(1, forumManager1.getForums().size());
// invitee has one invitation message from sharer
@@ -233,10 +233,10 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
assertTrue(listener0.responseReceived);
// forum was not added
assertEquals(0, forumSharingManager0.getAvailable().size());
assertEquals(0, forumSharingManager0.getInvited().size());
assertEquals(0, forumManager1.getForums().size());
// forum is no longer available to invitee who declined
assertEquals(0, forumSharingManager1.getAvailable().size());
assertEquals(0, forumSharingManager1.getInvited().size());
// invitee has one invitation message from sharer
List<ForumInvitationMessage> list =
@@ -283,7 +283,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
assertTrue(listener0.responseReceived);
// forum was added successfully
assertEquals(0, forumSharingManager0.getAvailable().size());
assertEquals(0, forumSharingManager0.getInvited().size());
assertEquals(1, forumManager1.getForums().size());
assertTrue(forumManager1.getForums().contains(forum0));
@@ -303,7 +303,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
syncToSharer();
// forum is gone
assertEquals(0, forumSharingManager0.getAvailable().size());
assertEquals(0, forumSharingManager0.getInvited().size());
assertEquals(0, forumManager1.getForums().size());
// sharer no longer shares forum with invitee
@@ -343,7 +343,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
assertTrue(listener0.responseReceived);
// forum was added successfully
assertEquals(0, forumSharingManager0.getAvailable().size());
assertEquals(0, forumSharingManager0.getInvited().size());
assertEquals(1, forumManager1.getForums().size());
assertTrue(forumManager1.getForums().contains(forum0));
@@ -394,8 +394,9 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
// sharer un-subscribes from forum
forumManager0.removeForum(forum0);
// from here on expect the response to fail with a DbException
thrown.expect(DbException.class);
// from here on expect the response to fail with an AssertionError,
// because there is in fact no invited forum available anymore
thrown.expect(AssertionError.class);
// sync first request message and leave message
syncToInvitee();
@@ -403,7 +404,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
assertTrue(listener1.requestReceived);
// invitee has no forums available
assertEquals(0, forumSharingManager1.getAvailable().size());
assertEquals(0, forumSharingManager1.getInvited().size());
} finally {
stopLifecycles();
}
@@ -709,10 +710,11 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
deliverMessage(sync2, contactId2, sync1, contactId1,
"Sharer2 to Invitee");
// make sure we have only one forum available
Collection<Forum> forums =
forumSharingManager1.getAvailable();
// make sure we now have two invitations to the same forum available
Collection<Forum> forums = forumSharingManager1.getInvited();
assertEquals(1, forums.size());
assertEquals(2,
forumSharingManager1.getSharedBy(forum0.getId()).size());
// make sure both sharers actually share the forum
Collection<Contact> contacts =
@@ -946,6 +948,8 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
if (!answer) return;
Forum f = event.getForum();
try {
eventWaiter.assertEquals(1,
forumSharingManager1.getInvited().size());
Contact c =
contactManager1.getContact(event.getContactId());
forumSharingManager1.respondToInvitation(f, c, accept);

View File

@@ -82,7 +82,7 @@ public class AvailableForumsActivity extends BriarActivity
try {
Collection<ForumContacts> available = new ArrayList<>();
long now = System.currentTimeMillis();
for (Forum f : forumSharingManager.getAvailable()) {
for (Forum f : forumSharingManager.getInvited()) {
try {
Collection<Contact> c =
forumSharingManager.getSharedBy(f.getId());

View File

@@ -188,7 +188,7 @@ public class ForumListFragment extends BaseEventFragment implements
try {
long now = System.currentTimeMillis();
int available =
forumSharingManager.getAvailable().size();
forumSharingManager.getInvited().size();
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Loading available took " + duration + " ms");

View File

@@ -38,9 +38,9 @@ public interface BlogSharingManager
ContactId contactId) throws DbException;
/**
* Returns all blogs to which the user could subscribe.
* Returns all blogs to which the user has been invited.
*/
Collection<Blog> getAvailable() throws DbException;
Collection<Blog> getInvited() throws DbException;
/**
* Returns all contacts who are sharing the given blog with us.

View File

@@ -34,8 +34,8 @@ public interface ForumSharingManager extends SharingManager<Forum, ForumInvitati
Collection<ForumInvitationMessage> getInvitationMessages(
ContactId contactId) throws DbException;
/** Returns all forums to which the user could subscribe. */
Collection<Forum> getAvailable() throws DbException;
/** Returns all forums to which the user has been invited. */
Collection<Forum> getInvited() throws DbException;
/** Returns all contacts who are sharing the given forum with us. */
Collection<Contact> getSharedBy(GroupId g) throws DbException;

View File

@@ -25,7 +25,6 @@ public interface SharingConstants {
int SHARE_MSG_TYPE_DECLINE = 3;
int SHARE_MSG_TYPE_LEAVE = 4;
int SHARE_MSG_TYPE_ABORT = 5;
String TASK = "task";
int TASK_ADD_SHAREABLE_TO_LIST_SHARED_WITH_US = 0;
int TASK_REMOVE_SHAREABLE_FROM_LIST_SHARED_WITH_US = 1;
int TASK_ADD_SHARED_SHAREABLE = 2;

View File

@@ -3,8 +3,6 @@ package org.briarproject.api.sharing;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.forum.Forum;
import org.briarproject.api.forum.ForumInvitationMessage;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
@@ -16,7 +14,7 @@ public interface SharingManager<S extends Shareable, IM extends InvitationMessag
ClientId getClientId();
/**
* Sends an invitation to share the given group with the given contact
* Sends an invitation to share the given shareable with the given contact
* and sends an optional message along with it.
*/
void sendInvitation(GroupId groupId, ContactId contactId,
@@ -35,8 +33,8 @@ public interface SharingManager<S extends Shareable, IM extends InvitationMessag
Collection<IM> getInvitationMessages(
ContactId contactId) throws DbException;
/** Returns all groups to which the user could subscribe. */
Collection<S> getAvailable() throws DbException;
/** Returns all shareables to which the user has been invited. */
Collection<S> getInvited() throws DbException;
/** Returns all contacts who are sharing the given group with us. */
Collection<Contact> getSharedBy(GroupId g) throws DbException;

View File

@@ -80,11 +80,6 @@ class BlogSharingManagerImpl extends
return CLIENT_ID;
}
@Override
protected ClientId getShareableClientId() {
return blogManager.getClientId();
}
@Override
protected BlogInvitationMessage createInvitationMessage(MessageId id,
BlogInvitation msg, ContactId contactId, boolean available,

View File

@@ -78,11 +78,6 @@ class ForumSharingManagerImpl extends
return CLIENT_ID;
}
@Override
protected ClientId getShareableClientId() {
return forumManager.getClientId();
}
@Override
protected ForumInvitationMessage createInvitationMessage(MessageId id,
ForumInvitation msg, ContactId contactId, boolean available,

View File

@@ -81,6 +81,7 @@ import static org.briarproject.api.sharing.SharingConstants.TO_BE_SHARED_BY_US;
import static org.briarproject.api.sharing.SharingConstants.TYPE;
import static org.briarproject.api.sharing.SharingMessage.BaseMessage;
import static org.briarproject.api.sharing.SharingMessage.Invitation;
import static org.briarproject.sharing.InviteeSessionState.State.AWAIT_LOCAL_RESPONSE;
abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM extends InvitationMessage, IS extends InviteeSessionState, SS extends SharerSessionState, IR extends InvitationReceivedEvent, IRR extends InvitationResponseReceivedEvent>
extends BdfIncomingMessageHook
@@ -116,8 +117,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
public abstract ClientId getClientId();
protected abstract ClientId getShareableClientId();
protected abstract IM createInvitationMessage(MessageId id, I msg,
ContactId contactId, boolean available, long time, boolean local,
boolean sent, boolean seen, boolean read);
@@ -331,7 +330,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
new BdfEntry(TYPE, SHARE_MSG_TYPE_INVITATION)
);
Transaction txn = db.startTransaction(false);
Transaction txn = db.startTransaction(true);
try {
Contact contact = db.getContact(txn, contactId);
Group group = getContactGroup(contact);
@@ -356,7 +355,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
if (!(s instanceof InviteeSessionState))
continue;
available = ((InviteeSessionState) s).getState() ==
InviteeSessionState.State.AWAIT_LOCAL_RESPONSE;
AWAIT_LOCAL_RESPONSE;
}
IM im = createInvitationMessage(m.getKey(), msg, contactId,
available, time, local, status.isSent(),
@@ -377,34 +376,54 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
}
@Override
public Collection<S> getAvailable() throws DbException {
public Collection<S> getInvited() throws DbException {
Transaction txn = db.startTransaction(true);
try {
Set<S> available = new HashSet<S>();
Transaction txn = db.startTransaction(true);
try {
// Get any shareables we subscribe to
Set<Group> subscribed = new HashSet<Group>(db.getGroups(txn,
getShareableClientId()));
// Get all shareables shared by contacts
for (Contact c : db.getContacts(txn)) {
Group g = getContactGroup(c);
List<S> shareables =
getShareableList(txn, g.getId(), SHARED_WITH_US);
for (S f : shareables) {
if (!subscribed.contains(f.getGroup()))
available.add(f);
}
}
txn.setComplete();
} finally {
db.endTransaction(txn);
Set<S> invited = new HashSet<S>();
Collection<Contact> contacts = db.getContacts(txn);
for (Contact contact : contacts) {
invited.addAll(getInvited(txn, contact));
}
return Collections.unmodifiableSet(available);
} catch (IOException e) {
txn.setComplete();
return Collections.unmodifiableCollection(invited);
} catch (FormatException e) {
throw new DbException(e);
} finally {
db.endTransaction(txn);
}
}
private Collection<S> getInvited(Transaction txn, Contact contact)
throws DbException, FormatException {
// query for all external invitations
BdfDictionary query = BdfDictionary.of(
new BdfEntry(TYPE, SHARE_MSG_TYPE_INVITATION),
new BdfEntry(LOCAL, false)
);
Group group = getContactGroup(contact);
Set<S> invited = new HashSet<S>();
Map<MessageId, BdfDictionary> map = clientHelper
.getMessageMetadataAsDictionary(txn, group.getId(), query);
for (Map.Entry<MessageId, BdfDictionary> m : map.entrySet()) {
BdfDictionary d = m.getValue();
try {
I msg = getIFactory().build(group.getId(), d);
IS iss = (IS) getSessionState(txn, msg.getSessionId(), true);
// get and add the shareable if the invitation is unanswered
if (iss.getState().equals(AWAIT_LOCAL_RESPONSE)) {
S s = getSFactory().parse(iss);
invited.add(s);
}
} catch (FormatException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
}
}
return invited;
}
@Override
public Collection<Contact> getSharedBy(GroupId g) throws DbException {
try {
@@ -473,7 +492,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
}
}
protected void removingShareable(Transaction txn, S f) throws DbException {
void removingShareable(Transaction txn, S f) throws DbException {
try {
for (Contact c : db.getContacts(txn)) {
GroupId g = getContactGroup(c).getId();
@@ -642,9 +661,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
new BdfEntry(IS_SHARER, false),
new BdfEntry(CONTACT_ID, c.getId().getInt()),
new BdfEntry(SHAREABLE_ID, f.getId()),
new BdfEntry(STATE,
InviteeSessionState.State.AWAIT_LOCAL_RESPONSE
.getValue())
new BdfEntry(STATE, AWAIT_LOCAL_RESPONSE.getValue())
);
Map<MessageId, BdfDictionary> map = clientHelper