Merge branch '793-show-open-button-after-accepting-invitations' into 'master'

Show open button in private conversation after accepting invitations

To keep the implementation simple, the Open button does appear where the Accept button had been previously.

In order to make the Open button functional, I had to make the `GroupId` of the invitation target available to the UI. Most code in this MR is due to that.

![device-2016-12-13-105228](/uploads/d0f27fc02f1411596458d9203a0810d2/device-2016-12-13-105228.png)

Closes #793

See merge request !457
This commit is contained in:
Torsten Grote
2016-12-20 14:07:13 +00:00
24 changed files with 210 additions and 112 deletions

View File

@@ -49,8 +49,11 @@ import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.blog.BlogActivity;
import org.briarproject.briar.android.contact.ConversationAdapter.ConversationListener;
import org.briarproject.briar.android.forum.ForumActivity;
import org.briarproject.briar.android.introduction.IntroductionActivity;
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
import org.briarproject.briar.android.view.BriarRecyclerView;
import org.briarproject.briar.android.view.TextInputView;
import org.briarproject.briar.android.view.TextInputView.TextInputListener;
@@ -850,6 +853,29 @@ public class ConversationActivity extends BriarActivity
});
}
@UiThread
@Override
public void openRequestedShareable(ConversationRequestItem item) {
if (item.getRequestedGroupId() == null)
throw new IllegalArgumentException();
Intent i;
switch (item.getRequestType()) {
case FORUM:
i = new Intent(this, ForumActivity.class);
break;
case BLOG:
i = new Intent(this, BlogActivity.class);
break;
case GROUP:
i = new Intent(this, GroupActivity.class);
break;
default:
throw new IllegalArgumentException("Unknown Request Type");
}
i.putExtra(GROUP_ID, item.getRequestedGroupId().getBytes());
startActivity(i);
}
@DatabaseExecutor
private void respondToIntroductionRequest(SessionId sessionId,
boolean accept, long time) throws DbException, FormatException {

View File

@@ -139,6 +139,9 @@ class ConversationAdapter
void onItemVisible(ConversationItem item);
void respondToRequest(ConversationRequestItem item, boolean accept);
void openRequestedShareable(ConversationRequestItem item);
}
}

View File

@@ -101,9 +101,6 @@ abstract class ConversationItem {
text = ctx.getString(
R.string.introduction_request_answered_received,
contactName, ir.getName());
return new ConversationNoticeInItem(ir.getMessageId(),
ir.getGroupId(), text, ir.getMessage(), ir.getTimestamp(),
ir.isRead());
} else if (ir.contactExists()){
text = ctx.getString(
R.string.introduction_request_exists_received,
@@ -114,8 +111,8 @@ abstract class ConversationItem {
}
return new ConversationRequestItem(ir.getMessageId(),
ir.getGroupId(), INTRODUCTION, ir.getSessionId(), text,
ir.getMessage(), ir.getTimestamp(), ir.isRead(),
ir.wasAnswered());
ir.getMessage(), ir.getTimestamp(), ir.isRead(), null,
ir.wasAnswered(), false);
}
}
@@ -203,14 +200,11 @@ abstract class ConversationItem {
} else {
throw new IllegalArgumentException("Unknown InvitationRequest");
}
if (!ir.isAvailable()) {
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
text, ir.getMessage(), ir.getTimestamp(), ir.isRead());
}
return new ConversationRequestItem(ir.getId(),
ir.getGroupId(), type, ir.getSessionId(), text,
ir.getMessage(), ir.getTimestamp(), ir.isRead(),
!ir.isAvailable());
ir.getInvitedGroupId(), !ir.isAvailable(),
ir.canBeOpened());
}
}

View File

@@ -17,18 +17,23 @@ class ConversationRequestItem extends ConversationNoticeInItem {
enum RequestType { INTRODUCTION, FORUM, BLOG, GROUP }
@Nullable
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,
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() {
@@ -39,12 +44,17 @@ class ConversationRequestItem extends ConversationNoticeInItem {
return sessionId;
}
@Nullable
public GroupId getRequestedGroupId() {
return requestedGroupId;
}
boolean wasAnswered() {
return answered;
}
void setAnswered(boolean answered) {
this.answered = answered;
public boolean canBeOpened() {
return canBeOpened;
}
@LayoutRes

View File

@@ -32,15 +32,25 @@ class ConversationRequestViewHolder extends ConversationNoticeInViewHolder {
final ConversationRequestItem item =
(ConversationRequestItem) conversationItem;
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) {
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);
}
});
@@ -48,7 +58,6 @@ class ConversationRequestViewHolder extends ConversationNoticeInViewHolder {
declineButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
item.setAnswered(true);
listener.respondToRequest(item, false);
}
});

