mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Address review comments
This commit is contained in:
@@ -14,6 +14,9 @@ import org.briarproject.briar.api.blog.BlogFactory;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class BlogFactoryImpl implements BlogFactory {
|
||||
@@ -58,13 +61,21 @@ class BlogFactoryImpl implements BlogFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blog parseBlog(Group g) throws FormatException {
|
||||
byte[] descriptor = g.getDescriptor();
|
||||
public Blog parseBlog(Group group) throws FormatException {
|
||||
byte[] descriptor = group.getDescriptor();
|
||||
// Author Name, Public Key
|
||||
BdfList blog = clientHelper.toList(descriptor);
|
||||
Author a =
|
||||
authorFactory.createAuthor(blog.getString(0), blog.getRaw(1));
|
||||
return new Blog(g, a, blog.getBoolean(2));
|
||||
String name = blog.getString(0);
|
||||
if (name.length() > MAX_AUTHOR_NAME_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
byte[] publicKey = blog.getRaw(1);
|
||||
if (publicKey.length > MAX_PUBLIC_KEY_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
Author author =
|
||||
authorFactory.createAuthor(name, publicKey);
|
||||
boolean rssFeed = blog.getBoolean(2);
|
||||
return new Blog(group, author, rssFeed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
boolean isFeedPost = meta.getBoolean(KEY_RSS_FEED, false);
|
||||
Status authorStatus;
|
||||
if (isFeedPost) {
|
||||
authorStatus = Status.UNKNOWN;
|
||||
authorStatus = Status.NONE;
|
||||
} else if (authorStatuses.containsKey(authorId)) {
|
||||
authorStatus = authorStatuses.get(authorId);
|
||||
} else {
|
||||
|
||||
@@ -10,18 +10,19 @@ import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
import org.briarproject.briar.api.blog.BlogFactory;
|
||||
import org.briarproject.briar.api.feed.Feed;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_BLOG_TITLE;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_ADDED;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_AUTHOR;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_DESC;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_LAST_ENTRY;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_TITLE;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_UPDATED;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_URL;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_PRIVATE_KEY;
|
||||
@@ -45,11 +46,13 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
|
||||
@Override
|
||||
public Feed createFeed(String url, SyndFeed syndFeed) {
|
||||
if (syndFeed.getTitle() == null) syndFeed.setTitle("RSS feed");
|
||||
String title = syndFeed.getTitle();
|
||||
if (title == null) title = "RSS";
|
||||
title = StringUtils.truncateUtf8(title, MAX_AUTHOR_NAME_LENGTH);
|
||||
|
||||
KeyPair keyPair = cryptoComponent.generateSignatureKeyPair();
|
||||
LocalAuthor localAuthor = authorFactory
|
||||
.createLocalAuthor(syndFeed.getTitle(),
|
||||
.createLocalAuthor(title,
|
||||
keyPair.getPublic().getEncoded(),
|
||||
keyPair.getPrivate().getEncoded());
|
||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||
@@ -62,8 +65,8 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
public Feed createFeed(Feed feed, SyndFeed f, long lastEntryTime) {
|
||||
long updated = clock.currentTimeMillis();
|
||||
return new Feed(feed.getUrl(), feed.getBlog(), feed.getLocalAuthor(),
|
||||
f.getTitle(), f.getDescription(), f.getAuthor(),
|
||||
feed.getAdded(), updated, lastEntryTime);
|
||||
f.getDescription(), f.getAuthor(), feed.getAdded(), updated,
|
||||
lastEntryTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,14 +80,13 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
.createLocalAuthor(blogTitle, publicKey, privateKey);
|
||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||
|
||||
String title = d.getOptionalString(KEY_FEED_TITLE);
|
||||
String desc = d.getOptionalString(KEY_FEED_DESC);
|
||||
String author = d.getOptionalString(KEY_FEED_AUTHOR);
|
||||
long added = d.getLong(KEY_FEED_ADDED, 0L);
|
||||
long updated = d.getLong(KEY_FEED_UPDATED, 0L);
|
||||
long lastEntryTime = d.getLong(KEY_FEED_LAST_ENTRY, 0L);
|
||||
|
||||
return new Feed(url, blog, localAuthor, title, desc, author, added,
|
||||
return new Feed(url, blog, localAuthor, desc, author, added,
|
||||
updated, lastEntryTime);
|
||||
}
|
||||
|
||||
@@ -101,7 +103,6 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
new BdfEntry(KEY_FEED_UPDATED, feed.getUpdated()),
|
||||
new BdfEntry(KEY_FEED_LAST_ENTRY, feed.getLastEntryTime())
|
||||
);
|
||||
if (feed.getTitle() != null) d.put(KEY_FEED_TITLE, feed.getTitle());
|
||||
if (feed.getDescription() != null)
|
||||
d.put(KEY_FEED_DESC, feed.getDescription());
|
||||
if (feed.getAuthor() != null) d.put(KEY_FEED_AUTHOR, feed.getAuthor());
|
||||
|
||||
@@ -433,9 +433,8 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
|
||||
// build post body
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (feed.getTitle() != null) {
|
||||
b.append("<h3>").append(feed.getTitle()).append("</h3>");
|
||||
}
|
||||
b.append("<h3>").append(feed.getTitle()).append("</h3>");
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(entry.getTitle())) {
|
||||
b.append("<h1>").append(entry.getTitle()).append("</h1>");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.briar.blog;
|
||||
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
@@ -417,6 +418,7 @@ public class BlogManagerIntegrationTest
|
||||
assertEquals(1, headers.size());
|
||||
BlogPostHeader header = headers.iterator().next();
|
||||
assertEquals(POST, header.getType());
|
||||
assertEquals(Author.Status.NONE, header.getAuthorStatus());
|
||||
assertTrue(header.isRssFeed());
|
||||
}
|
||||
|
||||
@@ -454,7 +456,7 @@ public class BlogManagerIntegrationTest
|
||||
for (BlogPostHeader h: headers) {
|
||||
assertTrue(h instanceof BlogCommentHeader);
|
||||
assertEquals(COMMENT, h.getType());
|
||||
assertTrue(((BlogCommentHeader) h).getParent().isRssFeed());
|
||||
assertTrue(((BlogCommentHeader) h).getRootPost().isRssFeed());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user