mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch '877-save-invitation-outcome-to-invitation-message-and-make-available-to-ui' into 'master'
Store invitation outcome in metadata and make it available to the UI This MR is based on !479 and should only be merged after that one has been merged as well. It stores the invitation outcome in the message metadata and includes it in the `canBeOpened()` calculation for private groups and sharables. Closes #877 See merge request !480
This commit is contained in:
@@ -174,6 +174,17 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
markMessageAvailableToAnswer(txn, m, false);
|
||||
}
|
||||
|
||||
void markInviteAccepted(Transaction txn, MessageId m, boolean accepted)
|
||||
throws DbException {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
messageEncoder.setInvitationAccepted(meta, accepted);
|
||||
try {
|
||||
clientHelper.mergeMessageMetadata(txn, m, meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
void subscribeToPrivateGroup(Transaction txn, MessageId inviteId)
|
||||
throws DbException, FormatException {
|
||||
InviteMessage invite = messageParser.getInviteMessage(txn, inviteId);
|
||||
@@ -199,8 +210,9 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
private void sendMessage(Transaction txn, Message m, MessageType type,
|
||||
GroupId privateGroupId, boolean visibleInConversation)
|
||||
throws DbException {
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(type, privateGroupId,
|
||||
m.getTimestamp(), true, true, visibleInConversation, false);
|
||||
BdfDictionary meta = messageEncoder
|
||||
.encodeMetadata(type, privateGroupId, m.getTimestamp(), true,
|
||||
true, visibleInConversation, false, false);
|
||||
try {
|
||||
clientHelper.addLocalMessage(txn, m, meta, true);
|
||||
} catch (FormatException e) {
|
||||
|
||||
@@ -12,6 +12,7 @@ interface GroupInvitationConstants {
|
||||
String MSG_KEY_LOCAL = "local";
|
||||
String MSG_KEY_VISIBLE_IN_UI = "visibleInUi";
|
||||
String MSG_KEY_AVAILABLE_TO_ANSWER = "availableToAnswer";
|
||||
String MSG_KEY_INVITATION_ACCEPTED = "invitationAccepted";
|
||||
|
||||
// Session keys
|
||||
String SESSION_KEY_SESSION_ID = "sessionId";
|
||||
|
||||
@@ -405,7 +405,9 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
PrivateGroup pg = privateGroupFactory
|
||||
.createPrivateGroup(invite.getGroupName(), invite.getCreator(),
|
||||
invite.getSalt());
|
||||
boolean canBeOpened = db.containsGroup(txn, invite.getPrivateGroupId());
|
||||
// Find out whether the private group can be opened
|
||||
boolean canBeOpened = meta.wasAccepted() &&
|
||||
db.containsGroup(txn, invite.getPrivateGroupId());
|
||||
return new GroupInvitationRequest(m, contactGroupId,
|
||||
meta.getTimestamp(), meta.isLocal(), status.isSent(),
|
||||
status.isSeen(), meta.isRead(), sessionId, pg, c,
|
||||
|
||||
@@ -112,7 +112,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
// Create the metadata
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(INVITE,
|
||||
privateGroup.getId(), m.getTimestamp(), false, false, false,
|
||||
false);
|
||||
false, false);
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
checkLength(previousMessageId, UniqueId.LENGTH);
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(JOIN,
|
||||
new GroupId(privateGroupId), m.getTimestamp(), false, false,
|
||||
false, false);
|
||||
false, false, false);
|
||||
if (previousMessageId == null) {
|
||||
return new BdfMessageContext(meta);
|
||||
} else {
|
||||
@@ -144,7 +144,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
checkLength(previousMessageId, UniqueId.LENGTH);
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(LEAVE,
|
||||
new GroupId(privateGroupId), m.getTimestamp(), false, false,
|
||||
false, false);
|
||||
false, false, false);
|
||||
if (previousMessageId == null) {
|
||||
return new BdfMessageContext(meta);
|
||||
} else {
|
||||
@@ -161,7 +161,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
checkLength(privateGroupId, UniqueId.LENGTH);
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(ABORT,
|
||||
new GroupId(privateGroupId), m.getTimestamp(), false, false,
|
||||
false, false);
|
||||
false, false, false);
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
MessageId inviteId = s.getLastRemoteMessageId();
|
||||
if (inviteId == null) throw new IllegalStateException();
|
||||
markMessageAvailableToAnswer(txn, inviteId, false);
|
||||
// Record the response
|
||||
markInviteAccepted(txn, inviteId, true);
|
||||
// Send a JOIN message
|
||||
Message sent = sendJoinMessage(txn, s, true);
|
||||
// Track the message
|
||||
|
||||
@@ -14,12 +14,14 @@ interface MessageEncoder {
|
||||
|
||||
BdfDictionary encodeMetadata(MessageType type, GroupId privateGroupId,
|
||||
long timestamp, boolean local, boolean read, boolean visible,
|
||||
boolean available);
|
||||
boolean available, boolean accepted);
|
||||
|
||||
void setVisibleInUi(BdfDictionary meta, boolean visible);
|
||||
|
||||
void setAvailableToAnswer(BdfDictionary meta, boolean available);
|
||||
|
||||
void setInvitationAccepted(BdfDictionary meta, boolean accepted);
|
||||
|
||||
Message encodeInviteMessage(GroupId contactGroupId, GroupId privateGroupId,
|
||||
long timestamp, String groupName, Author creator, byte[] salt,
|
||||
@Nullable String message, byte[] signature);
|
||||
|
||||
@@ -17,6 +17,7 @@ import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_MESSAGE_TYPE;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_PRIVATE_GROUP_ID;
|
||||
@@ -44,7 +45,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
@Override
|
||||
public BdfDictionary encodeMetadata(MessageType type,
|
||||
GroupId privateGroupId, long timestamp, boolean local, boolean read,
|
||||
boolean visible, boolean available) {
|
||||
boolean visible, boolean available, boolean accepted) {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(MSG_KEY_MESSAGE_TYPE, type.getValue());
|
||||
meta.put(MSG_KEY_PRIVATE_GROUP_ID, privateGroupId);
|
||||
@@ -53,6 +54,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
meta.put(MSG_KEY_READ, read);
|
||||
meta.put(MSG_KEY_VISIBLE_IN_UI, visible);
|
||||
meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, available);
|
||||
meta.put(MSG_KEY_INVITATION_ACCEPTED, accepted);
|
||||
return meta;
|
||||
}
|
||||
|
||||
@@ -66,6 +68,11 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, available);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInvitationAccepted(BdfDictionary meta, boolean accepted) {
|
||||
meta.put(MSG_KEY_INVITATION_ACCEPTED, accepted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message encodeInviteMessage(GroupId contactGroupId,
|
||||
GroupId privateGroupId, long timestamp, String groupName,
|
||||
|
||||
@@ -12,11 +12,11 @@ class MessageMetadata {
|
||||
private final MessageType type;
|
||||
private final GroupId privateGroupId;
|
||||
private final long timestamp;
|
||||
private final boolean local, read, visible, available;
|
||||
private final boolean local, read, visible, available, accepted;
|
||||
|
||||
MessageMetadata(MessageType type, GroupId privateGroupId,
|
||||
long timestamp, boolean local, boolean read, boolean visible,
|
||||
boolean available) {
|
||||
boolean available, boolean accepted) {
|
||||
this.privateGroupId = privateGroupId;
|
||||
this.type = type;
|
||||
this.timestamp = timestamp;
|
||||
@@ -24,6 +24,7 @@ class MessageMetadata {
|
||||
this.read = read;
|
||||
this.visible = visible;
|
||||
this.available = available;
|
||||
this.accepted = accepted;
|
||||
}
|
||||
|
||||
MessageType getMessageType() {
|
||||
@@ -53,4 +54,14 @@ class MessageMetadata {
|
||||
boolean isAvailableToAnswer() {
|
||||
return available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the invitation was accepted.
|
||||
*
|
||||
* Only applies to messages of type INVITE.
|
||||
*/
|
||||
public boolean wasAccepted() {
|
||||
return accepted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_MESSAGE_TYPE;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_PRIVATE_GROUP_ID;
|
||||
@@ -79,8 +80,9 @@ class MessageParserImpl implements MessageParser {
|
||||
boolean read = meta.getBoolean(MSG_KEY_READ, false);
|
||||
boolean visible = meta.getBoolean(MSG_KEY_VISIBLE_IN_UI, false);
|
||||
boolean available = meta.getBoolean(MSG_KEY_AVAILABLE_TO_ANSWER, false);
|
||||
boolean accepted = meta.getBoolean(MSG_KEY_INVITATION_ACCEPTED, false);
|
||||
return new MessageMetadata(type, privateGroupId, timestamp, local, read,
|
||||
visible, available);
|
||||
visible, available, accepted);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,12 +14,14 @@ interface MessageEncoder {
|
||||
|
||||
BdfDictionary encodeMetadata(MessageType type, GroupId shareableId,
|
||||
long timestamp, boolean local, boolean read, boolean visible,
|
||||
boolean available);
|
||||
boolean available, boolean accepted);
|
||||
|
||||
void setVisibleInUi(BdfDictionary meta, boolean visible);
|
||||
|
||||
void setAvailableToAnswer(BdfDictionary meta, boolean available);
|
||||
|
||||
void setInvitationAccepted(BdfDictionary meta, boolean accepted);
|
||||
|
||||
Message encodeInviteMessage(GroupId contactGroupId, long timestamp,
|
||||
@Nullable MessageId previousMessageId, BdfList descriptor,
|
||||
@Nullable String message);
|
||||
|
||||
@@ -20,10 +20,11 @@ import static org.briarproject.briar.sharing.MessageType.DECLINE;
|
||||
import static org.briarproject.briar.sharing.MessageType.INVITE;
|
||||
import static org.briarproject.briar.sharing.MessageType.LEAVE;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_MESSAGE_TYPE;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_SHAREABLE_ID;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_READ;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_SHAREABLE_ID;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_TIMESTAMP;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_VISIBLE_IN_UI;
|
||||
|
||||
@@ -44,7 +45,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
@Override
|
||||
public BdfDictionary encodeMetadata(MessageType type,
|
||||
GroupId shareableId, long timestamp, boolean local, boolean read,
|
||||
boolean visible, boolean available) {
|
||||
boolean visible, boolean available, boolean accepted) {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(MSG_KEY_MESSAGE_TYPE, type.getValue());
|
||||
meta.put(MSG_KEY_SHAREABLE_ID, shareableId);
|
||||
@@ -53,6 +54,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
meta.put(MSG_KEY_READ, read);
|
||||
meta.put(MSG_KEY_VISIBLE_IN_UI, visible);
|
||||
meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, available);
|
||||
meta.put(MSG_KEY_INVITATION_ACCEPTED, accepted);
|
||||
return meta;
|
||||
}
|
||||
|
||||
@@ -66,6 +68,11 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
meta.put(MSG_KEY_AVAILABLE_TO_ANSWER, available);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInvitationAccepted(BdfDictionary meta, boolean accepted) {
|
||||
meta.put(MSG_KEY_INVITATION_ACCEPTED, accepted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message encodeInviteMessage(GroupId contactGroupId, long timestamp,
|
||||
@Nullable MessageId previousMessageId, BdfList descriptor,
|
||||
|
||||
@@ -12,10 +12,11 @@ class MessageMetadata {
|
||||
private final MessageType type;
|
||||
private final GroupId shareableId;
|
||||
private final long timestamp;
|
||||
private final boolean local, read, visible, available;
|
||||
private final boolean local, read, visible, available, accepted;
|
||||
|
||||
MessageMetadata(MessageType type, GroupId shareableId, long timestamp,
|
||||
boolean local, boolean read, boolean visible, boolean available) {
|
||||
boolean local, boolean read, boolean visible, boolean available,
|
||||
boolean accepted) {
|
||||
this.shareableId = shareableId;
|
||||
this.type = type;
|
||||
this.timestamp = timestamp;
|
||||
@@ -23,6 +24,7 @@ class MessageMetadata {
|
||||
this.read = read;
|
||||
this.visible = visible;
|
||||
this.available = available;
|
||||
this.accepted = accepted;
|
||||
}
|
||||
|
||||
MessageType getMessageType() {
|
||||
@@ -53,4 +55,13 @@ class MessageMetadata {
|
||||
return available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the invitation was accepted.
|
||||
*
|
||||
* Only applies to messages of type INVITE.
|
||||
*/
|
||||
public boolean wasAccepted() {
|
||||
return accepted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_AVAILABLE_
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_MESSAGE_TYPE;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_READ;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_SHAREABLE_ID;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_TIMESTAMP;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_VISIBLE_IN_UI;
|
||||
@@ -68,8 +69,9 @@ abstract class MessageParserImpl<S extends Shareable>
|
||||
boolean read = meta.getBoolean(MSG_KEY_READ, false);
|
||||
boolean visible = meta.getBoolean(MSG_KEY_VISIBLE_IN_UI, false);
|
||||
boolean available = meta.getBoolean(MSG_KEY_AVAILABLE_TO_ANSWER, false);
|
||||
boolean accepted = meta.getBoolean(MSG_KEY_INVITATION_ACCEPTED, false);
|
||||
return new MessageMetadata(type, shareableId, timestamp, local, read,
|
||||
visible, available);
|
||||
visible, available, accepted);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -148,6 +148,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
MessageId inviteId = s.getLastRemoteMessageId();
|
||||
if (inviteId == null) throw new IllegalStateException();
|
||||
markMessageAvailableToAnswer(txn, inviteId, false);
|
||||
// Mark the invite message as accepted
|
||||
markInvitationAccepted(txn, inviteId, true);
|
||||
// Send a ACCEPT message
|
||||
Message sent = sendAcceptMessage(txn, s);
|
||||
// Track the message
|
||||
@@ -568,8 +570,9 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
private void sendMessage(Transaction txn, Message m, MessageType type,
|
||||
GroupId shareableId, boolean visibleInConversation)
|
||||
throws DbException {
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(type, shareableId,
|
||||
m.getTimestamp(), true, true, visibleInConversation, false);
|
||||
BdfDictionary meta = messageEncoder
|
||||
.encodeMetadata(type, shareableId, m.getTimestamp(), true, true,
|
||||
visibleInConversation, false, false);
|
||||
try {
|
||||
clientHelper.addLocalMessage(txn, m, meta, true);
|
||||
} catch (FormatException e) {
|
||||
@@ -599,6 +602,17 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
}
|
||||
}
|
||||
|
||||
private void markInvitationAccepted(Transaction txn, MessageId m,
|
||||
boolean accepted) throws DbException {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
messageEncoder.setInvitationAccepted(meta, accepted);
|
||||
try {
|
||||
clientHelper.mergeMessageMetadata(txn, m, meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setShareableVisibility(Transaction txn, Session session,
|
||||
Visibility v) throws DbException, FormatException {
|
||||
ContactId contactId = getContactId(txn, session.getContactGroupId());
|
||||
|
||||
@@ -15,6 +15,7 @@ interface SharingConstants {
|
||||
String MSG_KEY_LOCAL = "local";
|
||||
String MSG_KEY_VISIBLE_IN_UI = "visibleInUi";
|
||||
String MSG_KEY_AVAILABLE_TO_ANSWER = "availableToAnswer";
|
||||
String MSG_KEY_INVITATION_ACCEPTED = "invitationAccepted";
|
||||
|
||||
// Session keys
|
||||
String SESSION_KEY_STATE = "state";
|
||||
|
||||
@@ -319,7 +319,9 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
MessageStatus status) throws DbException, FormatException {
|
||||
// Look up the invite message to get the details of the private group
|
||||
InviteMessage<S> invite = messageParser.getInviteMessage(txn, m);
|
||||
boolean canBeOpened = db.containsGroup(txn, invite.getShareableId());
|
||||
// Find out whether the shareable can be opened
|
||||
boolean canBeOpened = meta.wasAccepted() &&
|
||||
db.containsGroup(txn, invite.getShareableId());
|
||||
return invitationFactory
|
||||
.createInvitationRequest(meta.isLocal(), status.isSent(),
|
||||
status.isSeen(), meta.isRead(), invite, c,
|
||||
|
||||
@@ -65,7 +65,7 @@ abstract class SharingValidator extends BdfMessageValidator {
|
||||
|
||||
BdfDictionary meta = messageEncoder
|
||||
.encodeMetadata(INVITE, shareableId, m.getTimestamp(), false,
|
||||
false, false, false);
|
||||
false, false, false, false);
|
||||
if (previousMessageId == null) {
|
||||
return new BdfMessageContext(meta);
|
||||
} else {
|
||||
@@ -88,7 +88,7 @@ abstract class SharingValidator extends BdfMessageValidator {
|
||||
|
||||
BdfDictionary meta = messageEncoder
|
||||
.encodeMetadata(type, new GroupId(shareableId),
|
||||
m.getTimestamp(), false, false, false, false);
|
||||
m.getTimestamp(), false, false, false, false, false);
|
||||
if (previousMessageId == null) {
|
||||
return new BdfMessageContext(meta);
|
||||
} else {
|
||||
|
||||
@@ -169,7 +169,7 @@ public abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
final boolean visible) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(type, privateGroupId,
|
||||
message.getTimestamp(), true, true, visible, false);
|
||||
message.getTimestamp(), true, true, visible, false, false);
|
||||
will(returnValue(meta));
|
||||
oneOf(clientHelper).addLocalMessage(txn, message, meta, true);
|
||||
}});
|
||||
|
||||
@@ -104,6 +104,7 @@ public class GroupInvitationIntegrationTest
|
||||
assertEquals(privateGroup0.getName(), request.getShareable().getName());
|
||||
assertFalse(request.isLocal());
|
||||
assertFalse(request.isRead());
|
||||
assertFalse(request.canBeOpened());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,6 +176,8 @@ public class GroupInvitationIntegrationTest
|
||||
foundResponse = true;
|
||||
InvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertTrue(response.wasAccepted());
|
||||
} else {
|
||||
assertTrue(((GroupInvitationRequest) m).canBeOpened());
|
||||
}
|
||||
}
|
||||
assertTrue(foundResponse);
|
||||
|
||||
@@ -638,10 +638,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
final long time1 = 1L, time2 = 2L;
|
||||
final MessageMetadata messageMetadata1 =
|
||||
new MessageMetadata(INVITE, privateGroup.getId(), time1, true,
|
||||
true, true, false);
|
||||
true, true, false, true);
|
||||
final MessageMetadata messageMetadata2 =
|
||||
new MessageMetadata(JOIN, privateGroup.getId(), time2, true,
|
||||
true, true, true);
|
||||
true, true, true, false);
|
||||
final InviteMessage invite =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time1, "name", author,
|
||||
|
||||
@@ -311,7 +311,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
} else {
|
||||
oneOf(messageEncoder).encodeMetadata(INVITE,
|
||||
message.getGroupId(), message.getTimestamp(), false,
|
||||
false, false, false);
|
||||
false, false, false, false);
|
||||
will(returnValue(meta));
|
||||
}
|
||||
}});
|
||||
@@ -389,7 +389,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId(), null);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(JOIN, message.getGroupId(),
|
||||
message.getTimestamp(), false, false, false, false);
|
||||
message.getTimestamp(), false, false, false, false, false);
|
||||
will(returnValue(meta));
|
||||
}});
|
||||
BdfMessageContext messageContext =
|
||||
@@ -404,7 +404,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
previousMessageId);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(JOIN, message.getGroupId(),
|
||||
message.getTimestamp(), false, false, false, false);
|
||||
message.getTimestamp(), false, false, false, false, false);
|
||||
will(returnValue(meta));
|
||||
}});
|
||||
BdfMessageContext messageContext =
|
||||
@@ -487,7 +487,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(), null);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(LEAVE, message.getGroupId(),
|
||||
message.getTimestamp(), false, false, false, false);
|
||||
message.getTimestamp(), false, false, false, false, false);
|
||||
will(returnValue(meta));
|
||||
}});
|
||||
BdfMessageContext messageContext =
|
||||
@@ -500,7 +500,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
public void testAcceptsValidLeaveMessage() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(LEAVE, message.getGroupId(),
|
||||
message.getTimestamp(), false, false, false, false);
|
||||
message.getTimestamp(), false, false, false, false, false);
|
||||
will(returnValue(meta));
|
||||
}});
|
||||
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
||||
@@ -557,7 +557,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
public void testAcceptsValidAbortMessage() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(ABORT, message.getGroupId(),
|
||||
message.getTimestamp(), false, false, false, false);
|
||||
message.getTimestamp(), false, false, false, false, false);
|
||||
will(returnValue(meta));
|
||||
}});
|
||||
BdfList body = BdfList.of(ABORT.getValue(), privateGroup.getId());
|
||||
|
||||
@@ -3,11 +3,9 @@ package org.briarproject.briar.privategroup.invitation;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||
@@ -132,15 +130,17 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
final JoinMessage properJoinMessage =
|
||||
new JoinMessage(messageId, contactGroupId, privateGroupId,
|
||||
messageTimestamp, lastRemoteMessageId);
|
||||
final Message inviteMsg =
|
||||
new Message(lastRemoteMessageId, contactGroupId, 1337L,
|
||||
getRandomBytes(42));
|
||||
final BdfList inviteList = BdfList.of("inviteMessage");
|
||||
final long timestamp = 0L;
|
||||
final GroupMessage joinGroupMessage =
|
||||
new GroupMessage(message, null, localAuthor);
|
||||
final BdfDictionary meta = new BdfDictionary();
|
||||
|
||||
expectMarkMessageAvailableToAnswer(lastRemoteMessageId, false);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).setInvitationAccepted(meta, true);
|
||||
oneOf(clientHelper)
|
||||
.mergeMessageMetadata(txn, lastRemoteMessageId, meta);
|
||||
}});
|
||||
expectSendJoinMessage(properJoinMessage, true);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageTracker).trackOutgoingMessage(txn, message);
|
||||
|
||||
@@ -136,6 +136,7 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(forum0.getName(), invitation.getForumName());
|
||||
assertEquals(contactId1From0, invitation.getContactId());
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
assertTrue(invitation.canBeOpened());
|
||||
} else {
|
||||
ForumInvitationResponse response =
|
||||
(ForumInvitationResponse) m;
|
||||
@@ -195,6 +196,7 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(forum0.getName(), invitation.getForumName());
|
||||
assertEquals(contactId1From0, invitation.getContactId());
|
||||
assertEquals(null, invitation.getMessage());
|
||||
assertFalse(invitation.canBeOpened());
|
||||
} else {
|
||||
ForumInvitationResponse response =
|
||||
(ForumInvitationResponse) m;
|
||||
|
||||
@@ -147,7 +147,7 @@ public abstract class SharingValidatorTest extends ValidatorTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder)
|
||||
.encodeMetadata(type, groupId, timestamp, false, false,
|
||||
false, false);
|
||||
false, false, false);
|
||||
will(returnValue(meta));
|
||||
}});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user