mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Don't open unsubscribed shareables
This commit is contained in:
@@ -855,8 +855,9 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void open(ConversationRequestItem item) {
|
||||
if (item.getRequestedGroupId() == null) return;
|
||||
public void openRequestedShareable(ConversationRequestItem item) {
|
||||
if (item.getRequestedGroupId() == null)
|
||||
throw new IllegalArgumentException();
|
||||
Intent i;
|
||||
switch (item.getRequestType()) {
|
||||
case FORUM:
|
||||
|
||||
@@ -140,7 +140,7 @@ class ConversationAdapter
|
||||
|
||||
void respondToRequest(ConversationRequestItem item, boolean accept);
|
||||
|
||||
void open(ConversationRequestItem item);
|
||||
void openRequestedShareable(ConversationRequestItem item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ abstract class ConversationItem {
|
||||
return new ConversationRequestItem(ir.getMessageId(),
|
||||
ir.getGroupId(), INTRODUCTION, ir.getSessionId(), text,
|
||||
ir.getMessage(), ir.getTimestamp(), ir.isRead(), null,
|
||||
ir.wasAnswered());
|
||||
ir.wasAnswered(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,8 @@ abstract class ConversationItem {
|
||||
return new ConversationRequestItem(ir.getId(),
|
||||
ir.getGroupId(), type, ir.getSessionId(), text,
|
||||
ir.getMessage(), ir.getTimestamp(), ir.isRead(),
|
||||
ir.getInvitedGroupId(), !ir.isAvailable());
|
||||
ir.getInvitedGroupId(), !ir.isAvailable(),
|
||||
ir.canBeOpened());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,17 +21,19 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
||||
private final GroupId requestedGroupId;
|
||||
private final RequestType requestType;
|
||||
private final SessionId sessionId;
|
||||
private boolean answered;
|
||||
private final boolean answered, canBeOpened;
|
||||
|
||||
ConversationRequestItem(MessageId id, GroupId groupId,
|
||||
RequestType requestType, SessionId sessionId, String text,
|
||||
@Nullable String msgText, long time, boolean read,
|
||||
@Nullable GroupId requestedGroupId, boolean answered) {
|
||||
@Nullable GroupId requestedGroupId, boolean answered,
|
||||
boolean canBeOpened) {
|
||||
super(id, groupId, text, msgText, time, read);
|
||||
this.requestType = requestType;
|
||||
this.sessionId = sessionId;
|
||||
this.requestedGroupId = requestedGroupId;
|
||||
this.answered = answered;
|
||||
this.canBeOpened = canBeOpened;
|
||||
}
|
||||
|
||||
RequestType getRequestType() {
|
||||
@@ -51,8 +53,8 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
||||
return answered;
|
||||
}
|
||||
|
||||
void setAnswered(boolean answered) {
|
||||
this.answered = answered;
|
||||
public boolean canBeOpened() {
|
||||
return canBeOpened;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.briarproject.briar.android.contact.ConversationAdapter.ConversationLi
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.INTRODUCTION;
|
||||
|
||||
@UiThread
|
||||
@NotNullByDefault
|
||||
@@ -33,27 +32,25 @@ class ConversationRequestViewHolder extends ConversationNoticeInViewHolder {
|
||||
final ConversationRequestItem item =
|
||||
(ConversationRequestItem) conversationItem;
|
||||
|
||||
if (item.getRequestType() == INTRODUCTION && item.wasAnswered()) {
|
||||
acceptButton.setVisibility(GONE);
|
||||
declineButton.setVisibility(GONE);
|
||||
} else if (item.wasAnswered()) {
|
||||
if (item.wasAnswered() && item.canBeOpened()) {
|
||||
acceptButton.setVisibility(VISIBLE);
|
||||
acceptButton.setText(R.string.open);
|
||||
acceptButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
item.setAnswered(true);
|
||||
listener.open(item);
|
||||
listener.openRequestedShareable(item);
|
||||
}
|
||||
});
|
||||
declineButton.setVisibility(GONE);
|
||||
} else if (item.wasAnswered()) {
|
||||
acceptButton.setVisibility(GONE);
|
||||
declineButton.setVisibility(GONE);
|
||||
} else {
|
||||
acceptButton.setVisibility(VISIBLE);
|
||||
acceptButton.setText(R.string.accept);
|
||||
acceptButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
item.setAnswered(true);
|
||||
listener.respondToRequest(item, true);
|
||||
}
|
||||
});
|
||||
@@ -61,7 +58,6 @@ class ConversationRequestViewHolder extends ConversationNoticeInViewHolder {
|
||||
declineButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
item.setAnswered(true);
|
||||
listener.respondToRequest(item, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,12 +16,12 @@ public class BlogInvitationRequest extends InvitationRequest {
|
||||
|
||||
public BlogInvitationRequest(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, String blogAuthorName,
|
||||
@Nullable String message, @Nullable GroupId blogId,
|
||||
boolean available, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
@Nullable String message, GroupId blogId,
|
||||
boolean available, boolean canBeOpened, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, message, blogId, available,
|
||||
time, local, sent, seen, read);
|
||||
canBeOpened, time, local, sent, seen, read);
|
||||
this.blogAuthorName = blogAuthorName;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ public class ForumInvitationRequest extends InvitationRequest {
|
||||
public ForumInvitationRequest(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, GroupId forumId,
|
||||
String forumName, @Nullable String message, boolean available,
|
||||
long time, boolean local, boolean sent, boolean seen,
|
||||
boolean read) {
|
||||
boolean canBeOpened, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, message, forumId, available,
|
||||
time, local, sent, seen, read);
|
||||
canBeOpened, time, local, sent, seen, read);
|
||||
this.forumName = forumName;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ public class GroupInvitationRequest extends InvitationRequest {
|
||||
public GroupInvitationRequest(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, @Nullable String message,
|
||||
GroupId privateGroupId, String groupName, Author creator,
|
||||
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) {
|
||||
super(id, sessionId, groupId, contactId, message, privateGroupId,
|
||||
available, time, local, sent, seen, read);
|
||||
available, canBeOpened, time, local, sent, seen, read);
|
||||
this.groupName = groupName;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,10 @@ public abstract class InvitationMessage extends BaseMessageHeader {
|
||||
|
||||
private final SessionId sessionId;
|
||||
private final ContactId contactId;
|
||||
@Nullable
|
||||
private final GroupId invitedGroupId;
|
||||
|
||||
public InvitationMessage(MessageId id, SessionId sessionId, GroupId groupId,
|
||||
ContactId contactId, @Nullable GroupId invitedGroupId, long time,
|
||||
ContactId contactId, GroupId invitedGroupId, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, groupId, time, local, read, sent, seen);
|
||||
|
||||
@@ -15,17 +15,19 @@ public abstract class InvitationRequest extends InvitationMessage {
|
||||
|
||||
@Nullable
|
||||
private final String message;
|
||||
private final boolean available;
|
||||
private final boolean available, canBeOpened;
|
||||
|
||||
public InvitationRequest(MessageId id, SessionId sessionId, GroupId groupId,
|
||||
ContactId contactId, @Nullable String message,
|
||||
@Nullable GroupId invitedGroupId, boolean available, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
GroupId invitedGroupId, boolean available,
|
||||
boolean canBeOpened, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
super(id, sessionId, groupId, contactId, invitedGroupId, time, local,
|
||||
sent, seen, read);
|
||||
if (available && canBeOpened) throw new IllegalArgumentException();
|
||||
this.message = message;
|
||||
this.available = available;
|
||||
this.canBeOpened = canBeOpened;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -37,4 +39,8 @@ public abstract class InvitationRequest extends InvitationMessage {
|
||||
return available;
|
||||
}
|
||||
|
||||
public boolean canBeOpened() {
|
||||
return canBeOpened;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@@ -17,7 +16,7 @@ public abstract class InvitationResponse extends InvitationMessage {
|
||||
|
||||
public InvitationResponse(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId,
|
||||
@Nullable GroupId invitedGroupId, boolean accept, long time,
|
||||
GroupId invitedGroupId, boolean accept, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, invitedGroupId, time, local,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user