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

@@ -2,8 +2,6 @@ package org.briarproject.android.blogs;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
@@ -39,19 +37,16 @@ import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.blogs.BlogConstants.MAX_BLOG_POST_BODY_LENGTH;
import static org.briarproject.api.blogs.BlogConstants.MAX_BLOG_POST_TITLE_LENGTH;
public class WriteBlogPostActivity extends BriarActivity
implements OnEditorActionListener {
private static final Logger LOG =
Logger.getLogger(WriteBlogPostActivity.class.getName());
private static final String contentType = "text/plain";
@Inject
protected AndroidNotificationManager notificationManager;
private TextInputEditText titleInput;
private EditText bodyInput;
private Button publishButton;
private ProgressBar progressBar;
@@ -76,16 +71,6 @@ public class WriteBlogPostActivity extends BriarActivity
setContentView(R.layout.activity_write_blog_post);
TextInputLayout titleLayout =
(TextInputLayout) findViewById(R.id.titleLayout);
if (titleLayout != null) {
titleLayout.setCounterMaxLength(MAX_BLOG_POST_TITLE_LENGTH);
}
titleInput = (TextInputEditText) findViewById(R.id.titleInput);
if (titleInput != null) {
titleInput.setOnEditorActionListener(this);
}
bodyInput = (EditText) findViewById(R.id.bodyInput);
bodyInput.addTextChangedListener(new TextWatcher() {
@Override
@@ -152,30 +137,24 @@ public class WriteBlogPostActivity extends BriarActivity
private void enableOrDisablePublishButton() {
int bodyLength =
StringUtils.toUtf8(bodyInput.getText().toString()).length;
if (bodyLength > 0 && bodyLength <= MAX_BLOG_POST_BODY_LENGTH &&
titleInput.getText().length() <= MAX_BLOG_POST_TITLE_LENGTH)
if (bodyLength > 0 && bodyLength <= MAX_BLOG_POST_BODY_LENGTH)
publishButton.setEnabled(true);
else
publishButton.setEnabled(false);
}
private void publish() {
// title
String title = titleInput.getText().toString();
if (title.length() > MAX_BLOG_POST_TITLE_LENGTH) return;
if (title.length() == 0) title = null;
// body
byte[] body = StringUtils.toUtf8(bodyInput.getText().toString());
String body = bodyInput.getText().toString();
// hide publish button, show progress bar
publishButton.setVisibility(GONE);
progressBar.setVisibility(VISIBLE);
storePost(title, body);
storePost(body);
}
private void storePost(final String title, final byte[] body) {
private void storePost(final String body) {
runOnDbThread(new Runnable() {
@Override
public void run() {
@@ -185,8 +164,7 @@ public class WriteBlogPostActivity extends BriarActivity
identityManager.getLocalAuthors();
LocalAuthor author = authors.iterator().next();
BlogPost p = blogPostFactory
.createBlogPost(groupId, title, now, null, author,
contentType, body);
.createBlogPost(groupId, now, null, author, body);
blogManager.addLocalPost(p);
postPublished();
} catch (DbException | GeneralSecurityException | FormatException e) {