View File

@@ -43,7 +43,7 @@
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/text"
android:layout_alignRight="@+id/text"
android:layout_below="@+id/declineButton"
android:layout_below="@+id/acceptButton"
android:layout_marginTop="@dimen/message_bubble_timestamp_margin"
android:textColor="@color/private_message_date"
android:textSize="@dimen/text_size_tiny"
@@ -57,6 +57,7 @@
android:layout_alignEnd="@+id/text"
android:layout_alignRight="@+id/text"
android:layout_below="@+id/text"
android:layout_marginBottom="-10dp"
android:text="@string/accept"/>
<Button
@@ -64,8 +65,8 @@
style="@style/BriarButtonFlat.Negative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginBottom="-15dp"
android:layout_alignBottom="@+id/acceptButton"
android:layout_alignTop="@+id/acceptButton"
android:layout_toLeftOf="@+id/acceptButton"
android:layout_toStartOf="@+id/acceptButton"
android:text="@string/decline"/>

View File

@@ -77,6 +77,7 @@
<string name="offline">Offline</string>
<string name="send">Send</string>
<string name="allow">Allow</string>
<string name="open">Open</string>
<string name="no_data">No data</string>
<string name="ellipsis"></string>
<string name="text_too_long">The entered text is too long</string>
@@ -182,8 +183,8 @@
<!-- Private Group Invitations -->
<string name="groups_invitations_title">Group Invitations</string>
<string name="groups_invitations_invitation_sent">You have invited %1$s to join the group "%2$s".</string>
<string name="groups_invitations_invitation_received">%1$s has invited you to join the group "%2$s".</string>
<string name="groups_invitations_invitation_sent">You have invited %1$s to join the group \"%2$s\".</string>
<string name="groups_invitations_invitation_received">%1$s has invited you to join the group \"%2$s\".</string>
<string name="groups_invitations_joined">Joined group</string>
<string name="groups_invitations_declined">Group invitation declined</string>
<plurals name="groups_invitations_open">

View File

@@ -37,13 +37,11 @@
<style name="BriarButtonFlat.Negative" parent="Widget.AppCompat.Button.Borderless">
<item name="android:textColor">@color/briar_button_negative</item>
<item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:padding">@dimen/margin_large</item>
</style>
<style name="BriarButtonFlat.Positive" parent="Widget.AppCompat.Button.Borderless">
<item name="android:textColor">@color/briar_button_positive</item>
<item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:padding">@dimen/margin_large</item>
</style>
<style name="BriarButtonFlat.Positive.Tiny" parent="BriarButtonFlat.Positive">

View File

@@ -16,11 +16,12 @@ public class BlogInvitationRequest extends InvitationRequest {
public BlogInvitationRequest(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, String blogAuthorName,
@Nullable String message, boolean available, long time,
@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, available, time,
local, sent, seen, read);
super(id, sessionId, groupId, contactId, message, blogId, available,
canBeOpened, time, local, sent, seen, read);
this.blogAuthorName = blogAuthorName;
}

View File

@@ -11,11 +11,12 @@ import org.briarproject.briar.api.sharing.InvitationResponse;
public class BlogInvitationResponse extends InvitationResponse {
public BlogInvitationResponse(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) {
GroupId groupId, ContactId contactId, GroupId blogId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, accept, time, local, sent,
seen, read);
super(id, sessionId, groupId, contactId, blogId, accept, time, local,
sent, seen, read);
}
}

View File

@@ -17,12 +17,13 @@ public class ForumInvitationRequest extends InvitationRequest {
private final String forumName;
public ForumInvitationRequest(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, String forumName,
@Nullable String message, boolean available, long time,
boolean local, boolean sent, boolean seen, boolean read) {
GroupId groupId, ContactId contactId, GroupId forumId,
String forumName, @Nullable String message, boolean available,
boolean canBeOpened, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, message, available, time,
local, sent, seen, read);
super(id, sessionId, groupId, contactId, message, forumId, available,
canBeOpened, time, local, sent, seen, read);
this.forumName = forumName;
}

