Re-introduce InvitationResponse

This was done, so private responses don't need to include a Nameable already.
Retreiving a nameable is tricky and requires a data migration,
so we just don't do it now.
This commit is contained in:
Torsten Grote
2018-09-07 16:03:20 -03:00
parent d430b4fd2d
commit 86f650503b
27 changed files with 144 additions and 215 deletions

View File

@@ -21,11 +21,11 @@ import org.briarproject.briar.android.controller.ActivityLifecycleController;
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler; import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
import org.briarproject.briar.api.android.AndroidNotificationManager; import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.Blog; import org.briarproject.briar.api.blog.Blog;
import org.briarproject.briar.api.blog.BlogInvitationResponse;
import org.briarproject.briar.api.blog.BlogManager; import org.briarproject.briar.api.blog.BlogManager;
import org.briarproject.briar.api.blog.BlogSharingManager; import org.briarproject.briar.api.blog.BlogSharingManager;
import org.briarproject.briar.api.blog.event.BlogInvitationResponseReceivedEvent; import org.briarproject.briar.api.blog.event.BlogInvitationResponseReceivedEvent;
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent; import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
import org.briarproject.briar.api.messaging.PrivateResponse;
import org.briarproject.briar.api.sharing.event.ContactLeftShareableEvent; import org.briarproject.briar.api.sharing.event.ContactLeftShareableEvent;
import java.util.ArrayList; import java.util.ArrayList;
@@ -107,8 +107,8 @@ 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.getMessageHeader(); BlogInvitationResponse r = b.getMessageHeader();
if (r.getNameable().getId().equals(groupId) && r.wasAccepted()) { if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
LOG.info("Blog invitation accepted"); LOG.info("Blog invitation accepted");
onBlogInvitationAccepted(b.getContactId()); onBlogInvitationAccepted(b.getContactId());
} }

View File

@@ -167,14 +167,14 @@ abstract class ConversationItem {
if (ir.wasAccepted()) { if (ir.wasAccepted()) {
text = ctx.getString( text = ctx.getString(
R.string.introduction_response_accepted_sent, R.string.introduction_response_accepted_sent,
ir.getNameable().getName()); ir.getIntroducedAuthor().getName());
text += "\n\n" + ctx.getString( text += "\n\n" + ctx.getString(
R.string.introduction_response_accepted_sent_info, R.string.introduction_response_accepted_sent_info,
ir.getNameable().getName()); ir.getIntroducedAuthor().getName());
} else { } else {
text = ctx.getString( text = ctx.getString(
R.string.introduction_response_declined_sent, R.string.introduction_response_declined_sent,
ir.getNameable().getName()); ir.getIntroducedAuthor().getName());
} }
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(), return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
text, null, ir.getTimestamp(), ir.isSent(), ir.isSeen()); text, null, ir.getTimestamp(), ir.isSent(), ir.isSeen());
@@ -191,7 +191,7 @@ abstract class ConversationItem {
} }
} }
String text = String text =
ctx.getString(res, contactName, ir.getNameable().getName()); ctx.getString(res, contactName, ir.getIntroducedAuthor().getName());
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(), return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
text, null, ir.getTimestamp(), ir.isRead()); text, null, ir.getTimestamp(), ir.isRead());
} }

View File

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

View File

@@ -100,7 +100,7 @@ class GroupControllerImpl extends
GroupInvitationResponseReceivedEvent g = GroupInvitationResponseReceivedEvent g =
(GroupInvitationResponseReceivedEvent) e; (GroupInvitationResponseReceivedEvent) e;
GroupInvitationResponse r = g.getMessageHeader(); GroupInvitationResponse r = g.getMessageHeader();
if (getGroupId().equals(r.getNameable().getId()) && r.wasAccepted()) { if (getGroupId().equals(r.getShareableId()) && r.wasAccepted()) {
listener.runOnUiThreadUnlessDestroyed( listener.runOnUiThreadUnlessDestroyed(
() -> listener.onInvitationAccepted(g.getContactId())); () -> listener.onInvitationAccepted(g.getContactId()));
} }

View File

@@ -4,16 +4,16 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.SessionId; import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.sharing.InvitationResponse;
@NotNullByDefault @NotNullByDefault
public class BlogInvitationResponse extends PrivateResponse<Blog> { public class BlogInvitationResponse extends InvitationResponse {
public BlogInvitationResponse(MessageId id, GroupId groupId, long time, public BlogInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, Blog blog, boolean accept) { SessionId sessionId, boolean accept, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId, blog, super(id, groupId, time, local, sent, seen, read, sessionId,
accept); accept, shareableId);
} }
} }

View File

@@ -4,19 +4,19 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.SessionId; import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.sharing.InvitationResponse;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class ForumInvitationResponse extends PrivateResponse<Forum> { public class ForumInvitationResponse extends InvitationResponse {
public ForumInvitationResponse(MessageId id, GroupId groupId, long time, public ForumInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, Forum forum, boolean accept) { SessionId sessionId, boolean accept, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId, forum, super(id, groupId, time, local, sent, seen, read, sessionId,
accept); accept, shareableId);
} }
} }

View File

