Unify all events related to private messages

This commit is contained in:
Torsten Grote
2018-09-05 15:57:40 -03:00
parent 61e18f104e
commit 29758b174a
27 changed files with 122 additions and 315 deletions

View File

@@ -41,13 +41,9 @@ import org.briarproject.briar.android.util.BriarNotificationBuilder;
import org.briarproject.briar.api.android.AndroidNotificationManager; import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent; import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent; 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.introduction.event.IntroductionSucceededEvent;
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent; 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.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@@ -235,19 +231,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} else if (e instanceof BlogPostAddedEvent) { } else if (e instanceof BlogPostAddedEvent) {
BlogPostAddedEvent b = (BlogPostAddedEvent) e; BlogPostAddedEvent b = (BlogPostAddedEvent) e;
showBlogPostNotification(b.getGroupId()); 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) { } else if (e instanceof IntroductionSucceededEvent) {
showIntroductionNotification(); showIntroductionNotification();
} }

View File

@@ -107,7 +107,7 @@ class BlogControllerImpl extends BaseControllerImpl
} else if (e instanceof BlogInvitationResponseReceivedEvent) { } else if (e instanceof BlogInvitationResponseReceivedEvent) {
BlogInvitationResponseReceivedEvent b = BlogInvitationResponseReceivedEvent b =
(BlogInvitationResponseReceivedEvent) e; (BlogInvitationResponseReceivedEvent) e;
PrivateResponse<Blog> r = b.getResponse(); PrivateResponse<Blog> r = b.getMessageHeader();
if (r.getObject().getId().equals(groupId) && r.wasAccepted()) { if (r.getObject().getId().equals(groupId) && r.wasAccepted()) {
LOG.info("Blog invitation accepted"); LOG.info("Blog invitation accepted");
onBlogInvitationAccepted(b.getContactId()); onBlogInvitationAccepted(b.getContactId());

View File

@@ -37,17 +37,9 @@ import org.briarproject.briar.android.keyagreement.ContactExchangeActivity;
import org.briarproject.briar.android.view.BriarRecyclerView; import org.briarproject.briar.android.view.BriarRecyclerView;
import org.briarproject.briar.api.android.AndroidNotificationManager; import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.client.MessageTracker.GroupCount; 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.ConversationManager;
import org.briarproject.briar.api.messaging.PrivateMessageHeader; 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.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.ArrayList;
import java.util.List; import java.util.List;
@@ -255,30 +247,6 @@ public class ContactListFragment extends BaseFragment implements EventListener {
PrivateMessageReceivedEvent p = (PrivateMessageReceivedEvent) e; PrivateMessageReceivedEvent p = (PrivateMessageReceivedEvent) e;
PrivateMessageHeader h = p.getMessageHeader(); PrivateMessageHeader h = p.getMessageHeader();
updateItem(p.getContactId(), h); 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);
} }
} }

View File

