mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Separate the sync layer from its clients. #112
This commit is contained in:
@@ -1,10 +1,37 @@
|
||||
package org.briarproject.api.forum;
|
||||
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
public interface Forum {
|
||||
public class Forum {
|
||||
|
||||
GroupId getId();
|
||||
private final Group group;
|
||||
private final String name;
|
||||
|
||||
String getName();
|
||||
public Forum(Group group, String name) {
|
||||
this.group = group;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public GroupId getId() {
|
||||
return group.getId();
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return group.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Forum && group.equals(((Forum) o).group);
|
||||
}
|
||||
}
|
||||
|
||||
19
briar-api/src/org/briarproject/api/forum/ForumConstants.java
Normal file
19
briar-api/src/org/briarproject/api/forum/ForumConstants.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.briarproject.api.forum;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface ForumConstants {
|
||||
|
||||
/** The maximum length of a forum's name in bytes. */
|
||||
int MAX_FORUM_NAME_LENGTH = MAX_GROUP_DESCRIPTOR_LENGTH - 10;
|
||||
|
||||
/** The length of a forum's random salt in bytes. */
|
||||
int FORUM_SALT_LENGTH = 32;
|
||||
|
||||
/** The maximum length of a forum post's content type in bytes. */
|
||||
int MAX_CONTENT_TYPE_LENGTH = 50;
|
||||
|
||||
/** The maximum length of a forum post's body in bytes. */
|
||||
int MAX_FORUM_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.briarproject.api.forum;
|
||||
|
||||
public interface ForumFactory {
|
||||
|
||||
/** Creates a forum with the given name and a random salt. */
|
||||
Forum createForum(String name);
|
||||
}
|
||||
@@ -3,14 +3,20 @@ package org.briarproject.api.forum;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface ForumManager {
|
||||
|
||||
/** Returns the unique ID of the forum client. */
|
||||
ClientId getClientId();
|
||||
|
||||
/** Creates a forum with the given name. */
|
||||
Forum createForum(String name);
|
||||
|
||||
/**
|
||||
* Subscribes to a forum, or returns false if the user already has the
|
||||
* maximum number of forum subscriptions.
|
||||
@@ -18,7 +24,7 @@ public interface ForumManager {
|
||||
boolean addForum(Forum f) throws DbException;
|
||||
|
||||
/** Stores a local forum post. */
|
||||
void addLocalPost(Message m) throws DbException;
|
||||
void addLocalPost(ForumPost p) throws DbException;
|
||||
|
||||
/** Returns all forums to which the user could subscribe. */
|
||||
Collection<Forum> getAvailableForums() throws DbException;
|
||||
|
||||
37
briar-api/src/org/briarproject/api/forum/ForumPost.java
Normal file
37
briar-api/src/org/briarproject/api/forum/ForumPost.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package org.briarproject.api.forum;
|
||||
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class ForumPost {
|
||||
|
||||
private final Message message;
|
||||
private final MessageId parent;
|
||||
private final Author author;
|
||||
private final String contentType;
|
||||
|
||||
public ForumPost(Message message, MessageId parent, Author author,
|
||||
String contentType) {
|
||||
this.message = message;
|
||||
this.parent = parent;
|
||||
this.author = author;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public MessageId getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package org.briarproject.api.forum;
|
||||
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -10,12 +10,12 @@ import java.security.GeneralSecurityException;
|
||||
|
||||
public interface ForumPostFactory {
|
||||
|
||||
Message createAnonymousPost(MessageId parent, Forum forum,
|
||||
String contentType, long timestamp, byte[] body) throws IOException,
|
||||
GeneralSecurityException;
|
||||
ForumPost createAnonymousPost(GroupId groupId, long timestamp,
|
||||
MessageId parent, String contentType, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
|
||||
Message createPseudonymousPost(MessageId parent, Forum forum,
|
||||
Author author, PrivateKey privateKey, String contentType,
|
||||
long timestamp, byte[] body) throws IOException,
|
||||
ForumPost createPseudonymousPost(GroupId groupId, long timestamp,
|
||||
MessageId parent, Author author, String contentType, byte[] body,
|
||||
PrivateKey privateKey) throws IOException,
|
||||
GeneralSecurityException;
|
||||
}
|
||||
|
||||
@@ -3,17 +3,46 @@ package org.briarproject.api.forum;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public interface ForumPostHeader {
|
||||
public class ForumPostHeader {
|
||||
|
||||
MessageId getId();
|
||||
private final MessageId id;
|
||||
private final long timestamp;
|
||||
private final Author author;
|
||||
private final Author.Status authorStatus;
|
||||
private final String contentType;
|
||||
private final boolean read;
|
||||
|
||||
Author getAuthor();
|
||||
public ForumPostHeader(MessageId id, long timestamp, Author author,
|
||||
Author.Status authorStatus, String contentType, boolean read) {
|
||||
this.id = id;
|
||||
this.timestamp = timestamp;
|
||||
this.author = author;
|
||||
this.authorStatus = authorStatus;
|
||||
this.contentType = contentType;
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
Author.Status getAuthorStatus();
|
||||
public MessageId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
String getContentType();
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
long getTimestamp();
|
||||
public Author.Status getAuthorStatus() {
|
||||
return authorStatus;
|
||||
}
|
||||
|
||||
boolean isRead();
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user