@@ -13,18 +13,24 @@ import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class IntroductionResponse extends PrivateResponse<Author> { public class IntroductionResponse extends PrivateResponse {
private final Author introducedAuthor;
private final Role ourRole; private final Role ourRole;
public IntroductionResponse(MessageId messageId, GroupId groupId, long time, public IntroductionResponse(MessageId messageId, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, Author author, boolean accepted, Role role) { SessionId sessionId, boolean accepted, Author author, Role role) {
super(messageId, groupId, time, local, sent, seen, read, sessionId, super(messageId, groupId, time, local, sent, seen, read, sessionId,
author, accepted); accepted);
this.introducedAuthor = author;
this.ourRole = role; this.ourRole = role;
} }
public Author getIntroducedAuthor() {
return introducedAuthor;
}
public boolean isIntroducer() { public boolean isIntroducer() {
return ourRole == INTRODUCER; return ourRole == INTRODUCER;
} }

View File

@@ -1,6 +1,5 @@
package org.briarproject.briar.api.messaging; package org.briarproject.briar.api.messaging;
import org.briarproject.bramble.api.Nameable;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
@@ -10,19 +9,16 @@ import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public abstract class PrivateResponse<N extends Nameable> public abstract class PrivateResponse extends PrivateMessageHeader {
extends PrivateMessageHeader {
private final SessionId sessionId; private final SessionId sessionId;
private final N nameable;
private final boolean accepted; private final boolean accepted;
public PrivateResponse(MessageId id, GroupId groupId, long time, public PrivateResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, N nameable, boolean accepted) { SessionId sessionId, boolean accepted) {
super(id, groupId, time, local, sent, seen, read); super(id, groupId, time, local, sent, seen, read);
this.sessionId = sessionId; this.sessionId = sessionId;
this.nameable = nameable;
this.accepted = accepted; this.accepted = accepted;
} }
@@ -30,10 +26,6 @@ public abstract class PrivateResponse<N extends Nameable>
return sessionId; return sessionId;
} }
public N getNameable() {
return nameable;
}
public boolean wasAccepted() { public boolean wasAccepted() {
return accepted; return accepted;
} }

View File

@@ -4,20 +4,19 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.SessionId; import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.sharing.InvitationResponse;
import org.briarproject.briar.api.privategroup.PrivateGroup;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class GroupInvitationResponse extends PrivateResponse<PrivateGroup> { public class GroupInvitationResponse extends InvitationResponse {
public GroupInvitationResponse(MessageId id, GroupId groupId, long time, public GroupInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read, boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, PrivateGroup privateGroup, boolean accept) { SessionId sessionId, boolean accept, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId, super(id, groupId, time, local, sent, seen, read, sessionId,
privateGroup, accept); accept, shareableId);
} }
} }

View File

@@ -0,0 +1,23 @@
package org.briarproject.briar.api.sharing;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.messaging.PrivateResponse;
public abstract class InvitationResponse extends PrivateResponse {
private final GroupId shareableId;
public InvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, boolean accepted, GroupId shareableId) {
super(id, groupId, time, local, sent, seen, read, sessionId, accepted);
this.shareableId = shareableId;
}
public GroupId getShareableId() {
return shareableId;
}
}

View File

@@ -152,8 +152,8 @@ abstract class AbstractProtocolEngine<S extends Session>
IntroductionResponse response = IntroductionResponse response =
new IntroductionResponse(m.getMessageId(), m.getGroupId(), new IntroductionResponse(m.getMessageId(), m.getGroupId(),
m.getTimestamp(), false, false, false, false, m.getTimestamp(), false, false, false, false,
s.getSessionId(), otherAuthor, s.getSessionId(), m instanceof AcceptMessage,
m instanceof AcceptMessage, s.getRole()); otherAuthor, s.getRole());
IntroductionResponseReceivedEvent e = IntroductionResponseReceivedEvent e =
new IntroductionResponseReceivedEvent(response, c.getId()); new IntroductionResponseReceivedEvent(response, c.getId());
txn.attach(e); txn.attach(e);

View File

@@ -495,7 +495,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
} else throw new AssertionError(); } else throw new AssertionError();
return new IntroductionResponse(m, contactGroupId, meta.getTimestamp(), return new IntroductionResponse(m, contactGroupId, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(), meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
sessionId, author, accept, role); sessionId, accept, author, role);
} }
private void removeSessionWithIntroducer(Transaction txn, private void removeSessionWithIntroducer(Transaction txn,

View File

@@ -15,7 +15,6 @@ import org.briarproject.briar.api.client.MessageTracker;
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.privategroup.GroupMessageFactory; import org.briarproject.briar.api.privategroup.GroupMessageFactory;
import org.briarproject.briar.api.privategroup.PrivateGroup;
import org.briarproject.briar.api.privategroup.PrivateGroupFactory; import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
import org.briarproject.briar.api.privategroup.PrivateGroupManager; import org.briarproject.briar.api.privategroup.PrivateGroupManager;
import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent; import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent;
@@ -193,10 +192,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
setPrivateGroupVisibility(txn, s, SHARED); setPrivateGroupVisibility(txn, s, SHARED);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId = getContactId(txn, m.getContactGroupId());
PrivateGroup privateGroup =
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
txn.attach(new GroupInvitationResponseReceivedEvent( txn.attach(new GroupInvitationResponseReceivedEvent(
createInvitationResponse(m, privateGroup, true), contactId)); createInvitationResponse(m, 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(),
@@ -217,10 +214,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
m.getTimestamp(), false); m.getTimestamp(), false);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId = getContactId(txn, m.getContactGroupId());
PrivateGroup privateGroup =
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
txn.attach(new GroupInvitationResponseReceivedEvent( txn.attach(new GroupInvitationResponseReceivedEvent(
createInvitationResponse(m, privateGroup, false), contactId)); createInvitationResponse(m, 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(),
@@ -258,11 +253,10 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
} }
private GroupInvitationResponse createInvitationResponse( private GroupInvitationResponse createInvitationResponse(
GroupInvitationMessage m, PrivateGroup privateGroup, GroupInvitationMessage m, boolean accept) {
boolean accept) {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes()); SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationResponse(m.getId(), m.getContactGroupId(), return new GroupInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, sessionId, m.getTimestamp(), false, false, true, false, sessionId,
privateGroup, accept); accept, m.getPrivateGroupId());
} }
} }