@@ -64,8 +64,6 @@ 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.IntroductionRequest;
import org.briarproject.briar.api.introduction.IntroductionResponse; 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.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;
@@ -74,8 +72,6 @@ import org.briarproject.briar.api.messaging.PrivateRequest;
import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.messaging.PrivateResponse;
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent; import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager; 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.FutureTaskListener;
import org.thoughtcrime.securesms.components.util.ListenableFutureTask; import org.thoughtcrime.securesms.components.util.ListenableFutureTask;
@@ -474,9 +470,7 @@ public class ConversationActivity extends BriarActivity
PrivateMessageReceivedEvent p = (PrivateMessageReceivedEvent) e; PrivateMessageReceivedEvent p = (PrivateMessageReceivedEvent) e;
if (p.getContactId().equals(contactId)) { if (p.getContactId().equals(contactId)) {
LOG.info("Message received, adding"); LOG.info("Message received, adding");
PrivateMessageHeader h = p.getMessageHeader(); onNewPrivateMessage(p.getMessageHeader());
addConversationItem(ConversationItem.from(h));
loadMessageBody(h.getId());
} }
} else if (e instanceof MessagesSentEvent) { } else if (e instanceof MessagesSentEvent) {
MessagesSentEvent m = (MessagesSentEvent) e; MessagesSentEvent m = (MessagesSentEvent) e;
@@ -502,38 +496,6 @@ public class ConversationActivity extends BriarActivity
LOG.info("Contact disconnected"); LOG.info("Contact disconnected");
displayContactOnlineStatus(); 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) { private void onNewPrivateMessage(PrivateMessageHeader h) {
getContactNameTask().addListener(new FutureTaskListener<String>() { if (h instanceof PrivateRequest || h instanceof PrivateResponse) {
@Override getContactNameTask().addListener(new FutureTaskListener<String>() {
public void onSuccess(String contactName) { @Override
runOnUiThreadUnlessDestroyed(() -> { public void onSuccess(String contactName) {
ConversationItem item = ConversationItem runOnUiThreadUnlessDestroyed(() -> {
.from(ConversationActivity.this, contactName, m); handlePrivateRequestAndResponse(h, contactName);
addConversationItem(item); });
}); }
}
@Override @Override
public void onFailure(Throwable exception) { public void onFailure(Throwable exception) {
runOnUiThreadUnlessDestroyed( runOnUiThreadUnlessDestroyed(
() -> handleDbException((DbException) exception)); () -> handleDbException((DbException) exception));
} }
}); });
} else {
addConversationItem(ConversationItem.from(h));
loadMessageBody(h.getId());
}
} }
private void handlePrivateResponse(PrivateResponse m) { @UiThread
getContactNameTask().addListener(new FutureTaskListener<String>() { private void handlePrivateRequestAndResponse(PrivateMessageHeader h,
@Override String contactName) {
public void onSuccess(String contactName) { ConversationItem item;
runOnUiThreadUnlessDestroyed(() -> { if (h instanceof PrivateRequest) {
ConversationItem item = ConversationItem PrivateRequest m = (PrivateRequest) h;
.from(ConversationActivity.this, contactName, m); item = ConversationItem
addConversationItem(item); .from(ConversationActivity.this, contactName, m);
}); } else if (h instanceof PrivateResponse) {
} PrivateResponse m = (PrivateResponse) h;
item = ConversationItem
@Override .from(ConversationActivity.this, contactName, m);
public void onFailure(Throwable exception) { } else {
runOnUiThreadUnlessDestroyed( throw new AssertionError("Unknown PrivateMessageHeader");
() -> handleDbException((DbException) exception)); }
} addConversationItem(item);
});
} }
private void markMessages(Collection<MessageId> messageIds, boolean sent, private void markMessages(Collection<MessageId> messageIds, boolean sent,

View File

@@ -84,8 +84,7 @@ class ForumControllerImpl extends
} else if (e instanceof ForumInvitationResponseReceivedEvent) { } else if (e instanceof ForumInvitationResponseReceivedEvent) {
ForumInvitationResponseReceivedEvent f = ForumInvitationResponseReceivedEvent f =
(ForumInvitationResponseReceivedEvent) e; (ForumInvitationResponseReceivedEvent) e;
ForumInvitationResponse r = ForumInvitationResponse r = f.getMessageHeader();
(ForumInvitationResponse) f.getResponse();
if (r.getObject().getId().equals(getGroupId()) && r.wasAccepted()) { if (r.getObject().getId().equals(getGroupId()) && r.wasAccepted()) {
LOG.info("Forum invitation was accepted"); LOG.info("Forum invitation was accepted");
onForumInvitationAccepted(f.getContactId()); onForumInvitationAccepted(f.getContactId());

View File

@@ -99,8 +99,7 @@ class GroupControllerImpl extends
} else if (e instanceof GroupInvitationResponseReceivedEvent) { } else if (e instanceof GroupInvitationResponseReceivedEvent) {
GroupInvitationResponseReceivedEvent g = GroupInvitationResponseReceivedEvent g =
(GroupInvitationResponseReceivedEvent) e; (GroupInvitationResponseReceivedEvent) e;
GroupInvitationResponse r = GroupInvitationResponse r = g.getMessageHeader();
(GroupInvitationResponse) g.getResponse();
if (getGroupId().equals(r.getObject().getId()) && r.wasAccepted()) { if (getGroupId().equals(r.getObject().getId()) && r.wasAccepted()) {
listener.runOnUiThreadUnlessDestroyed( listener.runOnUiThreadUnlessDestroyed(
() -> listener.onInvitationAccepted(g.getContactId())); () -> listener.onInvitationAccepted(g.getContactId()));

View File

@@ -4,18 +4,18 @@ import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.blog.Blog; import org.briarproject.briar.api.blog.Blog;
import org.briarproject.briar.api.messaging.PrivateRequest; 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; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class BlogInvitationRequestReceivedEvent extends public class BlogInvitationRequestReceivedEvent extends
InvitationRequestReceivedEvent<Blog> { PrivateMessageReceivedEvent<PrivateRequest<Blog>> {
public BlogInvitationRequestReceivedEvent(Blog blog, ContactId contactId, public BlogInvitationRequestReceivedEvent(PrivateRequest<Blog> request,
PrivateRequest<Blog> request) { ContactId contactId) {
super(blog, contactId, request); super(request, contactId);
} }
} }

View File

@@ -2,20 +2,19 @@ package org.briarproject.briar.api.blog.event;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; 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.blog.BlogInvitationResponse;
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent; import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class BlogInvitationResponseReceivedEvent public class BlogInvitationResponseReceivedEvent
extends InvitationResponseReceivedEvent<Blog> { extends PrivateMessageReceivedEvent<BlogInvitationResponse> {
public BlogInvitationResponseReceivedEvent(ContactId contactId, public BlogInvitationResponseReceivedEvent(BlogInvitationResponse response,
BlogInvitationResponse response) { ContactId contactId) {
super(contactId, response); super(response, contactId);
} }
} }

View File

@@ -4,18 +4,18 @@ import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.forum.Forum; import org.briarproject.briar.api.forum.Forum;
import org.briarproject.briar.api.messaging.PrivateRequest; 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; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class ForumInvitationRequestReceivedEvent extends public class ForumInvitationRequestReceivedEvent extends
InvitationRequestReceivedEvent<Forum> { PrivateMessageReceivedEvent<PrivateRequest<Forum>> {
public ForumInvitationRequestReceivedEvent(Forum forum, ContactId contactId, public ForumInvitationRequestReceivedEvent(PrivateRequest<Forum> request,
PrivateRequest<Forum> request) { ContactId contactId) {
super(forum, contactId, request); super(request, contactId);
} }
} }

View File

@@ -3,18 +3,18 @@ package org.briarproject.briar.api.forum.event;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.forum.ForumInvitationResponse; 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; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class ForumInvitationResponseReceivedEvent extends public class ForumInvitationResponseReceivedEvent extends
InvitationResponseReceivedEvent { PrivateMessageReceivedEvent<ForumInvitationResponse> {
public ForumInvitationResponseReceivedEvent(ContactId contactId, public ForumInvitationResponseReceivedEvent(
ForumInvitationResponse response) { ForumInvitationResponse response, ContactId contactId) {
super(contactId, response); super(response, contactId);
} }
} }

View File

@@ -1,32 +1,20 @@
package org.briarproject.briar.api.introduction.event; package org.briarproject.briar.api.introduction.event;
import org.briarproject.bramble.api.contact.ContactId; 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.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.introduction.IntroductionRequest; import org.briarproject.briar.api.introduction.IntroductionRequest;
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class IntroductionRequestReceivedEvent extends Event { public class IntroductionRequestReceivedEvent extends
PrivateMessageReceivedEvent<IntroductionRequest> {
private final ContactId contactId; public IntroductionRequestReceivedEvent(
private final IntroductionRequest introductionRequest; IntroductionRequest introductionRequest, ContactId contactId) {
super(introductionRequest, contactId);
public IntroductionRequestReceivedEvent(ContactId contactId,
IntroductionRequest introductionRequest) {
this.contactId = contactId;
this.introductionRequest = introductionRequest;
}
public ContactId getContactId() {
return contactId;
}
public IntroductionRequest getIntroductionRequest() {
return introductionRequest;
} }
} }

View File

@@ -1,31 +1,20 @@
package org.briarproject.briar.api.introduction.event; package org.briarproject.briar.api.introduction.event;
import org.briarproject.bramble.api.contact.ContactId; 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.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.introduction.IntroductionResponse; import org.briarproject.briar.api.introduction.IntroductionResponse;
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class IntroductionResponseReceivedEvent extends Event { public class IntroductionResponseReceivedEvent extends
PrivateMessageReceivedEvent<IntroductionResponse> {
private final ContactId contactId; public IntroductionResponseReceivedEvent(
private final IntroductionResponse introductionResponse; IntroductionResponse introductionResponse, ContactId contactId) {
super(introductionResponse, contactId);
public IntroductionResponseReceivedEvent(ContactId contactId,
IntroductionResponse introductionResponse) {
this.contactId = contactId;
this.introductionResponse = introductionResponse;
} }
public ContactId getContactId() {
return contactId;
}
public IntroductionResponse getIntroductionResponse() {
return introductionResponse;
}
} }

View File

@@ -3,7 +3,6 @@ package org.briarproject.briar.api.messaging.event;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.briar.api.messaging.PrivateMessageHeader; import org.briarproject.briar.api.messaging.PrivateMessageHeader;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@@ -13,28 +12,22 @@ import javax.annotation.concurrent.Immutable;
*/ */
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class PrivateMessageReceivedEvent extends Event { public class PrivateMessageReceivedEvent<H extends PrivateMessageHeader>
extends Event {
private final PrivateMessageHeader messageHeader; private final H messageHeader;
private final ContactId contactId; private final ContactId contactId;
private final GroupId groupId;
public PrivateMessageReceivedEvent(PrivateMessageHeader messageHeader, public PrivateMessageReceivedEvent(H messageHeader, ContactId contactId) {
ContactId contactId, GroupId groupId) {
this.messageHeader = messageHeader; this.messageHeader = messageHeader;
this.contactId = contactId; this.contactId = contactId;
this.groupId = groupId;
} }
public PrivateMessageHeader getMessageHeader() { public H getMessageHeader() {
return messageHeader; return messageHeader;
} }
public ContactId getContactId() { public ContactId getContactId() {
return contactId; return contactId;
} }
public GroupId getGroupId() {
return groupId;
}
} }

View File

@@ -2,20 +2,19 @@ package org.briarproject.briar.api.privategroup.event;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; 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.privategroup.invitation.GroupInvitationRequest;
import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class GroupInvitationRequestReceivedEvent extends public class GroupInvitationRequestReceivedEvent extends
InvitationRequestReceivedEvent<PrivateGroup> { PrivateMessageReceivedEvent<GroupInvitationRequest> {
public GroupInvitationRequestReceivedEvent(PrivateGroup group, public GroupInvitationRequestReceivedEvent(GroupInvitationRequest request,
ContactId contactId, GroupInvitationRequest request) { ContactId contactId) {
super(group, contactId, request); super(request, contactId);
} }
} }

View File

@@ -2,19 +2,18 @@ package org.briarproject.briar.api.privategroup.event;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent;
import org.briarproject.briar.api.privategroup.PrivateGroup; import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class GroupInvitationResponseReceivedEvent public class GroupInvitationResponseReceivedEvent
extends InvitationResponseReceivedEvent<PrivateGroup> { extends PrivateMessageReceivedEvent<GroupInvitationResponse> {
public GroupInvitationResponseReceivedEvent(ContactId contactId, public GroupInvitationResponseReceivedEvent(
PrivateResponse<PrivateGroup> response) { GroupInvitationResponse response, ContactId contactId) {
super(contactId, response); super(response, contactId);
} }
} }

View File

@@ -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<S extends Shareable>
extends Event {
private final S shareable;
private final ContactId contactId;
private final PrivateRequest<S> request;
protected InvitationRequestReceivedEvent(S shareable, ContactId contactId,
PrivateRequest<S> request) {
this.shareable = shareable;
this.contactId = contactId;
this.request = request;
}
public ContactId getContactId() {
return contactId;
}
public PrivateRequest<S> getRequest() {
return request;
}
public S getShareable() {
return shareable;
}
}

View File

@@ -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<S extends Shareable>
extends Event {
private final ContactId contactId;
private final PrivateResponse<S> response;
public InvitationResponseReceivedEvent(ContactId contactId,
PrivateResponse<S> response) {
this.contactId = contactId;
this.response = response;
}
public ContactId getContactId() {
return contactId;
}
public PrivateResponse<S> getResponse() {
return response;
}
}

View File

@@ -157,7 +157,7 @@ abstract class AbstractProtocolEngine<S extends Session>
s.getSessionId(), introduction, s.getSessionId(), introduction,
m instanceof AcceptMessage); m instanceof AcceptMessage);
IntroductionResponseReceivedEvent e = IntroductionResponseReceivedEvent e =
new IntroductionResponseReceivedEvent(c.getId(), response); new IntroductionResponseReceivedEvent(response, c.getId());
txn.attach(e); txn.attach(e);
} }

View File

@@ -262,7 +262,7 @@ class IntroduceeProtocolEngine
s.getSessionId(), introduction, m.getMessage(), false, s.getSessionId(), introduction, m.getMessage(), false,
contactExists); contactExists);
IntroductionRequestReceivedEvent e = IntroductionRequestReceivedEvent e =
new IntroductionRequestReceivedEvent(c.getId(), request); new IntroductionRequestReceivedEvent(request, c.getId());
txn.attach(e); txn.attach(e);
// Move to the AWAIT_RESPONSES state // Move to the AWAIT_RESPONSES state

