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