View File

@@ -14,11 +14,12 @@ import javax.annotation.concurrent.Immutable;
public class ForumInvitationResponse extends InvitationResponse {
public ForumInvitationResponse(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) {
GroupId groupId, ContactId contactId, GroupId forumId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, accept, time, local, sent,
seen, read);
super(id, sessionId, groupId, contactId, forumId, accept, time, local,
sent, seen, read);
}
}

View File

@@ -20,10 +20,11 @@ public class GroupInvitationRequest extends InvitationRequest {
public GroupInvitationRequest(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, @Nullable String message,
String groupName, Author creator, boolean available, long time,
GroupId privateGroupId, String groupName, Author creator,
boolean available, boolean canBeOpened, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, message, available, time,
local, sent, seen, read);
super(id, sessionId, groupId, contactId, message, privateGroupId,
available, canBeOpened, time, local, sent, seen, read);
this.groupName = groupName;
this.creator = creator;
}

View File

@@ -14,9 +14,10 @@ import javax.annotation.concurrent.Immutable;
public class GroupInvitationResponse extends InvitationResponse {
public GroupInvitationResponse(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, accept, time, local, sent,
seen, read);
GroupId groupId, ContactId contactId, GroupId privateGroupId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, privateGroupId, accept, time,
local, sent, seen, read);
}
}

View File

@@ -7,6 +7,7 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.BaseMessageHeader;
import org.briarproject.briar.api.client.SessionId;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@Immutable
@@ -15,14 +16,16 @@ public abstract class InvitationMessage extends BaseMessageHeader {
private final SessionId sessionId;
private final ContactId contactId;
private final GroupId invitedGroupId;
public InvitationMessage(MessageId id, SessionId sessionId, GroupId groupId,
ContactId contactId, long time, boolean local, boolean sent,
boolean seen, boolean read) {
ContactId contactId, GroupId invitedGroupId, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, groupId, time, local, read, sent, seen);
this.sessionId = sessionId;
this.contactId = contactId;
this.invitedGroupId = invitedGroupId;
}
public SessionId getSessionId() {
@@ -33,4 +36,9 @@ public abstract class InvitationMessage extends BaseMessageHeader {
return contactId;
}
@Nullable
public GroupId getInvitedGroupId() {
return invitedGroupId;
}
}

View File

@@ -15,16 +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, boolean available,
long time, boolean local, boolean sent, boolean seen,
boolean read) {
super(id, sessionId, groupId, contactId, time, local, sent, seen, read);
ContactId contactId, @Nullable String message,
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
@@ -36,4 +39,8 @@ public abstract class InvitationRequest extends InvitationMessage {
return available;
}
public boolean canBeOpened() {
return canBeOpened;
}
}

View File

@@ -15,10 +15,12 @@ public abstract class InvitationResponse extends InvitationMessage {
private final boolean accept;
public InvitationResponse(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time,
GroupId groupId, ContactId contactId,
GroupId invitedGroupId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, time, local, sent, seen, read);
super(id, sessionId, groupId, contactId, invitedGroupId, time, local,
sent, seen, read);
this.accept = accept;
}

View File

@@ -255,7 +255,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
GroupInvitationMessage m, ContactId c, boolean accept) {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationResponse(m.getId(), sessionId,
m.getPrivateGroupId(), c, accept, m.getTimestamp(), false,
false, true, false);
m.getContactGroupId(), c, m.getPrivateGroupId(), accept,
m.getTimestamp(), false, false, true, false);
}
}

View File

