mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Remember when declines were automatic due to deletion
so they can be shown differently for sender
This commit is contained in:
@@ -15,7 +15,7 @@ public class BlogInvitationResponse extends InvitationResponse {
|
||||
SessionId sessionId, boolean accept, GroupId shareableId,
|
||||
long autoDeleteTimer) {
|
||||
super(id, groupId, time, local, read, sent, seen, sessionId,
|
||||
accept, shareableId, autoDeleteTimer);
|
||||
accept, shareableId, autoDeleteTimer, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,14 +12,16 @@ import javax.annotation.concurrent.Immutable;
|
||||
public abstract class ConversationResponse extends ConversationMessageHeader {
|
||||
|
||||
private final SessionId sessionId;
|
||||
private final boolean accepted;
|
||||
private final boolean accepted, isAutoDecline;
|
||||
|
||||
public ConversationResponse(MessageId id, GroupId groupId, long time,
|
||||
boolean local, boolean read, boolean sent, boolean seen,
|
||||
SessionId sessionId, boolean accepted, long autoDeleteTimer) {
|
||||
SessionId sessionId, boolean accepted, long autoDeleteTimer,
|
||||
boolean isAutoDecline) {
|
||||
super(id, groupId, time, local, read, sent, seen, autoDeleteTimer);
|
||||
this.sessionId = sessionId;
|
||||
this.accepted = accepted;
|
||||
this.isAutoDecline = isAutoDecline;
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
@@ -30,4 +32,7 @@ public abstract class ConversationResponse extends ConversationMessageHeader {
|
||||
return accepted;
|
||||
}
|
||||
|
||||
public boolean isAutoDecline() {
|
||||
return isAutoDecline;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ForumInvitationResponse extends InvitationResponse {
|
||||
SessionId sessionId, boolean accept, GroupId shareableId,
|
||||
long autoDeleteTimer) {
|
||||
super(id, groupId, time, local, read, sent, seen, sessionId,
|
||||
accept, shareableId, autoDeleteTimer);
|
||||
accept, shareableId, autoDeleteTimer, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
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.conversation.ConversationMessageVisitor;
|
||||
import org.briarproject.briar.api.conversation.ConversationResponse;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class IntroductionResponse extends ConversationResponse {
|
||||
AuthorInfo introducedAuthorInfo, Role role, boolean canSucceed,
|
||||
long autoDeleteTimer) {
|
||||
super(messageId, groupId, time, local, read, sent, seen, sessionId,
|
||||
accepted, autoDeleteTimer);
|
||||
accepted, autoDeleteTimer, false);
|
||||
this.introducedAuthor = author;
|
||||
this.introducedAuthorInfo = introducedAuthorInfo;
|
||||
this.ourRole = role;
|
||||
|
||||
@@ -16,9 +16,9 @@ public class GroupInvitationResponse extends InvitationResponse {
|
||||
public GroupInvitationResponse(MessageId id, GroupId groupId, long time,
|
||||
boolean local, boolean read, boolean sent, boolean seen,
|
||||
SessionId sessionId, boolean accept, GroupId shareableId,
|
||||
long autoDeleteTimer) {
|
||||
long autoDeleteTimer, boolean isAutoDecline) {
|
||||
super(id, groupId, time, local, read, sent, seen, sessionId,
|
||||
accept, shareableId, autoDeleteTimer);
|
||||
accept, shareableId, autoDeleteTimer, isAutoDecline);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,9 +12,9 @@ public abstract class InvitationResponse extends ConversationResponse {
|
||||
public InvitationResponse(MessageId id, GroupId groupId, long time,
|
||||
boolean local, boolean read, boolean sent, boolean seen,
|
||||
SessionId sessionId, boolean accepted, GroupId shareableId,
|
||||
long autoDeleteTimer) {
|
||||
long autoDeleteTimer, boolean isAutoDecline) {
|
||||
super(id, groupId, time, local, read, sent, seen, sessionId, accepted,
|
||||
autoDeleteTimer);
|
||||
autoDeleteTimer, isAutoDecline);
|
||||
this.shareableId = shareableId;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,15 +180,20 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
return m;
|
||||
}
|
||||
|
||||
Message sendLeaveMessage(Transaction txn, S s, boolean visibleInUi)
|
||||
throws DbException {
|
||||
Message sendLeaveMessage(Transaction txn, S s) throws DbException {
|
||||
return sendLeaveMessage(txn, s, false, false);
|
||||
}
|
||||
|
||||
Message sendLeaveMessage(Transaction txn, S s, boolean visibleInUi,
|
||||
boolean isAutoDecline) throws DbException {
|
||||
if (!visibleInUi && isAutoDecline) throw new IllegalArgumentException();
|
||||
Message m;
|
||||
long localTimestamp = visibleInUi
|
||||
? getTimestampForVisibleMessage(txn, s)
|
||||
: getTimestampForInvisibleMessage(s);
|
||||
ContactId c = getContactId(txn, s.getContactGroupId());
|
||||
if (contactSupportsAutoDeletion(txn, c)) {
|
||||
// Set auto-delete timer if manually accepting an invitation
|
||||
// Set auto-delete timer if declining an invitation
|
||||
long timer = NO_AUTO_DELETE_TIMER;
|
||||
if (visibleInUi) {
|
||||
timer = autoDeleteManager.getAutoDeleteTimer(txn, c,
|
||||
@@ -198,8 +203,8 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
s.getPrivateGroupId(), localTimestamp,
|
||||
s.getLastLocalMessageId(), timer);
|
||||
sendMessage(txn, m, LEAVE, s.getPrivateGroupId(), visibleInUi,
|
||||
timer);
|
||||
// Set the auto-delete timer duration on the message
|
||||
timer, isAutoDecline);
|
||||
// Set the auto-delete timer duration on the local message
|
||||
if (timer != NO_AUTO_DELETE_TIMER) {
|
||||
db.setCleanupTimerDuration(txn, m.getId(), timer);
|
||||
}
|
||||
@@ -321,9 +326,17 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
private void sendMessage(Transaction txn, Message m, MessageType type,
|
||||
GroupId privateGroupId, boolean visibleInConversation,
|
||||
long autoDeleteTimer) throws DbException {
|
||||
sendMessage(txn, m, type, privateGroupId, visibleInConversation,
|
||||
autoDeleteTimer, false);
|
||||
}
|
||||
|
||||
private void sendMessage(Transaction txn, Message m, MessageType type,
|
||||
GroupId privateGroupId, boolean visibleInConversation,
|
||||
long autoDeleteTimer, boolean isAutoDecline) throws DbException {
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(type,
|
||||
privateGroupId, m.getTimestamp(), true, true,
|
||||
visibleInConversation, false, false, autoDeleteTimer);
|
||||
visibleInConversation, false, false, autoDeleteTimer,
|
||||
isAutoDecline);
|
||||
try {
|
||||
clientHelper.addLocalMessage(txn, m, meta, true, false);
|
||||
} catch (FormatException e) {
|
||||
|
||||
@@ -84,8 +84,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreatorSession onLeaveAction(Transaction txn, CreatorSession s)
|
||||
throws DbException {
|
||||
public CreatorSession onLeaveAction(Transaction txn, CreatorSession s,
|
||||
boolean isAutoDecline) throws DbException {
|
||||
switch (s.getState()) {
|
||||
case START:
|
||||
case DISSOLVED:
|
||||
@@ -180,7 +180,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
throw new DbException(e); // Invalid group metadata
|
||||
}
|
||||
// Send a LEAVE message
|
||||
Message sent = sendLeaveMessage(txn, s, false);
|
||||
Message sent = sendLeaveMessage(txn, s);
|
||||
// Move to the DISSOLVED state
|
||||
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
|
||||
sent.getId(), s.getLastRemoteMessageId(), sent.getTimestamp(),
|
||||
@@ -276,6 +276,6 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
|
||||
return new GroupInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, false, false, sessionId,
|
||||
accept, m.getPrivateGroupId(), m.getAutoDeleteTimer());
|
||||
accept, m.getPrivateGroupId(), m.getAutoDeleteTimer(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ interface GroupInvitationConstants {
|
||||
String MSG_KEY_AVAILABLE_TO_ANSWER = "availableToAnswer";
|
||||
String MSG_KEY_INVITATION_ACCEPTED = "invitationAccepted";
|
||||
String MSG_KEY_AUTO_DELETE_TIMER = "autoDeleteTimer";
|
||||
String MSG_KEY_IS_AUTO_DECLINE = "isAutoDecline";
|
||||
|
||||
// Session keys
|
||||
String SESSION_KEY_IS_SESSION = "isSession";
|
||||
|
||||
@@ -310,11 +310,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
public void respondToInvitation(ContactId c, SessionId sessionId,
|
||||
boolean accept) throws DbException {
|
||||
db.transaction(false,
|
||||
txn -> respondToInvitation(txn, c, sessionId, accept));
|
||||
txn -> respondToInvitation(txn, c, sessionId, accept, false));
|
||||
}
|
||||
|
||||
private void respondToInvitation(Transaction txn, ContactId c,
|
||||
SessionId sessionId, boolean accept) throws DbException {
|
||||
SessionId sessionId, boolean accept, boolean isAutoDecline)
|
||||
throws DbException {
|
||||
try {
|
||||
// Look up the session
|
||||
Contact contact = db.getContact(txn, c);
|
||||
@@ -326,7 +327,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
.parseInviteeSession(contactGroupId, ss.bdfSession);
|
||||
// Handle the join or leave action
|
||||
if (accept) session = inviteeEngine.onJoinAction(txn, session);
|
||||
else session = inviteeEngine.onLeaveAction(txn, session);
|
||||
else session =
|
||||
inviteeEngine.onLeaveAction(txn, session, isAutoDecline);
|
||||
// Store the updated session
|
||||
storeSession(txn, ss.storageId, session);
|
||||
} catch (FormatException e) {
|
||||
@@ -366,7 +368,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
} else if (type == LocalAction.JOIN) {
|
||||
return engine.onJoinAction(txn, session);
|
||||
} else if (type == LocalAction.LEAVE) {
|
||||
return engine.onLeaveAction(txn, session);
|
||||
return engine.onLeaveAction(txn, session, false);
|
||||
} else if (type == LocalAction.MEMBER_ADDED) {
|
||||
return engine.onMemberAddedAction(txn, session);
|
||||
} else {
|
||||
@@ -435,7 +437,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
return new GroupInvitationResponse(m, contactGroupId,
|
||||
meta.getTimestamp(), meta.isLocal(), meta.isRead(),
|
||||
status.isSent(), status.isSeen(), sessionId, accept,
|
||||
meta.getPrivateGroupId(), meta.getAutoDeleteTimer());
|
||||
meta.getPrivateGroupId(), meta.getAutoDeleteTimer(),
|
||||
meta.isAutoDecline());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -813,7 +816,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
// decline invitee sessions waiting for a response before
|
||||
if (session.state instanceof InviteeState &&
|
||||
session.state.isAwaitingResponse()) {
|
||||
respondToInvitation(txn, c, entry.getKey(), false);
|
||||
respondToInvitation(txn, c, entry.getKey(), false, true);
|
||||
}
|
||||
for (MessageId m : session.messages) {
|
||||
db.deleteMessage(txn, m);
|
||||
|
||||
@@ -110,8 +110,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
}
|
||||
// Create the metadata
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(INVITE,
|
||||
privateGroup.getId(), m.getTimestamp(), false, false, false,
|
||||
false, false, timer);
|
||||
privateGroup.getId(), m.getTimestamp(), timer);
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
|
||||
@@ -132,8 +131,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
}
|
||||
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(JOIN,
|
||||
new GroupId(privateGroupId), m.getTimestamp(), false, false,
|
||||
false, false, false, timer);
|
||||
new GroupId(privateGroupId), m.getTimestamp(), timer);
|
||||
if (previousMessageId == null) {
|
||||
return new BdfMessageContext(meta);
|
||||
} else {
|
||||
@@ -160,8 +158,7 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
}
|
||||
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(LEAVE,
|
||||
new GroupId(privateGroupId), m.getTimestamp(), false, false,
|
||||
false, false, false, timer);
|
||||
new GroupId(privateGroupId), m.getTimestamp(), timer);
|
||||
if (previousMessageId == null) {
|
||||
return new BdfMessageContext(meta);
|
||||
} else {
|
||||
@@ -177,8 +174,8 @@ class GroupInvitationValidator extends BdfMessageValidator {
|
||||
byte[] privateGroupId = body.getRaw(1);
|
||||
checkLength(privateGroupId, UniqueId.LENGTH);
|
||||
BdfDictionary meta = messageEncoder.encodeMetadata(ABORT,
|
||||
new GroupId(privateGroupId), m.getTimestamp(), false, false,
|
||||
false, false, false, NO_AUTO_DELETE_TIMER);
|
||||
new GroupId(privateGroupId), m.getTimestamp(),
|
||||
NO_AUTO_DELETE_TIMER);
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InviteeSession onLeaveAction(Transaction txn, InviteeSession s)
|
||||
throws DbException {
|
||||
public InviteeSession onLeaveAction(Transaction txn, InviteeSession s,
|
||||
boolean isAutoDecline) throws DbException {
|
||||
switch (s.getState()) {
|
||||
case START:
|
||||
case LEFT:
|
||||
@@ -98,7 +98,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
case ERROR:
|
||||
return s; // Ignored in these states
|
||||
case INVITED:
|
||||
return onLocalDecline(txn, s);
|
||||
return onLocalDecline(txn, s, isAutoDecline);
|
||||
case ACCEPTED:
|
||||
case JOINED:
|
||||
return onLocalLeave(txn, s);
|
||||
@@ -203,14 +203,14 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
s.getInviteTimestamp(), ACCEPTED);
|
||||
}
|
||||
|
||||
private InviteeSession onLocalDecline(Transaction txn, InviteeSession s)
|
||||
throws DbException {
|
||||
private InviteeSession onLocalDecline(Transaction txn, InviteeSession s,
|
||||
boolean isAutoDecline) throws DbException {
|
||||
// Mark the invite message unavailable to answer
|
||||
MessageId inviteId = s.getLastRemoteMessageId();
|
||||
if (inviteId == null) throw new IllegalStateException();
|
||||
markMessageAvailableToAnswer(txn, inviteId, false);
|
||||
// Send a LEAVE message
|
||||
Message sent = sendLeaveMessage(txn, s, true);
|
||||
Message sent = sendLeaveMessage(txn, s, true, isAutoDecline);
|
||||
// Track the message
|
||||
messageTracker.trackOutgoingMessage(txn, sent);
|
||||
// Move to the START state
|
||||
@@ -222,7 +222,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
private InviteeSession onLocalLeave(Transaction txn, InviteeSession s)
|
||||
throws DbException {
|
||||
// Send a LEAVE message
|
||||
Message sent = sendLeaveMessage(txn, s, false);
|
||||
Message sent = sendLeaveMessage(txn, s);
|
||||
try {
|
||||
// Make the private group invisible to the contact
|
||||
setPrivateGroupVisibility(txn, s, INVISIBLE);
|
||||
|
||||
@@ -14,7 +14,11 @@ interface MessageEncoder {
|
||||
|
||||
BdfDictionary encodeMetadata(MessageType type, GroupId privateGroupId,
|
||||
long timestamp, boolean local, boolean read, boolean visible,
|
||||
boolean available, boolean accepted, long autoDeleteTimer);
|
||||
boolean available, boolean accepted, long autoDeleteTimer,
|
||||
boolean isAutoDecline);
|
||||
|
||||
BdfDictionary encodeMetadata(MessageType type, GroupId privateGroupId,
|
||||
long timestamp, long autoDeleteTimer);
|
||||
|
||||
void setVisibleInUi(BdfDictionary meta, boolean visible);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_AUTO_DELETE_TIMER;
|
||||
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_IS_AUTO_DECLINE;
|
||||
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;
|
||||
@@ -48,7 +49,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
public BdfDictionary encodeMetadata(MessageType type,
|
||||
GroupId privateGroupId, long timestamp, boolean local, boolean read,
|
||||
boolean visible, boolean available, boolean accepted,
|
||||
long autoDeleteTimer) {
|
||||
long autoDeleteTimer, boolean isAutoDecline) {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(MSG_KEY_MESSAGE_TYPE, type.getValue());
|
||||
meta.put(MSG_KEY_PRIVATE_GROUP_ID, privateGroupId);
|
||||
@@ -61,9 +62,19 @@ class MessageEncoderImpl implements MessageEncoder {
|
||||
if (autoDeleteTimer != NO_AUTO_DELETE_TIMER) {
|
||||
meta.put(MSG_KEY_AUTO_DELETE_TIMER, autoDeleteTimer);
|
||||
}
|
||||
if (isAutoDecline) {
|
||||
meta.put(MSG_KEY_IS_AUTO_DECLINE, isAutoDecline);
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BdfDictionary encodeMetadata(MessageType type,
|
||||
GroupId privateGroupId, long timestamp, long autoDeleteTimer) {
|
||||
return encodeMetadata(type, privateGroupId, timestamp, false, false,
|
||||
false, false, false, autoDeleteTimer, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleInUi(BdfDictionary meta, boolean visible) {
|
||||
meta.put(MSG_KEY_VISIBLE_IN_UI, visible);
|
||||
|
||||
@@ -13,10 +13,12 @@ class MessageMetadata {
|
||||
private final GroupId privateGroupId;
|
||||
private final long timestamp, autoDeleteTimer;
|
||||
private final boolean local, read, visible, available, accepted;
|
||||
private final boolean isAutoDecline;
|
||||
|
||||
MessageMetadata(MessageType type, GroupId privateGroupId,
|
||||
long timestamp, boolean local, boolean read, boolean visible,
|
||||
boolean available, boolean accepted, long autoDeleteTimer) {
|
||||
boolean available, boolean accepted, long autoDeleteTimer,
|
||||
boolean isAutoDecline) {
|
||||
this.privateGroupId = privateGroupId;
|
||||
this.type = type;
|
||||
this.timestamp = timestamp;
|
||||
@@ -26,6 +28,7 @@ class MessageMetadata {
|
||||
this.available = available;
|
||||
this.accepted = accepted;
|
||||
this.autoDeleteTimer = autoDeleteTimer;
|
||||
this.isAutoDecline = isAutoDecline;
|
||||
}
|
||||
|
||||
MessageType getMessageType() {
|
||||
@@ -58,7 +61,7 @@ class MessageMetadata {
|
||||
|
||||
/**
|
||||
* Returns true if the invitation was accepted.
|
||||
*
|
||||
* <p>
|
||||
* Only applies to messages of type INVITE.
|
||||
*/
|
||||
public boolean wasAccepted() {
|
||||
@@ -68,4 +71,8 @@ class MessageMetadata {
|
||||
public long getAutoDeleteTimer() {
|
||||
return autoDeleteTimer;
|
||||
}
|
||||
|
||||
public boolean isAutoDecline() {
|
||||
return isAutoDecline;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_AUTO_DELETE_TIMER;
|
||||
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_IS_AUTO_DECLINE;
|
||||
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;
|
||||
@@ -82,8 +83,9 @@ class MessageParserImpl implements MessageParser {
|
||||
boolean accepted = meta.getBoolean(MSG_KEY_INVITATION_ACCEPTED, false);
|
||||
long timer = meta.getLong(MSG_KEY_AUTO_DELETE_TIMER,
|
||||
NO_AUTO_DELETE_TIMER);
|
||||
boolean isAutoDecline = meta.getBoolean(MSG_KEY_IS_AUTO_DECLINE, false);
|
||||
return new MessageMetadata(type, privateGroupId, timestamp, local, read,
|
||||
visible, available, accepted, timer);
|
||||
visible, available, accepted, timer, isAutoDecline);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -85,8 +85,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeerSession onLeaveAction(Transaction txn, PeerSession s)
|
||||
throws DbException {
|
||||
public PeerSession onLeaveAction(Transaction txn, PeerSession s,
|
||||
boolean isAutoDecline) throws DbException {
|
||||
switch (s.getState()) {
|
||||
case START:
|
||||
case AWAIT_MEMBER:
|
||||
@@ -213,7 +213,7 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
|
||||
private PeerSession onLocalLeaveFromBothJoined(Transaction txn,
|
||||
PeerSession s) throws DbException {
|
||||
// Send a LEAVE message
|
||||
Message sent = sendLeaveMessage(txn, s, false);
|
||||
Message sent = sendLeaveMessage(txn, s);
|
||||
try {
|
||||
// Make the private group invisible to the contact
|
||||
setPrivateGroupVisibility(txn, s, INVISIBLE);
|
||||
@@ -229,7 +229,7 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
|
||||
private PeerSession onLocalLeaveFromLocalJoined(Transaction txn,
|
||||
PeerSession s) throws DbException {
|
||||
// Send a LEAVE message
|
||||
Message sent = sendLeaveMessage(txn, s, false);
|
||||
Message sent = sendLeaveMessage(txn, s);
|
||||
try {
|
||||
// Make the private group invisible to the contact
|
||||
setPrivateGroupVisibility(txn, s, INVISIBLE);
|
||||
|
||||
@@ -16,7 +16,14 @@ interface ProtocolEngine<S extends Session<?>> {
|
||||
|
||||
S onJoinAction(Transaction txn, S session) throws DbException;
|
||||
|
||||
S onLeaveAction(Transaction txn, S session) throws DbException;
|
||||
/**
|
||||
* Leaves the group or declines an invitation.
|
||||
*
|
||||
* @param isAutoDecline true if automatically declined due to deletion
|
||||
* and false if initiated by the user.
|
||||
*/
|
||||
S onLeaveAction(Transaction txn, S session, boolean isAutoDecline)
|
||||
throws DbException;
|
||||
|
||||
S onMemberAddedAction(Transaction txn, S session) throws DbException;
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(type, privateGroupId,
|
||||
message.getTimestamp(), true, true, visible, false, false,
|
||||
NO_AUTO_DELETE_TIMER);
|
||||
NO_AUTO_DELETE_TIMER, false);
|
||||
will(returnValue(meta));
|
||||
oneOf(clientHelper).addLocalMessage(txn, message, meta, true,
|
||||
false);
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.conversation.ConversationManager.ConversationClient;
|
||||
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||
@@ -17,8 +16,6 @@ import org.briarproject.briar.test.BriarIntegrationTestComponent;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.bramble.api.cleanup.CleanupManager.BATCH_DELAY_MS;
|
||||
@@ -28,6 +25,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
|
||||
@@ -104,10 +102,9 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
assertEquals(1, getMessageHeaders(c1, contactId0From1).size());
|
||||
|
||||
// 1 marks the message as read - this starts 1's timer
|
||||
final MessageId messageId =
|
||||
final MessageId messageId0 =
|
||||
getMessageHeaders(c1, contactId0From1).get(0).getId();
|
||||
markMessageRead(c1, contact0From1, messageId);
|
||||
waitForEvents(c1);
|
||||
markMessageRead(c1, contact0From1, messageId0);
|
||||
assertGroupCount(c1, contactId0From1, 1, 0);
|
||||
|
||||
// Before 1's timer elapses, 1 should still see the message
|
||||
@@ -127,9 +124,10 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
assertGroupCount(c1, contactId0From1, 1, 0);
|
||||
forEachHeader(c1, contactId0From1, 1, h -> {
|
||||
// The only message is not the same as before, but declined response
|
||||
assertNotEquals(messageId, h.getId());
|
||||
assertNotEquals(messageId0, h.getId());
|
||||
assertTrue(h instanceof GroupInvitationResponse);
|
||||
assertFalse(((GroupInvitationResponse) h).wasAccepted());
|
||||
assertTrue(((GroupInvitationResponse) h).isAutoDecline());
|
||||
// The auto-decline message should have the expected timer
|
||||
assertEquals(MIN_AUTO_DELETE_TIMER_MS,
|
||||
h.getAutoDeleteTimer());
|
||||
@@ -162,10 +160,9 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
assertEquals(0, getMessageHeaders(c1, contactId0From1).size());
|
||||
|
||||
// 0 marks the message as read - this starts 0's timer
|
||||
MessageId messageId0 =
|
||||
MessageId messageId1 =
|
||||
getMessageHeaders(c0, contactId1From0).get(0).getId();
|
||||
markMessageRead(c0, contact1From0, messageId0);
|
||||
waitForEvents(c0);
|
||||
markMessageRead(c0, contact1From0, messageId1);
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
|
||||
// Before 0's timer elapses, 0 should still see the message
|
||||
@@ -174,7 +171,7 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
assertEquals(1, getMessageHeaders(c0, contactId1From0).size());
|
||||
|
||||
// When 0's timer has elapsed, the message should be deleted from 0's
|
||||
// view of the conversation but 1 should still see the message
|
||||
// view of the conversation
|
||||
c0.getTimeTravel().addCurrentTimeMillis(1);
|
||||
assertGroupCount(c0, contactId1From0, 0, 0);
|
||||
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
|
||||
@@ -196,6 +193,7 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
sendInvitation(pg, contact1From0.getId(), null);
|
||||
sync0To1(1, true);
|
||||
ack1To0(1);
|
||||
waitForEvents(c0);
|
||||
|
||||
// The message should have been added the views of the conversation
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
@@ -239,25 +237,24 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
assertEquals(1, getMessageHeaders(c0, contactId1From0).size());
|
||||
assertGroupCount(c1, contactId0From1, 2, 2);
|
||||
List<ConversationMessageHeader> headers1 =
|
||||
getMessageHeaders(c1, contactId0From1);
|
||||
assertEquals(2, headers1.size());
|
||||
assertEquals(2, getMessageHeaders(c1, contactId0From1).size());
|
||||
|
||||
// 1 marks the message as read - this starts 1's timer
|
||||
ConversationMessageHeader header = headers1.get(1); // newer message
|
||||
assertEquals(privateGroup,
|
||||
((GroupInvitationRequest) header).getNameable());
|
||||
MessageId messageId = header.getId();
|
||||
markMessageRead(c1, contact0From1, messageId);
|
||||
waitForEvents(c1);
|
||||
assertGroupCount(c1, contactId0From1, 2, 1);
|
||||
// 1 marks all the message as read - this starts 1's timer for 2nd msg
|
||||
forEachHeader(c1, contactId0From1, 2, h -> {
|
||||
try {
|
||||
markMessageRead(c1, contact0From1, h.getId());
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
});
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
|
||||
// Before 1's timer elapses, 1 should still see the message
|
||||
c0.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||
c1.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
assertEquals(1, getMessageHeaders(c0, contactId1From0).size());
|
||||
assertGroupCount(c1, contactId0From1, 2, 1);
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
assertEquals(2, getMessageHeaders(c1, contactId0From1).size());
|
||||
|
||||
// When 1's timer has elapsed, the message should be deleted from 1's
|
||||
@@ -266,7 +263,8 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
c1.getTimeTravel().addCurrentTimeMillis(1);
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
assertEquals(1, getMessageHeaders(c0, contactId1From0).size());
|
||||
assertGroupCount(c1, contactId0From1, 2, 1);
|
||||
// 1's total count is still 2, because of the added auto-decline
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
forEachHeader(c1, contactId0From1, 2, h -> {
|
||||
if (h instanceof GroupInvitationRequest) {
|
||||
// the request is for the first invitation
|
||||
@@ -277,6 +275,7 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
GroupInvitationResponse r = (GroupInvitationResponse) h;
|
||||
// is auto-decline for 2nd invitation
|
||||
assertEquals(privateGroup.getId(), r.getShareableId());
|
||||
assertTrue(r.isAutoDecline());
|
||||
assertFalse(r.wasAccepted());
|
||||
}
|
||||
});
|
||||
@@ -288,34 +287,48 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
waitForEvents(c1);
|
||||
// 0 marks the message as read - this starts 0's timer
|
||||
GroupInvitationResponse autoDeclineMessage = (GroupInvitationResponse)
|
||||
getMessageHeaders(c1, contactId0From1).get(1);
|
||||
getMessageHeaders(c0, contactId1From0).get(1);
|
||||
markMessageRead(c0, contact1From0, autoDeclineMessage.getId());
|
||||
waitForEvents(c0);
|
||||
assertGroupCount(c0, contactId1From0, 2, 0);
|
||||
assertGroupCount(c1, contactId0From1, 2, 1);
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
|
||||
// Timer of auto-decline elapses for both peers at the same time
|
||||
c0.getTimeTravel().addCurrentTimeMillis(timerLatency);
|
||||
c1.getTimeTravel().addCurrentTimeMillis(timerLatency);
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
assertGroupCount(c1, contactId0From1, 1, 1);
|
||||
assertGroupCount(c1, contactId0From1, 1, 0);
|
||||
|
||||
// 1 responds to first invitation (that had no timer)
|
||||
groupInvitationManager1.respondToInvitation(contactId0From1, pg, true);
|
||||
// Sync the accept response message to 0
|
||||
sync1To0(1, true);
|
||||
// Sync the ack to 1 - this starts 1's timer
|
||||
ack0To1(1);
|
||||
// Sync the ack (and creator's join messages (group + protocol) to 1
|
||||
// this starts 1's timer
|
||||
sync0To1(2, true);
|
||||
waitForEvents(c1);
|
||||
assertGroupCount(c0, contactId1From0, 2, 1);
|
||||
assertGroupCount(c1, contactId0From1, 2, 1);
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
forEachHeader(c1, contactId0From1, 2, h -> {
|
||||
if (h instanceof GroupInvitationRequest) {
|
||||
// the request is for the first invitation
|
||||
assertEquals(pg.getId(),
|
||||
((GroupInvitationRequest) h).getNameable().getId());
|
||||
} else {
|
||||
assertTrue(h instanceof GroupInvitationResponse);
|
||||
GroupInvitationResponse r = (GroupInvitationResponse) h;
|
||||
// is accept for 1nd invitation
|
||||
assertEquals(pg.getId(), r.getShareableId());
|
||||
assertFalse(r.isAutoDecline());
|
||||
assertTrue(r.wasAccepted());
|
||||
}
|
||||
});
|
||||
|
||||
// Before 1's timer elapses, 1 should still see the message
|
||||
c0.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||
c1.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||
assertGroupCount(c0, contactId1From0, 2, 1);
|
||||
assertEquals(2, getMessageHeaders(c0, contactId1From0).size());
|
||||
assertGroupCount(c1, contactId0From1, 2, 1);
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
assertEquals(2, getMessageHeaders(c1, contactId0From1).size());
|
||||
|
||||
// When 1's timer has elapsed, the message should be deleted from 1's
|
||||
@@ -324,12 +337,43 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
c1.getTimeTravel().addCurrentTimeMillis(1);
|
||||
assertGroupCount(c0, contactId1From0, 2, 1);
|
||||
assertEquals(2, getMessageHeaders(c0, contactId1From0).size());
|
||||
assertGroupCount(c1, contactId0From1, 1, 1);
|
||||
assertGroupCount(c1, contactId0From1, 1, 0);
|
||||
forEachHeader(c1, contactId0From1, 1, h -> {
|
||||
assertTrue(h instanceof GroupInvitationRequest);
|
||||
assertTrue(((GroupInvitationRequest) h).wasAnswered());
|
||||
assertTrue(((GroupInvitationRequest) h).canBeOpened());
|
||||
});
|
||||
|
||||
// 0 reads all messages
|
||||
forEachHeader(c0, contactId1From0, 2, h -> {
|
||||
try {
|
||||
if (!h.isRead()) markMessageRead(c0, contact1From0, h.getId());
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
});
|
||||
assertGroupCount(c0, contactId1From0, 2, 0);
|
||||
|
||||
// Before 0's timer elapses, 0 should still see the messages
|
||||
c0.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||
c1.getTimeTravel().addCurrentTimeMillis(timerLatency - 1);
|
||||
assertGroupCount(c0, contactId1From0, 2, 0);
|
||||
assertGroupCount(c1, contactId0From1, 1, 0);
|
||||
|
||||
// When 0's timer has elapsed, the messages should be deleted from 0's
|
||||
// view of the conversation, only the initial invitation remains
|
||||
c0.getTimeTravel().addCurrentTimeMillis(1);
|
||||
c1.getTimeTravel().addCurrentTimeMillis(1);
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
assertEquals(1, getMessageHeaders(c0, contactId1From0).size());
|
||||
assertGroupCount(c1, contactId0From1, 1, 0);
|
||||
assertEquals(1, getMessageHeaders(c1, contactId0From1).size());
|
||||
|
||||
// 1 joined the PrivateGroup
|
||||
assertEquals(pg,
|
||||
c1.getPrivateGroupManager().getPrivateGroup(pg.getId()));
|
||||
assertFalse(groupInvitationManager0
|
||||
.isInvitationAllowed(contact1From0, pg.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -363,8 +407,8 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
|
||||
// 1 responds to invitation
|
||||
groupInvitationManager1
|
||||
.respondToInvitation(contactId0From1, privateGroup, true);
|
||||
// Sync the accept response message to 0
|
||||
.respondToInvitation(contactId0From1, privateGroup, false);
|
||||
// Sync the decline response message to 0
|
||||
sync1To0(1, true);
|
||||
// Sync the ack to 1 - this starts 1's timer
|
||||
ack0To1(1);
|
||||
@@ -373,18 +417,19 @@ public class AutoDeleteIntegrationTest extends AbstractAutoDeleteTest {
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
|
||||
// 0 marks the message as read - this starts 0's timer
|
||||
GroupInvitationResponse autoDeclineMessage = (GroupInvitationResponse)
|
||||
getMessageHeaders(c1, contactId0From1).get(1);
|
||||
markMessageRead(c0, contact1From0, autoDeclineMessage.getId());
|
||||
waitForEvents(c0);
|
||||
GroupInvitationResponse message1 = (GroupInvitationResponse)
|
||||
getMessageHeaders(c0, contactId1From0).get(0);
|
||||
markMessageRead(c0, contact1From0, message1.getId());
|
||||
assertGroupCount(c0, contactId1From0, 1, 0);
|
||||
assertGroupCount(c1, contactId0From1, 2, 0);
|
||||
|
||||
// 1 joined the PrivateGroup
|
||||
assertEquals(privateGroup, c1.getPrivateGroupManager()
|
||||
.getPrivateGroup(privateGroup.getId()));
|
||||
assertFalse(groupInvitationManager0
|
||||
.isInvitationAllowed(contact1From0, privateGroup.getId()));
|
||||
// both peers delete all messages after their timers expire
|
||||
c0.getTimeTravel().addCurrentTimeMillis(timerLatency);
|
||||
c1.getTimeTravel().addCurrentTimeMillis(timerLatency);
|
||||
assertGroupCount(c0, contactId1From0, 0, 0);
|
||||
assertEquals(0, getMessageHeaders(c0, contactId1From0).size());
|
||||
assertGroupCount(c1, contactId0From1, 0, 0);
|
||||
assertEquals(0, getMessageHeaders(c1, contactId0From1).size());
|
||||
}
|
||||
|
||||
private PrivateGroup addPrivateGroup(String name, long timestamp)
|
||||
|
||||
@@ -123,19 +123,19 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
@Test
|
||||
public void testOnLeaveActionFromStart() throws Exception {
|
||||
CreatorSession session = getDefaultSession(START);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromDissolved() throws Exception {
|
||||
CreatorSession session = getDefaultSession(DISSOLVED);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromError() throws Exception {
|
||||
CreatorSession session = getDefaultSession(ERROR);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,7 +143,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
CreatorSession session = getDefaultSession(INVITED);
|
||||
|
||||
expectOnLocalLeave();
|
||||
CreatorSession newSession = engine.onLeaveAction(txn, session);
|
||||
CreatorSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
assertEquals(DISSOLVED, newSession.getState());
|
||||
assertEquals(messageId, newSession.getLastLocalMessageId());
|
||||
assertEquals(lastRemoteMessageId, newSession.getLastRemoteMessageId());
|
||||
@@ -157,7 +157,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
CreatorSession session = getDefaultSession(JOINED);
|
||||
|
||||
expectOnLocalLeave();
|
||||
CreatorSession newSession = engine.onLeaveAction(txn, session);
|
||||
CreatorSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
assertEquals(DISSOLVED, newSession.getState());
|
||||
assertEquals(messageId, newSession.getLastLocalMessageId());
|
||||
assertEquals(lastRemoteMessageId, newSession.getLastRemoteMessageId());
|
||||
@@ -171,7 +171,7 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
CreatorSession session = getDefaultSession(LEFT);
|
||||
|
||||
expectOnLocalLeave();
|
||||
CreatorSession newSession = engine.onLeaveAction(txn, session);
|
||||
CreatorSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
assertEquals(DISSOLVED, newSession.getState());
|
||||
assertEquals(messageId, newSession.getLastLocalMessageId());
|
||||
assertEquals(lastRemoteMessageId, newSession.getLastRemoteMessageId());
|
||||
|
||||
@@ -593,7 +593,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
.parseInviteeSession(contactGroup.getId(), bdfSession);
|
||||
will(returnValue(inviteeSession));
|
||||
if (accept) oneOf(inviteeEngine).onJoinAction(txn, inviteeSession);
|
||||
else oneOf(inviteeEngine).onLeaveAction(txn, inviteeSession);
|
||||
else oneOf(inviteeEngine).onLeaveAction(txn, inviteeSession, false);
|
||||
will(returnValue(inviteeSession));
|
||||
}});
|
||||
expectStoreSession(inviteeSession, storageMessage.getId());
|
||||
@@ -653,10 +653,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
long time1 = 1L, time2 = 2L;
|
||||
MessageMetadata messageMetadata1 =
|
||||
new MessageMetadata(INVITE, privateGroup.getId(), time1, true,
|
||||
true, true, false, true, NO_AUTO_DELETE_TIMER);
|
||||
true, true, false, true, NO_AUTO_DELETE_TIMER, false);
|
||||
MessageMetadata messageMetadata2 =
|
||||
new MessageMetadata(JOIN, privateGroup.getId(), time2, true,
|
||||
true, true, true, false, NO_AUTO_DELETE_TIMER);
|
||||
true, true, true, false, NO_AUTO_DELETE_TIMER, false);
|
||||
InviteMessage invite =
|
||||
new InviteMessage(message.getId(), contactGroup.getId(),
|
||||
privateGroup.getId(), time1, "name", author,
|
||||
@@ -876,7 +876,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(sessionParser)
|
||||
.parseCreatorSession(contactGroup.getId(), bdfSession);
|
||||
will(returnValue(creatorSession));
|
||||
oneOf(creatorEngine).onLeaveAction(txn, creatorSession);
|
||||
oneOf(creatorEngine).onLeaveAction(txn, creatorSession, false);
|
||||
will(returnValue(creatorSession));
|
||||
// session 2
|
||||
oneOf(sessionParser).getRole(bdfSession2);
|
||||
@@ -884,7 +884,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(sessionParser)
|
||||
.parseInviteeSession(contactGroup2.getId(), bdfSession2);
|
||||
will(returnValue(inviteeSession));
|
||||
oneOf(inviteeEngine).onLeaveAction(txn, inviteeSession);
|
||||
oneOf(inviteeEngine).onLeaveAction(txn, inviteeSession, false);
|
||||
will(returnValue(inviteeSession));
|
||||
// session 3
|
||||
oneOf(sessionParser).getRole(bdfSession3);
|
||||
@@ -892,7 +892,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(sessionParser)
|
||||
.parsePeerSession(contactGroup3.getId(), bdfSession3);
|
||||
will(returnValue(peerSession));
|
||||
oneOf(peerEngine).onLeaveAction(txn, peerSession);
|
||||
oneOf(peerEngine).onLeaveAction(txn, peerSession, false);
|
||||
will(returnValue(peerSession));
|
||||
}});
|
||||
|
||||
|
||||
@@ -636,8 +636,7 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
||||
long autoDeleteTimer, BdfDictionary metadata) {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeMetadata(type, message.getGroupId(),
|
||||
message.getTimestamp(), false, false, false, false, false,
|
||||
autoDeleteTimer);
|
||||
message.getTimestamp(), autoDeleteTimer);
|
||||
will(returnValue(metadata));
|
||||
}});
|
||||
}
|
||||
|
||||
@@ -193,25 +193,25 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
@Test
|
||||
public void testOnLeaveActionFromStart() throws Exception {
|
||||
InviteeSession session = getDefaultSession(START);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromLeft() throws Exception {
|
||||
InviteeSession session = getDefaultSession(LEFT);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromDissolved() throws Exception {
|
||||
InviteeSession session = getDefaultSession(DISSOLVED);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromError() throws Exception {
|
||||
InviteeSession session = getDefaultSession(ERROR);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,7 +223,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
}});
|
||||
|
||||
InviteeSession session = getDefaultSession(INVITED);
|
||||
InviteeSession newSession = engine.onLeaveAction(txn, session);
|
||||
InviteeSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
|
||||
assertEquals(START, newSession.getState());
|
||||
assertSessionRecordedSentMessage(newSession);
|
||||
@@ -245,7 +245,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
expectSendLeaveMessage(false);
|
||||
expectSetPrivateGroupVisibility(INVISIBLE);
|
||||
InviteeSession session = getDefaultSession(ACCEPTED);
|
||||
InviteeSession newSession = engine.onLeaveAction(txn, session);
|
||||
InviteeSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
|
||||
assertEquals(LEFT, newSession.getState());
|
||||
assertSessionRecordedSentMessage(newSession);
|
||||
@@ -257,7 +257,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
expectSendLeaveMessage(false);
|
||||
expectSetPrivateGroupVisibility(INVISIBLE);
|
||||
InviteeSession session = getDefaultSession(JOINED);
|
||||
InviteeSession newSession = engine.onLeaveAction(txn, session);
|
||||
InviteeSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
|
||||
assertEquals(LEFT, newSession.getState());
|
||||
assertSessionRecordedSentMessage(newSession);
|
||||
|
||||
@@ -145,31 +145,31 @@ public class PeerProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
@Test
|
||||
public void testOnLeaveActionFromStart() throws Exception {
|
||||
PeerSession session = getDefaultSession(START);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromAwaitMember() throws Exception {
|
||||
PeerSession session = getDefaultSession(AWAIT_MEMBER);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromNeitherJoined() throws Exception {
|
||||
PeerSession session = getDefaultSession(NEITHER_JOINED);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromLocalLeft() throws Exception {
|
||||
PeerSession session = getDefaultSession(LOCAL_LEFT);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLeaveActionFromError() throws Exception {
|
||||
PeerSession session = getDefaultSession(ERROR);
|
||||
assertEquals(session, engine.onLeaveAction(txn, session));
|
||||
assertEquals(session, engine.onLeaveAction(txn, session, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +178,7 @@ public class PeerProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
expectSendLeaveMessage(false);
|
||||
expectSetPrivateGroupVisibility(INVISIBLE);
|
||||
PeerSession newSession = engine.onLeaveAction(txn, session);
|
||||
PeerSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
|
||||
assertEquals(NEITHER_JOINED, newSession.getState());
|
||||
assertSessionRecordedSentMessage(newSession);
|
||||
@@ -191,7 +191,7 @@ public class PeerProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
expectSendLeaveMessage(false);
|
||||
expectSetPrivateGroupVisibility(INVISIBLE);
|
||||
PeerSession newSession = engine.onLeaveAction(txn, session);
|
||||
PeerSession newSession = engine.onLeaveAction(txn, session, false);
|
||||
|
||||
assertEquals(LOCAL_LEFT, newSession.getState());
|
||||
assertSessionRecordedSentMessage(newSession);
|
||||
|
||||
Reference in New Issue
Block a user