mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Merge branch '470-second-invitation-doesn-t-disappear-from-available-forums' into 'master'
Return proper Invitation objects in SharingManager Fixes #470 See merge request !265
This commit is contained in:
@@ -198,7 +198,7 @@ public class BlogSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// blog was added successfully
|
||||
assertEquals(0, blogSharingManager0.getInvited().size());
|
||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||
assertEquals(3, blogManager1.getBlogs().size());
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
@@ -257,10 +257,10 @@ public class BlogSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// blog was not added
|
||||
assertEquals(0, blogSharingManager0.getInvited().size());
|
||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||
assertEquals(2, blogManager1.getBlogs().size());
|
||||
// blog is no longer available to invitee who declined
|
||||
assertEquals(0, blogSharingManager1.getInvited().size());
|
||||
assertEquals(0, blogSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<InvitationMessage> list =
|
||||
@@ -317,7 +317,7 @@ public class BlogSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// blog was added successfully
|
||||
assertEquals(0, blogSharingManager0.getInvited().size());
|
||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||
assertEquals(3, blogManager1.getBlogs().size());
|
||||
assertTrue(blogManager1.getBlogs().contains(blog2));
|
||||
|
||||
@@ -335,7 +335,7 @@ public class BlogSharingIntegrationTest extends BriarTestCase {
|
||||
sync1To0();
|
||||
|
||||
// blog is gone
|
||||
assertEquals(0, blogSharingManager0.getInvited().size());
|
||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||
assertEquals(2, blogManager1.getBlogs().size());
|
||||
|
||||
// sharer no longer shares blog with invitee
|
||||
@@ -396,7 +396,7 @@ public class BlogSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// blog was not added, because it was there already
|
||||
assertEquals(0, blogSharingManager0.getInvited().size());
|
||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||
assertEquals(3, blogManager1.getBlogs().size());
|
||||
|
||||
stopLifecycles();
|
||||
@@ -495,7 +495,7 @@ public class BlogSharingIntegrationTest extends BriarTestCase {
|
||||
Blog b = event.getBlog();
|
||||
try {
|
||||
eventWaiter.assertEquals(1,
|
||||
blogSharingManager1.getInvited().size());
|
||||
blogSharingManager1.getInvitations().size());
|
||||
Contact c =
|
||||
contactManager1.getContact(event.getContactId());
|
||||
blogSharingManager1.respondToInvitation(b, c, accept);
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.briarproject.api.identity.AuthorFactory;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
@@ -186,7 +187,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// forum was added successfully
|
||||
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||
assertEquals(0, forumSharingManager0.getInvitations().size());
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
@@ -247,10 +248,10 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// forum was not added
|
||||
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||
assertEquals(0, forumSharingManager0.getInvitations().size());
|
||||
assertEquals(0, forumManager1.getForums().size());
|
||||
// forum is no longer available to invitee who declined
|
||||
assertEquals(0, forumSharingManager1.getInvited().size());
|
||||
assertEquals(0, forumSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<InvitationMessage> list =
|
||||
@@ -308,7 +309,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// forum was added successfully
|
||||
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||
assertEquals(0, forumSharingManager0.getInvitations().size());
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
assertTrue(forumManager1.getForums().contains(forum0));
|
||||
|
||||
@@ -328,7 +329,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
syncToSharer();
|
||||
|
||||
// forum is gone
|
||||
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||
assertEquals(0, forumSharingManager0.getInvitations().size());
|
||||
assertEquals(0, forumManager1.getForums().size());
|
||||
|
||||
// sharer no longer shares forum with invitee
|
||||
@@ -368,7 +369,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
// forum was added successfully
|
||||
assertEquals(0, forumSharingManager0.getInvited().size());
|
||||
assertEquals(0, forumSharingManager0.getInvitations().size());
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
assertTrue(forumManager1.getForums().contains(forum0));
|
||||
|
||||
@@ -431,7 +432,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
msgWaiter.await(TIMEOUT, 1);
|
||||
|
||||
// ensure that invitee has no forum invitations available
|
||||
assertEquals(0, forumSharingManager1.getInvited().size());
|
||||
assertEquals(0, forumSharingManager1.getInvitations().size());
|
||||
assertEquals(0, forumManager1.getForums().size());
|
||||
|
||||
// Try again, this time allow the response
|
||||
@@ -454,7 +455,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
msgWaiter.await(TIMEOUT, 1);
|
||||
|
||||
// ensure that invitee has no forum invitations available
|
||||
assertEquals(0, forumSharingManager1.getInvited().size());
|
||||
assertEquals(0, forumSharingManager1.getInvitations().size());
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
} finally {
|
||||
stopLifecycles();
|
||||
@@ -570,6 +571,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getInvitationMessages(contactId1)
|
||||
.size());
|
||||
assertEquals(0, forumSharingManager0.getInvitations().size());
|
||||
} finally {
|
||||
stopLifecycles();
|
||||
}
|
||||
@@ -767,8 +769,11 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
"Sharer2 to Invitee");
|
||||
|
||||
// make sure we now have two invitations to the same forum available
|
||||
Collection<Forum> forums = forumSharingManager1.getInvited();
|
||||
Collection<InvitationItem> forums =
|
||||
forumSharingManager1.getInvitations();
|
||||
assertEquals(1, forums.size());
|
||||
assertEquals(2, forums.iterator().next().getNewSharers().size());
|
||||
assertEquals(forum0, forums.iterator().next().getShareable());
|
||||
assertEquals(2,
|
||||
forumSharingManager1.getSharedBy(forum0.getId()).size());
|
||||
|
||||
@@ -1005,13 +1010,16 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
Forum f = event.getForum();
|
||||
try {
|
||||
eventWaiter.assertEquals(1,
|
||||
forumSharingManager1.getInvited().size());
|
||||
if (respond) {
|
||||
Contact c =
|
||||
contactManager1
|
||||
.getContact(event.getContactId());
|
||||
forumSharingManager1.respondToInvitation(f, c, accept);
|
||||
}
|
||||
forumSharingManager1.getInvitations().size());
|
||||
InvitationItem invitation =
|
||||
forumSharingManager1.getInvitations().iterator()
|
||||
.next();
|
||||
eventWaiter.assertEquals(f, invitation.getShareable());
|
||||
if (respond) {
|
||||
Contact c =
|
||||
contactManager1.getContact(event.getContactId());
|
||||
forumSharingManager1.respondToInvitation(f, c, accept);
|
||||
}
|
||||
} catch (DbException ex) {
|
||||
eventWaiter.rethrow(ex);
|
||||
} finally {
|
||||
|
||||
@@ -189,7 +189,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
int available =
|
||||
forumSharingManager.getInvited().size();
|
||||
forumSharingManager.getInvitations().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading available took " + duration + " ms");
|
||||
@@ -206,6 +206,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getActivity() == null) return;
|
||||
if (availableCount == 0) {
|
||||
snackbar.dismiss();
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.blogs.Blog;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
|
||||
class BlogInvitationAdapter extends InvitationAdapter {
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.android.sharing;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
|
||||
class ForumInvitationAdapter extends InvitationAdapter {
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.widget.TextView;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.TextAvatarView;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -48,7 +49,8 @@ abstract class InvitationAdapter extends
|
||||
final InvitationItem item = getItem(position);
|
||||
|
||||
Collection<String> names = new ArrayList<>();
|
||||
for (Contact c : item.getContacts()) names.add(c.getAuthor().getName());
|
||||
for (Contact c : item.getNewSharers())
|
||||
names.add(c.getAuthor().getName());
|
||||
ui.sharedBy.setText(ctx.getString(R.string.shared_by_format,
|
||||
StringUtils.join(names, ", ")));
|
||||
|
||||
@@ -153,7 +155,7 @@ abstract class InvitationAdapter extends
|
||||
public boolean areContentsTheSame(InvitationItem oldItem,
|
||||
InvitationItem newItem) {
|
||||
return oldItem.isSubscribed() == newItem.isSubscribed() &&
|
||||
oldItem.getContacts().equals(newItem.getContacts());
|
||||
oldItem.getNewSharers().equals(newItem.getNewSharers());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package org.briarproject.android.sharing;
|
||||
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class InvitationItem {
|
||||
|
||||
private final Shareable shareable;
|
||||
private final boolean subscribed;
|
||||
private final Collection<Contact> contacts;
|
||||
|
||||
InvitationItem(Shareable shareable, boolean subscribed,
|
||||
Collection<Contact> contacts) {
|
||||
|
||||
this.shareable = shareable;
|
||||
this.subscribed = subscribed;
|
||||
this.contacts = contacts;
|
||||
}
|
||||
|
||||
Shareable getShareable() {
|
||||
return shareable;
|
||||
}
|
||||
|
||||
boolean isSubscribed() {
|
||||
return subscribed;
|
||||
}
|
||||
|
||||
Collection<Contact> getContacts() {
|
||||
return contacts;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.briarproject.api.event.ContactRemovedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -9,11 +9,11 @@ import org.briarproject.api.blogs.BlogManager;
|
||||
import org.briarproject.api.blogs.BlogSharingManager;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.NoSuchGroupException;
|
||||
import org.briarproject.api.event.BlogInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.GroupAddedEvent;
|
||||
import org.briarproject.api.event.GroupRemovedEvent;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -71,30 +71,18 @@ public class InvitationsBlogActivity extends InvitationsActivity {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Collection<InvitationItem> invitations = new ArrayList<>();
|
||||
try {
|
||||
Collection<InvitationItem> invitations = new ArrayList<>();
|
||||
long now = System.currentTimeMillis();
|
||||
for (Blog b : blogSharingManager.getInvited()) {
|
||||
boolean subscribed;
|
||||
try {
|
||||
blogManager.getBlog(b.getId());
|
||||
subscribed = true;
|
||||
} catch (NoSuchGroupException e) {
|
||||
subscribed = false;
|
||||
}
|
||||
Collection<Contact> c =
|
||||
blogSharingManager.getSharedBy(b.getId());
|
||||
invitations.add(
|
||||
new InvitationItem(b, subscribed, c));
|
||||
}
|
||||
invitations.addAll(blogSharingManager.getInvitations());
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
displayInvitations(invitations, clear);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
displayInvitations(invitations, clear);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -106,7 +94,7 @@ public class InvitationsBlogActivity extends InvitationsActivity {
|
||||
public void run() {
|
||||
try {
|
||||
Blog b = (Blog) item.getShareable();
|
||||
for (Contact c : item.getContacts()) {
|
||||
for (Contact c : item.getNewSharers()) {
|
||||
blogSharingManager.respondToInvitation(b, c, accept);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.briarproject.R;
|
||||
import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.NoSuchGroupException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.ForumInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.GroupAddedEvent;
|
||||
@@ -14,6 +13,7 @@ import org.briarproject.api.event.GroupRemovedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -71,30 +71,18 @@ public class InvitationsForumActivity extends InvitationsActivity {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Collection<InvitationItem> invitations = new ArrayList<>();
|
||||
try {
|
||||
Collection<InvitationItem> forums = new ArrayList<>();
|
||||
long now = System.currentTimeMillis();
|
||||
for (Forum f : forumSharingManager.getInvited()) {
|
||||
boolean subscribed;
|
||||
try {
|
||||
forumManager.getForum(f.getId());
|
||||
subscribed = true;
|
||||
} catch (NoSuchGroupException e) {
|
||||
subscribed = false;
|
||||
}
|
||||
Collection<Contact> c =
|
||||
forumSharingManager.getSharedBy(f.getId());
|
||||
forums.add(
|
||||
new InvitationItem(f, subscribed, c));
|
||||
}
|
||||
invitations.addAll(forumSharingManager.getInvitations());
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
displayInvitations(forums, clear);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
displayInvitations(invitations, clear);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -106,7 +94,7 @@ public class InvitationsForumActivity extends InvitationsActivity {
|
||||
public void run() {
|
||||
try {
|
||||
Forum f = (Forum) item.getShareable();
|
||||
for (Contact c : item.getContacts()) {
|
||||
for (Contact c : item.getNewSharers()) {
|
||||
forumSharingManager.respondToInvitation(f, c, accept);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.api.blogs;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.SharingManager;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
@@ -40,7 +41,7 @@ public interface BlogSharingManager extends SharingManager<Blog> {
|
||||
/**
|
||||
* Returns all blogs to which the user has been invited.
|
||||
*/
|
||||
Collection<Blog> getInvited() throws DbException;
|
||||
Collection<InvitationItem> getInvitations() throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all contacts who are sharing the given blog with us.
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.api.forum;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.SharingManager;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
@@ -36,7 +37,7 @@ public interface ForumSharingManager extends SharingManager<Forum> {
|
||||
ContactId contactId) throws DbException;
|
||||
|
||||
/** Returns all forums to which the user has been invited. */
|
||||
Collection<Forum> getInvited() throws DbException;
|
||||
Collection<InvitationItem> getInvitations() throws DbException;
|
||||
|
||||
/** Returns all contacts who are sharing the given forum with us. */
|
||||
Collection<Contact> getSharedBy(GroupId g) throws DbException;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.briarproject.api.sharing;
|
||||
|
||||
import org.briarproject.api.contact.Contact;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class InvitationItem {
|
||||
|
||||
private final Shareable shareable;
|
||||
private final boolean subscribed;
|
||||
private final Collection<Contact> newSharers;
|
||||
|
||||
public InvitationItem(Shareable shareable, boolean subscribed,
|
||||
Collection<Contact> newSharers) {
|
||||
|
||||
this.shareable = shareable;
|
||||
this.subscribed = subscribed;
|
||||
this.newSharers = newSharers;
|
||||
}
|
||||
|
||||
public Shareable getShareable() {
|
||||
return shareable;
|
||||
}
|
||||
|
||||
public boolean isSubscribed() {
|
||||
return subscribed;
|
||||
}
|
||||
|
||||
public Collection<Contact> getNewSharers() {
|
||||
return newSharers;
|
||||
}
|
||||
}
|
||||
@@ -33,8 +33,8 @@ public interface SharingManager<S extends Shareable> {
|
||||
Collection<InvitationMessage> getInvitationMessages(
|
||||
ContactId contactId) throws DbException;
|
||||
|
||||
/** Returns all shareables to which the user has been invited. */
|
||||
Collection<S> getInvited() throws DbException;
|
||||
/** Returns all invitations to shareables. */
|
||||
Collection<InvitationItem> getInvitations() throws DbException;
|
||||
|
||||
/** Returns all contacts who are sharing the given group with us. */
|
||||
Collection<Contact> getSharedBy(GroupId g) throws DbException;
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.InvitationReceivedEvent;
|
||||
import org.briarproject.api.event.InvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
import org.briarproject.api.sharing.SharingManager;
|
||||
@@ -44,6 +45,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -397,16 +399,39 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<S> getInvited() throws DbException {
|
||||
public Collection<InvitationItem> getInvitations() throws DbException {
|
||||
List<InvitationItem> invitations = new ArrayList<InvitationItem>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Set<S> invited = new HashSet<S>();
|
||||
Set<S> shareables = new HashSet<S>();
|
||||
Map<GroupId, Collection<Contact>> newSharers =
|
||||
new HashMap<GroupId, Collection<Contact>>();
|
||||
Collection<Contact> contacts = db.getContacts(txn);
|
||||
|
||||
// get invitations from each contact
|
||||
for (Contact contact : contacts) {
|
||||
invited.addAll(getInvited(txn, contact));
|
||||
Collection<S> newShareables = getInvited(txn, contact);
|
||||
shareables.addAll(newShareables);
|
||||
for (S s : newShareables) {
|
||||
if (newSharers.containsKey(s.getId())) {
|
||||
newSharers.get(s.getId()).add(contact);
|
||||
} else {
|
||||
Collection<Contact> c = new ArrayList<Contact>();
|
||||
c.add(contact);
|
||||
newSharers.put(s.getId(), c);
|
||||
}
|
||||
}
|
||||
}
|
||||
// construct InvitationItem objects
|
||||
for (S s : shareables) {
|
||||
Collection<Contact> newS = newSharers.get(s.getId());
|
||||
boolean subscribed = db.containsGroup(txn, s.getId());
|
||||
InvitationItem invitation =
|
||||
new InvitationItem(s, subscribed, newS);
|
||||
invitations.add(invitation);
|
||||
}
|
||||
txn.setComplete();
|
||||
return Collections.unmodifiableCollection(invited);
|
||||
return Collections.unmodifiableCollection(invitations);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
} finally {
|
||||
@@ -447,20 +472,27 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
|
||||
|
||||
@Override
|
||||
public Collection<Contact> getSharedBy(GroupId g) throws DbException {
|
||||
List<Contact> subscribers;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
subscribers = getSharedBy(txn, g);
|
||||
txn.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return Collections.unmodifiableList(subscribers);
|
||||
}
|
||||
|
||||
private List<Contact> getSharedBy(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
try {
|
||||
List<Contact> subscribers = new ArrayList<Contact>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
GroupId contactGroup = getContactGroup(c).getId();
|
||||
if (listContains(txn, contactGroup, g, SHARED_WITH_US))
|
||||
subscribers.add(c);
|
||||
}
|
||||
txn.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
GroupId contactGroup = getContactGroup(c).getId();
|
||||
if (listContains(txn, contactGroup, g, SHARED_WITH_US))
|
||||
subscribers.add(c);
|
||||
}
|
||||
return Collections.unmodifiableList(subscribers);
|
||||
return subscribers;
|
||||
} catch (IOException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user