mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Show blog invitation requests and responses in private conversation
This commit is contained in:
@@ -21,11 +21,12 @@ import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.BlogPostAddedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.ForumInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.ForumPostReceivedEvent;
|
||||
import org.briarproject.api.event.IntroductionRequestReceivedEvent;
|
||||
import org.briarproject.api.event.IntroductionResponseReceivedEvent;
|
||||
import org.briarproject.api.event.IntroductionSucceededEvent;
|
||||
import org.briarproject.api.event.InvitationReceivedEvent;
|
||||
import org.briarproject.api.event.InvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.event.PrivateMessageReceivedEvent;
|
||||
import org.briarproject.api.event.SettingsUpdatedEvent;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
@@ -174,8 +175,11 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
} else if (e instanceof IntroductionSucceededEvent) {
|
||||
Contact c = ((IntroductionSucceededEvent) e).getContact();
|
||||
showIntroductionSucceededNotification(c);
|
||||
} else if (e instanceof ForumInvitationReceivedEvent) {
|
||||
ContactId c = ((ForumInvitationReceivedEvent) e).getContactId();
|
||||
} else if (e instanceof InvitationReceivedEvent) {
|
||||
ContactId c = ((InvitationReceivedEvent) e).getContactId();
|
||||
showNotificationForPrivateConversation(c);
|
||||
} else if (e instanceof InvitationResponseReceivedEvent) {
|
||||
ContactId c = ((InvitationResponseReceivedEvent) e).getContactId();
|
||||
showNotificationForPrivateConversation(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.briarproject.android.ActivityComponent;
|
||||
import org.briarproject.android.fragment.BaseFragment;
|
||||
import org.briarproject.android.keyagreement.KeyAgreementActivity;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.api.blogs.BlogSharingManager;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
@@ -37,6 +38,8 @@ import org.briarproject.api.event.ForumInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.ForumInvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.event.IntroductionRequestReceivedEvent;
|
||||
import org.briarproject.api.event.IntroductionResponseReceivedEvent;
|
||||
import org.briarproject.api.event.InvitationReceivedEvent;
|
||||
import org.briarproject.api.event.InvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.event.PrivateMessageReceivedEvent;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
@@ -91,6 +94,8 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
protected volatile IntroductionManager introductionManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile BlogSharingManager blogSharingManager;
|
||||
|
||||
public static ContactListFragment newInstance() {
|
||||
|
||||
@@ -277,14 +282,14 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
(IntroductionResponseReceivedEvent) e;
|
||||
IntroductionResponse ir = m.getIntroductionResponse();
|
||||
updateItem(m.getContactId(), ConversationItem.from(ir));
|
||||
} else if (e instanceof ForumInvitationReceivedEvent) {
|
||||
LOG.info("Forum Invitation received, reloading conversation...");
|
||||
ForumInvitationReceivedEvent m = (ForumInvitationReceivedEvent) e;
|
||||
} else if (e instanceof InvitationReceivedEvent) {
|
||||
LOG.info("Invitation received, reloading conversation...");
|
||||
InvitationReceivedEvent m = (InvitationReceivedEvent) e;
|
||||
reloadConversation(m.getContactId());
|
||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||
LOG.info("Forum Invitation Response received, reloading ...");
|
||||
ForumInvitationResponseReceivedEvent m =
|
||||
(ForumInvitationResponseReceivedEvent) e;
|
||||
} else if (e instanceof InvitationResponseReceivedEvent) {
|
||||
LOG.info("Invitation Response received, reloading ...");
|
||||
InvitationResponseReceivedEvent m =
|
||||
(InvitationResponseReceivedEvent) e;
|
||||
reloadConversation(m.getContactId());
|
||||
}
|
||||
}
|
||||
@@ -406,6 +411,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
now = System.currentTimeMillis();
|
||||
Collection<InvitationMessage> invitations =
|
||||
forumSharingManager.getInvitationMessages(id);
|
||||
invitations.addAll(blogSharingManager.getInvitationMessages(id));
|
||||
for (InvitationMessage i : invitations) {
|
||||
messages.add(ConversationItem.from(i));
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.briarproject.android.api.AndroidNotificationManager;
|
||||
import org.briarproject.android.introduction.IntroductionActivity;
|
||||
import org.briarproject.android.util.BriarRecyclerView;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.blogs.BlogSharingManager;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
@@ -44,15 +45,13 @@ import org.briarproject.api.event.ContactRemovedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.ForumInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.ForumInvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.event.IntroductionRequestReceivedEvent;
|
||||
import org.briarproject.api.event.IntroductionResponseReceivedEvent;
|
||||
import org.briarproject.api.event.InvitationReceivedEvent;
|
||||
import org.briarproject.api.event.InvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.event.MessagesAckedEvent;
|
||||
import org.briarproject.api.event.MessagesSentEvent;
|
||||
import org.briarproject.api.event.PrivateMessageReceivedEvent;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.introduction.IntroductionManager;
|
||||
import org.briarproject.api.introduction.IntroductionMessage;
|
||||
@@ -64,6 +63,8 @@ import org.briarproject.api.messaging.PrivateMessageFactory;
|
||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.api.plugins.ConnectionRegistry;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.api.sharing.InvitationResponse;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.util.StringUtils;
|
||||
@@ -128,6 +129,8 @@ public class ConversationActivity extends BriarActivity
|
||||
protected volatile IntroductionManager introductionManager;
|
||||
@Inject
|
||||
protected volatile ForumSharingManager forumSharingManager;
|
||||
@Inject
|
||||
protected volatile BlogSharingManager blogSharingManager;
|
||||
|
||||
private volatile GroupId groupId = null;
|
||||
private volatile ContactId contactId = null;
|
||||
@@ -337,6 +340,8 @@ public class ConversationActivity extends BriarActivity
|
||||
Collection<InvitationMessage> invitations =
|
||||
forumSharingManager
|
||||
.getInvitationMessages(contactId);
|
||||
invitations.addAll(blogSharingManager
|
||||
.getInvitationMessages(contactId));
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading headers took " + duration + " ms");
|
||||
@@ -388,13 +393,13 @@ public class ConversationActivity extends BriarActivity
|
||||
items.add(item);
|
||||
}
|
||||
for (InvitationMessage i : invitations) {
|
||||
if (i instanceof ForumInvitationRequest) {
|
||||
ForumInvitationRequest r =
|
||||
(ForumInvitationRequest) i;
|
||||
if (i instanceof InvitationRequest) {
|
||||
InvitationRequest r =
|
||||
(InvitationRequest) i;
|
||||
items.add(ConversationItem.from(r));
|
||||
} else if (i instanceof ForumInvitationResponse) {
|
||||
ForumInvitationResponse r =
|
||||
(ForumInvitationResponse) i;
|
||||
} else if (i instanceof InvitationResponse) {
|
||||
InvitationResponse r =
|
||||
(InvitationResponse) i;
|
||||
items.add(ConversationItem
|
||||
.from(ConversationActivity.this,
|
||||
contactName, r));
|
||||
@@ -541,6 +546,7 @@ public class ConversationActivity extends BriarActivity
|
||||
IntroductionRequestReceivedEvent event =
|
||||
(IntroductionRequestReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Introduction request received, adding...");
|
||||
IntroductionRequest ir = event.getIntroductionRequest();
|
||||
ConversationItem item = new ConversationIntroductionInItem(ir);
|
||||
addConversationItem(item);
|
||||
@@ -549,21 +555,24 @@ public class ConversationActivity extends BriarActivity
|
||||
IntroductionResponseReceivedEvent event =
|
||||
(IntroductionResponseReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Introduction response received, adding...");
|
||||
IntroductionResponse ir = event.getIntroductionResponse();
|
||||
ConversationItem item =
|
||||
ConversationItem.from(this, contactName, ir);
|
||||
addConversationItem(item);
|
||||
}
|
||||
} else if (e instanceof ForumInvitationReceivedEvent) {
|
||||
ForumInvitationReceivedEvent event =
|
||||
(ForumInvitationReceivedEvent) e;
|
||||
} else if (e instanceof InvitationReceivedEvent) {
|
||||
InvitationReceivedEvent event =
|
||||
(InvitationReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Invitation received, reloading...");
|
||||
loadMessages();
|
||||
}
|
||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||
ForumInvitationResponseReceivedEvent event =
|
||||
(ForumInvitationResponseReceivedEvent) e;
|
||||
} else if (e instanceof InvitationResponseReceivedEvent) {
|
||||
InvitationResponseReceivedEvent event =
|
||||
(InvitationResponseReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
LOG.info("Invitation response received, reloading...");
|
||||
loadMessages();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,22 @@ import android.widget.TextView;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.forum.ForumInvitationsActivity;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.api.blogs.BlogInvitationRequest;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
||||
import static android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static org.briarproject.android.contact.ConversationItem.BLOG_INVITATION_IN;
|
||||
import static org.briarproject.android.contact.ConversationItem.BLOG_INVITATION_OUT;
|
||||
import static org.briarproject.android.contact.ConversationItem.FORUM_INVITATION_IN;
|
||||
import static org.briarproject.android.contact.ConversationItem.FORUM_INVITATION_OUT;
|
||||
import static org.briarproject.android.contact.ConversationItem.INTRODUCTION_IN;
|
||||
@@ -46,13 +52,13 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
private IntroductionHandler intro;
|
||||
private String contactName;
|
||||
|
||||
public ConversationAdapter(Context context,
|
||||
ConversationAdapter(Context context,
|
||||
IntroductionHandler introductionHandler) {
|
||||
ctx = context;
|
||||
intro = introductionHandler;
|
||||
}
|
||||
|
||||
public void setContactName(String contactName) {
|
||||
void setContactName(String contactName) {
|
||||
this.contactName = contactName;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
@@ -87,13 +93,15 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_notice_out, viewGroup, false);
|
||||
return new NoticeHolder(v, type);
|
||||
} else if (type == FORUM_INVITATION_IN) {
|
||||
} else if (type == FORUM_INVITATION_IN || type == BLOG_INVITATION_IN) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_forum_invitation_in, viewGroup, false);
|
||||
R.layout.list_item_shareable_invitation_in, viewGroup,
|
||||
false);
|
||||
return new InvitationHolder(v, type);
|
||||
} else if (type == FORUM_INVITATION_OUT) {
|
||||
} else if (type == FORUM_INVITATION_OUT ||
|
||||
type == BLOG_INVITATION_OUT) {
|
||||
v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||
R.layout.list_item_forum_invitation_out, viewGroup, false);
|
||||
R.layout.list_item_introduction_out, viewGroup, false);
|
||||
return new InvitationHolder(v, type);
|
||||
}
|
||||
// incoming message (non-local)
|
||||
@@ -119,12 +127,12 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeOutItem) item);
|
||||
} else if (item instanceof ConversationNoticeInItem) {
|
||||
bindNotice((NoticeHolder) ui, (ConversationNoticeInItem) item);
|
||||
} else if (item instanceof ConversationForumInvitationOutItem) {
|
||||
} else if (item instanceof ConversationShareableInvitationOutItem) {
|
||||
bindInvitation((InvitationHolder) ui,
|
||||
(ConversationForumInvitationOutItem) item);
|
||||
} else if (item instanceof ConversationForumInvitationInItem) {
|
||||
(ConversationShareableInvitationOutItem) item);
|
||||
} else if (item instanceof ConversationShareableInvitationInItem) {
|
||||
bindInvitation((InvitationHolder) ui,
|
||||
(ConversationForumInvitationInItem) item);
|
||||
(ConversationShareableInvitationInItem) item);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled Conversation Item");
|
||||
}
|
||||
@@ -180,9 +188,9 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
String message = ir.getMessage();
|
||||
if (StringUtils.isNullOrEmpty(message)) {
|
||||
ui.messageLayout.setVisibility(View.GONE);
|
||||
ui.messageLayout.setVisibility(GONE);
|
||||
} else {
|
||||
ui.messageLayout.setVisibility(View.VISIBLE);
|
||||
ui.messageLayout.setVisibility(VISIBLE);
|
||||
ui.message.body.setText(StringUtils.trim(message));
|
||||
ui.message.date
|
||||
.setText(AndroidUtils.formatDate(ctx, item.getTime()));
|
||||
@@ -213,8 +221,8 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
ui.text.setText(ctx.getString(
|
||||
R.string.introduction_request_answered_received,
|
||||
contactName, ir.getName()));
|
||||
ui.acceptButton.setVisibility(View.GONE);
|
||||
ui.declineButton.setVisibility(View.GONE);
|
||||
ui.acceptButton.setVisibility(GONE);
|
||||
ui.declineButton.setVisibility(GONE);
|
||||
}
|
||||
// Incoming Introduction Request (Not Answered)
|
||||
else {
|
||||
@@ -230,12 +238,12 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
|
||||
if (item.getIntroductionRequest().doesIntroduceOtherIdentity()) {
|
||||
// don't allow accept when one of our identities is introduced
|
||||
ui.acceptButton.setVisibility(View.GONE);
|
||||
ui.acceptButton.setVisibility(GONE);
|
||||
ui.text.setText(ctx.getString(
|
||||
R.string.introduction_request_for_our_identity_received,
|
||||
contactName, ir.getName()));
|
||||
} else {
|
||||
ui.acceptButton.setVisibility(View.VISIBLE);
|
||||
ui.acceptButton.setVisibility(VISIBLE);
|
||||
ui.acceptButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -245,7 +253,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.declineButton.setVisibility(View.VISIBLE);
|
||||
ui.declineButton.setVisibility(VISIBLE);
|
||||
ui.declineButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -276,26 +284,38 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
|
||||
private void bindInvitation(InvitationHolder ui,
|
||||
final ConversationForumInvitationItem item) {
|
||||
final ConversationShareableInvitationItem item) {
|
||||
|
||||
ForumInvitationRequest fim = item.getForumInvitationMessage();
|
||||
InvitationRequest ir = item.getInvitationRequest();
|
||||
String name = "";
|
||||
int receivedRes = 0, sentRes = 0, buttonRes = 0;
|
||||
if (ir instanceof ForumInvitationRequest) {
|
||||
name = ((ForumInvitationRequest) ir).getForumName();
|
||||
receivedRes = R.string.forum_invitation_received;
|
||||
sentRes = R.string.forum_invitation_sent;
|
||||
buttonRes = R.string.forum_show_invitations;
|
||||
} else if (ir instanceof BlogInvitationRequest) {
|
||||
name = ((BlogInvitationRequest) ir).getBlogAuthorName();
|
||||
receivedRes = R.string.blogs_sharing_invitation_received;
|
||||
sentRes = R.string.blogs_sharing_invitation_sent;
|
||||
buttonRes = R.string.blogs_sharing_show_invitations;
|
||||
}
|
||||
|
||||
String message = fim.getMessage();
|
||||
String message = ir.getMessage();
|
||||
if (StringUtils.isNullOrEmpty(message)) {
|
||||
ui.messageLayout.setVisibility(View.GONE);
|
||||
ui.messageLayout.setVisibility(GONE);
|
||||
} else {
|
||||
ui.messageLayout.setVisibility(View.VISIBLE);
|
||||
ui.messageLayout.setVisibility(VISIBLE);
|
||||
ui.message.body.setText(StringUtils.trim(message));
|
||||
ui.message.date
|
||||
.setText(AndroidUtils.formatDate(ctx, item.getTime()));
|
||||
}
|
||||
|
||||
// Outgoing Invitation
|
||||
if (item instanceof ConversationForumInvitationOutItem) {
|
||||
ui.text.setText(ctx.getString(R.string.forum_invitation_sent,
|
||||
fim.getForumName(), contactName));
|
||||
ConversationForumInvitationOutItem i =
|
||||
(ConversationForumInvitationOutItem) item;
|
||||
if (item instanceof ConversationShareableInvitationOutItem) {
|
||||
ui.text.setText(ctx.getString(sentRes, name, contactName));
|
||||
ConversationShareableInvitationOutItem i =
|
||||
(ConversationShareableInvitationOutItem) item;
|
||||
if (i.isSeen()) {
|
||||
ui.status.setImageResource(R.drawable.message_delivered);
|
||||
ui.message.status.setImageResource(
|
||||
@@ -312,12 +332,12 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
// Incoming Invitation
|
||||
else {
|
||||
ui.text.setText(ctx.getString(R.string.forum_invitation_received,
|
||||
contactName, fim.getForumName()));
|
||||
ui.text.setText(ctx.getString(receivedRes, contactName, name));
|
||||
|
||||
if (fim.isAvailable()) {
|
||||
ui.showForumsButton.setVisibility(View.VISIBLE);
|
||||
ui.showForumsButton
|
||||
if (ir.isAvailable()) {
|
||||
ui.showInvitationsButton.setText(ctx.getString(buttonRes));
|
||||
ui.showInvitationsButton.setVisibility(VISIBLE);
|
||||
ui.showInvitationsButton
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -327,7 +347,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ui.showForumsButton.setVisibility(View.GONE);
|
||||
ui.showInvitationsButton.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
ui.date.setText(AndroidUtils.formatDate(ctx, item.getTime()));
|
||||
@@ -345,7 +365,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
return items.get(position);
|
||||
}
|
||||
|
||||
public ConversationItem getLastItem() {
|
||||
ConversationItem getLastItem() {
|
||||
if (items.size() > 0) {
|
||||
return items.get(items.size() - 1);
|
||||
} else {
|
||||
@@ -353,7 +373,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
public SparseArray<IncomingItem> getIncomingMessages() {
|
||||
SparseArray<IncomingItem> getIncomingMessages() {
|
||||
SparseArray<IncomingItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
@@ -365,7 +385,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public SparseArray<OutgoingItem> getOutgoingMessages() {
|
||||
SparseArray<OutgoingItem> getOutgoingMessages() {
|
||||
SparseArray<OutgoingItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
@@ -377,7 +397,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public SparseArray<ConversationMessageItem> getPrivateMessages() {
|
||||
SparseArray<ConversationMessageItem> getPrivateMessages() {
|
||||
SparseArray<ConversationMessageItem> messages = new SparseArray<>();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
@@ -408,7 +428,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
public TextView date;
|
||||
public ImageView status;
|
||||
|
||||
public MessageHolder(View v, int type) {
|
||||
MessageHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
layout = (ViewGroup) v.findViewById(R.id.msgLayout);
|
||||
@@ -432,7 +452,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public IntroductionHolder(View v, int type) {
|
||||
IntroductionHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
messageLayout = v.findViewById(R.id.messageLayout);
|
||||
@@ -457,7 +477,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public NoticeHolder(View v, int type) {
|
||||
NoticeHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
text = (TextView) v.findViewById(R.id.noticeText);
|
||||
@@ -476,21 +496,21 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
private final View messageLayout;
|
||||
private final MessageHolder message;
|
||||
private final TextView text;
|
||||
private final Button showForumsButton;
|
||||
private final Button showInvitationsButton;
|
||||
private final TextView date;
|
||||
private final ImageView status;
|
||||
|
||||
public InvitationHolder(View v, int type) {
|
||||
InvitationHolder(View v, int type) {
|
||||
super(v);
|
||||
|
||||
messageLayout = v.findViewById(R.id.messageLayout);
|
||||
message = new MessageHolder(messageLayout,
|
||||
type == FORUM_INVITATION_IN ? MSG_IN : MSG_OUT);
|
||||
text = (TextView) v.findViewById(R.id.introductionText);
|
||||
showForumsButton = (Button) v.findViewById(R.id.showForumsButton);
|
||||
showInvitationsButton = (Button) v.findViewById(R.id.showForumsButton);
|
||||
date = (TextView) v.findViewById(R.id.introductionTime);
|
||||
|
||||
if (type == FORUM_INVITATION_OUT) {
|
||||
if (type == FORUM_INVITATION_OUT || type == BLOG_INVITATION_OUT) {
|
||||
status = (ImageView) v.findViewById(R.id.introductionStatus);
|
||||
} else {
|
||||
status = null;
|
||||
@@ -543,7 +563,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
public interface IntroductionHandler {
|
||||
interface IntroductionHandler {
|
||||
void respondToIntroduction(SessionId sessionId, boolean accept);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationForumInvitationInItem
|
||||
extends ConversationForumInvitationItem
|
||||
implements ConversationItem.IncomingItem {
|
||||
|
||||
private boolean read;
|
||||
|
||||
public ConversationForumInvitationInItem(ForumInvitationRequest fim) {
|
||||
super(fim);
|
||||
|
||||
this.read = fim.isRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
int getType() {
|
||||
return FORUM_INVITATION_IN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
|
||||
abstract class ConversationForumInvitationItem extends ConversationItem {
|
||||
|
||||
private final ForumInvitationRequest fim;
|
||||
|
||||
public ConversationForumInvitationItem(ForumInvitationRequest fim) {
|
||||
super(fim.getId(), fim.getTimestamp());
|
||||
|
||||
this.fim = fim;
|
||||
}
|
||||
|
||||
public ForumInvitationRequest getForumInvitationMessage() {
|
||||
return fim;
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,15 @@ package org.briarproject.android.contact;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.blogs.BlogInvitationResponse;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.api.introduction.IntroductionMessage;
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.api.sharing.InvitationResponse;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
// This class is not thread-safe
|
||||
@@ -25,6 +27,8 @@ public abstract class ConversationItem {
|
||||
final static int NOTICE_OUT = 6;
|
||||
final static int FORUM_INVITATION_IN = 7;
|
||||
final static int FORUM_INVITATION_OUT = 8;
|
||||
final static int BLOG_INVITATION_IN = 9;
|
||||
final static int BLOG_INVITATION_OUT = 10;
|
||||
|
||||
private MessageId id;
|
||||
private long time;
|
||||
@@ -97,15 +101,27 @@ public abstract class ConversationItem {
|
||||
}
|
||||
}
|
||||
|
||||
public static ConversationItem from(ForumInvitationRequest fim) {
|
||||
public static ConversationItem from(InvitationRequest fim) {
|
||||
if (fim.isLocal()) {
|
||||
return new ConversationForumInvitationOutItem(fim);
|
||||
return new ConversationShareableInvitationOutItem(fim);
|
||||
} else {
|
||||
return new ConversationForumInvitationInItem(fim);
|
||||
return new ConversationShareableInvitationInItem(fim);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConversationItem from(Context ctx, String contactName,
|
||||
InvitationResponse ir) {
|
||||
|
||||
if (ir instanceof ForumInvitationResponse) {
|
||||
return from(ctx, contactName, (ForumInvitationResponse) ir);
|
||||
} else if (ir instanceof BlogInvitationResponse) {
|
||||
return from(ctx, contactName, (BlogInvitationResponse) ir);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown Invitation Response.");
|
||||
}
|
||||
}
|
||||
|
||||
private static ConversationItem from(Context ctx, String contactName,
|
||||
ForumInvitationResponse fir) {
|
||||
|
||||
if (fir.isLocal()) {
|
||||
@@ -137,6 +153,38 @@ public abstract class ConversationItem {
|
||||
}
|
||||
}
|
||||
|
||||
private static ConversationItem from(Context ctx, String contactName,
|
||||
BlogInvitationResponse fir) {
|
||||
|
||||
if (fir.isLocal()) {
|
||||
String text;
|
||||
if (fir.wasAccepted()) {
|
||||
text = ctx.getString(
|
||||
R.string.blogs_sharing_response_accepted_sent,
|
||||
contactName);
|
||||
} else {
|
||||
text = ctx.getString(
|
||||
R.string.blogs_sharing_response_declined_sent,
|
||||
contactName);
|
||||
}
|
||||
return new ConversationNoticeOutItem(fir.getId(), text,
|
||||
fir.getTimestamp(), fir.isSent(), fir.isSeen());
|
||||
} else {
|
||||
String text;
|
||||
if (fir.wasAccepted()) {
|
||||
text = ctx.getString(
|
||||
R.string.blogs_sharing_response_accepted_received,
|
||||
contactName);
|
||||
} else {
|
||||
text = ctx.getString(
|
||||
R.string.blogs_sharing_response_declined_received,
|
||||
contactName);
|
||||
}
|
||||
return new ConversationNoticeInItem(fir.getId(), text,
|
||||
fir.getTimestamp(), fir.isRead());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should not be used to get user-facing objects,
|
||||
* Its purpose is only to provide data for the contact list.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.blogs.BlogInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
|
||||
// This class is not thread-safe
|
||||
class ConversationShareableInvitationInItem
|
||||
extends ConversationShareableInvitationItem
|
||||
implements ConversationItem.IncomingItem {
|
||||
|
||||
private final int type;
|
||||
private boolean read;
|
||||
|
||||
ConversationShareableInvitationInItem(InvitationRequest ir) {
|
||||
super(ir);
|
||||
|
||||
if (ir instanceof ForumInvitationRequest) {
|
||||
this.type = FORUM_INVITATION_IN;
|
||||
} else if (ir instanceof BlogInvitationRequest) {
|
||||
this.type = BLOG_INVITATION_IN;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown Invitation Type.");
|
||||
}
|
||||
|
||||
this.read = ir.isRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
|
||||
abstract class ConversationShareableInvitationItem extends ConversationItem {
|
||||
|
||||
private final InvitationRequest fim;
|
||||
|
||||
ConversationShareableInvitationItem(InvitationRequest fim) {
|
||||
super(fim.getId(), fim.getTimestamp());
|
||||
|
||||
this.fim = fim;
|
||||
}
|
||||
|
||||
InvitationRequest getInvitationRequest() {
|
||||
return fim;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.blogs.BlogInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
|
||||
/**
|
||||
* This class is needed and can not be replaced by an ConversationNoticeOutItem,
|
||||
@@ -9,21 +11,31 @@ import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
* <p/>
|
||||
* This class is not thread-safe
|
||||
*/
|
||||
public class ConversationForumInvitationOutItem
|
||||
extends ConversationForumInvitationItem
|
||||
class ConversationShareableInvitationOutItem
|
||||
extends ConversationShareableInvitationItem
|
||||
implements ConversationItem.OutgoingItem {
|
||||
|
||||
private final int type;
|
||||
private boolean sent, seen;
|
||||
|
||||
public ConversationForumInvitationOutItem(ForumInvitationRequest fim) {
|
||||
super(fim);
|
||||
this.sent = fim.isSent();
|
||||
this.seen = fim.isSeen();
|
||||
ConversationShareableInvitationOutItem(InvitationRequest ir) {
|
||||
super(ir);
|
||||
|
||||
if (ir instanceof ForumInvitationRequest) {
|
||||
this.type = FORUM_INVITATION_OUT;
|
||||
} else if (ir instanceof BlogInvitationRequest) {
|
||||
this.type = BLOG_INVITATION_OUT;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown Invitation Type.");
|
||||
}
|
||||
|
||||
this.sent = ir.isSent();
|
||||
this.seen = ir.isSeen();
|
||||
}
|
||||
|
||||
@Override
|
||||
int getType() {
|
||||
return FORUM_INVITATION_OUT;
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user