View File

@@ -378,36 +378,21 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
.getMessageMetadataAsDictionary(txn, contactGroupId, query); .getMessageMetadataAsDictionary(txn, contactGroupId, query);
List<PrivateMessageHeader> messages = List<PrivateMessageHeader> messages =
new ArrayList<>(results.size()); new ArrayList<>(results.size());
// get invite message first and remember private groups
Map<SessionId, PrivateGroup> privateGroups = new HashMap<>();
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
MessageId m = e.getKey(); MessageId m = e.getKey();
MessageMetadata meta = MessageMetadata meta =
messageParser.parseMetadata(e.getValue()); messageParser.parseMetadata(e.getValue());
MessageType type = meta.getMessageType();
if (type != INVITE) continue;
MessageStatus status = db.getMessageStatus(txn, c, m); MessageStatus status = db.getMessageStatus(txn, c, m);
GroupInvitationRequest invite = parseInvitationRequest(txn,
contactGroupId, m, meta, status);
messages.add(invite);
privateGroups.put(invite.getSessionId(), invite.getNameable());
}
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
MessageId m = e.getKey();
MessageMetadata meta =
messageParser.parseMetadata(e.getValue());
MessageType type = meta.getMessageType(); MessageType type = meta.getMessageType();
if (type == INVITE) continue; if (type == INVITE) {
MessageStatus status = db.getMessageStatus(txn, c, m); messages.add(parseInvitationRequest(txn, contactGroupId, m,
SessionId sessionId = getSessionId(meta.getPrivateGroupId()); meta, status));
PrivateGroup privateGroup = privateGroups.get(sessionId); } else if (type == JOIN) {
if (privateGroup == null) throw new AssertionError();
if (type == JOIN) {
messages.add(parseInvitationResponse(contactGroupId, m, messages.add(parseInvitationResponse(contactGroupId, m,
meta, status, sessionId, privateGroup, true)); meta, status, true));
} else if (type == LEAVE) { } else if (type == LEAVE) {
messages.add(parseInvitationResponse(contactGroupId, m, messages.add(parseInvitationResponse(contactGroupId, m,
meta, status, sessionId, privateGroup, false)); meta, status, false));
} }
} }
return messages; return messages;
@@ -436,12 +421,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
private GroupInvitationResponse parseInvitationResponse( private GroupInvitationResponse parseInvitationResponse(
GroupId contactGroupId, MessageId m, MessageMetadata meta, GroupId contactGroupId, MessageId m, MessageMetadata meta,
MessageStatus status, SessionId sessionId, MessageStatus status, boolean accept) {
PrivateGroup privateGroup, boolean accept) { SessionId sessionId = getSessionId(meta.getPrivateGroupId());
return new GroupInvitationResponse(m, contactGroupId, return new GroupInvitationResponse(m, contactGroupId,
meta.getTimestamp(), meta.isLocal(), status.isSent(), meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), sessionId, privateGroup, status.isSeen(), meta.isRead(), sessionId, accept,
accept); meta.getPrivateGroupId()
);
} }
@Override @Override

View File

@@ -30,10 +30,10 @@ public class BlogInvitationFactoryImpl
@Override @Override
public BlogInvitationResponse createInvitationResponse(MessageId id, public BlogInvitationResponse createInvitationResponse(MessageId id,
GroupId contactGroupId, long time, boolean local, boolean sent, GroupId contactGroupId, long time, boolean local, boolean sent,
boolean seen, boolean read, Blog blog, boolean accept) { boolean seen, boolean read, boolean accept, GroupId shareableId) {
SessionId sessionId = new SessionId(blog.getId().getBytes()); SessionId sessionId = new SessionId(shareableId.getBytes());
return new BlogInvitationResponse(id, contactGroupId, time, local, sent, return new BlogInvitationResponse(id, contactGroupId, time, local, sent,
seen, read, sessionId, blog, accept); seen, read, sessionId, accept, shareableId);
} }
} }

View File

@@ -58,21 +58,21 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
@Override @Override
Event getInvitationResponseReceivedEvent(AcceptMessage m, Event getInvitationResponseReceivedEvent(AcceptMessage m,
ContactId contactId, Blog shareable) { ContactId contactId) {
BlogInvitationResponse response = invitationFactory BlogInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); true, m.getShareableId());
return new BlogInvitationResponseReceivedEvent(response, contactId); return new BlogInvitationResponseReceivedEvent(response, contactId);
} }
@Override @Override
Event getInvitationResponseReceivedEvent(DeclineMessage m, Event getInvitationResponseReceivedEvent(DeclineMessage m,
ContactId contactId, Blog shareable) { ContactId contactId) {
BlogInvitationResponse response = invitationFactory BlogInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); true, m.getShareableId());
return new BlogInvitationResponseReceivedEvent(response, contactId); return new BlogInvitationResponseReceivedEvent(response, contactId);
} }