@@ -381,10 +381,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
m, meta, status));
} else if (type == JOIN) {
messages.add(
parseInvitationResponse(c, m, meta, status, true));
parseInvitationResponse(c, contactGroupId, m, meta,
status, true));
} else if (type == LEAVE) {
messages.add(
parseInvitationResponse(c, m, meta, status, false));
parseInvitationResponse(c, contactGroupId, m, meta,
status, false));
}
}
db.commitTransaction(txn);
@@ -403,10 +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.getGroupName(), invite.getCreator(),
meta.isAvailableToAnswer(), meta.getTimestamp(), meta.isLocal(),
status.isSent(), status.isSeen(), meta.isRead());
invite.getMessage(), invite.getPrivateGroupId(),
invite.getGroupName(), invite.getCreator(),
meta.isAvailableToAnswer(), canBeOpened, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(),
meta.isRead());
}
private InviteMessage getInviteMessage(Transaction txn, MessageId m)
@@ -418,11 +423,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
}
private GroupInvitationResponse parseInvitationResponse(ContactId c,
MessageId m, MessageMetadata meta, MessageStatus status,
boolean accept) throws DbException, FormatException {
GroupId contactGroupId, MessageId m, MessageMetadata meta,
MessageStatus status, boolean accept)
throws DbException, FormatException {
SessionId sessionId = getSessionId(meta.getPrivateGroupId());
return new GroupInvitationResponse(m, sessionId,
meta.getPrivateGroupId(), c, accept, meta.getTimestamp(),
return new GroupInvitationResponse(m, sessionId, contactGroupId, c,
meta.getPrivateGroupId(), accept, meta.getTimestamp(),
meta.isLocal(), status.isSent(), status.isSeen(),
meta.isRead());
}

View File

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

View File

@@ -40,6 +40,7 @@ import org.briarproject.briar.api.sharing.InvitationMessage;
import java.security.SecureRandom;
import java.util.Collection;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
@@ -133,21 +134,23 @@ class BlogSharingManagerImpl extends
@Override
protected InvitationMessage createInvitationRequest(MessageId id,
BlogInvitation msg, ContactId contactId, boolean available,
long time, boolean local, boolean sent, boolean seen,
boolean read) {
BlogInvitation msg, ContactId contactId, GroupId blogId,
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(), available, time, local, sent, seen, read);
msg.getMessage(), blogId, available, canBeOpened, time, local,
sent, seen, read);
}
@Override
protected InvitationMessage createInvitationResponse(MessageId id,
SessionId sessionId, GroupId groupId, ContactId contactId,
boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) {
GroupId blogId, boolean accept, long time, boolean local,
boolean sent, boolean seen, boolean read) {
return new BlogInvitationResponse(id, sessionId, groupId, contactId,
accept, time, local, sent, seen, read);
blogId, accept, time, local, sent, seen, read);
}
@Override
@@ -333,14 +336,17 @@ class BlogSharingManagerImpl extends
@Override
public BlogInvitationRequestReceivedEvent build(
BlogInviteeSessionState localState, long time, String msg) {
BlogInviteeSessionState localState, long time,
@Nullable String msg) {
Blog blog = sFactory.parse(localState);
ContactId contactId = localState.getContactId();
BlogInvitationRequest request =
new BlogInvitationRequest(localState.getInvitationId(),
localState.getSessionId(), localState.getContactGroupId(),
contactId, blog.getAuthor().getName(), msg, true,
time, false, false, false, false);
localState.getSessionId(),
localState.getContactGroupId(), contactId,
blog.getAuthor().getName(), msg,
localState.getShareableId(), true, false, time,
false, false, false, false);
return new BlogInvitationRequestReceivedEvent(blog, contactId,
request);
}
@@ -358,8 +364,9 @@ class BlogSharingManagerImpl extends
BlogInvitationResponse response =
new BlogInvitationResponse(responseId,
localState.getSessionId(),
localState.getShareableId(),
localState.getContactId(), accept, time, false,
localState.getContactGroupId(),
localState.getContactId(),
localState.getShareableId(), accept, time, false,
false, false, false);
return new BlogInvitationResponseReceivedEvent(c, response);
}

View File

