Add support for comments and reblogging to Blog Client

Comments and reblogs need to depend on the post they refer to.
Since message dependencies are limited to one group,
the post and also the comments need to be wrapped
when commented on or reblogged to another blog.

For this reason, in addition to comments, two new wrapping message types
are introduced. They retain all data of the original messages and allow
for reconstruction and signature verification.

This commit breaks backwards compatibility with old blog posts.
It removes the content type, title and parent ID from the post
message structure.
This commit is contained in:
Torsten Grote
2016-08-11 19:34:52 -03:00
parent 743fc7dd1f
commit 3dd3a18694
29 changed files with 874 additions and 320 deletions

View File

@@ -0,0 +1,43 @@
package org.briarproject.api.blogs;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.Author.Status;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static org.briarproject.api.blogs.MessageType.COMMENT;
import static org.briarproject.api.blogs.MessageType.WRAPPED_COMMENT;
public class BlogCommentHeader extends BlogPostHeader {
private String comment;
private BlogPostHeader parent;
public BlogCommentHeader(@NotNull MessageType type,
@NotNull GroupId groupId, @Nullable String comment,
@NotNull BlogPostHeader parent, @NotNull MessageId id,
long timestamp, long timeReceived, @NotNull Author author,
@NotNull Status authorStatus, boolean read) {
super(type, groupId, id, parent.getId(), timestamp,
timeReceived, author, authorStatus, read);
if (type != COMMENT && type != WRAPPED_COMMENT)
throw new IllegalArgumentException("Incompatible Message Type");
this.comment = comment;
this.parent = parent;
}
@Nullable
public String getComment() {
return comment;
}
@NotNull
public BlogPostHeader getParent() {
return parent;
}
}

View File

@@ -10,12 +10,6 @@ public interface BlogConstants {
/** The length of a blogs's description in UTF-8 bytes. */
int MAX_BLOG_DESC_LENGTH = 240;
/** The maximum length of a blog post's content type in UTF-8 bytes. */
int MAX_CONTENT_TYPE_LENGTH = 50;
/** The length of a blog post's title in UTF-8 bytes. */
int MAX_BLOG_POST_TITLE_LENGTH = 100;
/** The maximum length of a blog post's body in bytes. */
int MAX_BLOG_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
@@ -31,17 +25,16 @@ public interface BlogConstants {
// Metadata keys
String KEY_TYPE = "type";
String KEY_DESCRIPTION = "description";
String KEY_TITLE = "title";
String KEY_TIMESTAMP = "timestamp";
String KEY_TIME_RECEIVED = "timeReceived";
String KEY_AUTHOR_ID = "id";
String KEY_AUTHOR_NAME = "name";
String KEY_PUBLIC_KEY = "publicKey";
String KEY_AUTHOR = "author";
String KEY_CONTENT_TYPE = "contentType";
String KEY_READ = "read";
String KEY_COMMENT = "comment";
String KEY_ORIGINAL_MSG_ID = "originalMessageId";
String KEY_CURRENT_MSG_ID = "currentMessageId";
String KEY_ORIGINAL_PARENT_MSG_ID = "originalParentMessageId";
String KEY_WRAPPED_MSG_ID = "wrappedMessageId";
}

View File

@@ -7,6 +7,7 @@ import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -31,6 +32,11 @@ public interface BlogManager {
/** Stores a local blog post. */
void addLocalPost(Transaction txn, BlogPost p) throws DbException;
/** Add a comment to an existing blog post or reblog it. */
void addLocalComment(LocalAuthor author, GroupId groupId,
@Nullable String comment, BlogPostHeader wHeader)
throws DbException;
/** Returns the blog with the given ID. */
Blog getBlog(GroupId g) throws DbException;
@@ -47,7 +53,7 @@ public interface BlogManager {
Collection<Blog> getBlogs() throws DbException;
/** Returns the header of the blog post with the given ID. */
BlogPostHeader getPostHeader(MessageId m) throws DbException;
BlogPostHeader getPostHeader(GroupId g, MessageId m) throws DbException;
/** Returns the body of the blog post with the given ID. */
byte[] getPostBody(MessageId m) throws DbException;

View File

@@ -9,19 +9,8 @@ import org.jetbrains.annotations.Nullable;
public class BlogPost extends ForumPost {
@Nullable
private final String title;
public BlogPost(@Nullable String title, @NotNull Message message,
@Nullable MessageId parent, @NotNull Author author,
@NotNull String contentType) {
super(message, parent, author, contentType);
this.title = title;
}
@Nullable
public String getTitle() {
return title;
public BlogPost(@NotNull Message message, @Nullable MessageId parent,
@NotNull Author author) {
super(message, parent, author);
}
}

View File

@@ -1,8 +1,10 @@
package org.briarproject.api.blogs;
import org.briarproject.api.FormatException;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -11,9 +13,30 @@ import java.security.GeneralSecurityException;
public interface BlogPostFactory {
BlogPost createBlogPost(@NotNull GroupId groupId, @Nullable String title,
long timestamp, @Nullable MessageId parent,
@NotNull LocalAuthor author, @NotNull String contentType,
@NotNull byte[] body)
BlogPost createBlogPost(@NotNull GroupId groupId, long timestamp,
@Nullable MessageId parent, @NotNull LocalAuthor author,
@NotNull String body)
throws FormatException, GeneralSecurityException;
Message createBlogComment(GroupId groupId, LocalAuthor author,
@Nullable String comment, MessageId originalId, MessageId wrappedId)
throws FormatException, GeneralSecurityException;
/** Wraps a blog post */
Message createWrappedPost(GroupId groupId, byte[] descriptor,
long timestamp, BdfList body)
throws FormatException;
/** Re-wraps a previously wrapped post */
Message createWrappedPost(GroupId groupId, BdfList body)
throws FormatException;
/** Wraps a blog comment */
Message createWrappedComment(GroupId groupId, byte[] descriptor,
long timestamp, BdfList body, MessageId currentId)
throws FormatException;
/** Re-wraps a previously wrapped comment */
Message createWrappedComment(GroupId groupId, BdfList body,
MessageId currentId) throws FormatException;
}

View File

@@ -3,33 +3,45 @@ package org.briarproject.api.blogs;
import org.briarproject.api.clients.PostHeader;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.Author.Status;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class BlogPostHeader extends PostHeader {
@Nullable
private final String title;
private final MessageType type;
private final GroupId groupId;
private final long timeReceived;
public BlogPostHeader(@Nullable String title, @NotNull MessageId id,
long timestamp, long timeReceived, @NotNull Author author,
@NotNull Status authorStatus, @NotNull String contentType,
boolean read) {
super(id, null, timestamp, author, authorStatus, contentType, read);
public BlogPostHeader(@NotNull MessageType type, @NotNull GroupId groupId,
@NotNull MessageId id, @Nullable MessageId parentId, long timestamp,
long timeReceived, @NotNull Author author,
@NotNull Status authorStatus, boolean read) {
super(id, parentId, timestamp, author, authorStatus, read);
this.title = title;
this.type = type;
this.groupId = groupId;
this.timeReceived = timeReceived;
}
@Nullable
public String getTitle() {
return title;
public BlogPostHeader(@NotNull MessageType type, @NotNull GroupId groupId,
@NotNull MessageId id, long timestamp, long timeReceived,
@NotNull Author author, @NotNull Status authorStatus,
boolean read) {
this(type, groupId, id, null, timestamp, timeReceived, author,
authorStatus, read);
}
public MessageType getType() {
return type;
}
public GroupId getGroupId() {
return groupId;
}
public long getTimeReceived() {
return timeReceived;
}
}