mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Show blog posts from RSS feeds with a dedicated icon
This adds a field to the post headers and some more tests.
This commit is contained in:
@@ -61,6 +61,7 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
|
||||
@@ -253,15 +254,18 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
@Override
|
||||
public void addLocalPost(Transaction txn, BlogPost p) throws DbException {
|
||||
try {
|
||||
GroupId groupId = p.getMessage().getGroupId();
|
||||
Blog b = getBlog(txn, groupId);
|
||||
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(KEY_TYPE, POST.getInt());
|
||||
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
|
||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(p.getAuthor()));
|
||||
meta.put(KEY_READ, true);
|
||||
meta.put(KEY_RSS_FEED, b.isRssFeed());
|
||||
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true);
|
||||
|
||||
// broadcast event about new post
|
||||
GroupId groupId = p.getMessage().getGroupId();
|
||||
MessageId postId = p.getMessage().getId();
|
||||
BlogPostHeader h =
|
||||
getPostHeaderFromMetadata(txn, groupId, postId, meta);
|
||||
@@ -350,6 +354,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
wMessage = blogPostFactory
|
||||
.wrapPost(groupId, wDescriptor, wTimestamp, body);
|
||||
meta.put(KEY_TYPE, WRAPPED_POST.getInt());
|
||||
meta.put(KEY_RSS_FEED, pOriginalHeader.isRssFeed());
|
||||
} else if (type == COMMENT) {
|
||||
Group wGroup = db.getGroup(txn, pOriginalHeader.getGroupId());
|
||||
byte[] wDescriptor = wGroup.getDescriptor();
|
||||
@@ -598,8 +603,11 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
String name = d.getString(KEY_AUTHOR_NAME);
|
||||
byte[] publicKey = d.getRaw(KEY_PUBLIC_KEY);
|
||||
Author author = new Author(authorId, name, publicKey);
|
||||
boolean isFeedPost = meta.getBoolean(KEY_RSS_FEED, false);
|
||||
Status authorStatus;
|
||||
if (authorStatuses.containsKey(authorId)) {
|
||||
if (isFeedPost) {
|
||||
authorStatus = Status.UNKNOWN;
|
||||
} else if (authorStatuses.containsKey(authorId)) {
|
||||
authorStatus = authorStatuses.get(authorId);
|
||||
} else {
|
||||
authorStatus = identityManager.getAuthorStatus(txn, authorId);
|
||||
@@ -616,7 +624,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
timestamp, timeReceived, author, authorStatus, read);
|
||||
} else {
|
||||
return new BlogPostHeader(type, groupId, id, timestamp,
|
||||
timeReceived, author, authorStatus, read);
|
||||
timeReceived, author, authorStatus, isFeedPost, read);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
|
||||
@@ -123,6 +124,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
|
||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(a));
|
||||
meta.put(KEY_RSS_FEED, b.isRssFeed());
|
||||
return new BdfMessageContext(meta);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.briar.blog;
|
||||
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
@@ -32,7 +33,7 @@ public class BlogManagerIntegrationTest
|
||||
extends BriarIntegrationTest<BriarIntegrationTestComponent> {
|
||||
|
||||
private BlogManager blogManager0, blogManager1;
|
||||
private Blog blog0, blog1;
|
||||
private Blog blog0, blog1, rssBlog;
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
@@ -50,6 +51,12 @@ public class BlogManagerIntegrationTest
|
||||
|
||||
blog0 = blogFactory.createBlog(author0);
|
||||
blog1 = blogFactory.createBlog(author1);
|
||||
|
||||
rssBlog = blogFactory.createFeedBlog(author0);
|
||||
Transaction txn = db0.startTransaction(false);
|
||||
blogManager0.addBlog(txn, rssBlog);
|
||||
db0.commitTransaction(txn);
|
||||
db0.endTransaction(txn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -393,4 +400,62 @@ public class BlogManagerIntegrationTest
|
||||
assertEquals(2, headers0.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFeedPost() throws Exception {
|
||||
assertTrue(rssBlog.isRssFeed());
|
||||
|
||||
// add a feed post to rssBlog
|
||||
final String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, body);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// make sure it got saved as an RSS feed post
|
||||
Collection<BlogPostHeader> headers =
|
||||
blogManager0.getPostHeaders(rssBlog.getId());
|
||||
assertEquals(1, headers.size());
|
||||
BlogPostHeader header = headers.iterator().next();
|
||||
assertEquals(POST, header.getType());
|
||||
assertTrue(header.isRssFeed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFeedReblog() throws Exception {
|
||||
// add a feed post to rssBlog
|
||||
final String body = getRandomString(42);
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(rssBlog.getId(), clock.currentTimeMillis(),
|
||||
null, author0, body);
|
||||
blogManager0.addLocalPost(p);
|
||||
|
||||
// reblog feed post to own blog
|
||||
Collection<BlogPostHeader> headers =
|
||||
blogManager0.getPostHeaders(rssBlog.getId());
|
||||
assertEquals(1, headers.size());
|
||||
BlogPostHeader header = headers.iterator().next();
|
||||
blogManager0.addLocalComment(author0, blog0.getId(), null, header);
|
||||
|
||||
// make sure it got saved as an RSS feed post
|
||||
headers = blogManager0.getPostHeaders(blog0.getId());
|
||||
assertEquals(1, headers.size());
|
||||
BlogCommentHeader commentHeader =
|
||||
(BlogCommentHeader) headers.iterator().next();
|
||||
assertEquals(COMMENT, commentHeader.getType());
|
||||
assertTrue(commentHeader.getParent().isRssFeed());
|
||||
|
||||
// reblog reblogged post again to own blog
|
||||
blogManager0
|
||||
.addLocalComment(author0, blog0.getId(), null, commentHeader);
|
||||
|
||||
// make sure it got saved as an RSS feed post
|
||||
headers = blogManager0.getPostHeaders(blog0.getId());
|
||||
assertEquals(2, headers.size());
|
||||
for (BlogPostHeader h: headers) {
|
||||
assertTrue(h instanceof BlogCommentHeader);
|
||||
assertEquals(COMMENT, h.getType());
|
||||
assertTrue(((BlogCommentHeader) h).getParent().isRssFeed());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.transport.TransportModule;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
import org.briarproject.briar.api.blog.BlogManager;
|
||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||
import org.briarproject.briar.api.feed.Feed;
|
||||
import org.briarproject.briar.api.feed.FeedManager;
|
||||
import org.briarproject.briar.blog.BlogModule;
|
||||
@@ -88,6 +89,13 @@ public class FeedManagerIntegrationTest extends BriarTestCase {
|
||||
assertEquals(feed.getTitle(), feed.getBlog().getName());
|
||||
assertEquals(feed.getTitle(), feed.getLocalAuthor().getName());
|
||||
|
||||
// check the feed entries have been added to the blog as expected
|
||||
Collection<BlogPostHeader> headers =
|
||||
blogManager.getPostHeaders(feedBlog.getId());
|
||||
for (BlogPostHeader header : headers) {
|
||||
assertTrue(header.isRssFeed());
|
||||
}
|
||||
|
||||
// now let's remove the feed's blog again
|
||||
blogManager.removeBlog(feedBlog);
|
||||
blogs = blogManager.getBlogs();
|
||||
|
||||
Reference in New Issue
Block a user