@@ -33,6 +33,7 @@ import org.briarproject.briar.api.sharing.InvitationMessage;
import java.security.SecureRandom;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_NAME;
@@ -81,21 +82,22 @@ class ForumSharingManagerImpl extends
@Override
protected InvitationMessage createInvitationRequest(MessageId id,
ForumInvitation msg, ContactId contactId, boolean available,
long time, boolean local, boolean sent, boolean seen,
boolean read) {
ForumInvitation msg, ContactId contactId, GroupId forumId,
boolean available, boolean canBeOpened, long time,
boolean local, boolean sent, boolean seen, boolean read) {
return new ForumInvitationRequest(id, msg.getSessionId(),
msg.getGroupId(), contactId, msg.getForumName(),
msg.getMessage(), available, time, local, sent, seen, read);
msg.getGroupId(), contactId, forumId, msg.getForumName(),
msg.getMessage(), available, canBeOpened, time, local, sent,
seen, read);
}
@Override
protected InvitationMessage createInvitationResponse(MessageId id,
SessionId sessionId, GroupId groupId, ContactId contactId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read) {
GroupId forumId, boolean accept, long time, boolean local,
boolean sent, boolean seen, boolean read) {
return new ForumInvitationResponse(id, sessionId, groupId, contactId,
accept, time, local, sent, seen, read);
forumId, accept, time, local, sent, seen, read);
}
@Override
@@ -263,13 +265,15 @@ class ForumSharingManagerImpl extends
@Override
public ForumInvitationRequestReceivedEvent build(
ForumInviteeSessionState localState, long time, String msg) {
ForumInviteeSessionState localState, long time,
@Nullable String msg) {
Forum forum = sFactory.parse(localState);
ContactId contactId = localState.getContactId();
ForumInvitationRequest request = new ForumInvitationRequest(
localState.getInvitationId(), localState.getSessionId(),
localState.getContactGroupId(), contactId, forum.getName(), msg,
true, time, false, false, false, false);
localState.getContactGroupId(), contactId,
localState.getShareableId(), forum.getName(), msg, true,
false, time, false, false, false, false);
return new ForumInvitationRequestReceivedEvent(forum, contactId,
request);
}
@@ -287,8 +291,9 @@ class ForumSharingManagerImpl extends
throw new IllegalStateException("No responseId");
ForumInvitationResponse response = new ForumInvitationResponse(
responseId, localState.getSessionId(),
localState.getShareableId(), localState.getContactId(),
accept, time, false, false, false, false);
localState.getContactGroupId(), localState.getContactId(),
localState.getShareableId(), accept, time, false, false,
false, false);
return new ForumInvitationResponseReceivedEvent(name, c, response);
}
}

View File

@@ -125,13 +125,14 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
protected abstract ClientId getClientId();
protected abstract InvitationMessage createInvitationRequest(MessageId id,
I msg, ContactId contactId, boolean available, long time,
boolean local, boolean sent, boolean seen, boolean read);
I msg, ContactId contactId, GroupId shareableId, boolean available,
boolean canBeOpened, long time, boolean local, boolean sent,
boolean seen, boolean read);
protected abstract InvitationMessage createInvitationResponse(MessageId id,
SessionId sessionId, GroupId groupId, ContactId contactId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read);
GroupId shareableId, boolean accept, long time, boolean local,
boolean sent, boolean seen, boolean read);
protected abstract ShareableFactory<S, I, IS, SS> getSFactory();
@@ -391,26 +392,31 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
try {
MessageStatus status =
db.getMessageStatus(txn, contactId, m.getKey());
SharingSessionState s;
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);
SessionId sessionId = msg.getSessionId();
s = getSessionState(txn, sessionId, true);
if (!local) {
// figure out whether the shareable is still available
SharingSessionState s =
getSessionState(txn, msg.getSessionId(),
true);
if (!(s instanceof InviteeSessionState))
continue;
available = ((InviteeSessionState) s).getState() ==
AWAIT_LOCAL_RESPONSE;
if (!available) {
canBeOpened = db.containsGroup(txn,
s.getShareableId());
}
}
InvitationMessage im =
createInvitationRequest(m.getKey(), msg,
contactId, available, time, local,
contactId, s.getShareableId(),
available, canBeOpened, time, local,
status.isSent(), status.isSeen(), read);
list.add(im);
} else if (type == SHARE_MSG_TYPE_ACCEPT ||
@@ -419,10 +425,12 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
BaseMessage msg = BaseMessage
.from(getIFactory(), group.getId(), d);
SessionId sessionId = msg.getSessionId();
InvitationMessage im = createInvitationResponse(
m.getKey(), sessionId, group.getId(), contactId,
accept, time, local, status.isSent(),
status.isSeen(), read);
s = getSessionState(txn, sessionId, true);
InvitationMessage im =
createInvitationResponse(m.getKey(), sessionId,
group.getId(), contactId,
s.getShareableId(), accept, time, local,
status.isSent(), status.isSeen(), read);
list.add(im);
} else {
throw new RuntimeException("Unexpected Message Type");

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));