mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Use ConversationManager to retrieve messages
This removes the public method for retrieving messages from individual conversation clients and just leaves methods that require a transaction to be used by the ConversationManager only.
This commit is contained in:
@@ -62,8 +62,8 @@ import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager;
|
||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||
@@ -159,6 +159,8 @@ public class ConversationActivity extends BriarActivity
|
||||
@Inject
|
||||
volatile MessagingManager messagingManager;
|
||||
@Inject
|
||||
volatile ConversationManager conversationManager;
|
||||
@Inject
|
||||
volatile EventBus eventBus;
|
||||
@Inject
|
||||
volatile SettingsManager settingsManager;
|
||||
@@ -337,23 +339,9 @@ public class ConversationActivity extends BriarActivity
|
||||
try {
|
||||
long start = now();
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> introductions =
|
||||
introductionManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> forumInvitations =
|
||||
forumSharingManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> blogInvitations =
|
||||
blogSharingManager.getMessages(contactId);
|
||||
Collection<PrivateMessageHeader> groupInvitations =
|
||||
groupInvitationManager.getMessages(contactId);
|
||||
List<PrivateMessageHeader> invitations = new ArrayList<>(
|
||||
forumInvitations.size() + blogInvitations.size() +
|
||||
groupInvitations.size());
|
||||
invitations.addAll(forumInvitations);
|
||||
invitations.addAll(blogInvitations);
|
||||
invitations.addAll(groupInvitations);
|
||||
conversationManager.getMessageHeaders(contactId);
|
||||
logDuration(LOG, "Loading messages", start);
|
||||
displayMessages(revision, headers, introductions, invitations);
|
||||
displayMessages(revision, headers);
|
||||
} catch (NoSuchContactException e) {
|
||||
finishOnUiThread();
|
||||
} catch (DbException e) {
|
||||
@@ -363,15 +351,12 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
|
||||
private void displayMessages(int revision,
|
||||
Collection<PrivateMessageHeader> headers,
|
||||
Collection<PrivateMessageHeader> introductions,
|
||||
Collection<PrivateMessageHeader> invitations) {
|
||||
Collection<PrivateMessageHeader> headers) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
if (revision == adapter.getRevision()) {
|
||||
adapter.incrementRevision();
|
||||
textInputView.setSendButtonEnabled(true);
|
||||
List<ConversationItem> items = createItems(headers,
|
||||
introductions, invitations);
|
||||
List<ConversationItem> items = createItems(headers);
|
||||
adapter.addAll(items);
|
||||
list.showData();
|
||||
// Scroll to the bottom
|
||||
@@ -390,38 +375,24 @@ public class ConversationActivity extends BriarActivity
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private List<ConversationItem> createItems(
|
||||
Collection<PrivateMessageHeader> headers,
|
||||
Collection<PrivateMessageHeader> introductions,
|
||||
Collection<PrivateMessageHeader> invitations) {
|
||||
int size =
|
||||
headers.size() + introductions.size() + invitations.size();
|
||||
List<ConversationItem> items = new ArrayList<>(size);
|
||||
Collection<PrivateMessageHeader> headers) {
|
||||
List<ConversationItem> items = new ArrayList<>(headers.size());
|
||||
for (PrivateMessageHeader h : headers) {
|
||||
ConversationItem item = ConversationItem.from(h);
|
||||
String body = bodyCache.get(h.getId());
|
||||
if (body == null) loadMessageBody(h.getId());
|
||||
else item.setBody(body);
|
||||
items.add(item);
|
||||
}
|
||||
for (PrivateMessageHeader m : introductions) {
|
||||
ConversationItem item;
|
||||
if (m instanceof IntroductionRequest) {
|
||||
IntroductionRequest i = (IntroductionRequest) m;
|
||||
if (h instanceof IntroductionResponse) {
|
||||
IntroductionResponse i = (IntroductionResponse) h;
|
||||
item = ConversationItem.from(this, contactName, i);
|
||||
} else {
|
||||
IntroductionResponse i = (IntroductionResponse) m;
|
||||
item = ConversationItem.from(this, contactName, i);
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
for (PrivateMessageHeader i : invitations) {
|
||||
ConversationItem item;
|
||||
if (i instanceof PrivateRequest) {
|
||||
item = ConversationItem
|
||||
.from(this, contactName, (PrivateRequest) i);
|
||||
} else {
|
||||
PrivateResponse r = (PrivateResponse) i;
|
||||
} else if (h instanceof PrivateRequest) {
|
||||
PrivateRequest r = (PrivateRequest) h;
|
||||
item = ConversationItem.from(this, contactName, r);
|
||||
} else if (h instanceof PrivateResponse) {
|
||||
PrivateResponse r = (PrivateResponse) h;
|
||||
item = ConversationItem.from(this, contactName, r);
|
||||
} else {
|
||||
item = ConversationItem.from(h);
|
||||
String body = bodyCache.get(h.getId());
|
||||
if (body == null) loadMessageBody(h.getId());
|
||||
else item.setBody(body);
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
@@ -513,9 +484,9 @@ public class ConversationActivity extends BriarActivity
|
||||
getContactNameTask().addListener(new FutureTaskListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(String contactName) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
handlePrivateRequestAndResponse(h, contactName);
|
||||
});
|
||||
runOnUiThreadUnlessDestroyed(
|
||||
() -> handlePrivateRequestAndResponse(h,
|
||||
contactName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,8 @@ import static org.briarproject.briar.android.contact.ConversationRequestItem.Req
|
||||
@NotNullByDefault
|
||||
abstract class ConversationItem {
|
||||
|
||||
protected @Nullable String body;
|
||||
@Nullable
|
||||
protected String body;
|
||||
private final MessageId id;
|
||||
private final GroupId groupId;
|
||||
private final long time;
|
||||
@@ -105,7 +106,7 @@ abstract class ConversationItem {
|
||||
R.string.groups_invitations_invitation_sent,
|
||||
contactName, ir.getName());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown InvitationRequest");
|
||||
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||
}
|
||||
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
|
||||
text, ir.getMessage(), ir.getTimestamp(), ir.isSent(),
|
||||
@@ -145,7 +146,7 @@ abstract class ConversationItem {
|
||||
contactName, ir.getName());
|
||||
type = GROUP;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown InvitationRequest");
|
||||
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||
}
|
||||
return new ConversationRequestItem(ir.getId(),
|
||||
ir.getGroupId(), type, ir.getSessionId(), text,
|
||||
@@ -229,22 +230,24 @@ abstract class ConversationItem {
|
||||
} else if (ir instanceof BlogInvitationResponse) {
|
||||
res = R.string.blogs_sharing_response_accepted_received;
|
||||
} else if (ir instanceof GroupInvitationResponse) {
|
||||
res = R.string.groups_invitations_response_accepted_received;
|
||||
res =
|
||||
R.string.groups_invitations_response_accepted_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
} else {
|
||||
if (ir instanceof ForumInvitationResponse) {
|
||||
res = R.string.forum_invitation_response_declined_received;
|
||||
} else if (ir instanceof BlogInvitationResponse) {
|
||||
res = R.string.blogs_sharing_response_declined_received;
|
||||
} else if (ir instanceof GroupInvitationResponse) {
|
||||
res = R.string.groups_invitations_response_declined_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
if (ir instanceof ForumInvitationResponse) {
|
||||
res = R.string.forum_invitation_response_declined_received;
|
||||
} else if (ir instanceof BlogInvitationResponse) {
|
||||
res = R.string.blogs_sharing_response_declined_received;
|
||||
} else if (ir instanceof GroupInvitationResponse) {
|
||||
res =
|
||||
R.string.groups_invitations_response_declined_received;
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown PrivateResponse");
|
||||
}
|
||||
}
|
||||
String text = ctx.getString(res, contactName);
|
||||
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
|
||||
@@ -258,11 +261,11 @@ abstract class ConversationItem {
|
||||
* PrivateMessageHeader.
|
||||
**/
|
||||
static ConversationItem from(Context ctx, PrivateMessageHeader h) {
|
||||
if(h instanceof IntroductionResponse) {
|
||||
if (h instanceof IntroductionResponse) {
|
||||
return from(ctx, "", (IntroductionResponse) h);
|
||||
} else if(h instanceof PrivateRequest) {
|
||||
} else if (h instanceof PrivateRequest) {
|
||||
return from(ctx, "", (PrivateRequest) h);
|
||||
} else if(h instanceof PrivateResponse) {
|
||||
} else if (h instanceof PrivateResponse) {
|
||||
return from(ctx, "", (PrivateResponse) h);
|
||||
} else {
|
||||
return from(h);
|
||||
|
||||
@@ -7,9 +7,6 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -48,11 +45,4 @@ public interface IntroductionManager extends ConversationClient {
|
||||
void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp, boolean accept) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all introduction messages for the given contact.
|
||||
*/
|
||||
@Deprecated
|
||||
Collection<PrivateMessageHeader> getMessages(ContactId contactId)
|
||||
throws DbException;
|
||||
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ public interface ConversationManager {
|
||||
void registerConversationClient(ConversationClient client);
|
||||
|
||||
/**
|
||||
* Returns (the headers) of all messages in the given private conversation.
|
||||
* Returns the headers of all messages in the given private conversation.
|
||||
*
|
||||
* Only {@link MessagingManager} returns only headers.
|
||||
* The others also return the message body.
|
||||
*/
|
||||
Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
Collection<PrivateMessageHeader> getMessageHeaders(ContactId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ public interface ConversationManager {
|
||||
|
||||
Group getContactGroup(Contact c);
|
||||
|
||||
Collection<PrivateMessageHeader> getMessages(Transaction txn,
|
||||
Collection<PrivateMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId contactId) throws DbException;
|
||||
|
||||
GroupCount getGroupCount(Transaction txn, ContactId c)
|
||||
|
||||
@@ -8,8 +8,6 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface MessagingManager extends ConversationClient {
|
||||
|
||||
@@ -43,13 +41,6 @@ public interface MessagingManager extends ConversationClient {
|
||||
*/
|
||||
GroupId getConversationId(ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the headers of all messages in the given private conversation.
|
||||
*/
|
||||
@Deprecated
|
||||
Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the body of the private message with the given ID.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -73,14 +72,6 @@ public interface GroupInvitationManager extends ConversationClient {
|
||||
*/
|
||||
void revealRelationship(ContactId c, GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all private group invitation messages related to the given
|
||||
* contact.
|
||||
*/
|
||||
@Deprecated
|
||||
Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all private groups to which the user has been invited.
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -36,14 +35,6 @@ public interface SharingManager<S extends Shareable>
|
||||
void respondToInvitation(ContactId c, SessionId id, boolean accept)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all group sharing messages sent by the Contact
|
||||
* identified by contactId.
|
||||
*/
|
||||
@Deprecated
|
||||
Collection<PrivateMessageHeader> getMessages(ContactId contactId)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all invitations to groups.
|
||||
*/
|
||||
|
||||
@@ -399,21 +399,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
throws DbException {
|
||||
Collection<PrivateMessageHeader> messages;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
messages = getMessages(txn, c);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(Transaction txn,
|
||||
public Collection<PrivateMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
|
||||
@@ -38,13 +38,13 @@ class ConversationManagerImpl implements ConversationManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
public Collection<PrivateMessageHeader> getMessageHeaders(ContactId c)
|
||||
throws DbException {
|
||||
List<PrivateMessageHeader> messages = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
for (ConversationClient client : clients) {
|
||||
messages.addAll(client.getMessages(txn, c));
|
||||
messages.addAll(client.getMessageHeaders(txn, c));
|
||||
}
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
|
||||
@@ -178,21 +178,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
throws DbException {
|
||||
Collection<PrivateMessageHeader> headers;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
headers = getMessages(txn, c);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(Transaction txn,
|
||||
public Collection<PrivateMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId c) throws DbException {
|
||||
Map<MessageId, BdfDictionary> metadata;
|
||||
Collection<MessageStatus> statuses;
|
||||
|
||||
@@ -368,21 +368,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
throws DbException {
|
||||
Collection<PrivateMessageHeader> messages;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
messages = getMessages(txn, c);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(Transaction txn,
|
||||
public Collection<PrivateMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
|
||||
@@ -321,21 +321,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(ContactId c)
|
||||
throws DbException {
|
||||
Collection<PrivateMessageHeader> messages;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
messages = getMessages(txn, c);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PrivateMessageHeader> getMessages(Transaction txn,
|
||||
public Collection<PrivateMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.briar.blog;
|
||||
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
@@ -63,10 +62,7 @@ public class BlogManagerIntegrationTest
|
||||
blog1 = blogFactory.createBlog(author1);
|
||||
|
||||
rssBlog = blogFactory.createFeedBlog(rssAuthor);
|
||||
Transaction txn = db0.startTransaction(false);
|
||||
blogManager0.addBlog(txn, rssBlog);
|
||||
db0.commitTransaction(txn);
|
||||
db0.endTransaction(txn);
|
||||
withinTransaction(db0, txn -> blogManager0.addBlog(txn, rssBlog));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,8 +9,8 @@ import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
@@ -299,18 +299,23 @@ public class IntroductionIntegrationTest
|
||||
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
assertEquals(2,
|
||||
introductionManager0.getMessages(contactId1From0).size());
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
withinTransactionReturns(db0, txn -> introductionManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
assertEquals(2, messages.size());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||
assertEquals(2,
|
||||
introductionManager0.getMessages(contactId2From0).size());
|
||||
messages = withinTransactionReturns(db0,
|
||||
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0));
|
||||
assertEquals(2, messages.size());
|
||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||
assertEquals(2,
|
||||
introductionManager1.getMessages(contactId0From1).size());
|
||||
messages = withinTransactionReturns(db1,
|
||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
assertGroupCount(messageTracker1, g1.getId(), 2, 1);
|
||||
// introducee2 should also have the decline response of introducee1
|
||||
assertEquals(3,
|
||||
introductionManager2.getMessages(contactId0From2).size());
|
||||
messages = withinTransactionReturns(db2,
|
||||
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2));
|
||||
assertEquals(3, messages.size());
|
||||
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
||||
|
||||
assertFalse(listener0.aborted);
|
||||
@@ -360,15 +365,19 @@ public class IntroductionIntegrationTest
|
||||
assertFalse(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
|
||||
assertEquals(2,
|
||||
introductionManager0.getMessages(contactId1From0).size());
|
||||
assertEquals(2,
|
||||
introductionManager0.getMessages(contactId2From0).size());
|
||||
assertEquals(3,
|
||||
introductionManager1.getMessages(contactId0From1).size());
|
||||
assertEquals(3,
|
||||
introductionManager2.getMessages(contactId0From2)
|
||||
.size());
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
withinTransactionReturns(db0, txn -> introductionManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
assertEquals(2, messages.size());
|
||||
messages = withinTransactionReturns(db0,
|
||||
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0));
|
||||
assertEquals(2, messages.size());
|
||||
messages = withinTransactionReturns(db1,
|
||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(3,messages.size());
|
||||
messages = withinTransactionReturns(db2,
|
||||
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2));
|
||||
assertEquals(3, messages.size());
|
||||
assertFalse(listener0.aborted);
|
||||
assertFalse(listener1.aborted);
|
||||
assertFalse(listener2.aborted);
|
||||
@@ -514,17 +523,21 @@ public class IntroductionIntegrationTest
|
||||
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
assertEquals(2,
|
||||
introductionManager0.getMessages(contactId1From0).size());
|
||||
assertEquals(2, withinTransactionReturns(db0,
|
||||
txn -> introductionManager0.getMessageHeaders(txn, contactId1From0))
|
||||
.size());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||
assertEquals(2,
|
||||
introductionManager0.getMessages(contactId2From0).size());
|
||||
assertEquals(2, withinTransactionReturns(db0,
|
||||
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0))
|
||||
.size());
|
||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||
assertEquals(3,
|
||||
introductionManager1.getMessages(contactId0From1).size());
|
||||
assertEquals(3, withinTransactionReturns(db1,
|
||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1))
|
||||
.size());
|
||||
assertGroupCount(messageTracker1, g1.getId(), 3, 2);
|
||||
assertEquals(3,
|
||||
introductionManager2.getMessages(contactId0From2).size());
|
||||
assertEquals(3, withinTransactionReturns(db2,
|
||||
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2))
|
||||
.size());
|
||||
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
||||
|
||||
assertFalse(listener0.aborted);
|
||||
@@ -548,7 +561,9 @@ public class IntroductionIntegrationTest
|
||||
assertFalse(listener1.requestReceived);
|
||||
|
||||
// make really sure we don't have that request
|
||||
assertTrue(introductionManager1.getMessages(contactId0From1).isEmpty());
|
||||
assertTrue(withinTransactionReturns(db1,
|
||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1))
|
||||
.isEmpty());
|
||||
|
||||
// The message was invalid, so no abort message was sent
|
||||
assertFalse(listener0.aborted);
|
||||
@@ -596,11 +611,11 @@ public class IntroductionIntegrationTest
|
||||
sync0To2(1, true);
|
||||
|
||||
// assert that introducees get notified about the existing contact
|
||||
IntroductionRequest ir1 =
|
||||
getIntroductionRequest(introductionManager1, contactId0From1);
|
||||
IntroductionRequest ir1 = getIntroductionRequest(db1,
|
||||
introductionManager1, contactId0From1);
|
||||
assertTrue(ir1.doesExist());
|
||||
IntroductionRequest ir2 =
|
||||
getIntroductionRequest(introductionManager2, contactId0From2);
|
||||
IntroductionRequest ir2 = getIntroductionRequest(db2,
|
||||
introductionManager2, contactId0From2);
|
||||
assertTrue(ir2.doesExist());
|
||||
|
||||
// sync ACCEPT messages back to introducer
|
||||
@@ -981,8 +996,7 @@ public class IntroductionIntegrationTest
|
||||
AcceptMessage m = visitor.visit(message);
|
||||
|
||||
// replace original response with modified one
|
||||
Transaction txn = db0.startTransaction(false);
|
||||
try {
|
||||
withinTransaction(db0, txn -> {
|
||||
db0.removeMessage(txn, message.getMessageId());
|
||||
Message msg = c0.getMessageEncoder()
|
||||
.encodeAcceptMessage(m.getGroupId(), m.getTimestamp(),
|
||||
@@ -1002,10 +1016,7 @@ public class IntroductionIntegrationTest
|
||||
session.getValue(), msg.getId());
|
||||
c0.getClientHelper().mergeMessageMetadata(txn, session.getKey(),
|
||||
session.getValue());
|
||||
db0.commitTransaction(txn);
|
||||
} finally {
|
||||
db0.endTransaction(txn);
|
||||
}
|
||||
});
|
||||
|
||||
// sync second response
|
||||
sync2To0(1, true);
|
||||
@@ -1091,19 +1102,23 @@ public class IntroductionIntegrationTest
|
||||
|
||||
private void assertDefaultUiMessages() throws DbException {
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
introductionManager0.getMessages(contactId1From0);
|
||||
withinTransactionReturns(db0, txn -> introductionManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
assertEquals(2, messages.size());
|
||||
assertMessagesAreAcked(messages);
|
||||
|
||||
messages = introductionManager0.getMessages(contactId2From0);
|
||||
messages = withinTransactionReturns(db0,
|
||||
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0));
|
||||
assertEquals(2, messages.size());
|
||||
assertMessagesAreAcked(messages);
|
||||
|
||||
messages = introductionManager1.getMessages(contactId0From1);
|
||||
messages = withinTransactionReturns(db1,
|
||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
assertMessagesAreAcked(messages);
|
||||
|
||||
messages = introductionManager2.getMessages(contactId0From2);
|
||||
messages = withinTransactionReturns(db2,
|
||||
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2));
|
||||
assertEquals(2, messages.size());
|
||||
assertMessagesAreAcked(messages);
|
||||
}
|
||||
@@ -1137,7 +1152,7 @@ public class IntroductionIntegrationTest
|
||||
assertTrue(
|
||||
latestEvent instanceof IntroductionResponseReceivedEvent);
|
||||
return ((IntroductionResponseReceivedEvent) latestEvent)
|
||||
.getResponse();
|
||||
.getMessageHeader();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1165,7 +1180,7 @@ public class IntroductionIntegrationTest
|
||||
IntroductionRequestReceivedEvent introEvent =
|
||||
((IntroductionRequestReceivedEvent) e);
|
||||
requestReceived = true;
|
||||
PrivateRequest<Introduction> ir = introEvent.getRequest();
|
||||
PrivateRequest<Introduction> ir = introEvent.getMessageHeader();
|
||||
ContactId contactId = introEvent.getContactId();
|
||||
sessionId = ir.getSessionId();
|
||||
long time = clock.currentTimeMillis();
|
||||
@@ -1206,7 +1221,7 @@ public class IntroductionIntegrationTest
|
||||
assertTrue(
|
||||
latestEvent instanceof IntroductionRequestReceivedEvent);
|
||||
return ((IntroductionRequestReceivedEvent) latestEvent)
|
||||
.getRequest();
|
||||
.getMessageHeader();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1283,10 +1298,12 @@ public class IntroductionIntegrationTest
|
||||
} else throw new AssertionError("Not implemented");
|
||||
}
|
||||
|
||||
private IntroductionRequest getIntroductionRequest(
|
||||
private IntroductionRequest getIntroductionRequest(DatabaseComponent db,
|
||||
IntroductionManager manager, ContactId contactId)
|
||||
throws DbException {
|
||||
for (PrivateMessageHeader im : manager.getMessages(contactId)) {
|
||||
Collection<PrivateMessageHeader> messages = withinTransactionReturns(db,
|
||||
txn -> manager.getMessageHeaders(txn, contactId));
|
||||
for (PrivateMessageHeader im : messages) {
|
||||
if (im instanceof IntroductionRequest) {
|
||||
return (IntroductionRequest) im;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.privategroup;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
@@ -245,11 +244,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
groupManager0.getPreviousMsgId(groupId0));
|
||||
|
||||
// share the group with 1
|
||||
Transaction txn0 = db0.startTransaction(false);
|
||||
db0.setGroupVisibility(txn0, contactId1From0, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db0.commitTransaction(txn0);
|
||||
db0.endTransaction(txn0);
|
||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
||||
contactId1From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author1 joins privateGroup0 with wrong timestamp
|
||||
joinTime = clock.currentTimeMillis();
|
||||
@@ -266,11 +262,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
groupManager1.getPreviousMsgId(groupId0));
|
||||
|
||||
// share the group with 0
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
db1.setGroupVisibility(txn1, contactId0From1, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db1.commitTransaction(txn1);
|
||||
db1.endTransaction(txn1);
|
||||
withinTransaction(db1, txn -> db1.setGroupVisibility(txn,
|
||||
contactId0From1, privateGroup0.getId(), SHARED));
|
||||
|
||||
// sync join messages
|
||||
sync0To1(1, false);
|
||||
@@ -303,11 +296,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
groupManager0.getPreviousMsgId(groupId0));
|
||||
|
||||
// share the group with 1
|
||||
Transaction txn0 = db0.startTransaction(false);
|
||||
db0.setGroupVisibility(txn0, contactId1From0, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db0.commitTransaction(txn0);
|
||||
db0.endTransaction(txn0);
|
||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
||||
contactId1From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author1 joins privateGroup0 with wrong signature in join message
|
||||
joinTime = clock.currentTimeMillis();
|
||||
@@ -325,11 +315,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
groupManager1.getPreviousMsgId(groupId0));
|
||||
|
||||
// share the group with 0
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
db1.setGroupVisibility(txn1, contactId0From1, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db1.commitTransaction(txn1);
|
||||
db1.endTransaction(txn1);
|
||||
withinTransaction(db1, txn -> db1.setGroupVisibility(txn,
|
||||
contactId0From1, privateGroup0.getId(), SHARED));
|
||||
|
||||
// sync join messages
|
||||
sync0To1(1, false);
|
||||
@@ -404,11 +391,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
addGroup();
|
||||
|
||||
// share the group with 2
|
||||
Transaction txn0 = db0.startTransaction(false);
|
||||
db0.setGroupVisibility(txn0, contactId2From0, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db0.commitTransaction(txn0);
|
||||
db0.endTransaction(txn0);
|
||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
||||
contactId2From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author2 joins privateGroup0
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
@@ -420,14 +404,12 @@ public class PrivateGroupManagerIntegrationTest
|
||||
GroupMessage joinMsg2 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author2,
|
||||
inviteTime, creatorSignature);
|
||||
Transaction txn2 = db2.startTransaction(false);
|
||||
groupManager2.addPrivateGroup(txn2, privateGroup0, joinMsg2, false);
|
||||
|
||||
// share the group with 0
|
||||
db2.setGroupVisibility(txn2, contactId0From1, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db2.commitTransaction(txn2);
|
||||
db2.endTransaction(txn2);
|
||||
withinTransaction(db2, txn -> {
|
||||
groupManager2.addPrivateGroup(txn, privateGroup0, joinMsg2, false);
|
||||
// share the group with 0
|
||||
db2.setGroupVisibility(txn,
|
||||
contactId0From1, privateGroup0.getId(), SHARED); // TODO contactId
|
||||
});
|
||||
|
||||
// sync join messages
|
||||
sync2To0(1, true);
|
||||
@@ -458,16 +440,10 @@ public class PrivateGroupManagerIntegrationTest
|
||||
}
|
||||
|
||||
// reveal contact relationship
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
groupManager1
|
||||
.relationshipRevealed(txn1, groupId0, author2.getId(), false);
|
||||
db1.commitTransaction(txn1);
|
||||
db1.endTransaction(txn1);
|
||||
txn2 = db2.startTransaction(false);
|
||||
groupManager2
|
||||
.relationshipRevealed(txn2, groupId0, author1.getId(), true);
|
||||
db2.commitTransaction(txn2);
|
||||
db2.endTransaction(txn2);
|
||||
withinTransaction(db1, txn -> groupManager1.relationshipRevealed(txn,
|
||||
groupId0, author2.getId(), false));
|
||||
withinTransaction(db2, txn -> groupManager2.relationshipRevealed(txn,
|
||||
groupId0, author1.getId(), true));
|
||||
|
||||
// assert that contact relationship is now revealed properly
|
||||
members1 = groupManager1.getMembers(groupId0);
|
||||
@@ -520,10 +496,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
assertFalse(groupManager1.isDissolved(groupId0));
|
||||
|
||||
// creator dissolves group
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
groupManager1.markGroupDissolved(txn1, groupId0);
|
||||
db1.commitTransaction(txn1);
|
||||
db1.endTransaction(txn1);
|
||||
withinTransaction(db1,
|
||||
txn -> groupManager1.markGroupDissolved(txn, groupId0));
|
||||
|
||||
// group is dissolved now
|
||||
assertTrue(groupManager1.isDissolved(groupId0));
|
||||
@@ -539,11 +513,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
groupManager0.getPreviousMsgId(groupId0));
|
||||
|
||||
// share the group with 1
|
||||
Transaction txn0 = db0.startTransaction(false);
|
||||
db0.setGroupVisibility(txn0, contactId1From0, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db0.commitTransaction(txn0);
|
||||
db0.endTransaction(txn0);
|
||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
||||
contactId1From0, privateGroup0.getId(), SHARED));
|
||||
|
||||
// author1 joins privateGroup0
|
||||
joinTime = clock.currentTimeMillis();
|
||||
@@ -558,11 +529,8 @@ public class PrivateGroupManagerIntegrationTest
|
||||
groupManager1.addPrivateGroup(privateGroup0, joinMsg1, false);
|
||||
|
||||
// share the group with 0
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
db1.setGroupVisibility(txn1, contactId0From1, privateGroup0.getId(),
|
||||
SHARED);
|
||||
db1.commitTransaction(txn1);
|
||||
db1.endTransaction(txn1);
|
||||
withinTransaction(db1, txn -> db1.setGroupVisibility(txn,
|
||||
contactId0From1, privateGroup0.getId(), SHARED));
|
||||
assertEquals(joinMsg1.getMessage().getId(),
|
||||
groupManager1.getPreviousMsgId(groupId0));
|
||||
|
||||
|
||||
@@ -93,7 +93,8 @@ public class GroupInvitationIntegrationTest
|
||||
assertFalse(item.isSubscribed());
|
||||
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
groupInvitationManager1.getMessages(contactId0From1);
|
||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(1, messages.size());
|
||||
GroupInvitationRequest request =
|
||||
(GroupInvitationRequest) messages.iterator().next();
|
||||
@@ -118,7 +119,8 @@ public class GroupInvitationIntegrationTest
|
||||
.respondToInvitation(contactId0From1, privateGroup0, false);
|
||||
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
groupInvitationManager1.getMessages(contactId0From1);
|
||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
boolean foundResponse = false;
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
@@ -134,8 +136,8 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
sync1To0(1, true);
|
||||
|
||||
messages =
|
||||
groupInvitationManager0.getMessages(contactId1From0);
|
||||
messages = withinTransactionReturns(db0, txn -> groupInvitationManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
assertEquals(2, messages.size());
|
||||
foundResponse = false;
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
@@ -167,7 +169,8 @@ public class GroupInvitationIntegrationTest
|
||||
.respondToInvitation(contactId0From1, privateGroup0, true);
|
||||
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
groupInvitationManager1.getMessages(contactId0From1);
|
||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
boolean foundResponse = false;
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
@@ -186,7 +189,8 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
sync1To0(1, true);
|
||||
|
||||
messages = groupInvitationManager0.getMessages(contactId1From0);
|
||||
messages = withinTransactionReturns(db1, txn -> groupInvitationManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
assertEquals(2, messages.size());
|
||||
foundResponse = false;
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
@@ -221,9 +225,9 @@ public class GroupInvitationIntegrationTest
|
||||
// 1 has one unread message
|
||||
Group g0 = groupInvitationManager1.getContactGroup(contact0From1);
|
||||
assertGroupCount(messageTracker1, g0.getId(), 1, 1, timestamp);
|
||||
PrivateMessageHeader m =
|
||||
groupInvitationManager1.getMessages(contactId0From1)
|
||||
.iterator().next();
|
||||
PrivateMessageHeader m = withinTransactionReturns(db1,
|
||||
txn -> groupInvitationManager1.getMessageHeaders(txn, contactId0From1)
|
||||
.iterator().next());
|
||||
|
||||
groupInvitationManager1
|
||||
.respondToInvitation(contactId0From1, privateGroup0, true);
|
||||
@@ -445,7 +449,8 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
// save MessageId of invitation
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
groupInvitationManager1.getMessages(contactId0From1);
|
||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(1, messages.size());
|
||||
MessageId inviteId = messages.iterator().next().getId();
|
||||
|
||||
@@ -454,17 +459,18 @@ public class GroupInvitationIntegrationTest
|
||||
.respondToInvitation(contactId0From1, privateGroup0, false);
|
||||
|
||||
// we should have an invitation and a decline message
|
||||
messages = groupInvitationManager1.getMessages(contactId0From1);
|
||||
messages = withinTransactionReturns(db1, txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
|
||||
// delete only invitation
|
||||
withinTransaction(db1, txn -> {
|
||||
db1.deleteMessage(txn, inviteId);
|
||||
db1.deleteMessageMetadata(txn, inviteId);
|
||||
// This should fail
|
||||
groupInvitationManager1.getMessageHeaders(txn, contactId0From1);
|
||||
});
|
||||
|
||||
// This should fail
|
||||
groupInvitationManager1.getMessages(contactId0From1);
|
||||
}
|
||||
|
||||
private void sendInvitation(long timestamp, @Nullable String msg) throws
|
||||
|
||||
@@ -669,8 +669,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
invite.getCreator(), invite.getSalt());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
@@ -700,13 +698,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(messageParser).parseMetadata(meta);
|
||||
will(returnValue(messageMetadata1));
|
||||
oneOf(db).getMessageStatus(txn, contactId, messageId2);
|
||||
// end transaction
|
||||
oneOf(db).commitTransaction(txn);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
groupInvitationManager.getMessages(contactId);
|
||||
groupInvitationManager.getMessageHeaders(txn, contactId);
|
||||
assertEquals(2, messages.size());
|
||||
for (PrivateMessageHeader m : messages) {
|
||||
assertEquals(contactGroup.getId(), m.getGroupId());
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION;
|
||||
@@ -147,8 +145,8 @@ public class BlogSharingIntegrationTest
|
||||
assertTrue(blogManager1.getBlogs().contains(blog2));
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<PrivateMessageHeader> list = new ArrayList<>(
|
||||
blogSharingManager1.getMessages(contactId0From1));
|
||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
||||
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the message
|
||||
for (PrivateMessageHeader m : list) {
|
||||
@@ -168,9 +166,9 @@ public class BlogSharingIntegrationTest
|
||||
}
|
||||
}
|
||||
// sharer has own invitation message and response
|
||||
assertEquals(2,
|
||||
blogSharingManager0.getMessages(contactId1From0)
|
||||
.size());
|
||||
assertEquals(2, withinTransactionReturns(db0,
|
||||
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||
.size());
|
||||
// blog can not be shared again
|
||||
assertFalse(blogSharingManager0.canBeShared(blog2.getId(),
|
||||
contact1From0));
|
||||
@@ -220,8 +218,8 @@ public class BlogSharingIntegrationTest
|
||||
assertTrue(blogManager1.getBlogs().contains(rssBlog));
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<PrivateMessageHeader> list = new ArrayList<>(
|
||||
blogSharingManager1.getMessages(contactId0From1));
|
||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
||||
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the message
|
||||
for (PrivateMessageHeader m : list) {
|
||||
@@ -241,8 +239,9 @@ public class BlogSharingIntegrationTest
|
||||
}
|
||||
}
|
||||
// sharer has own invitation message and response
|
||||
assertEquals(2, blogSharingManager0.getMessages(
|
||||
contactId1From0).size());
|
||||
assertEquals(2, withinTransactionReturns(db0,
|
||||
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||
.size());
|
||||
// blog can not be shared again
|
||||
assertFalse(blogSharingManager0.canBeShared(rssBlog.getId(),
|
||||
contact1From0));
|
||||
@@ -281,8 +280,8 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals(0, blogSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<PrivateMessageHeader> list = new ArrayList<>(
|
||||
blogSharingManager1.getMessages(contactId0From1));
|
||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
||||
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check things are alright with the message
|
||||
for (PrivateMessageHeader m : list) {
|
||||
@@ -301,9 +300,9 @@ public class BlogSharingIntegrationTest
|
||||
}
|
||||
}
|
||||
// sharer has own invitation message and response
|
||||
assertEquals(2,
|
||||
blogSharingManager0.getMessages(contactId1From0)
|
||||
.size());
|
||||
assertEquals(2, withinTransactionReturns(db0,
|
||||
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||
.size());
|
||||
// blog can be shared again
|
||||
assertTrue(
|
||||
blogSharingManager0.canBeShared(blog2.getId(), contact1From0));
|
||||
@@ -389,7 +388,8 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// make sure 1 knows that they have blog2 already
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
blogSharingManager1.getMessages(contactId0From1);
|
||||
withinTransactionReturns(db1, txn -> blogSharingManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
assertEquals(blog2, blogManager1.getBlog(blog2.getId()));
|
||||
|
||||
@@ -559,7 +559,7 @@ public class BlogSharingIntegrationTest
|
||||
BlogInvitationRequestReceivedEvent event =
|
||||
(BlogInvitationRequestReceivedEvent) e;
|
||||
eventWaiter.assertEquals(contactId1From0, event.getContactId());
|
||||
Blog b = event.getRequest().getObject();
|
||||
Blog b = event.getMessageHeader().getObject();
|
||||
try {
|
||||
Contact c = contactManager0.getContact(contactId1From0);
|
||||
blogSharingManager0.respondToInvitation(b, c, true);
|
||||
@@ -595,7 +595,7 @@ public class BlogSharingIntegrationTest
|
||||
(BlogInvitationRequestReceivedEvent) e;
|
||||
requestReceived = true;
|
||||
if (!answer) return;
|
||||
Blog b = event.getRequest().getObject();
|
||||
Blog b = event.getMessageHeader().getObject();
|
||||
try {
|
||||
eventWaiter.assertEquals(1,
|
||||
blogSharingManager1.getInvitations().size());
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.jodah.concurrentunit.Waiter;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
@@ -32,9 +31,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
@@ -131,8 +128,8 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<PrivateMessageHeader> list = new ArrayList<>(
|
||||
forumSharingManager1.getMessages(contactId0From1));
|
||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
||||
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the forum message
|
||||
for (PrivateMessageHeader m : list) {
|
||||
@@ -151,9 +148,8 @@ public class ForumSharingIntegrationTest
|
||||
}
|
||||
}
|
||||
// sharer has own invitation message and response
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getMessages(contactId1From0)
|
||||
.size());
|
||||
assertEquals(2, withinTransactionReturns(db0, txn ->
|
||||
forumSharingManager0.getMessageHeaders(txn, contactId1From0)).size());
|
||||
// forum can not be shared again
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
assertFalse(forumSharingManager0.canBeShared(forum0.getId(), c1));
|
||||
@@ -188,8 +184,8 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(0, forumSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<PrivateMessageHeader> list = new ArrayList<>(
|
||||
forumSharingManager1.getMessages(contactId0From1));
|
||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
||||
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check things are alright with the forum message
|
||||
for (PrivateMessageHeader m : list) {
|
||||
@@ -208,9 +204,8 @@ public class ForumSharingIntegrationTest
|
||||
}
|
||||
}
|
||||
// sharer has own invitation message and response
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getMessages(contactId1From0)
|
||||
.size());
|
||||
assertEquals(2, withinTransactionReturns(db0, txn ->
|
||||
forumSharingManager0.getMessageHeaders(txn, contactId1From0)).size());
|
||||
// forum can be shared again
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
assertTrue(forumSharingManager0.canBeShared(forum0.getId(), c1));
|
||||
@@ -451,10 +446,7 @@ public class ForumSharingIntegrationTest
|
||||
listenToEvents(true);
|
||||
|
||||
// invitee adds the same forum
|
||||
Transaction txn = db1.startTransaction(false);
|
||||
forumManager1.addForum(txn, forum0);
|
||||
db1.commitTransaction(txn);
|
||||
db1.endTransaction(txn);
|
||||
withinTransaction(db1, txn -> forumManager1.addForum(txn, forum0));
|
||||
|
||||
// send invitation
|
||||
forumSharingManager0
|
||||
@@ -486,10 +478,12 @@ public class ForumSharingIntegrationTest
|
||||
.contains(contact0From1));
|
||||
|
||||
// and both have each other's invitations (and no response)
|
||||
assertEquals(2, forumSharingManager0
|
||||
.getMessages(contactId1From0).size());
|
||||
assertEquals(2, forumSharingManager1
|
||||
.getMessages(contactId0From1).size());
|
||||
assertEquals(2, withinTransactionReturns(db0, txn2 ->
|
||||
forumSharingManager0.getMessageHeaders(txn2, contactId1From0))
|
||||
.size());
|
||||
assertEquals(2, withinTransactionReturns(db1, txn2 ->
|
||||
forumSharingManager1.getMessageHeaders(txn2, contactId0From1))
|
||||
.size());
|
||||
|
||||
// there are no more open invitations
|
||||
assertTrue(forumSharingManager0.getInvitations().isEmpty());
|
||||
@@ -564,10 +558,7 @@ public class ForumSharingIntegrationTest
|
||||
@Test
|
||||
public void testTwoContactsShareSameForum() throws Exception {
|
||||
// second sharer adds the same forum
|
||||
Transaction txn = db2.startTransaction(false);
|
||||
db2.addGroup(txn, forum0.getGroup());
|
||||
db2.commitTransaction(txn);
|
||||
db2.endTransaction(txn);
|
||||
withinTransaction(db2, txn -> db2.addGroup(txn, forum0.getGroup()));
|
||||
|
||||
// add listeners
|
||||
listener0 = new SharerListener();
|
||||
@@ -744,8 +735,9 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// get invitation MessageId for later
|
||||
MessageId invitationId = null;
|
||||
for (PrivateMessageHeader m : forumSharingManager1
|
||||
.getMessages(contactId0From1)) {
|
||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
||||
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||
for (PrivateMessageHeader m : list) {
|
||||
if (m instanceof ForumInvitationRequest) {
|
||||
invitationId = m.getId();
|
||||
}
|
||||
@@ -813,7 +805,7 @@ public class ForumSharingIntegrationTest
|
||||
(ForumInvitationRequestReceivedEvent) e;
|
||||
eventWaiter.assertEquals(contactId1From0, event.getContactId());
|
||||
requestReceived = true;
|
||||
Forum f = event.getRequest().getObject();
|
||||
Forum f = event.getMessageHeader().getObject();
|
||||
try {
|
||||
if (respond) {
|
||||
Contact c = contactManager0.getContact(contactId1From0);
|
||||
@@ -851,7 +843,7 @@ public class ForumSharingIntegrationTest
|
||||
(ForumInvitationRequestReceivedEvent) e;
|
||||
requestReceived = true;
|
||||
if (!answer) return;
|
||||
Forum f = event.getRequest().getObject();
|
||||
Forum f = event.getMessageHeader().getObject();
|
||||
try {
|
||||
if (respond) {
|
||||
eventWaiter.assertEquals(1,
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.test;
|
||||
|
||||
import net.jodah.concurrentunit.Waiter;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.client.ContactGroupFactory;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
@@ -380,18 +381,38 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface TransactionScope {
|
||||
void execute(Transaction txn) throws DbException;
|
||||
void execute(Transaction txn) throws DbException, FormatException;
|
||||
}
|
||||
|
||||
protected void withinTransaction(DatabaseComponent db, TransactionScope scope)
|
||||
throws DbException {
|
||||
protected void withinTransaction(DatabaseComponent db,
|
||||
TransactionScope scope) throws DbException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
scope.execute(txn);
|
||||
db.commitTransaction(txn);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface TransactionResultScope<R> {
|
||||
R execute(Transaction txn) throws DbException;
|
||||
}
|
||||
|
||||
protected <R> R withinTransactionReturns(DatabaseComponent db,
|
||||
TransactionResultScope<R> scope) throws DbException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
R r;
|
||||
try {
|
||||
r = scope.execute(txn);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user