mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Facades for private messaging. #173
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user