View File

@@ -116,8 +116,8 @@ class MessagingManagerImpl extends ConversationClientImpl
PrivateMessageHeader header = new PrivateMessageHeader( PrivateMessageHeader header = new PrivateMessageHeader(
m.getId(), groupId, timestamp, local, read, false, false); m.getId(), groupId, timestamp, local, read, false, false);
ContactId contactId = getContactId(txn, groupId); ContactId contactId = getContactId(txn, groupId);
PrivateMessageReceivedEvent event = new PrivateMessageReceivedEvent( PrivateMessageReceivedEvent<PrivateMessageHeader> event =
header, contactId, groupId); new PrivateMessageReceivedEvent<>(header, contactId);
txn.attach(event); txn.attach(event);
messageTracker.trackIncomingMessage(txn, m); messageTracker.trackIncomingMessage(txn, m);

View File

@@ -69,8 +69,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
} }
@Override @Override
public CreatorSession onJoinAction(Transaction txn, CreatorSession s) public CreatorSession onJoinAction(Transaction txn, CreatorSession s) {
throws DbException {
throw new UnsupportedOperationException(); // Invalid in this role throw new UnsupportedOperationException(); // Invalid in this role
} }
@@ -92,8 +91,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
} }
@Override @Override
public CreatorSession onMemberAddedAction(Transaction txn, CreatorSession s) public CreatorSession onMemberAddedAction(Transaction txn,
throws DbException { CreatorSession s) {
return s; // Ignored in this role return s; // Ignored in this role
} }
@@ -196,8 +195,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId = getContactId(txn, m.getContactGroupId());
PrivateGroup privateGroup = PrivateGroup privateGroup =
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId()); privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
txn.attach(new GroupInvitationResponseReceivedEvent(contactId, txn.attach(new GroupInvitationResponseReceivedEvent(
createInvitationResponse(m, privateGroup, true))); createInvitationResponse(m, privateGroup, true), contactId));
// Move to the JOINED state // Move to the JOINED state
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(), return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
sent.getId(), m.getId(), sent.getTimestamp(), sent.getId(), m.getId(), sent.getTimestamp(),
@@ -220,8 +219,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId = getContactId(txn, m.getContactGroupId());
PrivateGroup privateGroup = PrivateGroup privateGroup =
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId()); privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
txn.attach(new GroupInvitationResponseReceivedEvent(contactId, txn.attach(new GroupInvitationResponseReceivedEvent(
createInvitationResponse(m, privateGroup, false))); createInvitationResponse(m, privateGroup, false), contactId));
// Move to the START state // Move to the START state
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(), return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(), s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),