View File

@@ -30,10 +30,10 @@ public class ForumInvitationFactoryImpl
@Override @Override
public ForumInvitationResponse createInvitationResponse(MessageId id, public ForumInvitationResponse createInvitationResponse(MessageId id,
GroupId contactGroupId, long time, boolean local, boolean sent, GroupId contactGroupId, long time, boolean local, boolean sent,
boolean seen, boolean read, Forum forum, boolean accept) { boolean seen, boolean read, boolean accept, GroupId shareableId) {
SessionId sessionId = new SessionId(forum.getId().getBytes()); SessionId sessionId = new SessionId(shareableId.getBytes());
return new ForumInvitationResponse(id, contactGroupId, time, local, return new ForumInvitationResponse(id, contactGroupId, time, local,
sent, seen, read, sessionId, forum, accept); sent, seen, read, sessionId, accept, shareableId);
} }
} }

View File

@@ -31,8 +31,7 @@ import static org.briarproject.briar.api.forum.ForumManager.MAJOR_VERSION;
class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> { class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
private final ForumManager forumManager; private final ForumManager forumManager;
private final InvitationFactory<Forum, ForumInvitationResponse> private final InvitationFactory<Forum, ForumInvitationResponse> invitationFactory;
invitationFactory;
@Inject @Inject
ForumProtocolEngineImpl(DatabaseComponent db, ForumProtocolEngineImpl(DatabaseComponent db,
@@ -60,21 +59,21 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
@Override @Override
Event getInvitationResponseReceivedEvent(AcceptMessage m, Event getInvitationResponseReceivedEvent(AcceptMessage m,
ContactId contactId, Forum shareable) { ContactId contactId) {
ForumInvitationResponse response = invitationFactory ForumInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); true, m.getShareableId());
return new ForumInvitationResponseReceivedEvent(response, contactId); return new ForumInvitationResponseReceivedEvent(response, contactId);
} }
@Override @Override
Event getInvitationResponseReceivedEvent(DeclineMessage m, Event getInvitationResponseReceivedEvent(DeclineMessage m,
ContactId contactId, Forum shareable) { ContactId contactId) {
ForumInvitationResponse response = invitationFactory ForumInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
shareable, true); true, m.getShareableId());
return new ForumInvitationResponseReceivedEvent(response, contactId); return new ForumInvitationResponseReceivedEvent(response, contactId);
} }

View File

@@ -4,17 +4,17 @@ import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.messaging.PrivateRequest; import org.briarproject.briar.api.messaging.PrivateRequest;
import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.sharing.InvitationResponse;
import org.briarproject.briar.api.sharing.Shareable; import org.briarproject.briar.api.sharing.Shareable;
public interface InvitationFactory<S extends Shareable, I extends PrivateResponse<S>> { public interface InvitationFactory<S extends Shareable, R extends InvitationResponse> {
PrivateRequest<S> createInvitationRequest(boolean local, boolean sent, PrivateRequest<S> createInvitationRequest(boolean local, boolean sent,
boolean seen, boolean read, InviteMessage<S> m, ContactId c, boolean seen, boolean read, InviteMessage<S> m, ContactId c,
boolean available, boolean canBeOpened); boolean available, boolean canBeOpened);
I createInvitationResponse(MessageId id, R createInvitationResponse(MessageId id, GroupId contactGroupId, long time,
GroupId contactGroupId, long time, boolean local, boolean sent, boolean local, boolean sent, boolean seen, boolean read,
boolean seen, boolean read, S shareable, boolean accept); boolean accept, GroupId shareableId);
} }

View File

