mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Show all Forum Invitations, not only the first
This commit is contained in:
@@ -183,7 +183,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
// forum was added successfully
|
// forum was added successfully
|
||||||
assertEquals(0, forumSharingManager0.getAvailable().size());
|
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||||
assertEquals(1, forumManager1.getForums().size());
|
assertEquals(1, forumManager1.getForums().size());
|
||||||
|
|
||||||
// invitee has one invitation message from sharer
|
// invitee has one invitation message from sharer
|
||||||
@@ -233,10 +233,10 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
// forum was not added
|
// forum was not added
|
||||||
assertEquals(0, forumSharingManager0.getAvailable().size());
|
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||||
assertEquals(0, forumManager1.getForums().size());
|
assertEquals(0, forumManager1.getForums().size());
|
||||||
// forum is no longer available to invitee who declined
|
// 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
|
// invitee has one invitation message from sharer
|
||||||
List<ForumInvitationMessage> list =
|
List<ForumInvitationMessage> list =
|
||||||
@@ -283,7 +283,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
// forum was added successfully
|
// forum was added successfully
|
||||||
assertEquals(0, forumSharingManager0.getAvailable().size());
|
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||||
assertEquals(1, forumManager1.getForums().size());
|
assertEquals(1, forumManager1.getForums().size());
|
||||||
assertTrue(forumManager1.getForums().contains(forum0));
|
assertTrue(forumManager1.getForums().contains(forum0));
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
syncToSharer();
|
syncToSharer();
|
||||||
|
|
||||||
// forum is gone
|
// forum is gone
|
||||||
assertEquals(0, forumSharingManager0.getAvailable().size());
|
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||||
assertEquals(0, forumManager1.getForums().size());
|
assertEquals(0, forumManager1.getForums().size());
|
||||||
|
|
||||||
// sharer no longer shares forum with invitee
|
// sharer no longer shares forum with invitee
|
||||||
@@ -343,7 +343,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
// forum was added successfully
|
// forum was added successfully
|
||||||
assertEquals(0, forumSharingManager0.getAvailable().size());
|
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||||
assertEquals(1, forumManager1.getForums().size());
|
assertEquals(1, forumManager1.getForums().size());
|
||||||
assertTrue(forumManager1.getForums().contains(forum0));
|
assertTrue(forumManager1.getForums().contains(forum0));
|
||||||
|
|
||||||
@@ -394,8 +394,9 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
// sharer un-subscribes from forum
|
// sharer un-subscribes from forum
|
||||||
forumManager0.removeForum(forum0);
|
forumManager0.removeForum(forum0);
|
||||||
|
|
||||||
// from here on expect the response to fail with a DbException
|
// from here on expect the response to fail with an AssertionError,
|
||||||
thrown.expect(DbException.class);
|
// because there is in fact no invited forum available anymore
|
||||||
|
thrown.expect(AssertionError.class);
|
||||||
|
|
||||||
// sync first request message and leave message
|
// sync first request message and leave message
|
||||||
syncToInvitee();
|
syncToInvitee();
|
||||||
@@ -403,7 +404,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
assertTrue(listener1.requestReceived);
|
assertTrue(listener1.requestReceived);
|
||||||
|
|
||||||
// invitee has no forums available
|
// invitee has no forums available
|
||||||
assertEquals(0, forumSharingManager1.getAvailable().size());
|
assertEquals(0, forumSharingManager1.getInvited().size());
|
||||||
} finally {
|
} finally {
|
||||||
stopLifecycles();
|
stopLifecycles();
|
||||||
}
|
}
|
||||||
@@ -709,10 +710,11 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
deliverMessage(sync2, contactId2, sync1, contactId1,
|
deliverMessage(sync2, contactId2, sync1, contactId1,
|
||||||
"Sharer2 to Invitee");
|
"Sharer2 to Invitee");
|
||||||
|
|
||||||
// make sure we have only one forum available
|
// make sure we now have two invitations to the same forum available
|
||||||
Collection<Forum> forums =
|
Collection<Forum> forums = forumSharingManager1.getInvited();
|
||||||
forumSharingManager1.getAvailable();
|
|
||||||
assertEquals(1, forums.size());
|
assertEquals(1, forums.size());
|
||||||
|
assertEquals(2,
|
||||||
|
forumSharingManager1.getSharedBy(forum0.getId()).size());
|
||||||
|
|
||||||
// make sure both sharers actually share the forum
|
// make sure both sharers actually share the forum
|
||||||
Collection<Contact> contacts =
|
Collection<Contact> contacts =
|
||||||
@@ -946,6 +948,8 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
|||||||
if (!answer) return;
|
if (!answer) return;
|
||||||
Forum f = event.getForum();
|
Forum f = event.getForum();
|
||||||
try {
|
try {
|
||||||
|
eventWaiter.assertEquals(1,
|
||||||
|
forumSharingManager1.getInvited().size());
|
||||||
Contact c =
|
Contact c =
|
||||||
contactManager1.getContact(event.getContactId());
|
contactManager1.getContact(event.getContactId());
|
||||||
forumSharingManager1.respondToInvitation(f, c, accept);
|
forumSharingManager1.respondToInvitation(f, c, accept);
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class AvailableForumsActivity extends BriarActivity
|
|||||||
try {
|
try {
|
||||||
Collection<ForumContacts> available = new ArrayList<>();
|
Collection<ForumContacts> available = new ArrayList<>();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for (Forum f : forumSharingManager.getAvailable()) {
|
for (Forum f : forumSharingManager.getInvited()) {
|
||||||
try {
|
try {
|
||||||
Collection<Contact> c =
|
Collection<Contact> c =
|
||||||
forumSharingManager.getSharedBy(f.getId());
|
forumSharingManager.getSharedBy(f.getId());
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
try {
|
try {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
int available =
|
int available =
|
||||||
forumSharingManager.getAvailable().size();
|
forumSharingManager.getInvited().size();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Loading available took " + duration + " ms");
|
LOG.info("Loading available took " + duration + " ms");
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ public interface BlogSharingManager
|
|||||||
ContactId contactId) throws DbException;
|
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.
|
* Returns all contacts who are sharing the given blog with us.
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ public interface ForumSharingManager extends SharingManager<Forum, ForumInvitati
|
|||||||
Collection<ForumInvitationMessage> getInvitationMessages(
|
Collection<ForumInvitationMessage> getInvitationMessages(
|
||||||
ContactId contactId) throws DbException;
|
ContactId contactId) throws DbException;
|
||||||
|
|
||||||
/** Returns all forums to which the user could subscribe. */
|
/** Returns all forums to which the user has been invited. */
|
||||||
Collection<Forum> getAvailable() throws DbException;
|
Collection<Forum> getInvited() throws DbException;
|
||||||
|
|
||||||
/** Returns all contacts who are sharing the given forum with us. */
|
/** Returns all contacts who are sharing the given forum with us. */
|
||||||
Collection<Contact> getSharedBy(GroupId g) throws DbException;
|
Collection<Contact> getSharedBy(GroupId g) throws DbException;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public interface SharingConstants {
|
|||||||
int SHARE_MSG_TYPE_DECLINE = 3;
|
int SHARE_MSG_TYPE_DECLINE = 3;
|
||||||
int SHARE_MSG_TYPE_LEAVE = 4;
|
int SHARE_MSG_TYPE_LEAVE = 4;
|
||||||
int SHARE_MSG_TYPE_ABORT = 5;
|
int SHARE_MSG_TYPE_ABORT = 5;
|
||||||
String TASK = "task";
|
|
||||||
int TASK_ADD_SHAREABLE_TO_LIST_SHARED_WITH_US = 0;
|
int TASK_ADD_SHAREABLE_TO_LIST_SHARED_WITH_US = 0;
|
||||||
int TASK_REMOVE_SHAREABLE_FROM_LIST_SHARED_WITH_US = 1;
|
int TASK_REMOVE_SHAREABLE_FROM_LIST_SHARED_WITH_US = 1;
|
||||||
int TASK_ADD_SHARED_SHAREABLE = 2;
|
int TASK_ADD_SHARED_SHAREABLE = 2;
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package org.briarproject.api.sharing;
|
|||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.db.DbException;
|
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.ClientId;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
|
|
||||||
@@ -16,7 +14,7 @@ public interface SharingManager<S extends Shareable, IM extends InvitationMessag
|
|||||||
ClientId getClientId();
|
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.
|
* and sends an optional message along with it.
|
||||||
*/
|
*/
|
||||||
void sendInvitation(GroupId groupId, ContactId contactId,
|
void sendInvitation(GroupId groupId, ContactId contactId,
|
||||||
@@ -35,8 +33,8 @@ public interface SharingManager<S extends Shareable, IM extends InvitationMessag
|
|||||||
Collection<IM> getInvitationMessages(
|
Collection<IM> getInvitationMessages(
|
||||||
ContactId contactId) throws DbException;
|
ContactId contactId) throws DbException;
|
||||||
|
|
||||||
/** Returns all groups to which the user could subscribe. */
|
/** Returns all shareables to which the user has been invited. */
|
||||||
Collection<S> getAvailable() throws DbException;
|
Collection<S> getInvited() throws DbException;
|
||||||
|
|
||||||
/** Returns all contacts who are sharing the given group with us. */
|
/** Returns all contacts who are sharing the given group with us. */
|
||||||
Collection<Contact> getSharedBy(GroupId g) throws DbException;
|
Collection<Contact> getSharedBy(GroupId g) throws DbException;
|
||||||
|
|||||||
@@ -80,11 +80,6 @@ class BlogSharingManagerImpl extends
|
|||||||
return CLIENT_ID;
|
return CLIENT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ClientId getShareableClientId() {
|
|
||||||
return blogManager.getClientId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlogInvitationMessage createInvitationMessage(MessageId id,
|
protected BlogInvitationMessage createInvitationMessage(MessageId id,
|
||||||
BlogInvitation msg, ContactId contactId, boolean available,
|
BlogInvitation msg, ContactId contactId, boolean available,
|
||||||
|
|||||||
@@ -78,11 +78,6 @@ class ForumSharingManagerImpl extends
|
|||||||
return CLIENT_ID;
|
return CLIENT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ClientId getShareableClientId() {
|
|
||||||
return forumManager.getClientId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ForumInvitationMessage createInvitationMessage(MessageId id,
|
protected ForumInvitationMessage createInvitationMessage(MessageId id,
|
||||||
ForumInvitation msg, ContactId contactId, boolean available,
|
ForumInvitation msg, ContactId contactId, boolean available,
|
||||||
|
|||||||
@@ -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.SharingConstants.TYPE;
|
||||||
import static org.briarproject.api.sharing.SharingMessage.BaseMessage;
|
import static org.briarproject.api.sharing.SharingMessage.BaseMessage;
|
||||||
import static org.briarproject.api.sharing.SharingMessage.Invitation;
|
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>
|
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
|
extends BdfIncomingMessageHook
|
||||||
@@ -116,8 +117,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
|
|||||||
|
|
||||||
public abstract ClientId getClientId();
|
public abstract ClientId getClientId();
|
||||||
|
|
||||||
protected abstract ClientId getShareableClientId();
|
|
||||||
|
|
||||||
protected abstract IM createInvitationMessage(MessageId id, I msg,
|
protected abstract IM createInvitationMessage(MessageId id, I msg,
|
||||||
ContactId contactId, boolean available, long time, boolean local,
|
ContactId contactId, boolean available, long time, boolean local,
|
||||||
boolean sent, boolean seen, boolean read);
|
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)
|
new BdfEntry(TYPE, SHARE_MSG_TYPE_INVITATION)
|
||||||
);
|
);
|
||||||
|
|
||||||
Transaction txn = db.startTransaction(false);
|
Transaction txn = db.startTransaction(true);
|
||||||
try {
|
try {
|
||||||
Contact contact = db.getContact(txn, contactId);
|
Contact contact = db.getContact(txn, contactId);
|
||||||
Group group = getContactGroup(contact);
|
Group group = getContactGroup(contact);
|
||||||
@@ -356,7 +355,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
|
|||||||
if (!(s instanceof InviteeSessionState))
|
if (!(s instanceof InviteeSessionState))
|
||||||
continue;
|
continue;
|
||||||
available = ((InviteeSessionState) s).getState() ==
|
available = ((InviteeSessionState) s).getState() ==
|
||||||
InviteeSessionState.State.AWAIT_LOCAL_RESPONSE;
|
AWAIT_LOCAL_RESPONSE;
|
||||||
}
|
}
|
||||||
IM im = createInvitationMessage(m.getKey(), msg, contactId,
|
IM im = createInvitationMessage(m.getKey(), msg, contactId,
|
||||||
available, time, local, status.isSent(),
|
available, time, local, status.isSent(),
|
||||||
@@ -377,34 +376,54 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<S> getAvailable() throws DbException {
|
public Collection<S> getInvited() throws DbException {
|
||||||
|
Transaction txn = db.startTransaction(true);
|
||||||
try {
|
try {
|
||||||
Set<S> available = new HashSet<S>();
|
Set<S> invited = new HashSet<S>();
|
||||||
Transaction txn = db.startTransaction(true);
|
Collection<Contact> contacts = db.getContacts(txn);
|
||||||
try {
|
for (Contact contact : contacts) {
|
||||||
// Get any shareables we subscribe to
|
invited.addAll(getInvited(txn, contact));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableSet(available);
|
txn.setComplete();
|
||||||
} catch (IOException e) {
|
return Collections.unmodifiableCollection(invited);
|
||||||
|
} catch (FormatException e) {
|
||||||
throw new DbException(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
|
@Override
|
||||||
public Collection<Contact> getSharedBy(GroupId g) throws DbException {
|
public Collection<Contact> getSharedBy(GroupId g) throws DbException {
|
||||||
try {
|
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 {
|
try {
|
||||||
for (Contact c : db.getContacts(txn)) {
|
for (Contact c : db.getContacts(txn)) {
|
||||||
GroupId g = getContactGroup(c).getId();
|
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(IS_SHARER, false),
|
||||||
new BdfEntry(CONTACT_ID, c.getId().getInt()),
|
new BdfEntry(CONTACT_ID, c.getId().getInt()),
|
||||||
new BdfEntry(SHAREABLE_ID, f.getId()),
|
new BdfEntry(SHAREABLE_ID, f.getId()),
|
||||||
new BdfEntry(STATE,
|
new BdfEntry(STATE, AWAIT_LOCAL_RESPONSE.getValue())
|
||||||
InviteeSessionState.State.AWAIT_LOCAL_RESPONSE
|
|
||||||
.getValue())
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<MessageId, BdfDictionary> map = clientHelper
|
Map<MessageId, BdfDictionary> map = clientHelper
|
||||||
|
|||||||
Reference in New Issue
Block a user