Merge branch '810-fix-sharing-status-screens' into 'master'

Fix Sharing Status screens

* Remove distinction between "shared with" and "shared by"
* Show all contacts a blog is shared with
* Show online status of contacts in sharing screen

![device-2016-12-05-142949](/uploads/703fbd2d52815374e57edd89f754bf6c/device-2016-12-05-142949.png)

Closes #810

See merge request !445
This commit is contained in:
Torsten Grote
2016-12-07 16:52:29 +00:00
18 changed files with 234 additions and 213 deletions

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.data.MetadataEncoder;
@@ -37,6 +38,7 @@ import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.sharing.InvitationMessage;
import java.security.SecureRandom;
import java.util.Collection;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
@@ -52,6 +54,7 @@ class BlogSharingManagerImpl extends
SharingManagerImpl<Blog, BlogInvitation, BlogInviteeSessionState, BlogSharerSessionState, BlogInvitationRequestReceivedEvent, BlogInvitationResponseReceivedEvent>
implements BlogSharingManager, RemoveBlogHook {
private final ContactManager contactManager;
private final IdentityManager identityManager;
private final BlogManager blogManager;
@@ -68,13 +71,15 @@ class BlogSharingManagerImpl extends
DatabaseComponent db, MessageQueueManager messageQueueManager,
MetadataEncoder metadataEncoder, MetadataParser metadataParser,
ContactGroupFactory contactGroupFactory, SecureRandom random,
IdentityManager identityManager, MessageTracker messageTracker) {
ContactManager contactManager, IdentityManager identityManager,
MessageTracker messageTracker) {
super(db, messageQueueManager, clientHelper, metadataParser,
metadataEncoder, random, contactGroupFactory, messageTracker,
clock);
this.blogManager = blogManager;
this.contactManager = contactManager;
this.identityManager = identityManager;
sFactory = new SFactory(authorFactory, blogFactory, blogManager);
iFactory = new IFactory();
@@ -105,6 +110,27 @@ class BlogSharingManagerImpl extends
return super.canBeShared(txn, g, c);
}
@Override
public Collection<Contact> getSharedWith(GroupId g) throws DbException {
Blog blog = blogManager.getBlog(g);
LocalAuthor author = identityManager.getLocalAuthor();
if (blog.getAuthor().equals(author)) {
// This is our personal blog. It is shared with all our contacts
return contactManager.getActiveContacts();
} else {
// This is someone else's blog. Look up who it is shared with
Collection<Contact> shared = super.getSharedWith(g);
// If the blog author is our contact, also add her to the list
boolean isContact = contactManager
.contactExists(blog.getAuthor().getId(), author.getId());
if (isContact) {
shared.add(contactManager
.getContact(blog.getAuthor().getId(), author.getId()));
}
return shared;
}
}
@Override
protected InvitationMessage createInvitationRequest(MessageId id,
BlogInvitation msg, ContactId contactId, boolean available,

View File

@@ -514,34 +514,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
return invited;
}
@Override
public Collection<Contact> getSharedBy(GroupId g) throws DbException {
List<Contact> subscribers;
Transaction txn = db.startTransaction(true);
try {
subscribers = getSharedBy(txn, g);
db.commitTransaction(txn);
} finally {
db.endTransaction(txn);
}
return subscribers;
}
private List<Contact> getSharedBy(Transaction txn, GroupId g)
throws DbException {
try {
List<Contact> subscribers = new ArrayList<Contact>();
for (Contact c : db.getContacts(txn)) {
GroupId contactGroup = getContactGroup(c).getId();
if (listContains(txn, contactGroup, g, SHARED_WITH_US))
subscribers.add(c);
}
return subscribers;
} catch (IOException e) {
throw new DbException(e);
}
}
@Override
public Collection<Contact> getSharedWith(GroupId g) throws DbException {
try {
@@ -552,6 +524,8 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
GroupId contactGroup = getContactGroup(c).getId();
if (listContains(txn, contactGroup, g, SHARED_BY_US))
shared.add(c);
else if (listContains(txn, contactGroup, g, SHARED_WITH_US))
shared.add(c);
}
db.commitTransaction(txn);
} finally {