mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Show Responses to Forum Invitations in Private Conversation
Closes #472
This commit is contained in:
@@ -25,7 +25,8 @@ import org.briarproject.api.event.ForumInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.ForumInvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.event.MessageStateChangedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.forum.ForumPost;
|
||||
import org.briarproject.api.forum.ForumPostFactory;
|
||||
@@ -35,6 +36,7 @@ import org.briarproject.api.identity.AuthorFactory;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.SyncSession;
|
||||
@@ -187,18 +189,29 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<ForumInvitationMessage> list =
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<>(forumSharingManager1
|
||||
.getInvitationMessages(contactId0));
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the forum message
|
||||
ForumInvitationMessage invitation = list.get(0);
|
||||
assertFalse(invitation.isAvailable());
|
||||
assertEquals(forum0.getName(), invitation.getForumName());
|
||||
assertEquals(contactId1, invitation.getContactId());
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
// sharer has own invitation message
|
||||
assertEquals(1,
|
||||
for (InvitationMessage m : list) {
|
||||
if (m instanceof ForumInvitationRequest) {
|
||||
ForumInvitationRequest invitation =
|
||||
(ForumInvitationRequest) m;
|
||||
assertFalse(invitation.isAvailable());
|
||||
assertEquals(forum0.getName(), invitation.getForumName());
|
||||
assertEquals(contactId1, invitation.getContactId());
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
} else {
|
||||
ForumInvitationResponse response =
|
||||
(ForumInvitationResponse) m;
|
||||
assertEquals(contactId0, response.getContactId());
|
||||
assertTrue(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
}
|
||||
// sharer has own invitation message and response
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getInvitationMessages(contactId1)
|
||||
.size());
|
||||
// forum can not be shared again
|
||||
@@ -238,19 +251,30 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
// forum is no longer available to invitee who declined
|
||||
assertEquals(0, forumSharingManager1.getInvited().size());
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<ForumInvitationMessage> list =
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<>(forumSharingManager1
|
||||
.getInvitationMessages(contactId0));
|
||||
assertEquals(1, list.size());
|
||||
// check other things are alright with the forum message
|
||||
ForumInvitationMessage invitation = list.get(0);
|
||||
assertFalse(invitation.isAvailable());
|
||||
assertEquals(forum0.getName(), invitation.getForumName());
|
||||
assertEquals(contactId1, invitation.getContactId());
|
||||
assertEquals(null, invitation.getMessage());
|
||||
// sharer has own invitation message
|
||||
assertEquals(1,
|
||||
assertEquals(2, list.size());
|
||||
// check things are alright with the forum message
|
||||
for (InvitationMessage m : list) {
|
||||
if (m instanceof ForumInvitationRequest) {
|
||||
ForumInvitationRequest invitation =
|
||||
(ForumInvitationRequest) m;
|
||||
assertFalse(invitation.isAvailable());
|
||||
assertEquals(forum0.getName(), invitation.getForumName());
|
||||
assertEquals(contactId1, invitation.getContactId());
|
||||
assertEquals(null, invitation.getMessage());
|
||||
} else {
|
||||
ForumInvitationResponse response =
|
||||
(ForumInvitationResponse) m;
|
||||
assertEquals(contactId0, response.getContactId());
|
||||
assertFalse(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
}
|
||||
// sharer has own invitation message and response
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getInvitationMessages(contactId1)
|
||||
.size());
|
||||
// forum can be shared again
|
||||
@@ -438,12 +462,13 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
listener1.requestReceived = false;
|
||||
|
||||
// get SessionId from invitation
|
||||
List<ForumInvitationMessage> list = new ArrayList<>(
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
forumSharingManager1
|
||||
.getInvitationMessages(contactId0));
|
||||
assertEquals(1, list.size());
|
||||
ForumInvitationMessage msg = list.get(0);
|
||||
assertEquals(2, list.size());
|
||||
InvitationMessage msg = list.get(0);
|
||||
SessionId sessionId = msg.getSessionId();
|
||||
assertEquals(sessionId, list.get(1).getSessionId());
|
||||
|
||||
// get all sorts of stuff needed to send a message
|
||||
DatabaseComponent db = t0.getDatabaseComponent();
|
||||
@@ -501,6 +526,9 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
|
||||
// forum was added successfully
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getInvitationMessages(contactId1)
|
||||
.size());
|
||||
|
||||
// invitee now shares same forum back
|
||||
forumSharingManager1.sendInvitation(forum0.getId(),
|
||||
@@ -512,7 +540,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
|
||||
// make sure that no new request was received
|
||||
assertFalse(listener0.requestReceived);
|
||||
assertEquals(1,
|
||||
assertEquals(2,
|
||||
forumSharingManager0.getInvitationMessages(contactId1)
|
||||
.size());
|
||||
} finally {
|
||||
@@ -566,9 +594,9 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.responseReceived);
|
||||
|
||||
assertEquals(1, forumSharingManager0
|
||||
assertEquals(2, forumSharingManager0
|
||||
.getInvitationMessages(contactId1).size());
|
||||
assertEquals(2, forumSharingManager1
|
||||
assertEquals(3, forumSharingManager1
|
||||
.getInvitationMessages(contactId0).size());
|
||||
} else {
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
@@ -579,9 +607,9 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.responseReceived);
|
||||
|
||||
assertEquals(2, forumSharingManager0
|
||||
assertEquals(3, forumSharingManager0
|
||||
.getInvitationMessages(contactId1).size());
|
||||
assertEquals(1, forumSharingManager1
|
||||
assertEquals(2, forumSharingManager1
|
||||
.getInvitationMessages(contactId0).size());
|
||||
}
|
||||
} finally {
|
||||
@@ -616,12 +644,13 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
|
||||
forumSharingManager0.getSharedWith(forum0.getId()).size());
|
||||
|
||||
// remember SessionId from invitation
|
||||
List<ForumInvitationMessage> list = new ArrayList<>(
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
forumSharingManager1
|
||||
.getInvitationMessages(contactId0));
|
||||
assertEquals(1, list.size());
|
||||
ForumInvitationMessage msg = list.get(0);
|
||||
assertEquals(2, list.size());
|
||||
InvitationMessage msg = list.get(0);
|
||||
SessionId sessionId = msg.getSessionId();
|
||||
assertEquals(sessionId, list.get(1).getSessionId());
|
||||
|
||||
// contacts now remove each other
|
||||
contactManager0.removeContact(contactId1);
|
||||
|
||||
@@ -222,6 +222,10 @@
|
||||
<string name="forum_new_message_hint">New Entry</string>
|
||||
<string name="forum_message_reply_hint">New Reply</string>
|
||||
<string name="forum_invitation_already_sharing">Already sharing</string>
|
||||
<string name="forum_invitation_response_accepted_sent">You accepted the forum invitation from %s.</string>
|
||||
<string name="forum_invitation_response_declined_sent">You declined the forum invitation from %s.</string>
|
||||
<string name="forum_invitation_response_accepted_received">%s accepted the forum invitation.</string>
|
||||
<string name="forum_invitation_response_declined_received">%s declined the forum invitation.</string>
|
||||
|
||||
<!-- Dialogs -->
|
||||
<string name="dialog_title_lost_password">Lost Password</string>
|
||||
|
||||
@@ -34,10 +34,12 @@ 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.PrivateMessageReceivedEvent;
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
@@ -48,6 +50,7 @@ import org.briarproject.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.api.messaging.MessagingManager;
|
||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.api.plugins.ConnectionRegistry;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -277,6 +280,11 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
LOG.info("Forum Invitation received, reloading conversation...");
|
||||
ForumInvitationReceivedEvent m = (ForumInvitationReceivedEvent) e;
|
||||
reloadConversation(m.getContactId());
|
||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||
LOG.info("Forum Invitation Response received, reloading ...");
|
||||
ForumInvitationResponseReceivedEvent m =
|
||||
(ForumInvitationResponseReceivedEvent) e;
|
||||
reloadConversation(m.getContactId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,10 +402,16 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
LOG.info("Loading introduction messages took " + duration + " ms");
|
||||
|
||||
now = System.currentTimeMillis();
|
||||
Collection<ForumInvitationMessage> invitations =
|
||||
Collection<InvitationMessage> invitations =
|
||||
forumSharingManager.getInvitationMessages(id);
|
||||
for (ForumInvitationMessage i : invitations) {
|
||||
messages.add(ConversationItem.from(i));
|
||||
for (InvitationMessage i : invitations) {
|
||||
if (i instanceof ForumInvitationRequest) {
|
||||
ForumInvitationRequest r = (ForumInvitationRequest) i;
|
||||
messages.add(ConversationItem.from(r));
|
||||
} else if (i instanceof ForumInvitationResponse) {
|
||||
ForumInvitationResponse r = (ForumInvitationResponse) i;
|
||||
messages.add(ConversationItem.from(getActivity(), "", r));
|
||||
}
|
||||
}
|
||||
duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
|
||||
@@ -45,12 +45,14 @@ 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.MessagesAckedEvent;
|
||||
import org.briarproject.api.event.MessagesSentEvent;
|
||||
import org.briarproject.api.event.PrivateMessageReceivedEvent;
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
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;
|
||||
@@ -61,6 +63,7 @@ import org.briarproject.api.messaging.PrivateMessage;
|
||||
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.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.util.StringUtils;
|
||||
@@ -330,7 +333,7 @@ public class ConversationActivity extends BriarActivity
|
||||
Collection<IntroductionMessage> introductions =
|
||||
introductionManager
|
||||
.getIntroductionMessages(contactId);
|
||||
Collection<ForumInvitationMessage> invitations =
|
||||
Collection<InvitationMessage> invitations =
|
||||
forumSharingManager
|
||||
.getInvitationMessages(contactId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
@@ -349,7 +352,7 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
private void displayMessages(final Collection<PrivateMessageHeader> headers,
|
||||
final Collection<IntroductionMessage> introductions,
|
||||
final Collection<ForumInvitationMessage> invitations) {
|
||||
final Collection<InvitationMessage> invitations) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -383,9 +386,18 @@ public class ConversationActivity extends BriarActivity
|
||||
}
|
||||
items.add(item);
|
||||
}
|
||||
for (ForumInvitationMessage i : invitations) {
|
||||
ConversationItem item = ConversationItem.from(i);
|
||||
items.add(item);
|
||||
for (InvitationMessage i : invitations) {
|
||||
if (i instanceof ForumInvitationRequest) {
|
||||
ForumInvitationRequest r =
|
||||
(ForumInvitationRequest) i;
|
||||
items.add(ConversationItem.from(r));
|
||||
} else if (i instanceof ForumInvitationResponse) {
|
||||
ForumInvitationResponse r =
|
||||
(ForumInvitationResponse) i;
|
||||
items.add(ConversationItem
|
||||
.from(ConversationActivity.this,
|
||||
contactName, r));
|
||||
}
|
||||
}
|
||||
adapter.addAll(items);
|
||||
// Scroll to the bottom
|
||||
@@ -547,6 +559,12 @@ public class ConversationActivity extends BriarActivity
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
loadMessages();
|
||||
}
|
||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||
ForumInvitationResponseReceivedEvent event =
|
||||
(ForumInvitationResponseReceivedEvent) e;
|
||||
if (event.getContactId().equals(contactId)) {
|
||||
loadMessages();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.briarproject.R;
|
||||
import org.briarproject.android.forum.ForumInvitationsActivity;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.util.StringUtils;
|
||||
@@ -278,7 +278,7 @@ class ConversationAdapter extends RecyclerView.Adapter {
|
||||
private void bindInvitation(InvitationHolder ui,
|
||||
final ConversationForumInvitationItem item) {
|
||||
|
||||
ForumInvitationMessage fim = item.getForumInvitationMessage();
|
||||
ForumInvitationRequest fim = item.getForumInvitationMessage();
|
||||
|
||||
String message = fim.getMessage();
|
||||
if (StringUtils.isNullOrEmpty(message)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
|
||||
// This class is not thread-safe
|
||||
public class ConversationForumInvitationInItem
|
||||
@@ -9,7 +9,7 @@ public class ConversationForumInvitationInItem
|
||||
|
||||
private boolean read;
|
||||
|
||||
public ConversationForumInvitationInItem(ForumInvitationMessage fim) {
|
||||
public ConversationForumInvitationInItem(ForumInvitationRequest fim) {
|
||||
super(fim);
|
||||
|
||||
this.read = fim.isRead();
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
|
||||
abstract class ConversationForumInvitationItem extends ConversationItem {
|
||||
|
||||
private final ForumInvitationMessage fim;
|
||||
private final ForumInvitationRequest fim;
|
||||
|
||||
public ConversationForumInvitationItem(ForumInvitationMessage fim) {
|
||||
public ConversationForumInvitationItem(ForumInvitationRequest fim) {
|
||||
super(fim.getId(), fim.getTimestamp());
|
||||
|
||||
this.fim = fim;
|
||||
}
|
||||
|
||||
public ForumInvitationMessage getForumInvitationMessage() {
|
||||
public ForumInvitationRequest getForumInvitationMessage() {
|
||||
return fim;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
|
||||
/**
|
||||
* This class is needed and can not be replaced by an ConversationNoticeOutItem,
|
||||
@@ -15,7 +15,7 @@ public class ConversationForumInvitationOutItem
|
||||
|
||||
private boolean sent, seen;
|
||||
|
||||
public ConversationForumInvitationOutItem(ForumInvitationMessage fim) {
|
||||
public ConversationForumInvitationOutItem(ForumInvitationRequest fim) {
|
||||
super(fim);
|
||||
this.sent = fim.isSent();
|
||||
this.seen = fim.isSeen();
|
||||
|
||||
@@ -3,7 +3,8 @@ package org.briarproject.android.contact;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.api.introduction.IntroductionMessage;
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.api.introduction.IntroductionResponse;
|
||||
@@ -95,7 +96,7 @@ public abstract class ConversationItem {
|
||||
}
|
||||
}
|
||||
|
||||
public static ConversationItem from(ForumInvitationMessage fim) {
|
||||
public static ConversationItem from(ForumInvitationRequest fim) {
|
||||
if (fim.isLocal()) {
|
||||
return new ConversationForumInvitationOutItem(fim);
|
||||
} else {
|
||||
@@ -103,6 +104,38 @@ public abstract class ConversationItem {
|
||||
}
|
||||
}
|
||||
|
||||
public static ConversationItem from(Context ctx, String contactName,
|
||||
ForumInvitationResponse fir) {
|
||||
|
||||
if (fir.isLocal()) {
|
||||
String text;
|
||||
if (fir.wasAccepted()) {
|
||||
text = ctx.getString(
|
||||
R.string.forum_invitation_response_accepted_sent,
|
||||
contactName);
|
||||
} else {
|
||||
text = ctx.getString(
|
||||
R.string.forum_invitation_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.forum_invitation_response_accepted_received,
|
||||
contactName);
|
||||
} else {
|
||||
text = ctx.getString(
|
||||
R.string.forum_invitation_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 to provider data for the contact list.
|
||||
@@ -115,7 +148,7 @@ public abstract class ConversationItem {
|
||||
im.getTimestamp(), im.isRead());
|
||||
}
|
||||
|
||||
protected interface OutgoingItem {
|
||||
interface OutgoingItem {
|
||||
|
||||
MessageId getId();
|
||||
|
||||
@@ -128,7 +161,7 @@ public abstract class ConversationItem {
|
||||
void setSeen(boolean seen);
|
||||
}
|
||||
|
||||
protected interface IncomingItem {
|
||||
interface IncomingItem {
|
||||
|
||||
MessageId getId();
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@ package org.briarproject.api.blogs;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class BlogInvitationMessage extends InvitationMessage {
|
||||
public class BlogInvitationRequest extends InvitationRequest {
|
||||
|
||||
private final String blogTitle;
|
||||
|
||||
public BlogInvitationMessage(MessageId id, SessionId sessionId,
|
||||
public BlogInvitationRequest(MessageId id, SessionId sessionId,
|
||||
ContactId contactId, String blogTitle, String message,
|
||||
boolean available, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
@@ -10,7 +10,7 @@ import org.briarproject.api.sync.GroupId;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface BlogSharingManager
|
||||
extends SharingManager<Blog, BlogInvitationMessage> {
|
||||
extends SharingManager<Blog, BlogInvitationRequest> {
|
||||
|
||||
/**
|
||||
* Returns the unique ID of the blog sharing client.
|
||||
@@ -34,7 +34,7 @@ public interface BlogSharingManager
|
||||
* Returns all blogs sharing messages sent by the Contact
|
||||
* identified by contactId.
|
||||
*/
|
||||
Collection<BlogInvitationMessage> getInvitationMessages(
|
||||
Collection<BlogInvitationRequest> getInvitationMessages(
|
||||
ContactId contactId) throws DbException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,15 +2,14 @@ package org.briarproject.api.forum;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.messaging.BaseMessage;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class ForumInvitationMessage extends InvitationMessage {
|
||||
public class ForumInvitationRequest extends InvitationRequest {
|
||||
|
||||
private final String forumName;
|
||||
|
||||
public ForumInvitationMessage(MessageId id, SessionId sessionId,
|
||||
public ForumInvitationRequest(MessageId id, SessionId sessionId,
|
||||
ContactId contactId, String forumName, String message,
|
||||
boolean available, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.briarproject.api.forum;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationResponse;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class ForumInvitationResponse extends InvitationResponse {
|
||||
|
||||
public ForumInvitationResponse(MessageId id, SessionId sessionId,
|
||||
ContactId contactId, boolean accept, long time, boolean local,
|
||||
boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, contactId, accept, time, local, sent, seen, read);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,14 @@ package org.briarproject.api.forum;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sharing.SharingManager;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface ForumSharingManager extends SharingManager<Forum, ForumInvitationMessage> {
|
||||
public interface ForumSharingManager extends SharingManager<Forum, InvitationMessage> {
|
||||
|
||||
/** Returns the unique ID of the forum sharing client. */
|
||||
ClientId getClientId();
|
||||
@@ -31,7 +32,7 @@ public interface ForumSharingManager extends SharingManager<Forum, ForumInvitati
|
||||
* Returns all forum sharing messages sent by the Contact
|
||||
* identified by contactId.
|
||||
*/
|
||||
Collection<ForumInvitationMessage> getInvitationMessages(
|
||||
Collection<InvitationMessage> getInvitationMessages(
|
||||
ContactId contactId) throws DbException;
|
||||
|
||||
/** Returns all forums to which the user has been invited. */
|
||||
|
||||
@@ -9,19 +9,14 @@ public abstract class InvitationMessage extends BaseMessage {
|
||||
|
||||
private final SessionId sessionId;
|
||||
private final ContactId contactId;
|
||||
private final String message;
|
||||
private final boolean available;
|
||||
|
||||
public InvitationMessage(MessageId id, SessionId sessionId,
|
||||
ContactId contactId, String message,
|
||||
boolean available, long time, boolean local, boolean sent,
|
||||
ContactId contactId, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
|
||||
super(id, time, local, read, sent, seen);
|
||||
this.sessionId = sessionId;
|
||||
this.contactId = contactId;
|
||||
this.message = message;
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
@@ -32,12 +27,4 @@ public abstract class InvitationMessage extends BaseMessage {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.briarproject.api.sharing;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public abstract class InvitationRequest extends InvitationMessage {
|
||||
|
||||
private final String message;
|
||||
private final boolean available;
|
||||
|
||||
public InvitationRequest(MessageId id, SessionId sessionId,
|
||||
ContactId contactId, String message,
|
||||
boolean available, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, contactId, time, local, read, sent, seen);
|
||||
this.message = message;
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.api.sharing;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public abstract class InvitationResponse extends InvitationMessage {
|
||||
|
||||
private final boolean accept;
|
||||
|
||||
public InvitationResponse(MessageId id, SessionId sessionId,
|
||||
ContactId contactId, boolean accept, long time, boolean local,
|
||||
boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, contactId, time, local, read, sent, seen);
|
||||
this.accept = accept;
|
||||
}
|
||||
|
||||
public boolean wasAccepted() {
|
||||
return accept;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ public interface SharingMessage {
|
||||
private final SessionId sessionId;
|
||||
|
||||
BaseMessage(GroupId groupId, SessionId sessionId) {
|
||||
|
||||
this.groupId = groupId;
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.briarproject.sharing;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.blogs.Blog;
|
||||
import org.briarproject.api.blogs.BlogFactory;
|
||||
import org.briarproject.api.blogs.BlogInvitationMessage;
|
||||
import org.briarproject.api.blogs.BlogInvitationRequest;
|
||||
import org.briarproject.api.blogs.BlogManager;
|
||||
import org.briarproject.api.blogs.BlogManager.RemoveBlogHook;
|
||||
import org.briarproject.api.blogs.BlogSharingManager;
|
||||
@@ -40,15 +40,13 @@ import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
|
||||
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
|
||||
|
||||
class BlogSharingManagerImpl extends
|
||||
SharingManagerImpl<Blog, BlogInvitation, BlogInvitationMessage, BlogInviteeSessionState, BlogSharerSessionState, BlogInvitationReceivedEvent, BlogInvitationResponseReceivedEvent>
|
||||
SharingManagerImpl<Blog, BlogInvitation, BlogInvitationRequest, BlogInviteeSessionState, BlogSharerSessionState, BlogInvitationReceivedEvent, BlogInvitationResponseReceivedEvent>
|
||||
implements BlogSharingManager, RemoveBlogHook {
|
||||
|
||||
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
|
||||
"bee438b5de0b3a685badc4e49d76e72d"
|
||||
+ "21e01c4b569a775112756bdae267a028"));
|
||||
|
||||
private final BlogManager blogManager;
|
||||
|
||||
private final SFactory sFactory;
|
||||
private final IFactory iFactory;
|
||||
private final ISFactory isFactory;
|
||||
@@ -65,7 +63,6 @@ class BlogSharingManagerImpl extends
|
||||
|
||||
super(db, messageQueueManager, clientHelper, metadataParser,
|
||||
metadataEncoder, random, privateGroupFactory, clock);
|
||||
this.blogManager = blogManager;
|
||||
|
||||
sFactory = new SFactory(authorFactory, blogFactory, blogManager);
|
||||
iFactory = new IFactory();
|
||||
@@ -81,15 +78,23 @@ class BlogSharingManagerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlogInvitationMessage createInvitationMessage(MessageId id,
|
||||
protected BlogInvitationRequest createInvitationRequest(MessageId id,
|
||||
BlogInvitation msg, ContactId contactId, boolean available,
|
||||
long time, boolean local, boolean sent, boolean seen,
|
||||
boolean read) {
|
||||
return new BlogInvitationMessage(id, msg.getSessionId(), contactId,
|
||||
return new BlogInvitationRequest(id, msg.getSessionId(), contactId,
|
||||
msg.getBlogTitle(), msg.getMessage(), available, time, local,
|
||||
sent, seen, read);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlogInvitationRequest createInvitationResponse(MessageId id,
|
||||
SessionId sessionId, ContactId contactId, boolean accept, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
// TODO implement when doing blog sharing
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShareableFactory<Blog, BlogInvitation, BlogInviteeSessionState, BlogSharerSessionState> getSFactory() {
|
||||
return sFactory;
|
||||
@@ -125,7 +130,7 @@ class BlogSharingManagerImpl extends
|
||||
removingShareable(txn, b);
|
||||
}
|
||||
|
||||
static class SFactory implements
|
||||
private static class SFactory implements
|
||||
ShareableFactory<Blog, BlogInvitation, BlogInviteeSessionState, BlogSharerSessionState> {
|
||||
|
||||
private final AuthorFactory authorFactory;
|
||||
@@ -190,7 +195,7 @@ class BlogSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class IFactory implements
|
||||
private static class IFactory implements
|
||||
InvitationFactory<BlogInvitation, BlogSharerSessionState> {
|
||||
@Override
|
||||
public BlogInvitation build(GroupId groupId, BdfDictionary d)
|
||||
@@ -207,7 +212,7 @@ class BlogSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class ISFactory implements
|
||||
private static class ISFactory implements
|
||||
InviteeSessionStateFactory<Blog, BlogInviteeSessionState> {
|
||||
@Override
|
||||
public BlogInviteeSessionState build(SessionId sessionId,
|
||||
@@ -235,7 +240,7 @@ class BlogSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class SSFactory implements
|
||||
private static class SSFactory implements
|
||||
SharerSessionStateFactory<Blog, BlogSharerSessionState> {
|
||||
@Override
|
||||
public BlogSharerSessionState build(SessionId sessionId,
|
||||
@@ -263,7 +268,7 @@ class BlogSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class IRFactory implements
|
||||
private static class IRFactory implements
|
||||
InvitationReceivedEventFactory<BlogInviteeSessionState, BlogInvitationReceivedEvent> {
|
||||
|
||||
private final SFactory sFactory;
|
||||
@@ -281,7 +286,7 @@ class BlogSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class IRRFactory implements
|
||||
private static class IRRFactory implements
|
||||
InvitationResponseReceivedEventFactory<BlogSharerSessionState, BlogInvitationResponseReceivedEvent> {
|
||||
@Override
|
||||
public BlogInvitationResponseReceivedEvent build(
|
||||
|
||||
@@ -9,12 +9,12 @@ import org.briarproject.api.sync.MessageId;
|
||||
import static org.briarproject.api.forum.ForumConstants.FORUM_NAME;
|
||||
import static org.briarproject.api.forum.ForumConstants.FORUM_SALT;
|
||||
|
||||
public class ForumSharerSessionState extends SharerSessionState {
|
||||
class ForumSharerSessionState extends SharerSessionState {
|
||||
|
||||
private final String forumName;
|
||||
private final byte[] forumSalt;
|
||||
|
||||
public ForumSharerSessionState(SessionId sessionId, MessageId storageId,
|
||||
ForumSharerSessionState(SessionId sessionId, MessageId storageId,
|
||||
GroupId groupId, State state, ContactId contactId, GroupId forumId,
|
||||
String forumName, byte[] forumSalt) {
|
||||
super(sessionId, storageId, groupId, state, contactId, forumId);
|
||||
@@ -30,11 +30,11 @@ public class ForumSharerSessionState extends SharerSessionState {
|
||||
return d;
|
||||
}
|
||||
|
||||
public String getForumName() {
|
||||
String getForumName() {
|
||||
return forumName;
|
||||
}
|
||||
|
||||
public byte[] getForumSalt() {
|
||||
byte[] getForumSalt() {
|
||||
return forumSalt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,12 @@ import org.briarproject.api.event.ForumInvitationReceivedEvent;
|
||||
import org.briarproject.api.event.ForumInvitationResponseReceivedEvent;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumFactory;
|
||||
import org.briarproject.api.forum.ForumInvitationMessage;
|
||||
import org.briarproject.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.forum.ForumSharingManager;
|
||||
import org.briarproject.api.forum.ForumSharingMessage.ForumInvitation;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
@@ -35,15 +37,13 @@ import static org.briarproject.api.forum.ForumConstants.FORUM_NAME;
|
||||
import static org.briarproject.api.forum.ForumConstants.FORUM_SALT;
|
||||
|
||||
class ForumSharingManagerImpl extends
|
||||
SharingManagerImpl<Forum, ForumInvitation, ForumInvitationMessage, ForumInviteeSessionState, ForumSharerSessionState, ForumInvitationReceivedEvent, ForumInvitationResponseReceivedEvent>
|
||||
SharingManagerImpl<Forum, ForumInvitation, InvitationMessage, ForumInviteeSessionState, ForumSharerSessionState, ForumInvitationReceivedEvent, ForumInvitationResponseReceivedEvent>
|
||||
implements ForumSharingManager, ForumManager.RemoveForumHook {
|
||||
|
||||
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
|
||||
"cd11a5d04dccd9e2931d6fc3df456313"
|
||||
+ "63bb3e9d9d0e9405fccdb051f41f5449"));
|
||||
|
||||
private final ForumManager forumManager;
|
||||
|
||||
private final SFactory sFactory;
|
||||
private final IFactory iFactory;
|
||||
private final ISFactory isFactory;
|
||||
@@ -63,7 +63,6 @@ class ForumSharingManagerImpl extends
|
||||
SecureRandom random) {
|
||||
super(db, messageQueueManager, clientHelper, metadataParser,
|
||||
metadataEncoder, random, privateGroupFactory, clock);
|
||||
this.forumManager = forumManager;
|
||||
|
||||
sFactory = new SFactory(forumFactory, forumManager);
|
||||
iFactory = new IFactory();
|
||||
@@ -79,15 +78,23 @@ class ForumSharingManagerImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ForumInvitationMessage createInvitationMessage(MessageId id,
|
||||
protected InvitationMessage createInvitationRequest(MessageId id,
|
||||
ForumInvitation msg, ContactId contactId, boolean available,
|
||||
long time, boolean local, boolean sent, boolean seen,
|
||||
boolean read) {
|
||||
return new ForumInvitationMessage(id, msg.getSessionId(), contactId,
|
||||
return new ForumInvitationRequest(id, msg.getSessionId(), contactId,
|
||||
msg.getForumName(), msg.getMessage(), available, time, local,
|
||||
sent, seen, read);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InvitationMessage createInvitationResponse(MessageId id,
|
||||
SessionId sessionId, ContactId contactId, boolean accept,
|
||||
long time, boolean local, boolean sent, boolean seen, boolean read) {
|
||||
return new ForumInvitationResponse(id, sessionId, contactId, accept,
|
||||
time, local, sent, seen, read);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShareableFactory<Forum, ForumInvitation, ForumInviteeSessionState, ForumSharerSessionState> getSFactory() {
|
||||
return sFactory;
|
||||
@@ -123,7 +130,7 @@ class ForumSharingManagerImpl extends
|
||||
removingShareable(txn, f);
|
||||
}
|
||||
|
||||
static class SFactory implements
|
||||
private static class SFactory implements
|
||||
ShareableFactory<Forum, ForumInvitation, ForumInviteeSessionState, ForumSharerSessionState> {
|
||||
|
||||
private final ForumFactory forumFactory;
|
||||
@@ -169,7 +176,7 @@ class ForumSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class IFactory implements
|
||||
private static class IFactory implements
|
||||
InvitationFactory<ForumInvitation, ForumSharerSessionState> {
|
||||
@Override
|
||||
public ForumInvitation build(GroupId groupId, BdfDictionary d)
|
||||
@@ -185,7 +192,7 @@ class ForumSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class ISFactory implements
|
||||
private static class ISFactory implements
|
||||
InviteeSessionStateFactory<Forum, ForumInviteeSessionState> {
|
||||
@Override
|
||||
public ForumInviteeSessionState build(SessionId sessionId,
|
||||
@@ -209,7 +216,7 @@ class ForumSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class SSFactory implements
|
||||
private static class SSFactory implements
|
||||
SharerSessionStateFactory<Forum, ForumSharerSessionState> {
|
||||
@Override
|
||||
public ForumSharerSessionState build(SessionId sessionId,
|
||||
@@ -233,7 +240,7 @@ class ForumSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class IRFactory implements
|
||||
private static class IRFactory implements
|
||||
InvitationReceivedEventFactory<ForumInviteeSessionState, ForumInvitationReceivedEvent> {
|
||||
|
||||
private final SFactory sFactory;
|
||||
@@ -251,7 +258,7 @@ class ForumSharingManagerImpl extends
|
||||
}
|
||||
}
|
||||
|
||||
static class IRRFactory implements
|
||||
private static class IRRFactory implements
|
||||
InvitationResponseReceivedEventFactory<ForumSharerSessionState, ForumInvitationResponseReceivedEvent> {
|
||||
@Override
|
||||
public ForumInvitationResponseReceivedEvent build(
|
||||
|
||||
@@ -23,7 +23,7 @@ import static org.briarproject.api.sharing.SharingMessage.BaseMessage;
|
||||
import static org.briarproject.api.sharing.SharingMessage.Invitation;
|
||||
import static org.briarproject.api.sharing.SharingMessage.SimpleMessage;
|
||||
|
||||
public class SharerEngine<I extends Invitation, SS extends SharerSessionState, IRR extends InvitationResponseReceivedEvent>
|
||||
class SharerEngine<I extends Invitation, SS extends SharerSessionState, IRR extends InvitationResponseReceivedEvent>
|
||||
implements ProtocolEngine<SharerSessionState.Action, SS, BaseMessage> {
|
||||
|
||||
private static final Logger LOG =
|
||||
|
||||
@@ -117,10 +117,14 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
|
||||
|
||||
public abstract ClientId getClientId();
|
||||
|
||||
protected abstract IM createInvitationMessage(MessageId id, I msg,
|
||||
protected abstract IM createInvitationRequest(MessageId id, I msg,
|
||||
ContactId contactId, boolean available, long time, boolean local,
|
||||
boolean sent, boolean seen, boolean read);
|
||||
|
||||
protected abstract IM createInvitationResponse(MessageId id,
|
||||
SessionId sessionId, ContactId contactId, boolean accept, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read);
|
||||
|
||||
protected abstract ShareableFactory<S, I, IS, SS> getSFactory();
|
||||
|
||||
protected abstract InvitationFactory<I, SS> getIFactory();
|
||||
@@ -325,11 +329,6 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
|
||||
public Collection<IM> getInvitationMessages(ContactId contactId)
|
||||
throws DbException {
|
||||
|
||||
// query for all invitations
|
||||
BdfDictionary query = BdfDictionary.of(
|
||||
new BdfEntry(TYPE, SHARE_MSG_TYPE_INVITATION)
|
||||
);
|
||||
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
@@ -337,30 +336,51 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IM
|
||||
|
||||
Collection<IM> list = new ArrayList<IM>();
|
||||
Map<MessageId, BdfDictionary> map = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, group.getId(), query);
|
||||
.getMessageMetadataAsDictionary(txn, group.getId());
|
||||
for (Map.Entry<MessageId, BdfDictionary> m : map.entrySet()) {
|
||||
BdfDictionary d = m.getValue();
|
||||
long type = d.getLong(TYPE);
|
||||
if (type == SHARE_MSG_TYPE_LEAVE ||
|
||||
type == SHARE_MSG_TYPE_ABORT) continue;
|
||||
try {
|
||||
I msg = getIFactory().build(group.getId(), d);
|
||||
MessageStatus status =
|
||||
db.getMessageStatus(txn, contactId, m.getKey());
|
||||
long time = d.getLong(TIME);
|
||||
boolean local = d.getBoolean(LOCAL);
|
||||
boolean read = d.getBoolean(READ, false);
|
||||
boolean available = false;
|
||||
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 (type == SHARE_MSG_TYPE_INVITATION) {
|
||||
I msg = getIFactory().build(group.getId(), d);
|
||||
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;
|
||||
}
|
||||
IM im = createInvitationRequest(m.getKey(), msg,
|
||||
contactId, available, time, local,
|
||||
status.isSent(), status.isSeen(), read);
|
||||
list.add(im);
|
||||
}
|
||||
else if (type == SHARE_MSG_TYPE_ACCEPT ||
|
||||
type == SHARE_MSG_TYPE_DECLINE) {
|
||||
boolean accept = type == SHARE_MSG_TYPE_ACCEPT;
|
||||
BaseMessage msg = BaseMessage
|
||||
.from(getIFactory(), group.getId(), d);
|
||||
SessionId sessionId = msg.getSessionId();
|
||||
IM im = createInvitationResponse(m.getKey(), sessionId,
|
||||
contactId, accept, time, local,
|
||||
status.isSent(), status.isSeen(), read);
|
||||
list.add(im);
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException("Unexpected Message Type");
|
||||
}
|
||||
IM im = createInvitationMessage(m.getKey(), msg, contactId,
|
||||
available, time, local, status.isSent(),
|
||||
status.isSeen(), read);
|
||||
list.add(im);
|
||||
} catch (FormatException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
|
||||
Reference in New Issue
Block a user