137 lines
4.5 KiB
Vala
137 lines
4.5 KiB
Vala
/*
|
|
* RepositoriesImpl.vala
|
|
*
|
|
* Repository implementations for Linux state management
|
|
*/
|
|
|
|
namespace RSSuper {
|
|
|
|
/**
|
|
* FeedRepositoryImpl - Implementation of FeedRepository
|
|
*/
|
|
public class FeedRepositoryImpl : Object, FeedRepository {
|
|
private Database db;
|
|
|
|
public FeedRepositoryImpl(Database db) {
|
|
this.db = db;
|
|
}
|
|
|
|
public override void get_feed_items(string? subscription_id, State<FeedItem[]> callback) {
|
|
try {
|
|
var feedItems = db.getFeedItems(subscription_id);
|
|
callback.set_success(feedItems);
|
|
} catch (Error e) {
|
|
callback.set_error("Failed to get feed items", e);
|
|
}
|
|
}
|
|
|
|
public override FeedItem? get_feed_item_by_id(string id) throws Error {
|
|
return db.getFeedItemById(id);
|
|
}
|
|
|
|
public override void insert_feed_item(FeedItem item) throws Error {
|
|
db.insertFeedItem(item);
|
|
}
|
|
|
|
public override void insert_feed_items(FeedItem[] items) throws Error {
|
|
foreach (var item in items) {
|
|
db.insertFeedItem(item);
|
|
}
|
|
}
|
|
|
|
public override void update_feed_item(FeedItem item) throws Error {
|
|
db.updateFeedItem(item);
|
|
}
|
|
|
|
public override void mark_as_read(string id, bool is_read) throws Error {
|
|
db.markFeedItemAsRead(id, is_read);
|
|
}
|
|
|
|
public override void mark_as_starred(string id, bool is_starred) throws Error {
|
|
db.markFeedItemAsStarred(id, is_starred);
|
|
}
|
|
|
|
public override void delete_feed_item(string id) throws Error {
|
|
db.deleteFeedItem(id);
|
|
}
|
|
|
|
public override int get_unread_count(string? subscription_id) throws Error {
|
|
return db.getUnreadCount(subscription_id);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* SubscriptionRepositoryImpl - Implementation of SubscriptionRepository
|
|
*/
|
|
public class SubscriptionRepositoryImpl : Object, SubscriptionRepository {
|
|
private Database db;
|
|
|
|
public SubscriptionRepositoryImpl(Database db) {
|
|
this.db = db;
|
|
}
|
|
|
|
public override void get_all_subscriptions(State<FeedSubscription[]> callback) {
|
|
try {
|
|
var subscriptions = db.getAllSubscriptions();
|
|
callback.set_success(subscriptions);
|
|
} catch (Error e) {
|
|
callback.set_error("Failed to get subscriptions", e);
|
|
}
|
|
}
|
|
|
|
public override void get_enabled_subscriptions(State<FeedSubscription[]> callback) {
|
|
try {
|
|
var subscriptions = db.getEnabledSubscriptions();
|
|
callback.set_success(subscriptions);
|
|
} catch (Error e) {
|
|
callback.set_error("Failed to get enabled subscriptions", e);
|
|
}
|
|
}
|
|
|
|
public override void get_subscriptions_by_category(string category, State<FeedSubscription[]> callback) {
|
|
try {
|
|
var subscriptions = db.getSubscriptionsByCategory(category);
|
|
callback.set_success(subscriptions);
|
|
} catch (Error e) {
|
|
callback.set_error("Failed to get subscriptions by category", e);
|
|
}
|
|
}
|
|
|
|
public override FeedSubscription? get_subscription_by_id(string id) throws Error {
|
|
return db.getSubscriptionById(id);
|
|
}
|
|
|
|
public override FeedSubscription? get_subscription_by_url(string url) throws Error {
|
|
return db.getSubscriptionByUrl(url);
|
|
}
|
|
|
|
public override void insert_subscription(FeedSubscription subscription) throws Error {
|
|
db.insertSubscription(subscription);
|
|
}
|
|
|
|
public override void update_subscription(FeedSubscription subscription) throws Error {
|
|
db.updateSubscription(subscription);
|
|
}
|
|
|
|
public override void delete_subscription(string id) throws Error {
|
|
db.deleteSubscription(id);
|
|
}
|
|
|
|
public override void set_enabled(string id, bool enabled) throws Error {
|
|
db.setSubscriptionEnabled(id, enabled);
|
|
}
|
|
|
|
public override void set_error(string id, string? error) throws Error {
|
|
db.setSubscriptionError(id, error);
|
|
}
|
|
|
|
public override void update_last_fetched_at(string id, ulong last_fetched_at) throws Error {
|
|
db.setSubscriptionLastFetchedAt(id, last_fetched_at);
|
|
}
|
|
|
|
public override void update_next_fetch_at(string id, ulong next_fetch_at) throws Error {
|
|
db.setSubscriptionNextFetchAt(id, next_fetch_at);
|
|
}
|
|
}
|
|
}
|