mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Implement background task for fetching RSS feeds
* Implemented in briar-core as a `ScheduledExecutorService` that gets started when the app starts * The briar-api has a `FeedManager` interface that the UI can use to register and unregister feeds * In this first iteration, feeds are fetched via HTTP(S), not Tor Closes #484
This commit is contained in:
89
briar-api/src/org/briarproject/api/feed/Feed.java
Normal file
89
briar-api/src/org/briarproject/api/feed/Feed.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package org.briarproject.api.feed;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.data.BdfDictionary;
|
||||
import org.briarproject.api.data.BdfEntry;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_BLOG_GROUP_ID;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_ADDED;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_AUTHOR;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_DESC;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_TITLE;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_UPDATED;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_URL;
|
||||
|
||||
public class Feed {
|
||||
|
||||
final private String url;
|
||||
final private GroupId blogId;
|
||||
final private String title, description, author;
|
||||
final private long added, updated;
|
||||
|
||||
public Feed(String url, GroupId blogId, @Nullable String title,
|
||||
@Nullable String description, @Nullable String author,
|
||||
long added, long updated) {
|
||||
|
||||
this.url = url;
|
||||
this.blogId = blogId;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.author = author;
|
||||
this.added = added;
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public GroupId getBlogId() {
|
||||
return blogId;
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
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 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);
|
||||
return new Feed(url, blogId, title, desc, author, added, updated);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public long getAdded() {
|
||||
return added;
|
||||
}
|
||||
|
||||
public long getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
}
|
||||
21
briar-api/src/org/briarproject/api/feed/FeedConstants.java
Normal file
21
briar-api/src/org/briarproject/api/feed/FeedConstants.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.api.feed;
|
||||
|
||||
public interface FeedConstants {
|
||||
|
||||
/* delay after start before fetching feed, in minutes */
|
||||
int FETCH_DELAY_INITIAL = 1;
|
||||
|
||||
/* the interval the feed should be fetched, in minutes */
|
||||
int FETCH_INTERVAL = 30;
|
||||
|
||||
// group metadata keys
|
||||
String KEY_FEEDS = "feeds";
|
||||
String KEY_FEED_URL = "feedURL";
|
||||
String KEY_BLOG_GROUP_ID = "blogGroupId";
|
||||
String KEY_FEED_TITLE = "feedTitle";
|
||||
String KEY_FEED_DESC = "feedDesc";
|
||||
String KEY_FEED_AUTHOR = "feedAuthor";
|
||||
String KEY_FEED_ADDED = "feedAdded";
|
||||
String KEY_FEED_UPDATED = "feedUpdated";
|
||||
|
||||
}
|
||||
24
briar-api/src/org/briarproject/api/feed/FeedManager.java
Normal file
24
briar-api/src/org/briarproject/api/feed/FeedManager.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.api.feed;
|
||||
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface FeedManager {
|
||||
|
||||
/** Returns the unique ID of the client. */
|
||||
ClientId getClientId();
|
||||
|
||||
/** Adds a RSS feed. */
|
||||
void addFeed(String url, GroupId g) throws DbException, IOException;
|
||||
|
||||
/** Removes a RSS feed. */
|
||||
void removeFeed(String url) throws DbException;
|
||||
|
||||
/** Gets a list of all added RSS feeds */
|
||||
List<Feed> getFeeds() throws DbException;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user