mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Add transactional helper methods to DbViewModel.
This commit is contained in:
@@ -407,36 +407,36 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<GroupMember> getMembers(GroupId g) throws DbException {
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Collection<GroupMember> members = new ArrayList<>();
|
||||
Map<Author, Visibility> authors = getMembers(txn, g);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
PrivateGroup privateGroup = getPrivateGroup(txn, g);
|
||||
for (Entry<Author, Visibility> m : authors.entrySet()) {
|
||||
Author a = m.getKey();
|
||||
AuthorInfo authorInfo =
|
||||
authorManager.getAuthorInfo(txn, a.getId());
|
||||
Status status = authorInfo.getStatus();
|
||||
Visibility v = m.getValue();
|
||||
ContactId c = null;
|
||||
if (v != INVISIBLE &&
|
||||
(status == VERIFIED || status == UNVERIFIED)) {
|
||||
c = contactManager.getContact(txn, a.getId(), la.getId())
|
||||
.getId();
|
||||
}
|
||||
boolean isCreator = privateGroup.getCreator().equals(a);
|
||||
members.add(new GroupMember(a, authorInfo, isCreator, c, v));
|
||||
}
|
||||
db.commitTransaction(txn);
|
||||
return members;
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
public Collection<GroupMember> getMembers(GroupId g)
|
||||
throws DbException {
|
||||
return db.transactionWithResult(true, txn -> getMembers(txn, g));
|
||||
}
|
||||
|
||||
private Map<Author, Visibility> getMembers(Transaction txn, GroupId g)
|
||||
@Override
|
||||
public Collection<GroupMember> getMembers(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
Collection<GroupMember> members = new ArrayList<>();
|
||||
Map<Author, Visibility> authors = getMemberAuthors(txn, g);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
PrivateGroup privateGroup = getPrivateGroup(txn, g);
|
||||
for (Entry<Author, Visibility> m : authors.entrySet()) {
|
||||
Author a = m.getKey();
|
||||
AuthorInfo authorInfo = authorManager.getAuthorInfo(txn, a.getId());
|
||||
Status status = authorInfo.getStatus();
|
||||
Visibility v = m.getValue();
|
||||
ContactId c = null;
|
||||
if (v != INVISIBLE &&
|
||||
(status == VERIFIED || status == UNVERIFIED)) {
|
||||
c = contactManager.getContact(txn, a.getId(), la.getId())
|
||||
.getId();
|
||||
}
|
||||
boolean isCreator = privateGroup.getCreator().equals(a);
|
||||
members.add(new GroupMember(a, authorInfo, isCreator, c, v));
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
private Map<Author, Visibility> getMemberAuthors(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary meta =
|
||||
@@ -458,7 +458,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
@Override
|
||||
public boolean isMember(Transaction txn, GroupId g, Author a)
|
||||
throws DbException {
|
||||
for (Author member : getMembers(txn, g).keySet()) {
|
||||
for (Author member : getMemberAuthors(txn, g).keySet()) {
|
||||
if (member.equals(a)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -426,17 +426,17 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
@Override
|
||||
public Collection<Contact> getSharedWith(GroupId g) throws DbException {
|
||||
return db.transactionWithResult(true, txn -> getSharedWith(txn, g));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Contact> getSharedWith(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
// TODO report also pending invitations
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
if (db.getGroupVisibility(txn, c.getId(), g) == SHARED)
|
||||
contacts.add(c);
|
||||
}
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
if (db.getGroupVisibility(txn, c.getId(), g) == SHARED)
|
||||
contacts.add(c);
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.briarproject.briar.api.identity.AuthorInfo.Status.VERIFIED;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.briar.api.identity.AuthorInfo.Status.VERIFIED;
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_CONTACT;
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_US;
|
||||
|
||||
Reference in New Issue
Block a user