@@ -113,7 +113,13 @@ abstract class ProtocolEngineImpl<S extends Shareable>
private Message sendInviteMessage(Transaction txn, Session s, private Message sendInviteMessage(Transaction txn, Session s,
@Nullable String message, long timestamp) throws DbException { @Nullable String message, long timestamp) throws DbException {
BdfList descriptor = getDescriptor(txn, s.getShareableId()); Group g = db.getGroup(txn, s.getShareableId());
BdfList descriptor;
try {
descriptor = clientHelper.toList(g.getDescriptor());
} catch (FormatException e) {
throw new DbException(e); // Invalid group descriptor
}
long localTimestamp = Math.max(timestamp, getLocalTimestamp(s)); long localTimestamp = Math.max(timestamp, getLocalTimestamp(s));
Message m = messageEncoder.encodeInviteMessage(s.getContactGroupId(), Message m = messageEncoder.encodeInviteMessage(s.getContactGroupId(),
localTimestamp, s.getLastLocalMessageId(), descriptor, message); localTimestamp, s.getLastLocalMessageId(), descriptor, message);
@@ -287,7 +293,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
if (m.getTimestamp() <= s.getInviteTimestamp()) if (m.getTimestamp() <= s.getInviteTimestamp())
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Mark the invite message visible in the UI and (un)available to answer // Mark the invite message visible in the UI and (un)available to answer
markMessageVisibleInUi(txn, m.getId()); markMessageVisibleInUi(txn, m.getId());
@@ -311,7 +317,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
if (m.getTimestamp() <= s.getInviteTimestamp()) if (m.getTimestamp() <= s.getInviteTimestamp())
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Mark the invite message visible in the UI and unavailable to answer // Mark the invite message visible in the UI and unavailable to answer
markMessageVisibleInUi(txn, m.getId()); markMessageVisibleInUi(txn, m.getId());
@@ -358,7 +364,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
if (m.getTimestamp() <= s.getInviteTimestamp()) if (m.getTimestamp() <= s.getInviteTimestamp())
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Mark the response visible in the UI // Mark the response visible in the UI
markMessageVisibleInUi(txn, m.getId()); markMessageVisibleInUi(txn, m.getId());
@@ -367,8 +373,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
m.getTimestamp(), false); m.getTimestamp(), false);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId = getContactId(txn, m.getContactGroupId());
S shareable = getShareable(txn, s.getShareableId()); txn.attach(getInvitationResponseReceivedEvent(m, contactId));
txn.attach(getInvitationResponseReceivedEvent(m, contactId, shareable));
// Move to the next state // Move to the next state
return new Session(nextState, s.getContactGroupId(), s.getShareableId(), return new Session(nextState, s.getContactGroupId(), s.getShareableId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(), s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
@@ -386,7 +391,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
} }
abstract Event getInvitationResponseReceivedEvent(AcceptMessage m, abstract Event getInvitationResponseReceivedEvent(AcceptMessage m,
ContactId contactId, S shareable); ContactId contactId);
@Override @Override
public Session onDeclineMessage(Transaction txn, Session s, public Session onDeclineMessage(Transaction txn, Session s,
@@ -411,7 +416,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
if (m.getTimestamp() <= s.getInviteTimestamp()) if (m.getTimestamp() <= s.getInviteTimestamp())
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Mark the response visible in the UI // Mark the response visible in the UI
markMessageVisibleInUi(txn, m.getId()); markMessageVisibleInUi(txn, m.getId());
@@ -426,8 +431,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
} }
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId = getContactId(txn, m.getContactGroupId());
S shareable = getShareable(txn, s.getShareableId()); txn.attach(getInvitationResponseReceivedEvent(m, contactId));
txn.attach(getInvitationResponseReceivedEvent(m, contactId, shareable));
// Move to the next state // Move to the next state
return new Session(START, s.getContactGroupId(), s.getShareableId(), return new Session(START, s.getContactGroupId(), s.getShareableId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(), s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
@@ -435,7 +439,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
} }
abstract Event getInvitationResponseReceivedEvent(DeclineMessage m, abstract Event getInvitationResponseReceivedEvent(DeclineMessage m,
ContactId contactId, S shareable); ContactId contactId);
@Override @Override
public Session onLeaveMessage(Transaction txn, Session s, public Session onLeaveMessage(Transaction txn, Session s,
@@ -459,7 +463,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
private Session onRemoteLeaveWhenInvited(Transaction txn, Session s, private Session onRemoteLeaveWhenInvited(Transaction txn, Session s,
LeaveMessage m) throws DbException, FormatException { LeaveMessage m) throws DbException, FormatException {
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Mark any invite messages in the session unavailable to answer // Mark any invite messages in the session unavailable to answer
markInvitesUnavailableToAnswer(txn, s); markInvitesUnavailableToAnswer(txn, s);
@@ -472,7 +476,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
private Session onRemoteLeaveWhenLocalLeft(Transaction txn, Session s, private Session onRemoteLeaveWhenLocalLeft(Transaction txn, Session s,
LeaveMessage m) throws DbException, FormatException { LeaveMessage m) throws DbException, FormatException {
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Move to the next state // Move to the next state
return new Session(START, s.getContactGroupId(), s.getShareableId(), return new Session(START, s.getContactGroupId(), s.getShareableId(),
@@ -483,7 +487,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
private Session onRemoteLeaveWhenSharing(Transaction txn, Session s, private Session onRemoteLeaveWhenSharing(Transaction txn, Session s,
LeaveMessage m) throws DbException, FormatException { LeaveMessage m) throws DbException, FormatException {
// The dependency, if any, must be the last remote message // The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Broadcast event informing that contact left // Broadcast event informing that contact left
ContactId contactId = getContactId(txn, s.getContactGroupId()); ContactId contactId = getContactId(txn, s.getContactGroupId());
@@ -526,26 +530,6 @@ abstract class ProtocolEngineImpl<S extends Shareable>
sent.getId(), null, 0, 0); sent.getId(), null, 0, 0);
} }
private S getShareable(Transaction txn, GroupId groupId)
throws DbException {
BdfList descriptor = getDescriptor(txn, groupId);
try {
return messageParser.createShareable(descriptor);
} catch (FormatException e) {
throw new DbException(e);
}
}
private BdfList getDescriptor(Transaction txn, GroupId groupId)
throws DbException {
Group g = db.getGroup(txn, groupId);
try {
return clientHelper.toList(g.getDescriptor());
} catch (FormatException e) {
throw new DbException(e); // Invalid group descriptor
}
}
private void markInvitesUnavailableToAnswer(Transaction txn, Session s) private void markInvitesUnavailableToAnswer(Transaction txn, Session s)
throws DbException, FormatException { throws DbException, FormatException {
GroupId shareableId = s.getShareableId(); GroupId shareableId = s.getShareableId();
@@ -639,11 +623,11 @@ abstract class ProtocolEngineImpl<S extends Shareable>
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue()); return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
} }
private boolean isValidDependency(Session session, private boolean isInvalidDependency(Session session,
@Nullable MessageId dependency) { @Nullable MessageId dependency) {
MessageId expected = session.getLastRemoteMessageId(); MessageId expected = session.getLastRemoteMessageId();
if (dependency == null) return expected == null; if (dependency == null) return expected != null;
return expected != null && dependency.equals(expected); return expected == null || !dependency.equals(expected);
} }
private long getLocalTimestamp(Session session) { private long getLocalTimestamp(Session session) {

View File

@@ -28,7 +28,7 @@ import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.client.SessionId; import org.briarproject.briar.api.client.SessionId;
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.PrivateRequest;
import org.briarproject.briar.api.messaging.PrivateResponse; import org.briarproject.briar.api.sharing.InvitationResponse;
import org.briarproject.briar.api.sharing.Shareable; import org.briarproject.briar.api.sharing.Shareable;
import org.briarproject.briar.api.sharing.SharingInvitationItem; import org.briarproject.briar.api.sharing.SharingInvitationItem;
import org.briarproject.briar.api.sharing.SharingManager; import org.briarproject.briar.api.sharing.SharingManager;
@@ -329,37 +329,23 @@ abstract class SharingManagerImpl<S extends Shareable>
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
Map<MessageId, BdfDictionary> results = clientHelper Map<MessageId, BdfDictionary> results = clientHelper
.getMessageMetadataAsDictionary(txn, contactGroupId, query); .getMessageMetadataAsDictionary(txn, contactGroupId, query);
List<PrivateMessageHeader> messages = Collection<PrivateMessageHeader> messages =
new ArrayList<>(results.size()); new ArrayList<>(results.size());
// get invite messages first and remember shareables
Map<GroupId, S> shareables = new HashMap<>();
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
MessageId m = e.getKey(); MessageId m = e.getKey();
MessageMetadata meta = MessageMetadata meta =
messageParser.parseMetadata(e.getValue()); messageParser.parseMetadata(e.getValue());
MessageType type = meta.getMessageType();
if (type != INVITE) continue;
MessageStatus status = db.getMessageStatus(txn, c, m); MessageStatus status = db.getMessageStatus(txn, c, m);
PrivateRequest<S> invite = parseInvitationRequest(txn, c, m,
meta, status);
messages.add(invite);
shareables.put(invite.getNameable().getId(), invite.getNameable());
}
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
MessageId m = e.getKey();
MessageMetadata meta =
messageParser.parseMetadata(e.getValue());
MessageType type = meta.getMessageType(); MessageType type = meta.getMessageType();
if (type == INVITE) continue; if (type == INVITE) {
MessageStatus status = db.getMessageStatus(txn, c, m); messages.add(parseInvitationRequest(txn, c, m,
S shareable = shareables.get(meta.getShareableId()); meta, status));
if (shareable == null) throw new AssertionError(); } else if (type == ACCEPT) {
if (type == ACCEPT) {
messages.add(parseInvitationResponse(contactGroupId, m, messages.add(parseInvitationResponse(contactGroupId, m,
meta, status, shareable, true)); meta, status, true));
} else if (type == DECLINE) { } else if (type == DECLINE) {
messages.add(parseInvitationResponse(contactGroupId, m, messages.add(parseInvitationResponse(contactGroupId, m,
meta, status, shareable, false)); meta, status, false));
} }
} }
return messages; return messages;
@@ -382,12 +368,12 @@ abstract class SharingManagerImpl<S extends Shareable>
meta.isAvailableToAnswer(), canBeOpened); meta.isAvailableToAnswer(), canBeOpened);
} }
private PrivateResponse<S> parseInvitationResponse(GroupId contactGroupId, private InvitationResponse parseInvitationResponse(GroupId contactGroupId,
MessageId m, MessageMetadata meta, MessageStatus status, MessageId m, MessageMetadata meta, MessageStatus status,
S shareable, boolean accept) { boolean accept) {
return invitationFactory.createInvitationResponse(m, contactGroupId, return invitationFactory.createInvitationResponse(m, contactGroupId,
meta.getTimestamp(), meta.isLocal(), status.isSent(), meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), shareable, accept); status.isSeen(), meta.isRead(), accept, meta.getShareableId());
} }
@Override @Override