View File

@@ -56,8 +56,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
@Override @Override
public InviteeSession onInviteAction(Transaction txn, InviteeSession s, public InviteeSession onInviteAction(Transaction txn, InviteeSession s,
@Nullable String message, long timestamp, byte[] signature) @Nullable String message, long timestamp, byte[] signature) {
throws DbException {
throw new UnsupportedOperationException(); // Invalid in this role throw new UnsupportedOperationException(); // Invalid in this role
} }
@@ -99,8 +98,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
} }
@Override @Override
public InviteeSession onMemberAddedAction(Transaction txn, InviteeSession s) public InviteeSession onMemberAddedAction(Transaction txn,
throws DbException { InviteeSession s) {
return s; // Ignored in this role return s; // Ignored in this role
} }
@@ -244,9 +243,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
// Broadcast an event // Broadcast an event
PrivateGroup privateGroup = privateGroupFactory.createPrivateGroup( PrivateGroup privateGroup = privateGroupFactory.createPrivateGroup(
m.getGroupName(), m.getCreator(), m.getSalt()); m.getGroupName(), m.getCreator(), m.getSalt());
txn.attach( txn.attach(new GroupInvitationRequestReceivedEvent(
new GroupInvitationRequestReceivedEvent(privateGroup, contactId, createInvitationRequest(m, privateGroup), contactId));
createInvitationRequest(m, privateGroup, contactId)));
// Move to the INVITED state // Move to the INVITED state
return new InviteeSession(s.getContactGroupId(), s.getPrivateGroupId(), return new InviteeSession(s.getContactGroupId(), s.getPrivateGroupId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(), s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
@@ -328,7 +326,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
} }
private GroupInvitationRequest createInvitationRequest(InviteMessage m, private GroupInvitationRequest createInvitationRequest(InviteMessage m,
PrivateGroup pg, ContactId c) { PrivateGroup pg) {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes()); SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationRequest(m.getId(), m.getContactGroupId(), return new GroupInvitationRequest(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, sessionId, pg, m.getTimestamp(), false, false, true, false, sessionId, pg,

View File

@@ -53,8 +53,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
PrivateRequest<Blog> request = invitationFactory PrivateRequest<Blog> request = invitationFactory
.createInvitationRequest(false, false, true, false, m, .createInvitationRequest(false, false, true, false, m,
contactId, available, canBeOpened); contactId, available, canBeOpened);
return new BlogInvitationRequestReceivedEvent(m.getShareable(), return new BlogInvitationRequestReceivedEvent(request, contactId);
contactId, request);
} }
@Override @Override
@@ -64,7 +63,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); shareable, true);
return new BlogInvitationResponseReceivedEvent(contactId, response); return new BlogInvitationResponseReceivedEvent(response, contactId);
} }
@Override @Override
@@ -74,7 +73,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); shareable, true);
return new BlogInvitationResponseReceivedEvent(contactId, response); return new BlogInvitationResponseReceivedEvent(response, contactId);
} }
@Override @Override

