mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Store RSS feeds in a separate dedicated blog
A fake LocalAuthor is created for this new blog and stored in the feed's metadata.
This commit is contained in:
@@ -1,39 +1,32 @@
|
||||
package org.briarproject.briar.api.feed;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_BLOG_GROUP_ID;
|
||||
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;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class Feed {
|
||||
|
||||
private final String url;
|
||||
private final GroupId blogId;
|
||||
private final Blog blog;
|
||||
private final LocalAuthor localAuthor;
|
||||
@Nullable
|
||||
private final String title, description, author;
|
||||
private final long added, updated, lastEntryTime;
|
||||
|
||||
public Feed(String url, GroupId blogId, @Nullable String title,
|
||||
@Nullable String description, @Nullable String author,
|
||||
long added, long updated, long lastEntryTime) {
|
||||
public Feed(String url, Blog blog, LocalAuthor localAuthor,
|
||||
@Nullable String title, @Nullable String description,
|
||||
@Nullable String author, long added, long updated,
|
||||
long lastEntryTime) {
|
||||
|
||||
this.url = url;
|
||||
this.blogId = blogId;
|
||||
this.blog = blog;
|
||||
this.localAuthor = localAuthor;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.author = author;
|
||||
@@ -42,13 +35,14 @@ public class Feed {
|
||||
this.lastEntryTime = lastEntryTime;
|
||||
}
|
||||
|
||||
public Feed(String url, GroupId blogId, @Nullable String title,
|
||||
@Nullable String description, @Nullable String author, long added) {
|
||||
this(url, blogId, title, description, author, added, 0L, 0L);
|
||||
public Feed(String url, Blog blog, LocalAuthor localAuthor,
|
||||
@Nullable String title, @Nullable String description,
|
||||
@Nullable String author, long added) {
|
||||
this(url, blog, localAuthor, title, description, author, added, 0L, 0L);
|
||||
}
|
||||
|
||||
public Feed(String url, GroupId blogId, long added) {
|
||||
this(url, blogId, null, null, null, added, 0L, 0L);
|
||||
public Feed(String url, Blog blog, LocalAuthor localAuthor, long added) {
|
||||
this(url, blog, localAuthor, null, null, null, added, 0L, 0L);
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
@@ -56,34 +50,15 @@ public class Feed {
|
||||
}
|
||||
|
||||
public GroupId getBlogId() {
|
||||
return blogId;
|
||||
return blog.getId();
|
||||
}
|
||||
|
||||
public BdfDictionary toBdfDictionary() {
|
||||
BdfDictionary d = BdfDictionary.of(
|
||||
new BdfEntry(KEY_FEED_URL, url),
|
||||
new BdfEntry(KEY_BLOG_GROUP_ID, blogId.getBytes()),
|
||||
new BdfEntry(KEY_FEED_ADDED, added),
|
||||
new BdfEntry(KEY_FEED_UPDATED, updated),
|
||||
new BdfEntry(KEY_FEED_LAST_ENTRY, lastEntryTime)
|
||||
);
|
||||
if (title != null) d.put(KEY_FEED_TITLE, title);
|
||||
if (description != null) d.put(KEY_FEED_DESC, description);
|
||||
if (author != null) d.put(KEY_FEED_AUTHOR, author);
|
||||
return d;
|
||||
public Blog getBlog() {
|
||||
return blog;
|
||||
}
|
||||
|
||||
public static Feed from(BdfDictionary d) throws FormatException {
|
||||
String url = d.getString(KEY_FEED_URL);
|
||||
GroupId blogId = new GroupId(d.getRaw(KEY_BLOG_GROUP_ID));
|
||||
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, blogId, title, desc, author, added, updated,
|
||||
lastEntryTime);
|
||||
public LocalAuthor getLocalAuthor() {
|
||||
return localAuthor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -118,13 +93,13 @@ public class Feed {
|
||||
if (this == o) return true;
|
||||
if (o instanceof Feed) {
|
||||
Feed f = (Feed) o;
|
||||
return url.equals(f.url) && blogId.equals(f.getBlogId()) &&
|
||||
equalsWithNull(title, f.getTitle()) &&
|
||||
equalsWithNull(description, f.getDescription()) &&
|
||||
equalsWithNull(author, f.getAuthor()) &&
|
||||
added == f.getAdded() &&
|
||||
updated == f.getUpdated() &&
|
||||
lastEntryTime == f.getLastEntryTime();
|
||||
return url.equals(f.url) && blog.equals(f.blog) &&
|
||||
equalsWithNull(title, f.title) &&
|
||||
equalsWithNull(description, f.description) &&
|
||||
equalsWithNull(author, f.author) &&
|
||||
added == f.added &&
|
||||
updated == f.updated &&
|
||||
lastEntryTime == f.lastEntryTime;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -134,4 +109,5 @@ public class Feed {
|
||||
if (a == null || b == null) return false;
|
||||
return a.equals(b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ public interface FeedConstants {
|
||||
// group metadata keys
|
||||
String KEY_FEEDS = "feeds";
|
||||
String KEY_FEED_URL = "feedURL";
|
||||
String KEY_BLOG_GROUP_ID = "blogGroupId";
|
||||
String KEY_BLOG_TITLE = "blogTitle";
|
||||
String KEY_PUBLIC_KEY = "publicKey";
|
||||
String KEY_PRIVATE_KEY = "privateKey";
|
||||
String KEY_FEED_TITLE = "feedTitle";
|
||||
String KEY_FEED_DESC = "feedDesc";
|
||||
String KEY_FEED_AUTHOR = "feedAuthor";
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.api.feed;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -17,9 +16,9 @@ public interface FeedManager {
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.feed");
|
||||
|
||||
/**
|
||||
* Adds an RSS feed.
|
||||
* Adds an RSS feed as a new dedicated blog.
|
||||
*/
|
||||
void addFeed(String url, GroupId g) throws DbException, IOException;
|
||||
void addFeed(String url) throws DbException, IOException;
|
||||
|
||||
/**
|
||||
* Removes an RSS feed.
|
||||
|
||||
Reference in New Issue
Block a user