Facades for private messaging. #173

This commit is contained in:
akwizgran
2015-12-17 15:29:20 +00:00
parent 4450ab171a
commit 87689855da
10 changed files with 144 additions and 62 deletions

View File

@@ -6,7 +6,7 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.PrivateConversation;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageHeader;
@@ -14,6 +14,7 @@ import org.briarproject.api.sync.MessageId;
import java.util.Collection;
// Temporary facade during sync protocol refactoring
class MessagingManagerImpl implements MessagingManager {
private final DatabaseComponent db;
@@ -23,28 +24,23 @@ class MessagingManagerImpl implements MessagingManager {
this.db = db;
}
@Override
public boolean addGroup(Group g) throws DbException {
return db.addGroup(g);
}
@Override
public void addLocalMessage(Message m) throws DbException {
db.addLocalMessage(m);
}
@Override
public Group getGroup(GroupId g) throws DbException {
return db.getGroup(g);
public PrivateConversation getConversation(GroupId g) throws DbException {
return new PrivateConversationImpl(db.getGroup(g));
}
@Override
public GroupId getInboxGroupId(ContactId c) throws DbException {
public GroupId getConversationId(ContactId c) throws DbException {
return db.getInboxGroupId(c);
}
@Override
public Collection<MessageHeader> getInboxMessageHeaders(ContactId c)
public Collection<MessageHeader> getMessageHeaders(ContactId c)
throws DbException {
return db.getInboxMessageHeaders(c);
}
@@ -55,8 +51,9 @@ class MessagingManagerImpl implements MessagingManager {
}
@Override
public void setInboxGroup(ContactId c, Group g) throws DbException {
db.setInboxGroup(c, g);
public void setConversation(ContactId c, PrivateConversation p)
throws DbException {
db.setInboxGroup(c, ((PrivateConversationImpl) p).getGroup());
}
@Override

View File

@@ -3,11 +3,13 @@ package org.briarproject.messaging;
import com.google.inject.AbstractModule;
import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.messaging.PrivateMessageFactory;
public class MessagingModule extends AbstractModule {
@Override
protected void configure() {
bind(MessagingManager.class).to(MessagingManagerImpl.class);
bind(PrivateMessageFactory.class).to(PrivateMessageFactoryImpl.class);
}
}

View File

@@ -0,0 +1,35 @@
package org.briarproject.messaging;
import org.briarproject.api.messaging.PrivateConversation;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
// Temporary facade during sync protocol refactoring
class PrivateConversationImpl implements PrivateConversation {
private final Group group;
PrivateConversationImpl(Group group) {
this.group = group;
}
@Override
public GroupId getId() {
return group.getId();
}
Group getGroup() {
return group;
}
@Override
public int hashCode() {
return group.hashCode();
}
@Override
public boolean equals(Object o) {
return o instanceof PrivateConversationImpl
&& group.equals(((PrivateConversationImpl) o).group);
}
}

View File

@@ -0,0 +1,33 @@
package org.briarproject.messaging;
import com.google.inject.Inject;
import org.briarproject.api.messaging.PrivateConversation;
import org.briarproject.api.messaging.PrivateMessageFactory;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.sync.MessageId;
import java.io.IOException;
import java.security.GeneralSecurityException;
// Temporary facade during sync protocol refactoring
class PrivateMessageFactoryImpl implements PrivateMessageFactory {
private final MessageFactory messageFactory;
@Inject
PrivateMessageFactoryImpl(MessageFactory messageFactory) {
this.messageFactory = messageFactory;
}
@Override
public Message createPrivateMessage(MessageId parent,
PrivateConversation conversation, String contentType,
long timestamp, byte[] body)
throws IOException, GeneralSecurityException {
return messageFactory.createAnonymousMessage(parent,
((PrivateConversationImpl) conversation).getGroup(),
contentType, timestamp, body);
}
}