View File

@@ -55,8 +55,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
PrivateRequest<Forum> request = invitationFactory PrivateRequest<Forum> request = invitationFactory
.createInvitationRequest(false, false, true, false, m, .createInvitationRequest(false, false, true, false, m,
contactId, available, canBeOpened); contactId, available, canBeOpened);
return new ForumInvitationRequestReceivedEvent(m.getShareable(), return new ForumInvitationRequestReceivedEvent(request, contactId);
contactId, request);
} }
@Override @Override
@@ -66,7 +65,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); shareable, true);
return new ForumInvitationResponseReceivedEvent(contactId, response); return new ForumInvitationResponseReceivedEvent(response, contactId);
} }
@Override @Override
@@ -76,7 +75,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); shareable, true);
return new ForumInvitationResponseReceivedEvent(contactId, response); return new ForumInvitationResponseReceivedEvent(response, contactId);
} }
@Override @Override

View File

@@ -24,14 +24,16 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.test.TestDatabaseModule; import org.briarproject.bramble.test.TestDatabaseModule;
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.introduction.Introduction;
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.IntroductionRequest;
import org.briarproject.briar.api.introduction.IntroductionResponse;
import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent; import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent; import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent; import org.briarproject.briar.api.introduction.event.IntroductionResponseReceivedEvent;
import org.briarproject.briar.api.introduction.event.IntroductionSucceededEvent; import org.briarproject.briar.api.introduction.event.IntroductionSucceededEvent;
import org.briarproject.briar.api.messaging.PrivateMessageHeader; 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.briarproject.briar.test.BriarIntegrationTest;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -1131,11 +1133,11 @@ public class IntroductionIntegrationTest
protected volatile Event latestEvent; protected volatile Event latestEvent;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
IntroductionResponse getResponse() { PrivateResponse<Introduction> getResponse() {
assertTrue( assertTrue(
latestEvent instanceof IntroductionResponseReceivedEvent); latestEvent instanceof IntroductionResponseReceivedEvent);
return ((IntroductionResponseReceivedEvent) latestEvent) return ((IntroductionResponseReceivedEvent) latestEvent)
.getIntroductionResponse(); .getResponse();
} }
} }
@@ -1163,7 +1165,7 @@ public class IntroductionIntegrationTest
IntroductionRequestReceivedEvent introEvent = IntroductionRequestReceivedEvent introEvent =
((IntroductionRequestReceivedEvent) e); ((IntroductionRequestReceivedEvent) e);
requestReceived = true; requestReceived = true;
IntroductionRequest ir = introEvent.getIntroductionRequest(); PrivateRequest<Introduction> ir = introEvent.getRequest();
ContactId contactId = introEvent.getContactId(); ContactId contactId = introEvent.getContactId();
sessionId = ir.getSessionId(); sessionId = ir.getSessionId();
long time = clock.currentTimeMillis(); long time = clock.currentTimeMillis();
@@ -1200,11 +1202,11 @@ public class IntroductionIntegrationTest
} }
} }
private IntroductionRequest getRequest() { private PrivateRequest<Introduction> getRequest() {
assertTrue( assertTrue(
latestEvent instanceof IntroductionRequestReceivedEvent); latestEvent instanceof IntroductionRequestReceivedEvent);
return ((IntroductionRequestReceivedEvent) latestEvent) return ((IntroductionRequestReceivedEvent) latestEvent)
.getIntroductionRequest(); .getRequest();
} }
} }

View File

@@ -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.getShareable(); Blog b = event.getRequest().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.getShareable(); Blog b = event.getRequest().getObject();
try { try {
eventWaiter.assertEquals(1, eventWaiter.assertEquals(1,
blogSharingManager1.getInvitations().size()); blogSharingManager1.getInvitations().size());

View File

@@ -813,7 +813,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.getShareable(); Forum f = event.getRequest().getObject();
try { try {
if (respond) { if (respond) {
Contact c = contactManager0.getContact(contactId1From0); Contact c = contactManager0.getContact(contactId1From0);
@@ -851,7 +851,7 @@ public class ForumSharingIntegrationTest
(ForumInvitationRequestReceivedEvent) e; (ForumInvitationRequestReceivedEvent) e;
requestReceived = true; requestReceived = true;
if (!answer) return; if (!answer) return;
Forum f = event.getShareable(); Forum f = event.getRequest().getObject();
try { try {
if (respond) { if (respond) {
eventWaiter.assertEquals(1, eventWaiter.assertEquals(1,