mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Refactor ConversationItem creation
This commit is contained in:
@@ -256,7 +256,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
int position = adapter.findItemPosition(c);
|
int position = adapter.findItemPosition(c);
|
||||||
ContactListItem item = adapter.getItemAt(position);
|
ContactListItem item = adapter.getItemAt(position);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
ConversationItem i = ConversationItem.from(getContext(), h);
|
ConversationItem i = ConversationItem.from(getContext(), "", h);
|
||||||
item.addMessage(i);
|
item.addMessage(i);
|
||||||
adapter.updateItemAt(position, item);
|
adapter.updateItemAt(position, item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ import org.briarproject.briar.api.client.ProtocolStateException;
|
|||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||||
import org.briarproject.briar.api.introduction.IntroductionManager;
|
import org.briarproject.briar.api.introduction.IntroductionManager;
|
||||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
|
||||||
import org.briarproject.briar.api.messaging.ConversationManager;
|
import org.briarproject.briar.api.messaging.ConversationManager;
|
||||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||||
@@ -365,15 +364,8 @@ public class ConversationActivity extends BriarActivity
|
|||||||
List<ConversationItem> items = new ArrayList<>(headers.size());
|
List<ConversationItem> items = new ArrayList<>(headers.size());
|
||||||
for (PrivateMessageHeader h : headers) {
|
for (PrivateMessageHeader h : headers) {
|
||||||
ConversationItem item;
|
ConversationItem item;
|
||||||
if (h instanceof IntroductionResponse) {
|
if (h instanceof PrivateRequest || h instanceof PrivateResponse) {
|
||||||
IntroductionResponse i = (IntroductionResponse) h;
|
item = ConversationItem.from(this, contactName.getValue(), h);
|
||||||
item = ConversationItem.from(this, contactName.getValue(), i);
|
|
||||||
} else if (h instanceof PrivateRequest) {
|
|
||||||
PrivateRequest r = (PrivateRequest) h;
|
|
||||||
item = ConversationItem.from(this, contactName.getValue(), r);
|
|
||||||
} else if (h instanceof PrivateResponse) {
|
|
||||||
PrivateResponse r = (PrivateResponse) h;
|
|
||||||
item = ConversationItem.from(this, contactName.getValue(), r);
|
|
||||||
} else {
|
} else {
|
||||||
item = ConversationItem.from(h);
|
item = ConversationItem.from(h);
|
||||||
String body = bodyCache.get(h.getId());
|
String body = bodyCache.get(h.getId());
|
||||||
@@ -703,7 +695,7 @@ public class ConversationActivity extends BriarActivity
|
|||||||
@UiThread
|
@UiThread
|
||||||
@Override
|
@Override
|
||||||
public void respondToRequest(ConversationRequestItem item, boolean accept) {
|
public void respondToRequest(ConversationRequestItem item, boolean accept) {
|
||||||
item.setAnswered(true);
|
item.setAnswered();
|
||||||
int position = adapter.findItemPosition(item);
|
int position = adapter.findItemPosition(item);
|
||||||
if (position != INVALID_POSITION) {
|
if (position != INVALID_POSITION) {
|
||||||
adapter.notifyItemChanged(position, item);
|
adapter.notifyItemChanged(position, item);
|
||||||
|
|||||||
@@ -2,34 +2,17 @@ package org.briarproject.briar.android.contact;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
import android.support.annotation.StringRes;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.contact.ConversationRequestItem.RequestType;
|
|
||||||
import org.briarproject.briar.api.blog.BlogInvitationRequest;
|
|
||||||
import org.briarproject.briar.api.blog.BlogInvitationResponse;
|
|
||||||
import org.briarproject.briar.api.forum.ForumInvitationRequest;
|
|
||||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
|
||||||
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
|
||||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
|
||||||
import org.briarproject.briar.api.sharing.Shareable;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.BLOG;
|
|
||||||
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.FORUM;
|
|
||||||
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.GROUP;
|
|
||||||
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.INTRODUCTION;
|
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
abstract class ConversationItem {
|
abstract class ConversationItem {
|
||||||
@@ -89,190 +72,37 @@ abstract class ConversationItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ConversationItem from(Context ctx, String contactName,
|
static ConversationItem from(Context ctx, String contactName,
|
||||||
PrivateRequest ir) {
|
PrivateMessageHeader h) {
|
||||||
if (ir.isLocal()) {
|
if (h.isLocal()) {
|
||||||
String text;
|
return fromLocal(ctx, contactName, h);
|
||||||
if (ir instanceof IntroductionRequest) {
|
|
||||||
text = ctx.getString(R.string.introduction_request_sent,
|
|
||||||
contactName, ir.getName());
|
|
||||||
} else if (ir instanceof ForumInvitationRequest) {
|
|
||||||
text = ctx.getString(R.string.forum_invitation_sent,
|
|
||||||
ir.getName(), contactName);
|
|
||||||
} else if (ir instanceof BlogInvitationRequest) {
|
|
||||||
text = ctx.getString(R.string.blogs_sharing_invitation_sent,
|
|
||||||
ir.getName(), contactName);
|
|
||||||
} else if (ir instanceof GroupInvitationRequest) {
|
|
||||||
text = ctx.getString(
|
|
||||||
R.string.groups_invitations_invitation_sent,
|
|
||||||
contactName, ir.getName());
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unknown PrivateRequest");
|
|
||||||
}
|
|
||||||
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
|
|
||||||
text, ir.getMessage(), ir.getTimestamp(), ir.isSent(),
|
|
||||||
ir.isSeen());
|
|
||||||
} else {
|
} else {
|
||||||
String text;
|
return fromRemote(ctx, contactName, h);
|
||||||
RequestType type;
|
|
||||||
boolean canBeOpened;
|
|
||||||
if (ir instanceof IntroductionRequest) {
|
|
||||||
type = INTRODUCTION;
|
|
||||||
if (ir.wasAnswered()) {
|
|
||||||
text = ctx.getString(
|
|
||||||
R.string.introduction_request_answered_received,
|
|
||||||
contactName, ir.getName());
|
|
||||||
} else if (((IntroductionRequest) ir).isContact()) {
|
|
||||||
text = ctx.getString(
|
|
||||||
R.string.introduction_request_exists_received,
|
|
||||||
contactName, ir.getName());
|
|
||||||
} else {
|
|
||||||
text = ctx.getString(R.string.introduction_request_received,
|
|
||||||
contactName, ir.getName());
|
|
||||||
}
|
|
||||||
return new ConversationRequestItem(ir.getId(),
|
|
||||||
ir.getGroupId(), type, ir.getSessionId(), text,
|
|
||||||
ir.getMessage(), ir.getTimestamp(), ir.isRead(), null,
|
|
||||||
ir.wasAnswered(), false);
|
|
||||||
} else if (ir instanceof ForumInvitationRequest) {
|
|
||||||
text = ctx.getString(R.string.forum_invitation_received,
|
|
||||||
contactName, ir.getName());
|
|
||||||
type = FORUM;
|
|
||||||
canBeOpened = ((ForumInvitationRequest) ir).canBeOpened();
|
|
||||||
} else if (ir instanceof BlogInvitationRequest) {
|
|
||||||
text = ctx.getString(R.string.blogs_sharing_invitation_received,
|
|
||||||
contactName, ir.getName());
|
|
||||||
type = BLOG;
|
|
||||||
canBeOpened = ((BlogInvitationRequest) ir).canBeOpened();
|
|
||||||
} else if (ir instanceof GroupInvitationRequest) {
|
|
||||||
text = ctx.getString(
|
|
||||||
R.string.groups_invitations_invitation_received,
|
|
||||||
contactName, ir.getName());
|
|
||||||
type = GROUP;
|
|
||||||
canBeOpened = ((GroupInvitationRequest) ir).canBeOpened();
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unknown PrivateRequest");
|
|
||||||
}
|
|
||||||
return new ConversationRequestItem(ir.getId(),
|
|
||||||
ir.getGroupId(), type, ir.getSessionId(), text,
|
|
||||||
ir.getMessage(), ir.getTimestamp(), ir.isRead(),
|
|
||||||
((Shareable) ir.getNameable()).getId(), !ir.wasAnswered(),
|
|
||||||
canBeOpened);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConversationItem from(Context ctx, String contactName,
|
private static ConversationItem fromLocal(Context ctx, String contactName,
|
||||||
IntroductionResponse ir) {
|
PrivateMessageHeader h) {
|
||||||
if (ir.isLocal()) {
|
if (h instanceof PrivateRequest) {
|
||||||
String text;
|
PrivateRequest r = (PrivateRequest) h;
|
||||||
if (ir.wasAccepted()) {
|
return new ConversationNoticeOutItem(ctx, contactName, r);
|
||||||
text = ctx.getString(
|
|
||||||
R.string.introduction_response_accepted_sent,
|
|
||||||
ir.getIntroducedAuthor().getName());
|
|
||||||
text += "\n\n" + ctx.getString(
|
|
||||||
R.string.introduction_response_accepted_sent_info,
|
|
||||||
ir.getIntroducedAuthor().getName());
|
|
||||||
} else {
|
|
||||||
text = ctx.getString(
|
|
||||||
R.string.introduction_response_declined_sent,
|
|
||||||
ir.getIntroducedAuthor().getName());
|
|
||||||
}
|
|
||||||
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
|
|
||||||
text, null, ir.getTimestamp(), ir.isSent(), ir.isSeen());
|
|
||||||
} else {
|
|
||||||
@StringRes int res;
|
|
||||||
if (ir.wasAccepted()) {
|
|
||||||
res = R.string.introduction_response_accepted_received;
|
|
||||||
} else {
|
|
||||||
if (ir.isIntroducer()) {
|
|
||||||
res = R.string.introduction_response_declined_received;
|
|
||||||
} else {
|
|
||||||
res =
|
|
||||||
R.string.introduction_response_declined_received_by_introducee;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String text =
|
|
||||||
ctx.getString(res, contactName, ir.getIntroducedAuthor().getName());
|
|
||||||
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
|
|
||||||
text, null, ir.getTimestamp(), ir.isRead());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ConversationItem from(Context ctx, String contactName,
|
|
||||||
PrivateResponse ir) {
|
|
||||||
@StringRes int res;
|
|
||||||
if (ir.isLocal()) {
|
|
||||||
if (ir.wasAccepted()) {
|
|
||||||
if (ir instanceof ForumInvitationResponse) {
|
|
||||||
res = R.string.forum_invitation_response_accepted_sent;
|
|
||||||
} else if (ir instanceof BlogInvitationResponse) {
|
|
||||||
res = R.string.blogs_sharing_response_accepted_sent;
|
|
||||||
} else if (ir instanceof GroupInvitationResponse) {
|
|
||||||
res = R.string.groups_invitations_response_accepted_sent;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Unknown PrivateResponse");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (ir instanceof ForumInvitationResponse) {
|
|
||||||
res = R.string.forum_invitation_response_declined_sent;
|
|
||||||
} else if (ir instanceof BlogInvitationResponse) {
|
|
||||||
res = R.string.blogs_sharing_response_declined_sent;
|
|
||||||
} else if (ir instanceof GroupInvitationResponse) {
|
|
||||||
res = R.string.groups_invitations_response_declined_sent;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Unknown PrivateResponse");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String text = ctx.getString(res, contactName);
|
|
||||||
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
|
|
||||||
text, null, ir.getTimestamp(), ir.isSent(), ir.isSeen());
|
|
||||||
} else {
|
|
||||||
if (ir.wasAccepted()) {
|
|
||||||
if (ir instanceof ForumInvitationResponse) {
|
|
||||||
res = R.string.forum_invitation_response_accepted_received;
|
|
||||||
} else if (ir instanceof BlogInvitationResponse) {
|
|
||||||
res = R.string.blogs_sharing_response_accepted_received;
|
|
||||||
} else if (ir instanceof GroupInvitationResponse) {
|
|
||||||
res =
|
|
||||||
R.string.groups_invitations_response_accepted_received;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Unknown PrivateResponse");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (ir instanceof ForumInvitationResponse) {
|
|
||||||
res = R.string.forum_invitation_response_declined_received;
|
|
||||||
} else if (ir instanceof BlogInvitationResponse) {
|
|
||||||
res = R.string.blogs_sharing_response_declined_received;
|
|
||||||
} else if (ir instanceof GroupInvitationResponse) {
|
|
||||||
res =
|
|
||||||
R.string.groups_invitations_response_declined_received;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Unknown PrivateResponse");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String text = ctx.getString(res, contactName);
|
|
||||||
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
|
|
||||||
text, null, ir.getTimestamp(), ir.isRead());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method should not be used to display the resulting ConversationItem
|
|
||||||
* in the UI, but only to update list information based on the
|
|
||||||
* PrivateMessageHeader.
|
|
||||||
**/
|
|
||||||
static ConversationItem from(Context ctx, PrivateMessageHeader h) {
|
|
||||||
if (h instanceof IntroductionResponse) {
|
|
||||||
return from(ctx, "", (IntroductionResponse) h);
|
|
||||||
} else if (h instanceof PrivateRequest) {
|
|
||||||
return from(ctx, "", (PrivateRequest) h);
|
|
||||||
} else if (h instanceof PrivateResponse) {
|
} else if (h instanceof PrivateResponse) {
|
||||||
return from(ctx, "", (PrivateResponse) h);
|
PrivateResponse r = (PrivateResponse) h;
|
||||||
|
return new ConversationNoticeOutItem(ctx, contactName, r);
|
||||||
} else {
|
} else {
|
||||||
return from(h);
|
return new ConversationMessageOutItem(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ConversationItem fromRemote(Context ctx, String contactName,
|
||||||
|
PrivateMessageHeader h) {
|
||||||
|
if (h instanceof PrivateRequest) {
|
||||||
|
PrivateRequest r = (PrivateRequest) h;
|
||||||
|
return new ConversationRequestItem(ctx, contactName, r);
|
||||||
|
} else if (h instanceof PrivateResponse) {
|
||||||
|
PrivateResponse r = (PrivateResponse) h;
|
||||||
|
return new ConversationNoticeInItem(ctx, contactName, r);
|
||||||
|
} else {
|
||||||
|
return new ConversationMessageInItem(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.api.blog.BlogInvitationResponse;
|
||||||
|
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||||
|
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||||
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
@@ -24,6 +31,13 @@ class ConversationNoticeInItem extends ConversationItem {
|
|||||||
this.msgText = msgText;
|
this.msgText = msgText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConversationNoticeInItem(Context ctx, String contactName,
|
||||||
|
PrivateResponse r) {
|
||||||
|
super(r.getId(), r.getGroupId(), getText(ctx, contactName, r),
|
||||||
|
r.getTimestamp(), r.isRead());
|
||||||
|
this.msgText = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
String getMsgText() {
|
String getMsgText() {
|
||||||
return msgText;
|
return msgText;
|
||||||
@@ -40,4 +54,54 @@ class ConversationNoticeInItem extends ConversationItem {
|
|||||||
return R.layout.list_item_conversation_notice_in;
|
return R.layout.list_item_conversation_notice_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getText(Context ctx, String contactName,
|
||||||
|
PrivateResponse r) {
|
||||||
|
if (r.wasAccepted()) {
|
||||||
|
if (r instanceof IntroductionResponse) {
|
||||||
|
IntroductionResponse ir = (IntroductionResponse) r;
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.introduction_response_accepted_received,
|
||||||
|
contactName, ir.getIntroducedAuthor().getName());
|
||||||
|
} else if (r instanceof ForumInvitationResponse) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.forum_invitation_response_accepted_received,
|
||||||
|
contactName);
|
||||||
|
} else if (r instanceof BlogInvitationResponse) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.blogs_sharing_response_accepted_received,
|
||||||
|
contactName);
|
||||||
|
} else if (r instanceof GroupInvitationResponse) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.groups_invitations_response_accepted_received,
|
||||||
|
contactName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (r instanceof IntroductionResponse) {
|
||||||
|
IntroductionResponse ir = (IntroductionResponse) r;
|
||||||
|
@StringRes int res;
|
||||||
|
if (ir.isIntroducer()) {
|
||||||
|
res = R.string.introduction_response_declined_received;
|
||||||
|
} else {
|
||||||
|
res =
|
||||||
|
R.string.introduction_response_declined_received_by_introducee;
|
||||||
|
}
|
||||||
|
return ctx.getString(res, contactName,
|
||||||
|
ir.getIntroducedAuthor().getName());
|
||||||
|
} else if (r instanceof ForumInvitationResponse) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.forum_invitation_response_declined_received,
|
||||||
|
contactName);
|
||||||
|
} else if (r instanceof BlogInvitationResponse) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.blogs_sharing_response_declined_received,
|
||||||
|
contactName);
|
||||||
|
} else if (r instanceof GroupInvitationResponse) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.groups_invitations_response_declined_received,
|
||||||
|
contactName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown PrivateResponse");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
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.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.api.blog.BlogInvitationRequest;
|
||||||
|
import org.briarproject.briar.api.blog.BlogInvitationResponse;
|
||||||
|
import org.briarproject.briar.api.forum.ForumInvitationRequest;
|
||||||
|
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||||
|
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||||
|
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||||
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||||
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
@@ -17,11 +26,18 @@ class ConversationNoticeOutItem extends ConversationOutItem {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final String msgText;
|
private final String msgText;
|
||||||
|
|
||||||
ConversationNoticeOutItem(MessageId id, GroupId groupId,
|
ConversationNoticeOutItem(Context ctx, String contactName,
|
||||||
String text, @Nullable String msgText, long time,
|
PrivateRequest r) {
|
||||||
boolean sent, boolean seen) {
|
super(r.getId(), r.getGroupId(), getText(ctx, contactName, r),
|
||||||
super(id, groupId, text, time, sent, seen);
|
r.getTimestamp(), r.isSent(), r.isSeen());
|
||||||
this.msgText = msgText;
|
this.msgText = r.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConversationNoticeOutItem(Context ctx, String contactName,
|
||||||
|
PrivateResponse r) {
|
||||||
|
super(r.getId(), r.getGroupId(), getText(ctx, contactName, r),
|
||||||
|
r.getTimestamp(), r.isSent(), r.isSeen());
|
||||||
|
this.msgText = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -35,4 +51,57 @@ class ConversationNoticeOutItem extends ConversationOutItem {
|
|||||||
return R.layout.list_item_conversation_notice_out;
|
return R.layout.list_item_conversation_notice_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getText(Context ctx, String contactName,
|
||||||
|
PrivateRequest r) {
|
||||||
|
if (r instanceof IntroductionRequest) {
|
||||||
|
return ctx.getString(R.string.introduction_request_sent,
|
||||||
|
contactName, r.getName());
|
||||||
|
} else if (r instanceof ForumInvitationRequest) {
|
||||||
|
return ctx.getString(R.string.forum_invitation_sent,
|
||||||
|
r.getName(), contactName);
|
||||||
|
} else if (r instanceof BlogInvitationRequest) {
|
||||||
|
return ctx.getString(R.string.blogs_sharing_invitation_sent,
|
||||||
|
r.getName(), contactName);
|
||||||
|
} else if (r instanceof GroupInvitationRequest) {
|
||||||
|
return ctx.getString(R.string.groups_invitations_invitation_sent,
|
||||||
|
contactName, r.getName());
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getText(Context ctx, String contactName,
|
||||||
|
PrivateResponse ir) {
|
||||||
|
if (ir.wasAccepted()) {
|
||||||
|
if (ir instanceof IntroductionResponse) {
|
||||||
|
String name = ((IntroductionResponse) ir).getIntroducedAuthor()
|
||||||
|
.getName();
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.introduction_response_accepted_sent,
|
||||||
|
name) + "\n\n" + ctx.getString(
|
||||||
|
R.string.introduction_response_accepted_sent_info,
|
||||||
|
name);
|
||||||
|
} else if (ir instanceof ForumInvitationResponse) {
|
||||||
|
return ctx.getString(R.string.forum_invitation_response_accepted_sent, contactName);
|
||||||
|
} else if (ir instanceof BlogInvitationResponse) {
|
||||||
|
return ctx.getString(R.string.blogs_sharing_response_accepted_sent, contactName);
|
||||||
|
} else if (ir instanceof GroupInvitationResponse) {
|
||||||
|
return ctx.getString(R.string.groups_invitations_response_accepted_sent, contactName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ir instanceof IntroductionResponse) {
|
||||||
|
String name = ((IntroductionResponse) ir).getIntroducedAuthor()
|
||||||
|
.getName();
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.introduction_response_declined_sent, name);
|
||||||
|
} else if (ir instanceof ForumInvitationResponse) {
|
||||||
|
return ctx.getString(R.string.forum_invitation_response_declined_sent, contactName);
|
||||||
|
} else if (ir instanceof BlogInvitationResponse) {
|
||||||
|
return ctx.getString(R.string.blogs_sharing_response_declined_sent, contactName);
|
||||||
|
} else if (ir instanceof GroupInvitationResponse) {
|
||||||
|
return ctx.getString(R.string.groups_invitations_response_declined_sent, contactName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown PrivateResponse");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.api.blog.BlogInvitationRequest;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
|
import org.briarproject.briar.api.forum.ForumInvitationRequest;
|
||||||
|
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||||
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||||
|
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||||
|
import org.briarproject.briar.api.sharing.Shareable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.BLOG;
|
||||||
|
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.FORUM;
|
||||||
|
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.GROUP;
|
||||||
|
import static org.briarproject.briar.android.contact.ConversationRequestItem.RequestType.INTRODUCTION;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ConversationRequestItem extends ConversationNoticeInItem {
|
class ConversationRequestItem extends ConversationNoticeInItem {
|
||||||
@@ -24,17 +36,20 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
|||||||
private final boolean canBeOpened;
|
private final boolean canBeOpened;
|
||||||
private boolean answered;
|
private boolean answered;
|
||||||
|
|
||||||
ConversationRequestItem(MessageId id, GroupId groupId,
|
ConversationRequestItem(Context ctx, String contactName,
|
||||||
RequestType requestType, SessionId sessionId, String text,
|
PrivateRequest r) {
|
||||||
@Nullable String msgText, long time, boolean read,
|
super(r.getId(), r.getGroupId(), getText(ctx, contactName, r),
|
||||||
@Nullable GroupId requestedGroupId, boolean answered,
|
r.getMessage(), r.getTimestamp(), r.isRead());
|
||||||
boolean canBeOpened) {
|
this.requestType = getType(r);
|
||||||
super(id, groupId, text, msgText, time, read);
|
this.sessionId = r.getSessionId();
|
||||||
this.requestType = requestType;
|
this.answered = r.wasAnswered();
|
||||||
this.sessionId = sessionId;
|
if (r instanceof InvitationRequest) {
|
||||||
this.requestedGroupId = requestedGroupId;
|
this.requestedGroupId = ((Shareable) r.getNameable()).getId();
|
||||||
this.answered = answered;
|
this.canBeOpened = ((InvitationRequest) r).canBeOpened();
|
||||||
this.canBeOpened = canBeOpened;
|
} else {
|
||||||
|
this.requestedGroupId = null;
|
||||||
|
this.canBeOpened = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestType getRequestType() {
|
RequestType getRequestType() {
|
||||||
@@ -54,8 +69,8 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
|||||||
return answered;
|
return answered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAnswered(boolean answered) {
|
void setAnswered() {
|
||||||
this.answered = answered;
|
this.answered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBeOpened() {
|
public boolean canBeOpened() {
|
||||||
@@ -68,4 +83,46 @@ class ConversationRequestItem extends ConversationNoticeInItem {
|
|||||||
return R.layout.list_item_conversation_request;
|
return R.layout.list_item_conversation_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getText(Context ctx, String contactName,
|
||||||
|
PrivateRequest r) {
|
||||||
|
if (r instanceof IntroductionRequest) {
|
||||||
|
if (r.wasAnswered()) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.introduction_request_answered_received,
|
||||||
|
contactName, r.getName());
|
||||||
|
} else if (((IntroductionRequest) r).isContact()) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.introduction_request_exists_received,
|
||||||
|
contactName, r.getName());
|
||||||
|
} else {
|
||||||
|
return ctx.getString(R.string.introduction_request_received,
|
||||||
|
contactName, r.getName());
|
||||||
|
}
|
||||||
|
} else if (r instanceof ForumInvitationRequest) {
|
||||||
|
return ctx.getString(R.string.forum_invitation_received,
|
||||||
|
contactName, r.getName());
|
||||||
|
} else if (r instanceof BlogInvitationRequest) {
|
||||||
|
return ctx.getString(R.string.blogs_sharing_invitation_received,
|
||||||
|
contactName, r.getName());
|
||||||
|
} else if (r instanceof GroupInvitationRequest) {
|
||||||
|
return ctx.getString(
|
||||||
|
R.string.groups_invitations_invitation_received,
|
||||||
|
contactName, r.getName());
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RequestType getType(PrivateRequest r) {
|
||||||
|
if (r instanceof IntroductionRequest) {
|
||||||
|
return INTRODUCTION;
|
||||||
|
} else if (r instanceof ForumInvitationRequest) {
|
||||||
|
return FORUM;
|
||||||
|
} else if (r instanceof BlogInvitationRequest) {
|
||||||
|
return BLOG;
|
||||||
|
} else if (r instanceof GroupInvitationRequest) {
|
||||||
|
return GROUP;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user