From 29758b174a7fffd14d967ef56a6771899785c789 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 5 Sep 2018 15:57:40 -0300 Subject: [PATCH] Unify all events related to private messages --- .../AndroidNotificationManagerImpl.java | 17 --- .../android/blog/BlogControllerImpl.java | 2 +- .../android/contact/ContactListFragment.java | 32 ------ .../android/contact/ConversationActivity.java | 108 ++++++------------ .../android/forum/ForumControllerImpl.java | 3 +- .../conversation/GroupControllerImpl.java | 3 +- .../BlogInvitationRequestReceivedEvent.java | 10 +- .../BlogInvitationResponseReceivedEvent.java | 11 +- .../ForumInvitationRequestReceivedEvent.java | 10 +- .../ForumInvitationResponseReceivedEvent.java | 10 +- .../IntroductionRequestReceivedEvent.java | 24 +--- .../IntroductionResponseReceivedEvent.java | 23 +--- .../event/PrivateMessageReceivedEvent.java | 17 +-- .../GroupInvitationRequestReceivedEvent.java | 11 +- .../GroupInvitationResponseReceivedEvent.java | 13 +-- .../event/InvitationRequestReceivedEvent.java | 38 ------ .../InvitationResponseReceivedEvent.java | 32 ------ .../introduction/AbstractProtocolEngine.java | 2 +- .../IntroduceeProtocolEngine.java | 2 +- .../briar/messaging/MessagingManagerImpl.java | 4 +- .../invitation/CreatorProtocolEngine.java | 15 ++- .../invitation/InviteeProtocolEngine.java | 14 +-- .../briar/sharing/BlogProtocolEngineImpl.java | 7 +- .../sharing/ForumProtocolEngineImpl.java | 7 +- .../IntroductionIntegrationTest.java | 14 ++- .../sharing/BlogSharingIntegrationTest.java | 4 +- .../sharing/ForumSharingIntegrationTest.java | 4 +- 27 files changed, 122 insertions(+), 315 deletions(-) delete mode 100644 briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationRequestReceivedEvent.java delete mode 100644 briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationResponseReceivedEvent.java diff --git a/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java index a36ca358e..37e8d61d5 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java @@ -41,13 +41,9 @@ import org.briarproject.briar.android.util.BriarNotificationBuilder; import org.briarproject.briar.api.android.AndroidNotificationManager; import org.briarproject.briar.api.blog.event.BlogPostAddedEvent; import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent; -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.event.PrivateMessageReceivedEvent; import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent; -import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent; -import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent; import java.util.Set; import java.util.concurrent.Callable; @@ -235,19 +231,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } else if (e instanceof BlogPostAddedEvent) { BlogPostAddedEvent b = (BlogPostAddedEvent) e; showBlogPostNotification(b.getGroupId()); - } else if (e instanceof IntroductionRequestReceivedEvent) { - ContactId c = ((IntroductionRequestReceivedEvent) e).getContactId(); - showContactNotification(c); - } else if (e instanceof IntroductionResponseReceivedEvent) { - ContactId c = - ((IntroductionResponseReceivedEvent) e).getContactId(); - showContactNotification(c); - } else if (e instanceof InvitationRequestReceivedEvent) { - ContactId c = ((InvitationRequestReceivedEvent) e).getContactId(); - showContactNotification(c); - } else if (e instanceof InvitationResponseReceivedEvent) { - ContactId c = ((InvitationResponseReceivedEvent) e).getContactId(); - showContactNotification(c); } else if (e instanceof IntroductionSucceededEvent) { showIntroductionNotification(); } diff --git a/briar-android/src/main/java/org/briarproject/briar/android/blog/BlogControllerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/blog/BlogControllerImpl.java index d62a52c18..7bd289a62 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/blog/BlogControllerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/blog/BlogControllerImpl.java @@ -107,7 +107,7 @@ class BlogControllerImpl extends BaseControllerImpl } else if (e instanceof BlogInvitationResponseReceivedEvent) { BlogInvitationResponseReceivedEvent b = (BlogInvitationResponseReceivedEvent) e; - PrivateResponse r = b.getResponse(); + PrivateResponse r = b.getMessageHeader(); if (r.getObject().getId().equals(groupId) && r.wasAccepted()) { LOG.info("Blog invitation accepted"); onBlogInvitationAccepted(b.getContactId()); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java index dea7d542c..fa79b0931 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/contact/ContactListFragment.java @@ -37,17 +37,9 @@ import org.briarproject.briar.android.keyagreement.ContactExchangeActivity; import org.briarproject.briar.android.view.BriarRecyclerView; import org.briarproject.briar.api.android.AndroidNotificationManager; import org.briarproject.briar.api.client.MessageTracker.GroupCount; -import org.briarproject.briar.api.introduction.IntroductionRequest; -import org.briarproject.briar.api.introduction.IntroductionResponse; -import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent; -import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent; import org.briarproject.briar.api.messaging.ConversationManager; 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.api.messaging.event.PrivateMessageReceivedEvent; -import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent; -import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent; import java.util.ArrayList; import java.util.List; @@ -255,30 +247,6 @@ public class ContactListFragment extends BaseFragment implements EventListener { PrivateMessageReceivedEvent p = (PrivateMessageReceivedEvent) e; PrivateMessageHeader h = p.getMessageHeader(); updateItem(p.getContactId(), h); - } else if (e instanceof IntroductionRequestReceivedEvent) { - LOG.info("Introduction request received, updating item"); - IntroductionRequestReceivedEvent m = - (IntroductionRequestReceivedEvent) e; - IntroductionRequest ir = m.getIntroductionRequest(); - updateItem(m.getContactId(), ir); - } else if (e instanceof IntroductionResponseReceivedEvent) { - LOG.info("Introduction response received, updating item"); - IntroductionResponseReceivedEvent m = - (IntroductionResponseReceivedEvent) e; - IntroductionResponse ir = m.getIntroductionResponse(); - updateItem(m.getContactId(), ir); - } else if (e instanceof InvitationRequestReceivedEvent) { - LOG.info("Invitation Request received, update item"); - InvitationRequestReceivedEvent m = - (InvitationRequestReceivedEvent) e; - PrivateRequest ir = m.getRequest(); - updateItem(m.getContactId(), ir); - } else if (e instanceof InvitationResponseReceivedEvent) { - LOG.info("Invitation response received, updating item"); - InvitationResponseReceivedEvent m = - (InvitationResponseReceivedEvent) e; - PrivateResponse ir = m.getResponse(); - updateItem(m.getContactId(), ir); } } diff --git a/briar-android/src/main/java/org/briarproject/briar/android/contact/ConversationActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/contact/ConversationActivity.java index 07270b460..a9f9898e7 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/contact/ConversationActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/contact/ConversationActivity.java @@ -64,8 +64,6 @@ import org.briarproject.briar.api.forum.ForumSharingManager; import org.briarproject.briar.api.introduction.IntroductionManager; import org.briarproject.briar.api.introduction.IntroductionRequest; import org.briarproject.briar.api.introduction.IntroductionResponse; -import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent; -import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent; import org.briarproject.briar.api.messaging.MessagingManager; import org.briarproject.briar.api.messaging.PrivateMessage; import org.briarproject.briar.api.messaging.PrivateMessageFactory; @@ -74,8 +72,6 @@ import org.briarproject.briar.api.messaging.PrivateRequest; import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager; -import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent; -import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent; import org.thoughtcrime.securesms.components.util.FutureTaskListener; import org.thoughtcrime.securesms.components.util.ListenableFutureTask; @@ -474,9 +470,7 @@ public class ConversationActivity extends BriarActivity PrivateMessageReceivedEvent p = (PrivateMessageReceivedEvent) e; if (p.getContactId().equals(contactId)) { LOG.info("Message received, adding"); - PrivateMessageHeader h = p.getMessageHeader(); - addConversationItem(ConversationItem.from(h)); - loadMessageBody(h.getId()); + onNewPrivateMessage(p.getMessageHeader()); } } else if (e instanceof MessagesSentEvent) { MessagesSentEvent m = (MessagesSentEvent) e; @@ -502,38 +496,6 @@ public class ConversationActivity extends BriarActivity LOG.info("Contact disconnected"); displayContactOnlineStatus(); } - } else if (e instanceof IntroductionRequestReceivedEvent) { - IntroductionRequestReceivedEvent event = - (IntroductionRequestReceivedEvent) e; - if (event.getContactId().equals(contactId)) { - LOG.info("Introduction request received, adding..."); - PrivateRequest ir = event.getIntroductionRequest(); - handlePrivateRequest(ir); - } - } else if (e instanceof IntroductionResponseReceivedEvent) { - IntroductionResponseReceivedEvent event = - (IntroductionResponseReceivedEvent) e; - if (event.getContactId().equals(contactId)) { - LOG.info("Introduction response received, adding..."); - PrivateResponse ir = event.getIntroductionResponse(); - handlePrivateResponse(ir); - } - } else if (e instanceof InvitationRequestReceivedEvent) { - InvitationRequestReceivedEvent event = - (InvitationRequestReceivedEvent) e; - if (event.getContactId().equals(contactId)) { - LOG.info("Invitation received, adding..."); - PrivateRequest ir = event.getRequest(); - handlePrivateRequest(ir); - } - } else if (e instanceof InvitationResponseReceivedEvent) { - InvitationResponseReceivedEvent event = - (InvitationResponseReceivedEvent) e; - if (event.getContactId().equals(contactId)) { - LOG.info("Invitation response received, adding..."); - PrivateResponse ir = event.getResponse(); - handlePrivateResponse(ir); - } } } @@ -546,42 +508,44 @@ public class ConversationActivity extends BriarActivity }); } - private void handlePrivateRequest(PrivateRequest m) { - getContactNameTask().addListener(new FutureTaskListener() { - @Override - public void onSuccess(String contactName) { - runOnUiThreadUnlessDestroyed(() -> { - ConversationItem item = ConversationItem - .from(ConversationActivity.this, contactName, m); - addConversationItem(item); - }); - } + private void onNewPrivateMessage(PrivateMessageHeader h) { + if (h instanceof PrivateRequest || h instanceof PrivateResponse) { + getContactNameTask().addListener(new FutureTaskListener() { + @Override + public void onSuccess(String contactName) { + runOnUiThreadUnlessDestroyed(() -> { + handlePrivateRequestAndResponse(h, contactName); + }); + } - @Override - public void onFailure(Throwable exception) { - runOnUiThreadUnlessDestroyed( - () -> handleDbException((DbException) exception)); - } - }); + @Override + public void onFailure(Throwable exception) { + runOnUiThreadUnlessDestroyed( + () -> handleDbException((DbException) exception)); + } + }); + } else { + addConversationItem(ConversationItem.from(h)); + loadMessageBody(h.getId()); + } } - private void handlePrivateResponse(PrivateResponse m) { - getContactNameTask().addListener(new FutureTaskListener() { - @Override - public void onSuccess(String contactName) { - runOnUiThreadUnlessDestroyed(() -> { - ConversationItem item = ConversationItem - .from(ConversationActivity.this, contactName, m); - addConversationItem(item); - }); - } - - @Override - public void onFailure(Throwable exception) { - runOnUiThreadUnlessDestroyed( - () -> handleDbException((DbException) exception)); - } - }); + @UiThread + private void handlePrivateRequestAndResponse(PrivateMessageHeader h, + String contactName) { + ConversationItem item; + if (h instanceof PrivateRequest) { + PrivateRequest m = (PrivateRequest) h; + item = ConversationItem + .from(ConversationActivity.this, contactName, m); + } else if (h instanceof PrivateResponse) { + PrivateResponse m = (PrivateResponse) h; + item = ConversationItem + .from(ConversationActivity.this, contactName, m); + } else { + throw new AssertionError("Unknown PrivateMessageHeader"); + } + addConversationItem(item); } private void markMessages(Collection messageIds, boolean sent, diff --git a/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumControllerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumControllerImpl.java index ea8365c1a..695d14f03 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumControllerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/forum/ForumControllerImpl.java @@ -84,8 +84,7 @@ class ForumControllerImpl extends } else if (e instanceof ForumInvitationResponseReceivedEvent) { ForumInvitationResponseReceivedEvent f = (ForumInvitationResponseReceivedEvent) e; - ForumInvitationResponse r = - (ForumInvitationResponse) f.getResponse(); + ForumInvitationResponse r = f.getMessageHeader(); if (r.getObject().getId().equals(getGroupId()) && r.wasAccepted()) { LOG.info("Forum invitation was accepted"); onForumInvitationAccepted(f.getContactId()); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/privategroup/conversation/GroupControllerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/privategroup/conversation/GroupControllerImpl.java index aa5d8c951..ba5f87c42 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/privategroup/conversation/GroupControllerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/privategroup/conversation/GroupControllerImpl.java @@ -99,8 +99,7 @@ class GroupControllerImpl extends } else if (e instanceof GroupInvitationResponseReceivedEvent) { GroupInvitationResponseReceivedEvent g = (GroupInvitationResponseReceivedEvent) e; - GroupInvitationResponse r = - (GroupInvitationResponse) g.getResponse(); + GroupInvitationResponse r = g.getMessageHeader(); if (getGroupId().equals(r.getObject().getId()) && r.wasAccepted()) { listener.runOnUiThreadUnlessDestroyed( () -> listener.onInvitationAccepted(g.getContactId())); diff --git a/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationRequestReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationRequestReceivedEvent.java index ee90a2e12..699717407 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationRequestReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationRequestReceivedEvent.java @@ -4,18 +4,18 @@ import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.briar.api.blog.Blog; import org.briarproject.briar.api.messaging.PrivateRequest; -import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault public class BlogInvitationRequestReceivedEvent extends - InvitationRequestReceivedEvent { + PrivateMessageReceivedEvent> { - public BlogInvitationRequestReceivedEvent(Blog blog, ContactId contactId, - PrivateRequest request) { - super(blog, contactId, request); + public BlogInvitationRequestReceivedEvent(PrivateRequest request, + ContactId contactId) { + super(request, contactId); } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationResponseReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationResponseReceivedEvent.java index ee9b22d1f..28df8444a 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationResponseReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/blog/event/BlogInvitationResponseReceivedEvent.java @@ -2,20 +2,19 @@ package org.briarproject.briar.api.blog.event; import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; -import org.briarproject.briar.api.blog.Blog; import org.briarproject.briar.api.blog.BlogInvitationResponse; -import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault public class BlogInvitationResponseReceivedEvent - extends InvitationResponseReceivedEvent { + extends PrivateMessageReceivedEvent { - public BlogInvitationResponseReceivedEvent(ContactId contactId, - BlogInvitationResponse response) { - super(contactId, response); + public BlogInvitationResponseReceivedEvent(BlogInvitationResponse response, + ContactId contactId) { + super(response, contactId); } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationRequestReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationRequestReceivedEvent.java index 7fe834892..673cdd2eb 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationRequestReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationRequestReceivedEvent.java @@ -4,18 +4,18 @@ import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.briar.api.forum.Forum; import org.briarproject.briar.api.messaging.PrivateRequest; -import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault public class ForumInvitationRequestReceivedEvent extends - InvitationRequestReceivedEvent { + PrivateMessageReceivedEvent> { - public ForumInvitationRequestReceivedEvent(Forum forum, ContactId contactId, - PrivateRequest request) { - super(forum, contactId, request); + public ForumInvitationRequestReceivedEvent(PrivateRequest request, + ContactId contactId) { + super(request, contactId); } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationResponseReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationResponseReceivedEvent.java index 460ea3cab..13d3081e8 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationResponseReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/forum/event/ForumInvitationResponseReceivedEvent.java @@ -3,18 +3,18 @@ package org.briarproject.briar.api.forum.event; import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.briar.api.forum.ForumInvitationResponse; -import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault public class ForumInvitationResponseReceivedEvent extends - InvitationResponseReceivedEvent { + PrivateMessageReceivedEvent { - public ForumInvitationResponseReceivedEvent(ContactId contactId, - ForumInvitationResponse response) { - super(contactId, response); + public ForumInvitationResponseReceivedEvent( + ForumInvitationResponse response, ContactId contactId) { + super(response, contactId); } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionRequestReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionRequestReceivedEvent.java index 9fe4871e2..a07a66cac 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionRequestReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionRequestReceivedEvent.java @@ -1,32 +1,20 @@ package org.briarproject.briar.api.introduction.event; import org.briarproject.bramble.api.contact.ContactId; -import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.briar.api.introduction.IntroductionRequest; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault -public class IntroductionRequestReceivedEvent extends Event { +public class IntroductionRequestReceivedEvent extends + PrivateMessageReceivedEvent { - private final ContactId contactId; - private final IntroductionRequest introductionRequest; - - public IntroductionRequestReceivedEvent(ContactId contactId, - IntroductionRequest introductionRequest) { - - this.contactId = contactId; - this.introductionRequest = introductionRequest; - } - - public ContactId getContactId() { - return contactId; - } - - public IntroductionRequest getIntroductionRequest() { - return introductionRequest; + public IntroductionRequestReceivedEvent( + IntroductionRequest introductionRequest, ContactId contactId) { + super(introductionRequest, contactId); } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionResponseReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionResponseReceivedEvent.java index 2cd3d1c29..d1aeb1495 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionResponseReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/introduction/event/IntroductionResponseReceivedEvent.java @@ -1,31 +1,20 @@ package org.briarproject.briar.api.introduction.event; import org.briarproject.bramble.api.contact.ContactId; -import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.briar.api.introduction.IntroductionResponse; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault -public class IntroductionResponseReceivedEvent extends Event { +public class IntroductionResponseReceivedEvent extends + PrivateMessageReceivedEvent { - private final ContactId contactId; - private final IntroductionResponse introductionResponse; - - public IntroductionResponseReceivedEvent(ContactId contactId, - IntroductionResponse introductionResponse) { - - this.contactId = contactId; - this.introductionResponse = introductionResponse; + public IntroductionResponseReceivedEvent( + IntroductionResponse introductionResponse, ContactId contactId) { + super(introductionResponse, contactId); } - public ContactId getContactId() { - return contactId; - } - - public IntroductionResponse getIntroductionResponse() { - return introductionResponse; - } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/messaging/event/PrivateMessageReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/messaging/event/PrivateMessageReceivedEvent.java index d82bff8f6..584bdfe31 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/messaging/event/PrivateMessageReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/messaging/event/PrivateMessageReceivedEvent.java @@ -3,7 +3,6 @@ package org.briarproject.briar.api.messaging.event; import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; -import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.briar.api.messaging.PrivateMessageHeader; import javax.annotation.concurrent.Immutable; @@ -13,28 +12,22 @@ import javax.annotation.concurrent.Immutable; */ @Immutable @NotNullByDefault -public class PrivateMessageReceivedEvent extends Event { +public class PrivateMessageReceivedEvent + extends Event { - private final PrivateMessageHeader messageHeader; + private final H messageHeader; private final ContactId contactId; - private final GroupId groupId; - public PrivateMessageReceivedEvent(PrivateMessageHeader messageHeader, - ContactId contactId, GroupId groupId) { + public PrivateMessageReceivedEvent(H messageHeader, ContactId contactId) { this.messageHeader = messageHeader; this.contactId = contactId; - this.groupId = groupId; } - public PrivateMessageHeader getMessageHeader() { + public H getMessageHeader() { return messageHeader; } public ContactId getContactId() { return contactId; } - - public GroupId getGroupId() { - return groupId; - } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationRequestReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationRequestReceivedEvent.java index 6ce0ff1ac..2edd5f022 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationRequestReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationRequestReceivedEvent.java @@ -2,20 +2,19 @@ package org.briarproject.briar.api.privategroup.event; import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; -import org.briarproject.briar.api.privategroup.PrivateGroup; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest; -import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault public class GroupInvitationRequestReceivedEvent extends - InvitationRequestReceivedEvent { + PrivateMessageReceivedEvent { - public GroupInvitationRequestReceivedEvent(PrivateGroup group, - ContactId contactId, GroupInvitationRequest request) { - super(group, contactId, request); + public GroupInvitationRequestReceivedEvent(GroupInvitationRequest request, + ContactId contactId) { + super(request, contactId); } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationResponseReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationResponseReceivedEvent.java index e1af29e15..bc016a890 100644 --- a/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationResponseReceivedEvent.java +++ b/briar-api/src/main/java/org/briarproject/briar/api/privategroup/event/GroupInvitationResponseReceivedEvent.java @@ -2,19 +2,18 @@ package org.briarproject.briar.api.privategroup.event; import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; -import org.briarproject.briar.api.messaging.PrivateResponse; -import org.briarproject.briar.api.privategroup.PrivateGroup; -import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent; +import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; +import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse; import javax.annotation.concurrent.Immutable; @Immutable @NotNullByDefault public class GroupInvitationResponseReceivedEvent - extends InvitationResponseReceivedEvent { + extends PrivateMessageReceivedEvent { - public GroupInvitationResponseReceivedEvent(ContactId contactId, - PrivateResponse response) { - super(contactId, response); + public GroupInvitationResponseReceivedEvent( + GroupInvitationResponse response, ContactId contactId) { + super(response, contactId); } } diff --git a/briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationRequestReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationRequestReceivedEvent.java deleted file mode 100644 index a7aeb9336..000000000 --- a/briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationRequestReceivedEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.briarproject.briar.api.sharing.event; - -import org.briarproject.bramble.api.contact.ContactId; -import org.briarproject.bramble.api.event.Event; -import org.briarproject.bramble.api.nullsafety.NotNullByDefault; -import org.briarproject.briar.api.messaging.PrivateRequest; -import org.briarproject.briar.api.sharing.Shareable; - -import javax.annotation.concurrent.Immutable; - -@Immutable -@NotNullByDefault -public abstract class InvitationRequestReceivedEvent - extends Event { - - private final S shareable; - private final ContactId contactId; - private final PrivateRequest request; - - protected InvitationRequestReceivedEvent(S shareable, ContactId contactId, - PrivateRequest request) { - this.shareable = shareable; - this.contactId = contactId; - this.request = request; - } - - public ContactId getContactId() { - return contactId; - } - - public PrivateRequest getRequest() { - return request; - } - - public S getShareable() { - return shareable; - } -} diff --git a/briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationResponseReceivedEvent.java b/briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationResponseReceivedEvent.java deleted file mode 100644 index 85e15462c..000000000 --- a/briar-api/src/main/java/org/briarproject/briar/api/sharing/event/InvitationResponseReceivedEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.briarproject.briar.api.sharing.event; - -import org.briarproject.bramble.api.contact.ContactId; -import org.briarproject.bramble.api.event.Event; -import org.briarproject.bramble.api.nullsafety.NotNullByDefault; -import org.briarproject.briar.api.messaging.PrivateResponse; -import org.briarproject.briar.api.sharing.Shareable; - -import javax.annotation.concurrent.Immutable; - -@Immutable -@NotNullByDefault -public abstract class InvitationResponseReceivedEvent - extends Event { - - private final ContactId contactId; - private final PrivateResponse response; - - public InvitationResponseReceivedEvent(ContactId contactId, - PrivateResponse response) { - this.contactId = contactId; - this.response = response; - } - - public ContactId getContactId() { - return contactId; - } - - public PrivateResponse getResponse() { - return response; - } -} diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/AbstractProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/introduction/AbstractProtocolEngine.java index 424ea2f39..bb944f6be 100644 --- a/briar-core/src/main/java/org/briarproject/briar/introduction/AbstractProtocolEngine.java +++ b/briar-core/src/main/java/org/briarproject/briar/introduction/AbstractProtocolEngine.java @@ -157,7 +157,7 @@ abstract class AbstractProtocolEngine s.getSessionId(), introduction, m instanceof AcceptMessage); IntroductionResponseReceivedEvent e = - new IntroductionResponseReceivedEvent(c.getId(), response); + new IntroductionResponseReceivedEvent(response, c.getId()); txn.attach(e); } diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java index 248882cea..4f9997de9 100644 --- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java +++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java @@ -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 diff --git a/briar-core/src/main/java/org/briarproject/briar/messaging/MessagingManagerImpl.java b/briar-core/src/main/java/org/briarproject/briar/messaging/MessagingManagerImpl.java index 8d06c9934..d5206aa1d 100644 --- a/briar-core/src/main/java/org/briarproject/briar/messaging/MessagingManagerImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/messaging/MessagingManagerImpl.java @@ -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 event = + new PrivateMessageReceivedEvent<>(header, contactId); txn.attach(event); messageTracker.trackIncomingMessage(txn, m); diff --git a/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/CreatorProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/CreatorProtocolEngine.java index be9c4d326..b73bf186a 100644 --- a/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/CreatorProtocolEngine.java +++ b/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/CreatorProtocolEngine.java @@ -69,8 +69,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine { } @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 { } @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 { 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 { 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(), diff --git a/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/InviteeProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/InviteeProtocolEngine.java index 67690c80c..722b562b8 100644 --- a/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/InviteeProtocolEngine.java +++ b/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/InviteeProtocolEngine.java @@ -56,8 +56,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine { @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 { } @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 { // 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 { } 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, diff --git a/briar-core/src/main/java/org/briarproject/briar/sharing/BlogProtocolEngineImpl.java b/briar-core/src/main/java/org/briarproject/briar/sharing/BlogProtocolEngineImpl.java index 8df04ab0c..aae6e5db2 100644 --- a/briar-core/src/main/java/org/briarproject/briar/sharing/BlogProtocolEngineImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/sharing/BlogProtocolEngineImpl.java @@ -53,8 +53,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl { PrivateRequest 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 { .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 { .createInvitationResponse(m.getId(), m.getContactGroupId(), m.getTimestamp(), false, false, true, false, shareable, true); - return new BlogInvitationResponseReceivedEvent(contactId, response); + return new BlogInvitationResponseReceivedEvent(response, contactId); } @Override diff --git a/briar-core/src/main/java/org/briarproject/briar/sharing/ForumProtocolEngineImpl.java b/briar-core/src/main/java/org/briarproject/briar/sharing/ForumProtocolEngineImpl.java index 383090150..081886d1b 100644 --- a/briar-core/src/main/java/org/briarproject/briar/sharing/ForumProtocolEngineImpl.java +++ b/briar-core/src/main/java/org/briarproject/briar/sharing/ForumProtocolEngineImpl.java @@ -55,8 +55,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl { PrivateRequest 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 { .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 { .createInvitationResponse(m.getId(), m.getContactGroupId(), m.getTimestamp(), false, false, true, false, shareable, true); - return new ForumInvitationResponseReceivedEvent(contactId, response); + return new ForumInvitationResponseReceivedEvent(response, contactId); } @Override diff --git a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java index c7dfdcb8f..b9cec1cc5 100644 --- a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroductionIntegrationTest.java @@ -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 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 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 getRequest() { assertTrue( latestEvent instanceof IntroductionRequestReceivedEvent); return ((IntroductionRequestReceivedEvent) latestEvent) - .getIntroductionRequest(); + .getRequest(); } } diff --git a/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java index 6663c6d86..68f44bc5d 100644 --- a/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/sharing/BlogSharingIntegrationTest.java @@ -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()); diff --git a/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java b/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java index 46db59820..b956403f0 100644 --- a/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/sharing/ForumSharingIntegrationTest.java @@ -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,