From bf3f91d9ce21acf3fd52ed6ad4c25a956f1490aa Mon Sep 17 00:00:00 2001 From: Andrej Kacian Date: Wed, 25 Jun 2014 22:59:35 +0200 Subject: [PATCH] RSSyl: handle expiring comments after their parent is gone --- src/plugins/rssyl/rssyl_add_item.c | 2 -- src/plugins/rssyl/rssyl_parse_feed.c | 32 +++++++++++++++++++++++-- src/plugins/rssyl/rssyl_update_format.c | 1 - 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/plugins/rssyl/rssyl_add_item.c b/src/plugins/rssyl/rssyl_add_item.c index 54020af37..50a5102d4 100644 --- a/src/plugins/rssyl/rssyl_add_item.c +++ b/src/plugins/rssyl/rssyl_add_item.c @@ -285,8 +285,6 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item) g_return_if_fail(ritem != NULL); /* If item title is empty, try to fill it from source title (Atom only). */ - debug_print(",%s,\n", (feed_item->title ? feed_item->title : "")); - debug_print(",%s,\n", (feed_item->sourcetitle ? feed_item->sourcetitle : "")); tmp = feed_item_get_sourcetitle(feed_item); if( feed_item_get_title(feed_item) == NULL || strlen(feed_item->title) == 0 ) { diff --git a/src/plugins/rssyl/rssyl_parse_feed.c b/src/plugins/rssyl/rssyl_parse_feed.c index 88dc40612..37c2ba00f 100644 --- a/src/plugins/rssyl/rssyl_parse_feed.c +++ b/src/plugins/rssyl/rssyl_parse_feed.c @@ -55,6 +55,7 @@ static void rssyl_foreach_parse_func(gpointer data, gpointer user_data) struct _RSSylExpireItemsCtx { gboolean exists; FeedItem *item; + GSList *expired_ids; }; typedef struct _RSSylExpireItemsCtx RSSylExpireItemsCtx; @@ -96,27 +97,54 @@ static void rssyl_expire_items(RFolderItem *ritem, Feed *feed) g_return_if_fail(feed != NULL); ctx = malloc( sizeof(RSSylExpireItemsCtx) ); + ctx->expired_ids = NULL; /* Check each locally stored item, if it is still in the upstream * feed - xnay it if not. */ for( i = ritem->items; i != NULL; i = i->next ) { item = (FeedItem *)i->data; - /* Do not expire comments, they expire with their parents */ + /* Comments will be expired later, once we know which parent items + * have been expired. */ if (feed_item_get_parent_id(item) != NULL) continue; + /* Find matching item in the fresh feed. */ ctx->exists = FALSE; ctx->item = item; feed_foreach_item(feed, expire_items_func, ctx); if( !ctx->exists ) { + /* No match, add item ids to the list and get rid of it. */ + debug_print("RSSyl: expiring '%s'\n", feed_item_get_id(item)); + ctx->expired_ids = g_slist_prepend(ctx->expired_ids, + g_strdup(feed_item_get_id(item))); fctx = (RFeedCtx *)item->data; - /* TODO: expire item's comments (items with our parent_id) */ g_remove(fctx->path); } } + /* Now do one more pass over folder contents, and expire comments + * whose parents are gone. */ + for( i = ritem->items; i != NULL; i = i->next ) { + item = (FeedItem *)i->data; + + /* Handle comments expiration. */ + if (feed_item_get_parent_id(item) != NULL) { + /* If its parent's id is on list of expired ids, this comment + * can go as well. */ + if (g_slist_find_custom(ctx->expired_ids, + feed_item_get_parent_id(item), (GCompareFunc)g_strcmp0)) { + debug_print("RSSyl: expiring comment '%s'\n", feed_item_get_id(item)); + fctx = (RFeedCtx *)item->data; + g_remove(fctx->path); + } + } + } + + debug_print("RSSyl: expired %d items\n", g_slist_length(ctx->expired_ids)); + + g_slist_free_full(ctx->expired_ids, g_free); g_free(ctx); } diff --git a/src/plugins/rssyl/rssyl_update_format.c b/src/plugins/rssyl/rssyl_update_format.c index 323da2072..35fe172c7 100644 --- a/src/plugins/rssyl/rssyl_update_format.c +++ b/src/plugins/rssyl/rssyl_update_format.c @@ -152,7 +152,6 @@ static void rssyl_update_format_func(FolderItem *item, gpointer data) rssyl_feed_start_refresh_timeout(ritem); - /* TODO: copy feed preferences from old structure */ ritem->official_title = g_strdup(of->official_name); ritem->default_refresh_interval = (of->default_refresh_interval != 0 ? TRUE : FALSE); -- 2.25.1