RSSyl: handle expiring comments after their parent is gone
authorAndrej Kacian <andrej@kacian.sk>
Wed, 25 Jun 2014 20:59:35 +0000 (22:59 +0200)
committerAndrej Kacian <andrej@kacian.sk>
Wed, 25 Jun 2014 20:59:35 +0000 (22:59 +0200)
src/plugins/rssyl/rssyl_add_item.c
src/plugins/rssyl/rssyl_parse_feed.c
src/plugins/rssyl/rssyl_update_format.c

index 54020af372135625ed1238375d992868e009a6a0..50a5102d4ea8c2c4d8a13dddf5dcb0c4f5d96e85 100644 (file)
@@ -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). */
        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 : "<null>"));
-       debug_print(",%s,\n", (feed_item->sourcetitle ? feed_item->sourcetitle : "<null>"));
        tmp = feed_item_get_sourcetitle(feed_item);
        if( feed_item_get_title(feed_item) == NULL ||
                        strlen(feed_item->title) == 0 ) {
        tmp = feed_item_get_sourcetitle(feed_item);
        if( feed_item_get_title(feed_item) == NULL ||
                        strlen(feed_item->title) == 0 ) {
index 88dc406126d155c4067290b08116486a12aea50d..37c2ba00fc2efae16595321165b84405690e2ce1 100644 (file)
@@ -55,6 +55,7 @@ static void rssyl_foreach_parse_func(gpointer data, gpointer user_data)
 struct _RSSylExpireItemsCtx {
        gboolean exists;
        FeedItem *item;
 struct _RSSylExpireItemsCtx {
        gboolean exists;
        FeedItem *item;
+       GSList *expired_ids;
 };
 
 typedef struct _RSSylExpireItemsCtx RSSylExpireItemsCtx;
 };
 
 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) );
        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;
 
 
        /* 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;
 
                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 ) {
                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;
                        fctx = (RFeedCtx *)item->data;
-                       /* TODO: expire item's comments (items with our parent_id) */
                        g_remove(fctx->path);
                }
        }
 
                        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);
 }
 
        g_free(ctx);
 }
 
index 323da2072e309f1adfbde41303cb02c57ff35814..35fe172c75b49dc479b2713805be77b4e9c97031 100644 (file)
@@ -152,7 +152,6 @@ static void rssyl_update_format_func(FolderItem *item, gpointer data)
 
                        rssyl_feed_start_refresh_timeout(ritem);
 
 
                        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);
                        ritem->official_title = g_strdup(of->official_name);
                        ritem->default_refresh_interval =
                                (of->default_refresh_interval != 0 ? TRUE : FALSE);