Commit 3053e3cf authored by Torsten Grote's avatar Torsten Grote

[core] fix wrong order of message status flags in conversation headers

parent f4b06e1f
Pipeline #2782 passed with stage
in 10 minutes and 52 seconds
......@@ -13,10 +13,10 @@ import javax.annotation.Nullable;
public class BlogInvitationRequest extends InvitationRequest<Blog> {
public BlogInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, Blog blog, @Nullable String text,
boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, blog,
super(id, groupId, time, local, read, sent, seen, sessionId, blog,
text, available, canBeOpened);
}
......
......@@ -11,9 +11,9 @@ import org.briarproject.briar.api.sharing.InvitationResponse;
public class BlogInvitationResponse extends InvitationResponse {
public BlogInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, boolean accept, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId,
super(id, groupId, time, local, read, sent, seen, sessionId,
accept, shareableId);
}
......
......@@ -21,10 +21,10 @@ public abstract class ConversationRequest<N extends Nameable>
private final boolean answered;
public ConversationRequest(MessageId messageId, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, N nameable, @Nullable String text,
boolean answered) {
super(messageId, groupId, time, local, sent, seen, read);
super(messageId, groupId, time, local, read, sent, seen);
this.sessionId = sessionId;
this.nameable = nameable;
this.text = text;
......
......@@ -15,9 +15,9 @@ public abstract class ConversationResponse extends ConversationMessageHeader {
private final boolean accepted;
public ConversationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, boolean accepted) {
super(id, groupId, time, local, sent, seen, read);
super(id, groupId, time, local, read, sent, seen);
this.sessionId = sessionId;
this.accepted = accepted;
}
......
......@@ -15,10 +15,10 @@ import javax.annotation.concurrent.Immutable;
public class ForumInvitationRequest extends InvitationRequest<Forum> {
public ForumInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, Forum forum, @Nullable String text,
boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, forum,
super(id, groupId, time, local, read, sent, seen, sessionId, forum,
text, available, canBeOpened);
}
......
......@@ -14,9 +14,9 @@ import javax.annotation.concurrent.Immutable;
public class ForumInvitationResponse extends InvitationResponse {
public ForumInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, boolean accept, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId,
super(id, groupId, time, local, read, sent, seen, sessionId,
accept, shareableId);
}
......
......@@ -19,10 +19,10 @@ public class IntroductionRequest extends ConversationRequest<Author> {
private final AuthorInfo authorInfo;
public IntroductionRequest(MessageId messageId, GroupId groupId,
long time, boolean local, boolean sent, boolean seen, boolean read,
long time, boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, Author author, @Nullable String text,
boolean answered, AuthorInfo authorInfo) {
super(messageId, groupId, time, local, sent, seen, read, sessionId,
super(messageId, groupId, time, local, read, sent, seen, sessionId,
author, text, answered);
this.authorInfo = authorInfo;
}
......
......@@ -22,10 +22,10 @@ public class IntroductionResponse extends ConversationResponse {
private final Role ourRole;
public IntroductionResponse(MessageId messageId, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, boolean accepted, Author author,
AuthorInfo introducedAuthorInfo, Role role) {
super(messageId, groupId, time, local, sent, seen, read, sessionId,
super(messageId, groupId, time, local, read, sent, seen, sessionId,
accepted);
this.introducedAuthor = author;
this.introducedAuthorInfo = introducedAuthorInfo;
......
......@@ -16,10 +16,10 @@ import javax.annotation.concurrent.Immutable;
public class GroupInvitationRequest extends InvitationRequest<PrivateGroup> {
public GroupInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, PrivateGroup shareable,
@Nullable String text, boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, shareable,
super(id, groupId, time, local, read, sent, seen, sessionId, shareable,
text, available, canBeOpened);
}
......
......@@ -14,9 +14,9 @@ import javax.annotation.concurrent.Immutable;
public class GroupInvitationResponse extends InvitationResponse {
public GroupInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, boolean accept, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId,
super(id, groupId, time, local, read, sent, seen, sessionId,
accept, shareableId);
}
......
......@@ -13,10 +13,10 @@ public abstract class InvitationRequest<S extends Shareable> extends
private final boolean canBeOpened;
public InvitationRequest(MessageId messageId, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, S object, @Nullable String text,
boolean available, boolean canBeOpened) {
super(messageId, groupId, time, local, sent, seen, read, sessionId,
super(messageId, groupId, time, local, read, sent, seen, sessionId,
object, text, !available);
this.canBeOpened = canBeOpened;
}
......
......@@ -10,9 +10,9 @@ public abstract class InvitationResponse extends ConversationResponse {
private final GroupId shareableId;
public InvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
boolean local, boolean read, boolean sent, boolean seen,
SessionId sessionId, boolean accepted, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId, accepted);
super(id, groupId, time, local, read, sent, seen, sessionId, accepted);
this.shareableId = shareableId;
}
......
......@@ -453,7 +453,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
authorInfos.put(author.getId(), authorInfo);
}
return new IntroductionRequest(m, contactGroupId, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
meta.isLocal(), meta.isRead(), status.isSent(), status.isSeen(),
sessionId, author, text, !meta.isAvailableToAnswer(),
authorInfo);
}
......@@ -487,7 +487,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
authorInfos.put(author.getId(), authorInfo);
}
return new IntroductionResponse(m, contactGroupId, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
meta.isLocal(), meta.isRead(), status.isSent(), status.isSeen(),
sessionId, accept, author, authorInfo, role);
}
......
......@@ -414,8 +414,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
boolean canBeOpened = meta.wasAccepted() &&
db.containsGroup(txn, invite.getPrivateGroupId());
return new GroupInvitationRequest(m, contactGroupId,
meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), sessionId, pg,
meta.getTimestamp(), meta.isLocal(), meta.isRead(),
status.isSent(), status.isSeen(), sessionId, pg,
invite.getText(), meta.isAvailableToAnswer(), canBeOpened);
}
......@@ -424,10 +424,9 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
MessageStatus status, boolean accept) {
SessionId sessionId = getSessionId(meta.getPrivateGroupId());
return new GroupInvitationResponse(m, contactGroupId,
meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), sessionId, accept,
meta.getPrivateGroupId()
);
meta.getTimestamp(), meta.isLocal(), meta.isRead(),
status.isSent(), status.isSeen(), sessionId, accept,
meta.getPrivateGroupId());
}
@Override
......
......@@ -329,7 +329,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
PrivateGroup pg) {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, sessionId, pg,
m.getTimestamp(), false, false, false, false, sessionId, pg,
m.getText(), true, false);
}
......
......@@ -23,7 +23,7 @@ public class BlogInvitationFactoryImpl
ContactId c, boolean available, boolean canBeOpened) {
SessionId sessionId = new SessionId(m.getShareableId().getBytes());
return new BlogInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), local, sent, seen, read, sessionId,
m.getTimestamp(), local, read, sent, seen, sessionId,
m.getShareable(), m.getText(), available, canBeOpened);
}
......@@ -32,8 +32,8 @@ public class BlogInvitationFactoryImpl
GroupId contactGroupId, long time, boolean local, boolean sent,
boolean seen, boolean read, boolean accept, GroupId shareableId) {
SessionId sessionId = new SessionId(shareableId.getBytes());
return new BlogInvitationResponse(id, contactGroupId, time, local, sent,
seen, read, sessionId, accept, shareableId);
return new BlogInvitationResponse(id, contactGroupId, time, local, read,
sent, seen, sessionId, accept, shareableId);
}
}
......@@ -23,7 +23,7 @@ public class ForumInvitationFactoryImpl
ContactId c, boolean available, boolean canBeOpened) {
SessionId sessionId = new SessionId(m.getShareableId().getBytes());
return new ForumInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), local, sent, seen, read, sessionId,
m.getTimestamp(), local, read, sent, seen, sessionId,
m.getShareable(), m.getText(), available, canBeOpened);
}
......@@ -33,7 +33,7 @@ public class ForumInvitationFactoryImpl
boolean seen, boolean read, boolean accept, GroupId shareableId) {
SessionId sessionId = new SessionId(shareableId.getBytes());
return new ForumInvitationResponse(id, contactGroupId, time, local,
sent, seen, read, sessionId, accept, shareableId);
read, sent, seen, sessionId, accept, shareableId);
}
}
......@@ -25,6 +25,7 @@ import org.briarproject.bramble.test.TestDatabaseModule;
import org.briarproject.briar.api.client.ProtocolStateException;
import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
import org.briarproject.briar.api.conversation.ConversationResponse;
import org.briarproject.briar.api.introduction.IntroductionManager;
import org.briarproject.briar.api.introduction.IntroductionRequest;
import org.briarproject.briar.api.introduction.IntroductionResponse;
......@@ -138,6 +139,18 @@ public class IntroductionIntegrationTest
assertGroupCount(messageTracker0, g1.getId(), 1, 0);
assertGroupCount(messageTracker0, g2.getId(), 1, 0);
// check that request message states are correct
Collection<ConversationMessageHeader> messages =
db0.transactionWithResult(true, txn -> introductionManager0
.getMessageHeaders(txn, contactId1From0));
assertEquals(1, messages.size());
assertMessageState(messages.iterator().next(), true, false, false);
messages =
db0.transactionWithResult(true, txn -> introductionManager0
.getMessageHeaders(txn, contactId2From0));
assertEquals(1, messages.size());
assertMessageState(messages.iterator().next(), true, false, false);
// sync first REQUEST message
sync0To1(1, true);
eventWaiter.await(TIMEOUT, 1);
......@@ -146,6 +159,17 @@ public class IntroductionIntegrationTest
listener1.getRequest().getName());
assertGroupCount(messageTracker1, g1.getId(), 2, 1);
// check that accept message state is correct
messages =
db1.transactionWithResult(true, txn -> introductionManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(2, messages.size());
for (ConversationMessageHeader h : messages) {
if (h instanceof ConversationResponse) {
assertMessageState(h, true, false, false);
}
}
// sync second REQUEST message
sync0To2(1, true);
eventWaiter.await(TIMEOUT, 1);
......
......@@ -163,14 +163,21 @@ public class GroupInvitationIntegrationTest
long timestamp = clock.currentTimeMillis();
sendInvitation(timestamp, null);
// check that invitation message state is correct
Collection<ConversationMessageHeader> messages =
db0.transactionWithResult(true, txn -> groupInvitationManager0
.getMessageHeaders(txn, contactId1From0));
assertEquals(1, messages.size());
assertMessageState(messages.iterator().next(), true, false, false);
sync0To1(1, true);
assertFalse(groupInvitationManager1.getInvitations().isEmpty());
groupInvitationManager1
.respondToInvitation(contactId0From1, privateGroup0, true);
Collection<ConversationMessageHeader> messages =
db1.transactionWithResult(true, txn -> groupInvitationManager1
messages = db1.transactionWithResult(true,
txn -> groupInvitationManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(2, messages.size());
boolean foundResponse = false;
......@@ -178,6 +185,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) {
foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m;
assertMessageState(response, true, false, false);
assertEquals(privateGroup0.getId(), response.getShareableId());
assertTrue(response.wasAccepted());
} else {
......
......@@ -19,6 +19,7 @@ import org.briarproject.briar.api.blog.BlogSharingManager;
import org.briarproject.briar.api.blog.event.BlogInvitationRequestReceivedEvent;
import org.briarproject.briar.api.blog.event.BlogInvitationResponseReceivedEvent;
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
import org.briarproject.briar.api.conversation.ConversationResponse;
import org.briarproject.briar.test.BriarIntegrationTest;
import org.briarproject.briar.test.BriarIntegrationTestComponent;
import org.briarproject.briar.test.DaggerBriarIntegrationTestComponent;
......@@ -128,12 +129,29 @@ public class BlogSharingIntegrationTest
MAJOR_VERSION, contact1From0).getId();
assertGroupCount(messageTracker0, g, 1, 0);
// check that request message state is correct
Collection<ConversationMessageHeader> messages =
db0.transactionWithResult(true, txn -> blogSharingManager0
.getMessageHeaders(txn, contactId1From0));
assertEquals(1, messages.size());
assertMessageState(messages.iterator().next(), true, false, false);
// sync first request message
sync0To1(1, true);
eventWaiter.await(TIMEOUT, 1);
assertTrue(listener1.requestReceived);
assertGroupCount(messageTracker1, g, 2, 1);
// check that accept message state is correct
messages = db1.transactionWithResult(true, txn -> blogSharingManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(2, messages.size());
for (ConversationMessageHeader h : messages) {
if (h instanceof ConversationResponse) {
assertMessageState(h, true, false, false);
}
}
// sync response back
sync1To0(1, true);
eventWaiter.await(TIMEOUT, 1);
......
......@@ -13,6 +13,7 @@ import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.test.TestDatabaseModule;
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
import org.briarproject.briar.api.conversation.ConversationResponse;
import org.briarproject.briar.api.forum.Forum;
import org.briarproject.briar.api.forum.ForumInvitationRequest;
import org.briarproject.briar.api.forum.ForumInvitationResponse;
......@@ -114,11 +115,28 @@ public class ForumSharingIntegrationTest
.sendInvitation(forum0.getId(), contactId1From0, "Hi!",
clock.currentTimeMillis());
// check that request message state is correct
Collection<ConversationMessageHeader> messages =
db0.transactionWithResult(true, txn -> forumSharingManager0
.getMessageHeaders(txn, contactId1From0));
assertEquals(1, messages.size());
assertMessageState(messages.iterator().next(), true, false, false);
// sync first request message
sync0To1(1, true);
eventWaiter.await(TIMEOUT, 1);
assertTrue(listener1.requestReceived);
// check that accept message state is correct
messages = db1.transactionWithResult(true, txn -> forumSharingManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(2, messages.size());
for (ConversationMessageHeader h : messages) {
if (h instanceof ConversationResponse) {
assertMessageState(h, true, false, false);
}
}
// sync response back
sync1To0(1, true);
eventWaiter.await(TIMEOUT, 1);
......
......@@ -40,6 +40,7 @@ import org.briarproject.bramble.versioning.VersioningModule;
import org.briarproject.briar.api.blog.BlogFactory;
import org.briarproject.briar.api.blog.BlogPostFactory;
import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
import org.briarproject.briar.api.forum.ForumPostFactory;
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
......@@ -330,6 +331,13 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
}
}
protected void assertMessageState(ConversationMessageHeader h, boolean read,
boolean sent, boolean seen) {
assertEquals("read", read, h.isRead());
assertEquals("sent", sent, h.isSent());
assertEquals("seen", seen, h.isSeen());
}
@After
public void tearDown() throws Exception {
stopLifecycles();
......
......@@ -77,7 +77,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
@Test
fun listIntroductionRequest() {
val request = IntroductionRequest(
message.id, group.id, timestamp, true, true, false, true, sessionId, author, text,
message.id, group.id, timestamp, true, true, true, false, sessionId, author, text,
false, AuthorInfo(UNVERIFIED)
)
......@@ -217,7 +217,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
@Test
fun testIntroductionRequestWithNullText() {
val request = IntroductionRequest(
message.id, group.id, timestamp, true, true, false, true, sessionId, author, null,
message.id, group.id, timestamp, true, true, true, false, sessionId, author, null,
false, AuthorInfo(VERIFIED)
)
val json = """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment