Don't open unsubscribed shareables

This commit is contained in:
Torsten Grote
2016-12-16 17:58:23 -02:00
parent 2ef9b8f4b6
commit c04580e321
17 changed files with 75 additions and 56 deletions

View File

@@ -405,11 +405,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
SessionId sessionId = getSessionId(meta.getPrivateGroupId());
// Look up the invite message to get the details of the private group
InviteMessage invite = getInviteMessage(txn, m);
boolean canBeOpened = db.containsGroup(txn, invite.getPrivateGroupId());
return new GroupInvitationRequest(m, sessionId, contactGroupId, c,
invite.getMessage(), invite.getPrivateGroupId(),
invite.getGroupName(), invite.getCreator(),
meta.isAvailableToAnswer(), meta.getTimestamp(), meta.isLocal(),
status.isSent(), status.isSeen(), meta.isRead());
meta.isAvailableToAnswer(), canBeOpened, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(),
meta.isRead());
}
private InviteMessage getInviteMessage(Transaction txn, MessageId m)

View File

@@ -319,7 +319,7 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationRequest(m.getId(), sessionId,
m.getContactGroupId(), c, m.getMessage(), m.getPrivateGroupId(),
m.getGroupName(), m.getCreator(), true, m.getTimestamp(), false,
false, true, false);
m.getGroupName(), m.getCreator(), true, false, m.getTimestamp(),
false, false, true, false);
}
}

View File

@@ -135,13 +135,13 @@ class BlogSharingManagerImpl extends
@Override
protected InvitationMessage createInvitationRequest(MessageId id,
BlogInvitation msg, ContactId contactId, GroupId blogId,
boolean available, long time, boolean local, boolean sent,
boolean seen, boolean read) {
boolean available, boolean canBeOpened, long time, boolean local,
boolean sent, boolean seen, boolean read) {
return new BlogInvitationRequest(id, msg.getSessionId(),
msg.getGroupId(), contactId, msg.getBlogAuthorName(),
msg.getMessage(), blogId, available, time, local, sent, seen,
read);
msg.getMessage(), blogId, available, canBeOpened, time, local,
sent, seen, read);
}
@Override
@@ -345,8 +345,8 @@ class BlogSharingManagerImpl extends
localState.getSessionId(),
localState.getContactGroupId(), contactId,
blog.getAuthor().getName(), msg,
localState.getShareableId(), true, time, false,
false, false, false);
localState.getShareableId(), true, false, time,
false, false, false, false);
return new BlogInvitationRequestReceivedEvent(blog, contactId,
request);
}

View File

@@ -83,11 +83,12 @@ class ForumSharingManagerImpl extends
@Override
protected InvitationMessage createInvitationRequest(MessageId id,
ForumInvitation msg, ContactId contactId, GroupId forumId,
boolean available, long time, boolean local, boolean sent,
boolean seen, boolean read) {
boolean available, boolean canBeOpened, long time,
boolean local, boolean sent, boolean seen, boolean read) {
return new ForumInvitationRequest(id, msg.getSessionId(),
msg.getGroupId(), contactId, forumId, msg.getForumName(),
msg.getMessage(), available, time, local, sent, seen, read);
msg.getMessage(), available, canBeOpened, time, local, sent,
seen, read);
}
@Override
@@ -272,7 +273,7 @@ class ForumSharingManagerImpl extends
localState.getInvitationId(), localState.getSessionId(),
localState.getContactGroupId(), contactId,
localState.getShareableId(), forum.getName(), msg, true,
time, false, false, false, false);
false, time, false, false, false, false);
return new ForumInvitationRequestReceivedEvent(forum, contactId,
request);
}

View File

@@ -126,7 +126,8 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
protected abstract InvitationMessage createInvitationRequest(MessageId id,
I msg, ContactId contactId, GroupId shareableId, boolean available,
long time, boolean local, boolean sent, boolean seen, boolean read);
boolean canBeOpened, long time, boolean local, boolean sent,
boolean seen, boolean read);
protected abstract InvitationMessage createInvitationResponse(MessageId id,
SessionId sessionId, GroupId groupId, ContactId contactId,
@@ -395,7 +396,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
long time = d.getLong(TIME);
boolean local = d.getBoolean(LOCAL);
boolean read = d.getBoolean(MSG_KEY_READ, false);
boolean available = false;
boolean available = false, canBeOpened = false;
if (type == SHARE_MSG_TYPE_INVITATION) {
I msg = getIFactory().build(group.getId(), d);
@@ -407,12 +408,16 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
continue;
available = ((InviteeSessionState) s).getState() ==
AWAIT_LOCAL_RESPONSE;
if (!available) {
canBeOpened = db.containsGroup(txn,
s.getShareableId());
}
}
InvitationMessage im =
createInvitationRequest(m.getKey(), msg,
contactId, s.getShareableId(),
available, time, local, status.isSent(),
status.isSeen(), read);
available, canBeOpened, time, local,
status.isSent(), status.isSeen(), read);
list.add(im);
} else if (type == SHARE_MSG_TYPE_ACCEPT ||
type == SHARE_MSG_TYPE_DECLINE) {

View File

@@ -640,13 +640,17 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
new HashMap<MessageId, BdfDictionary>();
results.put(message.getId(), meta);
results.put(messageId2, meta2);
long time1 = 1L, time2 = 2L;
final long time1 = 1L, time2 = 2L;
final MessageMetadata messageMetadata1 =
new MessageMetadata(INVITE, privateGroup.getId(), time1, true,
true, true, true);
true, true, false);
final MessageMetadata messageMetadata2 =
new MessageMetadata(JOIN, privateGroup.getId(), time2, true,
true, true, true);
final InviteMessage invite =
new InviteMessage(message.getId(), contactGroup.getId(),
privateGroup.getId(), time1, "name", author,
new byte[0], null, new byte[0]);
context.checking(new Expectations() {{
oneOf(db).startTransaction(true);
@@ -669,6 +673,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(clientHelper).toList(message);
will(returnValue(body));
oneOf(messageParser).parseInviteMessage(message, body);
will(returnValue(invite));
oneOf(db).containsGroup(txn, privateGroup.getId());
will(returnValue(true));
// second message
oneOf(messageParser).parseMetadata(meta2);
will(returnValue(messageMetadata2));