mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Store additional properties of RSS feed in metadata.
This commit is contained in:
@@ -17,6 +17,7 @@ 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 org.briarproject.briar.api.feed.RssProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -27,6 +28,9 @@ 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_PRIVATE_KEY;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_RSS_AUTHOR;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_RSS_LINK;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_RSS_TITLE;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_RSS_URI;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_UPDATED;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_URL;
|
||||
|
||||
@@ -56,20 +60,20 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||
long added = clock.currentTimeMillis();
|
||||
|
||||
return new Feed(url, blog, localAuthor, added);
|
||||
RssProperties properties =
|
||||
new RssProperties(url, null, null, null, null, null);
|
||||
return new Feed(blog, localAuthor, properties, added, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feed createFeed(Feed feed, SyndFeed f, long lastEntryTime) {
|
||||
long updated = clock.currentTimeMillis();
|
||||
return new Feed(feed.getUrl(), feed.getBlog(), feed.getLocalAuthor(),
|
||||
f.getDescription(), f.getAuthor(), feed.getAdded(), updated,
|
||||
lastEntryTime);
|
||||
return new Feed(feed.getBlog(), feed.getLocalAuthor(),
|
||||
feed.getProperties(), feed.getAdded(), updated, lastEntryTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feed createFeed(BdfDictionary d) throws FormatException {
|
||||
String url = d.getString(KEY_FEED_URL);
|
||||
|
||||
BdfList authorList = d.getList(KEY_FEED_AUTHOR);
|
||||
PrivateKey privateKey =
|
||||
@@ -80,14 +84,21 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
author.getPublicKey(), privateKey);
|
||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||
|
||||
String desc = d.getOptionalString(KEY_FEED_DESC);
|
||||
String url = d.getOptionalString(KEY_FEED_URL);
|
||||
String description = d.getOptionalString(KEY_FEED_DESC);
|
||||
String rssAuthor = d.getOptionalString(KEY_FEED_RSS_AUTHOR);
|
||||
String title = d.getOptionalString(KEY_FEED_RSS_TITLE);
|
||||
String link = d.getOptionalString(KEY_FEED_RSS_LINK);
|
||||
String uri = d.getOptionalString(KEY_FEED_RSS_URI);
|
||||
RssProperties properties = new RssProperties(url, title, description,
|
||||
rssAuthor, link, uri);
|
||||
|
||||
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, desc, rssAuthor, added,
|
||||
updated, lastEntryTime);
|
||||
return new Feed(blog, localAuthor, properties, added, updated,
|
||||
lastEntryTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,17 +106,25 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
LocalAuthor localAuthor = feed.getLocalAuthor();
|
||||
BdfList authorList = clientHelper.toList(localAuthor);
|
||||
BdfDictionary d = BdfDictionary.of(
|
||||
new BdfEntry(KEY_FEED_URL, feed.getUrl()),
|
||||
new BdfEntry(KEY_FEED_AUTHOR, authorList),
|
||||
new BdfEntry(KEY_FEED_PRIVATE_KEY, localAuthor.getPrivateKey()),
|
||||
new BdfEntry(KEY_FEED_ADDED, feed.getAdded()),
|
||||
new BdfEntry(KEY_FEED_UPDATED, feed.getUpdated()),
|
||||
new BdfEntry(KEY_FEED_LAST_ENTRY, feed.getLastEntryTime())
|
||||
);
|
||||
if (feed.getDescription() != null)
|
||||
d.put(KEY_FEED_DESC, feed.getDescription());
|
||||
if (feed.getRssAuthor() != null)
|
||||
d.put(KEY_FEED_RSS_AUTHOR, feed.getRssAuthor());
|
||||
RssProperties properties = feed.getProperties();
|
||||
if (properties.getUrl() != null)
|
||||
d.put(KEY_FEED_URL, properties.getUrl());
|
||||
if (properties.getDescription() != null)
|
||||
d.put(KEY_FEED_DESC, properties.getDescription());
|
||||
if (properties.getAuthor() != null)
|
||||
d.put(KEY_FEED_RSS_AUTHOR, properties.getAuthor());
|
||||
if (properties.getTitle() != null)
|
||||
d.put(KEY_FEED_RSS_TITLE, properties.getTitle());
|
||||
if (properties.getLink() != null)
|
||||
d.put(KEY_FEED_RSS_LINK, properties.getLink());
|
||||
if (properties.getUri() != null)
|
||||
d.put(KEY_FEED_RSS_URI, properties.getUri());
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
@@ -297,8 +297,10 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
||||
List<Feed> newFeeds = new ArrayList<>(feeds.size());
|
||||
for (Feed feed : feeds) {
|
||||
try {
|
||||
String url = feed.getProperties().getUrl();
|
||||
if (url == null) continue;
|
||||
// fetch and clean feed
|
||||
SyndFeed sf = fetchSyndFeed(feed.getUrl());
|
||||
SyndFeed sf = fetchSyndFeed(url);
|
||||
// sort and add new entries
|
||||
long lastEntryTime = postFeedEntries(feed, sf.getEntries());
|
||||
newFeeds.add(feedFactory.createFeed(feed, sf, lastEntryTime));
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.briarproject.briar.api.blog.BlogManager;
|
||||
import org.briarproject.briar.api.blog.BlogPost;
|
||||
import org.briarproject.briar.api.blog.BlogPostFactory;
|
||||
import org.briarproject.briar.api.feed.Feed;
|
||||
import org.briarproject.briar.api.feed.RssProperties;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -83,8 +84,9 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
private final GroupId blogGroupId = blogGroup.getId();
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final Blog blog = new Blog(blogGroup, localAuthor, true);
|
||||
private final Feed feed =
|
||||
new Feed("http://example.org", blog, localAuthor, 0);
|
||||
private final RssProperties properties = new RssProperties(
|
||||
"http://example.org", null, null, null, null, null);
|
||||
private final Feed feed = new Feed(blog, localAuthor, properties, 0, 0, 0);
|
||||
private final BdfDictionary feedDict = new BdfDictionary();
|
||||
|
||||
private final FeedManagerImpl feedManager =
|
||||
|
||||
@@ -80,7 +80,7 @@ public class FeedManagerIntegrationTest extends BrambleTestCase {
|
||||
assertTrue(feed.getLastEntryTime() > 0);
|
||||
assertTrue(feed.getAdded() > 0);
|
||||
assertTrue(feed.getUpdated() > 0);
|
||||
assertEquals(url, feed.getUrl());
|
||||
assertEquals(url, feed.getProperties().getUrl());
|
||||
assertEquals(feedBlog, feed.getBlog());
|
||||
assertEquals("Schneier on Security", feed.getTitle());
|
||||
assertEquals(feed.getTitle(), feed.getBlog().getName());
|
||||
|
||||
Reference in New Issue
Block a user