mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Facades for forums. #172
This commit is contained in:
@@ -222,8 +222,10 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
if (!duplicate && subscribed)
|
||||
eventBus.broadcast(new MessageAddedEvent(m.getGroup(), null));
|
||||
if (!duplicate && subscribed) {
|
||||
GroupId g = m.getGroup().getId();
|
||||
eventBus.broadcast(new MessageAddedEvent(g, null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1050,8 +1052,10 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
if (visible) {
|
||||
if (!duplicate)
|
||||
eventBus.broadcast(new MessageAddedEvent(m.getGroup(), c));
|
||||
if (!duplicate) {
|
||||
GroupId g = m.getGroup().getId();
|
||||
eventBus.broadcast(new MessageAddedEvent(g, c));
|
||||
}
|
||||
eventBus.broadcast(new MessageToAckEvent(c));
|
||||
}
|
||||
}
|
||||
|
||||
22
briar-core/src/org/briarproject/forum/ForumFactoryImpl.java
Normal file
22
briar-core/src/org/briarproject/forum/ForumFactoryImpl.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.forum;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumFactory;
|
||||
import org.briarproject.api.sync.GroupFactory;
|
||||
|
||||
// Temporary facade during sync protocol refactoring
|
||||
class ForumFactoryImpl implements ForumFactory {
|
||||
|
||||
private final GroupFactory groupFactory;
|
||||
|
||||
@Inject
|
||||
ForumFactoryImpl(GroupFactory groupFactory) {
|
||||
this.groupFactory = groupFactory;
|
||||
}
|
||||
|
||||
public Forum createForum(String name) {
|
||||
return new ForumImpl(groupFactory.createGroup(name));
|
||||
}
|
||||
}
|
||||
37
briar-core/src/org/briarproject/forum/ForumImpl.java
Normal file
37
briar-core/src/org/briarproject/forum/ForumImpl.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package org.briarproject.forum;
|
||||
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
// Temporary facade during sync protocol refactoring
|
||||
class ForumImpl implements Forum {
|
||||
|
||||
private final Group group;
|
||||
|
||||
ForumImpl(Group group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public GroupId getId() {
|
||||
return group.getId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return group.getName();
|
||||
}
|
||||
|
||||
Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return group.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof ForumImpl && group.equals(((ForumImpl) o).group);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
@@ -13,8 +14,12 @@ import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageHeader;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
// Temporary facade during sync protocol refactoring
|
||||
class ForumManagerImpl implements ForumManager {
|
||||
|
||||
private final DatabaseComponent db;
|
||||
@@ -25,8 +30,8 @@ class ForumManagerImpl implements ForumManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addGroup(Group g) throws DbException {
|
||||
return db.addGroup(g);
|
||||
public boolean addForum(Forum f) throws DbException {
|
||||
return db.addGroup(((ForumImpl) f).getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,18 +40,24 @@ class ForumManagerImpl implements ForumManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Group> getAvailableGroups() throws DbException {
|
||||
return db.getAvailableGroups();
|
||||
public Collection<Forum> getAvailableForums() throws DbException {
|
||||
Collection<Group> groups = db.getAvailableGroups();
|
||||
List<Forum> forums = new ArrayList<Forum>(groups.size());
|
||||
for (Group g : groups) forums.add(new ForumImpl(g));
|
||||
return Collections.unmodifiableList(forums);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getGroup(GroupId g) throws DbException {
|
||||
return db.getGroup(g);
|
||||
public Forum getForum(GroupId g) throws DbException {
|
||||
return new ForumImpl(db.getGroup(g));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Group> getGroups() throws DbException {
|
||||
return db.getGroups();
|
||||
public Collection<Forum> getForums() throws DbException {
|
||||
Collection<Group> groups = db.getGroups();
|
||||
List<Forum> forums = new ArrayList<Forum>(groups.size());
|
||||
for (Group g : groups) forums.add(new ForumImpl(g));
|
||||
return Collections.unmodifiableList(forums);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,8 +82,8 @@ class ForumManagerImpl implements ForumManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(Group g) throws DbException {
|
||||
db.removeGroup(g);
|
||||
public void removeForum(Forum f) throws DbException {
|
||||
db.removeGroup(((ForumImpl) f).getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,12 +2,16 @@ package org.briarproject.forum;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
import org.briarproject.api.forum.ForumFactory;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
import org.briarproject.api.forum.ForumPostFactory;
|
||||
|
||||
public class ForumModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ForumFactory.class).to(ForumFactoryImpl.class);
|
||||
bind(ForumManager.class).to(ForumManagerImpl.class);
|
||||
bind(ForumPostFactory.class).to(ForumPostFactoryImpl.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.briarproject.forum;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.forum.ForumPostFactory;
|
||||
import org.briarproject.api.identity.Author;
|
||||
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 ForumPostFactoryImpl implements ForumPostFactory {
|
||||
|
||||
private final MessageFactory messageFactory;
|
||||
|
||||
@Inject
|
||||
ForumPostFactoryImpl(MessageFactory messageFactory) {
|
||||
this.messageFactory = messageFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createAnonymousPost(MessageId parent, Forum forum,
|
||||
String contentType, long timestamp, byte[] body)
|
||||
throws IOException, GeneralSecurityException {
|
||||
return messageFactory.createAnonymousMessage(parent,
|
||||
((ForumImpl) forum).getGroup(), contentType, timestamp, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createPseudonymousPost(MessageId parent, Forum forum,
|
||||
Author author, PrivateKey privateKey, String contentType,
|
||||
long timestamp, byte[] body)
|
||||
throws IOException, GeneralSecurityException {
|
||||
return messageFactory.createPseudonymousMessage(parent,
|
||||
((ForumImpl) forum).getGroup(), author, privateKey, contentType,
|
||||
timestamp, body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user