mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Unify all events related to private messages
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
} else if (e instanceof BlogInvitationResponseReceivedEvent) {
|
||||
BlogInvitationResponseReceivedEvent b =
|
||||
(BlogInvitationResponseReceivedEvent) e;
|
||||
PrivateResponse<Blog> r = b.getResponse();
|
||||
PrivateResponse<Blog> r = b.getMessageHeader();
|
||||
if (r.getObject().getId().equals(groupId) && r.wasAccepted()) {
|
||||
LOG.info("Blog invitation accepted");
|
||||
onBlogInvitationAccepted(b.getContactId());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String>() {
|
||||
@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<String>() {
|
||||
@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<String>() {
|
||||
@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<MessageId> messageIds, boolean sent,
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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<Blog> {
|
||||
PrivateMessageReceivedEvent<PrivateRequest<Blog>> {
|
||||
|
||||
public BlogInvitationRequestReceivedEvent(Blog blog, ContactId contactId,
|
||||
PrivateRequest<Blog> request) {
|
||||
super(blog, contactId, request);
|
||||
public BlogInvitationRequestReceivedEvent(PrivateRequest<Blog> request,
|
||||
ContactId contactId) {
|
||||
super(request, contactId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Blog> {
|
||||
extends PrivateMessageReceivedEvent<BlogInvitationResponse> {
|
||||
|
||||
public BlogInvitationResponseReceivedEvent(ContactId contactId,
|
||||
BlogInvitationResponse response) {
|
||||
super(contactId, response);
|
||||
public BlogInvitationResponseReceivedEvent(BlogInvitationResponse response,
|
||||
ContactId contactId) {
|
||||
super(response, contactId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Forum> {
|
||||
PrivateMessageReceivedEvent<PrivateRequest<Forum>> {
|
||||
|
||||
public ForumInvitationRequestReceivedEvent(Forum forum, ContactId contactId,
|
||||
PrivateRequest<Forum> request) {
|
||||
super(forum, contactId, request);
|
||||
public ForumInvitationRequestReceivedEvent(PrivateRequest<Forum> request,
|
||||
ContactId contactId) {
|
||||
super(request, contactId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<ForumInvitationResponse> {
|
||||
|
||||
public ForumInvitationResponseReceivedEvent(ContactId contactId,
|
||||
ForumInvitationResponse response) {
|
||||
super(contactId, response);
|
||||
public ForumInvitationResponseReceivedEvent(
|
||||
ForumInvitationResponse response, ContactId contactId) {
|
||||
super(response, contactId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<IntroductionRequest> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<IntroductionResponse> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<H extends PrivateMessageHeader>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PrivateGroup> {
|
||||
PrivateMessageReceivedEvent<GroupInvitationRequest> {
|
||||
|
||||
public GroupInvitationRequestReceivedEvent(PrivateGroup group,
|
||||
ContactId contactId, GroupInvitationRequest request) {
|
||||
super(group, contactId, request);
|
||||
public GroupInvitationRequestReceivedEvent(GroupInvitationRequest request,
|
||||
ContactId contactId) {
|
||||
super(request, contactId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<PrivateGroup> {
|
||||
extends PrivateMessageReceivedEvent<GroupInvitationResponse> {
|
||||
|
||||
public GroupInvitationResponseReceivedEvent(ContactId contactId,
|
||||
PrivateResponse<PrivateGroup> response) {
|
||||
super(contactId, response);
|
||||
public GroupInvitationResponseReceivedEvent(
|
||||
GroupInvitationResponse response, ContactId contactId) {
|
||||
super(response, contactId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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