mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Show Responses to Forum Invitations in Private Conversation
Closes #472
This commit is contained in:
@@ -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