View File

@@ -159,7 +159,7 @@ public class IntroductionIntegrationTest
eventWaiter.await(TIMEOUT, 1); eventWaiter.await(TIMEOUT, 1);
assertTrue(listener0.response1Received); assertTrue(listener0.response1Received);
assertEquals(introducee2.getAuthor().getName(), assertEquals(introducee2.getAuthor().getName(),
listener0.getResponse().getNameable().getName()); listener0.getResponse().getIntroducedAuthor().getName());
assertGroupCount(messageTracker0, g1.getId(), 2, 1); assertGroupCount(messageTracker0, g1.getId(), 2, 1);
// sync second ACCEPT message // sync second ACCEPT message
@@ -167,7 +167,7 @@ public class IntroductionIntegrationTest
eventWaiter.await(TIMEOUT, 1); eventWaiter.await(TIMEOUT, 1);
assertTrue(listener0.response2Received); assertTrue(listener0.response2Received);
assertEquals(introducee1.getAuthor().getName(), assertEquals(introducee1.getAuthor().getName(),
listener0.getResponse().getNameable().getName()); listener0.getResponse().getIntroducedAuthor().getName());
assertGroupCount(messageTracker0, g2.getId(), 2, 1); assertGroupCount(messageTracker0, g2.getId(), 2, 1);
// sync forwarded ACCEPT messages to introducees // sync forwarded ACCEPT messages to introducees
@@ -265,7 +265,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct // assert that the name on the decline event is correct
assertEquals(introducee2.getAuthor().getName(), assertEquals(introducee2.getAuthor().getName(),
listener0.getResponse().getNameable().getName()); listener0.getResponse().getIntroducedAuthor().getName());
// sync second response // sync second response
sync2To0(1, true); sync2To0(1, true);
@@ -282,7 +282,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct // assert that the name on the decline event is correct
eventWaiter.await(TIMEOUT, 1); eventWaiter.await(TIMEOUT, 1);
assertEquals(introducee1.getAuthor().getName(), assertEquals(introducee1.getAuthor().getName(),
listener2.getResponse().getNameable().getName()); listener2.getResponse().getIntroducedAuthor().getName());
// note how the introducer does not forward the second response, // note how the introducer does not forward the second response,
// because after the first decline the protocol finished // because after the first decline the protocol finished
@@ -356,7 +356,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct // assert that the name on the decline event is correct
eventWaiter.await(TIMEOUT, 1); eventWaiter.await(TIMEOUT, 1);
assertEquals(contact2From0.getAuthor().getName(), assertEquals(contact2From0.getAuthor().getName(),
listener1.getResponse().getNameable().getName()); listener1.getResponse().getIntroducedAuthor().getName());
assertFalse(contactManager1 assertFalse(contactManager1
.contactExists(author2.getId(), author1.getId())); .contactExists(author2.getId(), author1.getId()));
@@ -484,7 +484,7 @@ public class IntroductionIntegrationTest
// assert that the name on the decline event is correct // assert that the name on the decline event is correct
eventWaiter.await(TIMEOUT, 1); eventWaiter.await(TIMEOUT, 1);
assertEquals(introducee1.getAuthor().getName(), assertEquals(introducee1.getAuthor().getName(),
listener2.getResponse().getNameable().getName()); listener2.getResponse().getIntroducedAuthor().getName());
// assert that introducee2 is in correct state // assert that introducee2 is in correct state
introduceeSession = getIntroduceeSession(c2); introduceeSession = getIntroduceeSession(c2);

