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