mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Unify all events related to private messages
This commit is contained in:
@@ -157,7 +157,7 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
s.getSessionId(), introduction,
|
||||
m instanceof AcceptMessage);
|
||||
IntroductionResponseReceivedEvent e =
|
||||
new IntroductionResponseReceivedEvent(c.getId(), response);
|
||||
new IntroductionResponseReceivedEvent(response, c.getId());
|
||||
txn.attach(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ class IntroduceeProtocolEngine
|
||||
s.getSessionId(), introduction, m.getMessage(), false,
|
||||
contactExists);
|
||||
IntroductionRequestReceivedEvent e =
|
||||
new IntroductionRequestReceivedEvent(c.getId(), request);
|
||||
new IntroductionRequestReceivedEvent(request, c.getId());
|
||||
txn.attach(e);
|
||||
|
||||
// Move to the AWAIT_RESPONSES state
|
||||
|
||||
@@ -116,8 +116,8 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
PrivateMessageHeader header = new PrivateMessageHeader(
|
||||
m.getId(), groupId, timestamp, local, read, false, false);
|
||||
ContactId contactId = getContactId(txn, groupId);
|
||||
PrivateMessageReceivedEvent event = new PrivateMessageReceivedEvent(
|
||||
header, contactId, groupId);
|
||||
PrivateMessageReceivedEvent<PrivateMessageHeader> event =
|
||||
new PrivateMessageReceivedEvent<>(header, contactId);
|
||||
txn.attach(event);
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
|
||||
|
||||
@@ -69,8 +69,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreatorSession onJoinAction(Transaction txn, CreatorSession s)
|
||||
throws DbException {
|
||||
public CreatorSession onJoinAction(Transaction txn, CreatorSession s) {
|
||||
throw new UnsupportedOperationException(); // Invalid in this role
|
||||
}
|
||||
|
||||
@@ -92,8 +91,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreatorSession onMemberAddedAction(Transaction txn, CreatorSession s)
|
||||
throws DbException {
|
||||
public CreatorSession onMemberAddedAction(Transaction txn,
|
||||
CreatorSession s) {
|
||||
return s; // Ignored in this role
|
||||
}
|
||||
|
||||
@@ -196,8 +195,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
PrivateGroup privateGroup =
|
||||
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(contactId,
|
||||
createInvitationResponse(m, privateGroup, true)));
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(
|
||||
createInvitationResponse(m, privateGroup, true), contactId));
|
||||
// Move to the JOINED state
|
||||
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
|
||||
sent.getId(), m.getId(), sent.getTimestamp(),
|
||||
@@ -220,8 +219,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
PrivateGroup privateGroup =
|
||||
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(contactId,
|
||||
createInvitationResponse(m, privateGroup, false)));
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(
|
||||
createInvitationResponse(m, privateGroup, false), contactId));
|
||||
// Move to the START state
|
||||
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
|
||||
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
|
||||
|
||||
@@ -56,8 +56,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
|
||||
@Override
|
||||
public InviteeSession onInviteAction(Transaction txn, InviteeSession s,
|
||||
@Nullable String message, long timestamp, byte[] signature)
|
||||
throws DbException {
|
||||
@Nullable String message, long timestamp, byte[] signature) {
|
||||
throw new UnsupportedOperationException(); // Invalid in this role
|
||||
}
|
||||
|
||||
@@ -99,8 +98,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InviteeSession onMemberAddedAction(Transaction txn, InviteeSession s)
|
||||
throws DbException {
|
||||
public InviteeSession onMemberAddedAction(Transaction txn,
|
||||
InviteeSession s) {
|
||||
return s; // Ignored in this role
|
||||
}
|
||||
|
||||
@@ -244,9 +243,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
// Broadcast an event
|
||||
PrivateGroup privateGroup = privateGroupFactory.createPrivateGroup(
|
||||
m.getGroupName(), m.getCreator(), m.getSalt());
|
||||
txn.attach(
|
||||
new GroupInvitationRequestReceivedEvent(privateGroup, contactId,
|
||||
createInvitationRequest(m, privateGroup, contactId)));
|
||||
txn.attach(new GroupInvitationRequestReceivedEvent(
|
||||
createInvitationRequest(m, privateGroup), contactId));
|
||||
// Move to the INVITED state
|
||||
return new InviteeSession(s.getContactGroupId(), s.getPrivateGroupId(),
|
||||
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
|
||||
@@ -328,7 +326,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
}
|
||||
|
||||
private GroupInvitationRequest createInvitationRequest(InviteMessage m,
|
||||
PrivateGroup pg, ContactId c) {
|
||||
PrivateGroup pg) {
|
||||
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
|
||||
return new GroupInvitationRequest(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false, sessionId, pg,
|
||||
|
||||
@@ -53,8 +53,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
|
||||
PrivateRequest<Blog> request = invitationFactory
|
||||
.createInvitationRequest(false, false, true, false, m,
|
||||
contactId, available, canBeOpened);
|
||||
return new BlogInvitationRequestReceivedEvent(m.getShareable(),
|
||||
contactId, request);
|
||||
return new BlogInvitationRequestReceivedEvent(request, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +63,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
return new BlogInvitationResponseReceivedEvent(contactId, response);
|
||||
return new BlogInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +73,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
return new BlogInvitationResponseReceivedEvent(contactId, response);
|
||||
return new BlogInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,8 +55,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
|
||||
PrivateRequest<Forum> request = invitationFactory
|
||||
.createInvitationRequest(false, false, true, false, m,
|
||||
contactId, available, canBeOpened);
|
||||
return new ForumInvitationRequestReceivedEvent(m.getShareable(),
|
||||
contactId, request);
|
||||
return new ForumInvitationRequestReceivedEvent(request, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +65,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
return new ForumInvitationResponseReceivedEvent(contactId, response);
|
||||
return new ForumInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +75,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
return new ForumInvitationResponseReceivedEvent(contactId, response);
|
||||
return new ForumInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,14 +24,16 @@ import org.briarproject.bramble.api.sync.MessageId;
|
||||
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.introduction.Introduction;
|
||||
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.event.IntroductionAbortedEvent;
|
||||
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
|
||||
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
|
||||
import org.briarproject.briar.api.introduction.event.IntroductionSucceededEvent;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||
import org.briarproject.briar.test.BriarIntegrationTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -1131,11 +1133,11 @@ public class IntroductionIntegrationTest
|
||||
protected volatile Event latestEvent;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
IntroductionResponse getResponse() {
|
||||
PrivateResponse<Introduction> getResponse() {
|
||||
assertTrue(
|
||||
latestEvent instanceof IntroductionResponseReceivedEvent);
|
||||
return ((IntroductionResponseReceivedEvent) latestEvent)
|
||||
.getIntroductionResponse();
|
||||
.getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1163,7 +1165,7 @@ public class IntroductionIntegrationTest
|
||||
IntroductionRequestReceivedEvent introEvent =
|
||||
((IntroductionRequestReceivedEvent) e);
|
||||
requestReceived = true;
|
||||
IntroductionRequest ir = introEvent.getIntroductionRequest();
|
||||
PrivateRequest<Introduction> ir = introEvent.getRequest();
|
||||
ContactId contactId = introEvent.getContactId();
|
||||
sessionId = ir.getSessionId();
|
||||
long time = clock.currentTimeMillis();
|
||||
@@ -1200,11 +1202,11 @@ public class IntroductionIntegrationTest
|
||||
}
|
||||
}
|
||||
|
||||
private IntroductionRequest getRequest() {
|
||||
private PrivateRequest<Introduction> getRequest() {
|
||||
assertTrue(
|
||||
latestEvent instanceof IntroductionRequestReceivedEvent);
|
||||
return ((IntroductionRequestReceivedEvent) latestEvent)
|
||||
.getIntroductionRequest();
|
||||
.getRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -559,7 +559,7 @@ public class BlogSharingIntegrationTest
|
||||
BlogInvitationRequestReceivedEvent event =
|
||||
(BlogInvitationRequestReceivedEvent) e;
|
||||
eventWaiter.assertEquals(contactId1From0, event.getContactId());
|
||||
Blog b = event.getShareable();
|
||||
Blog b = event.getRequest().getObject();
|
||||
try {
|
||||
Contact c = contactManager0.getContact(contactId1From0);
|
||||
blogSharingManager0.respondToInvitation(b, c, true);
|
||||
@@ -595,7 +595,7 @@ public class BlogSharingIntegrationTest
|
||||
(BlogInvitationRequestReceivedEvent) e;
|
||||
requestReceived = true;
|
||||
if (!answer) return;
|
||||
Blog b = event.getShareable();
|
||||
Blog b = event.getRequest().getObject();
|
||||
try {
|
||||
eventWaiter.assertEquals(1,
|
||||
blogSharingManager1.getInvitations().size());
|
||||
|
||||
@@ -813,7 +813,7 @@ public class ForumSharingIntegrationTest
|
||||
(ForumInvitationRequestReceivedEvent) e;
|
||||
eventWaiter.assertEquals(contactId1From0, event.getContactId());
|
||||
requestReceived = true;
|
||||
Forum f = event.getShareable();
|
||||
Forum f = event.getRequest().getObject();
|
||||
try {
|
||||
if (respond) {
|
||||
Contact c = contactManager0.getContact(contactId1From0);
|
||||
@@ -851,7 +851,7 @@ public class ForumSharingIntegrationTest
|
||||
(ForumInvitationRequestReceivedEvent) e;
|
||||
requestReceived = true;
|
||||
if (!answer) return;
|
||||
Forum f = event.getShareable();
|
||||
Forum f = event.getRequest().getObject();
|
||||
try {
|
||||
if (respond) {
|
||||
eventWaiter.assertEquals(1,
|
||||
|
||||
Reference in New Issue
Block a user