View File

@@ -310,8 +310,6 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
oneOf(messageTracker) oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1, .trackMessage(txn, contactGroupId, inviteTimestamp + 1,
false); false);
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
will(returnValue(privateGroup));
}}); }});
expectGetContactId(); expectGetContactId();
expectSetPrivateGroupVisibility(SHARED); expectSetPrivateGroupVisibility(SHARED);
@@ -401,8 +399,6 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
oneOf(messageTracker) oneOf(messageTracker)
.trackMessage(txn, contactGroupId, inviteTimestamp + 1, .trackMessage(txn, contactGroupId, inviteTimestamp + 1,
false); false);
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
will(returnValue(privateGroup));
}}); }});
expectGetContactId(); expectGetContactId();
CreatorSession newSession = CreatorSession newSession =

View File

@@ -2,7 +2,6 @@ package org.briarproject.briar.privategroup.invitation;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
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.messaging.PrivateMessageHeader; import org.briarproject.briar.api.messaging.PrivateMessageHeader;
@@ -127,7 +126,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) { if (m instanceof GroupInvitationResponse) {
foundResponse = true; foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m; GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable()); assertEquals(privateGroup0.getId(), response.getShareableId());
assertTrue(response.isLocal()); assertTrue(response.isLocal());
assertFalse(response.wasAccepted()); assertFalse(response.wasAccepted());
} }
@@ -144,7 +143,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) { if (m instanceof GroupInvitationResponse) {
foundResponse = true; foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m; GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable()); assertEquals(privateGroup0.getId(), response.getShareableId());
assertFalse(response.isLocal()); assertFalse(response.isLocal());
assertFalse(response.wasAccepted()); assertFalse(response.wasAccepted());
} }
@@ -177,7 +176,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) { if (m instanceof GroupInvitationResponse) {
foundResponse = true; foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m; GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable()); assertEquals(privateGroup0.getId(), response.getShareableId());
assertTrue(response.wasAccepted()); assertTrue(response.wasAccepted());
} else { } else {
GroupInvitationRequest request = (GroupInvitationRequest) m; GroupInvitationRequest request = (GroupInvitationRequest) m;
@@ -197,7 +196,7 @@ public class GroupInvitationIntegrationTest
if (m instanceof GroupInvitationResponse) { if (m instanceof GroupInvitationResponse) {
foundResponse = true; foundResponse = true;
GroupInvitationResponse response = (GroupInvitationResponse) m; GroupInvitationResponse response = (GroupInvitationResponse) m;
assertEquals(privateGroup0, response.getNameable()); assertEquals(privateGroup0.getId(), response.getShareableId());
assertTrue(response.wasAccepted()); assertTrue(response.wasAccepted());
} }
} }
@@ -441,38 +440,6 @@ public class GroupInvitationIntegrationTest
sync1To0(1, true); sync1To0(1, true);
} }
@Test(expected = AssertionError.class)
public void testDeleteOnlyInvitationFails() throws Exception {
// send invitation
sendInvitation(clock.currentTimeMillis(), null);
sync0To1(1, true);
// save MessageId of invitation
Collection<PrivateMessageHeader> messages =
withinTransactionReturns(db1, txn -> groupInvitationManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(1, messages.size());
MessageId inviteId = messages.iterator().next().getId();
// decline invitation
groupInvitationManager1
.respondToInvitation(contactId0From1, privateGroup0, false);
// we should have an invitation and a decline message
messages = withinTransactionReturns(db1, txn -> groupInvitationManager1
.getMessageHeaders(txn, contactId0From1));
assertEquals(2, messages.size());
// delete only invitation
withinTransaction(db1, txn -> {
db1.deleteMessage(txn, inviteId);
db1.deleteMessageMetadata(txn, inviteId);
// This should fail
groupInvitationManager1.getMessageHeaders(txn, contactId0From1);
});
}
private void sendInvitation(long timestamp, @Nullable String msg) throws private void sendInvitation(long timestamp, @Nullable String msg) throws
DbException { DbException {
byte[] signature = groupInvitationFactory.signInvitation(contact1From0, byte[] signature = groupInvitationFactory.signInvitation(contact1From0,

View File

@@ -680,8 +680,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
contactGroup.getId(), query); contactGroup.getId(), query);
will(returnValue(results)); will(returnValue(results));
// first message // first message
oneOf(messageParser).parseMetadata(meta2);
will(returnValue(messageMetadata2));
oneOf(messageParser).parseMetadata(meta); oneOf(messageParser).parseMetadata(meta);
will(returnValue(messageMetadata1)); will(returnValue(messageMetadata1));
oneOf(db).getMessageStatus(txn, contactId, message.getId()); oneOf(db).getMessageStatus(txn, contactId, message.getId());
@@ -695,8 +693,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
// second message // second message
oneOf(messageParser).parseMetadata(meta2); oneOf(messageParser).parseMetadata(meta2);
will(returnValue(messageMetadata2)); will(returnValue(messageMetadata2));
oneOf(messageParser).parseMetadata(meta);
will(returnValue(messageMetadata1));
oneOf(db).getMessageStatus(txn, contactId, messageId2); oneOf(db).getMessageStatus(txn, contactId, messageId2);
}}); }});
@@ -712,7 +708,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
} else if (m.getId().equals(messageId2)) { } else if (m.getId().equals(messageId2)) {
assertTrue(m instanceof GroupInvitationResponse); assertTrue(m instanceof GroupInvitationResponse);
assertEquals(time2, m.getTimestamp()); assertEquals(time2, m.getTimestamp());
assertEquals(pg, ((GroupInvitationResponse) m).getNameable()); assertEquals(pg.getId(),
((GroupInvitationResponse) m).getShareableId());
} else { } else {
throw new AssertionError(); throw new AssertionError();
} }

View File

@@ -160,7 +160,7 @@ public class BlogSharingIntegrationTest
assertEquals("Hi!", invitation.getMessage()); assertEquals("Hi!", invitation.getMessage());
} else { } else {
BlogInvitationResponse response = (BlogInvitationResponse) m; BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(blog2, response.getNameable()); assertEquals(blog2.getId(), response.getShareableId());
assertTrue(response.wasAccepted()); assertTrue(response.wasAccepted());
assertTrue(response.isLocal()); assertTrue(response.isLocal());
} }
@@ -233,7 +233,7 @@ public class BlogSharingIntegrationTest
assertEquals("Hi!", invitation.getMessage()); assertEquals("Hi!", invitation.getMessage());
} else { } else {
BlogInvitationResponse response = (BlogInvitationResponse) m; BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(rssBlog, response.getNameable()); assertEquals(rssBlog.getId(), response.getShareableId());
assertTrue(response.wasAccepted()); assertTrue(response.wasAccepted());
assertTrue(response.isLocal()); assertTrue(response.isLocal());
} }
@@ -294,7 +294,7 @@ public class BlogSharingIntegrationTest
assertEquals(null, invitation.getMessage()); assertEquals(null, invitation.getMessage());
} else { } else {
BlogInvitationResponse response = (BlogInvitationResponse) m; BlogInvitationResponse response = (BlogInvitationResponse) m;
assertEquals(blog2, response.getNameable()); assertEquals(blog2.getId(), response.getShareableId());
assertFalse(response.wasAccepted()); assertFalse(response.wasAccepted());
assertTrue(response.isLocal()); assertTrue(response.isLocal());
} }

View File

@@ -142,7 +142,7 @@ public class ForumSharingIntegrationTest
assertTrue(invitation.canBeOpened()); assertTrue(invitation.canBeOpened());
} else { } else {
ForumInvitationResponse response = (ForumInvitationResponse) m; ForumInvitationResponse response = (ForumInvitationResponse) m;
assertEquals(forum0, response.getNameable()); assertEquals(forum0.getId(), response.getShareableId());
assertTrue(response.wasAccepted()); assertTrue(response.wasAccepted());
assertTrue(response.isLocal()); assertTrue(response.isLocal());
} }
@@ -198,7 +198,7 @@ public class ForumSharingIntegrationTest
assertFalse(invitation.canBeOpened()); assertFalse(invitation.canBeOpened());
} else { } else {
ForumInvitationResponse response = (ForumInvitationResponse) m; ForumInvitationResponse response = (ForumInvitationResponse) m;
assertEquals(forum0, response.getNameable()); assertEquals(forum0.getId(), response.getShareableId());
assertFalse(response.wasAccepted()); assertFalse(response.wasAccepted());
assertTrue(response.isLocal()); assertTrue(response.isLocal());
} }