static void
theoldreader_source_merge_feed (TheOldReaderSourcePtr source, const gchar *url, const gchar *title, const gchar *id, nodePtr folder)
{
	nodePtr	node;

	node = feedlist_find_node (source->root, NODE_BY_URL, url);
	if (!node) {
		debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
		node = node_new (feed_get_node_type ());
		node_set_title (node, title);
		node_set_data (node, feed_new ());
		
		node_set_subscription (node, subscription_new (url, NULL, NULL));
		node->subscription->type = source->root->source->type->feedSubscriptionType;
	
		/* Save TheOldReader feed id which we need to fetch items... */
		node->subscription->metadata = metadata_list_append (node->subscription->metadata, "theoldreader-feed-id", id);

		db_subscription_update (node->subscription);
	
		node_set_parent (node, folder?folder:source->root, -1);
		feedlist_node_imported (node);
		
		/**
		 * @todo mark the ones as read immediately after this is done
		 * the feed as retrieved by this has the read and unread
		 * status inherently.
		 */
		subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
		subscription_update_favicon (node->subscription);

	} else {
		node_source_update_folder (node, folder);
	}
}
/* 
 * Find a node by the name under root or create it.
 * 
 * @param name		Folder display name
 * @param parent	Parent folder or source root node
 *
 * @returns a valid nodePtr
 */
static nodePtr
ttrss_source_find_or_create_folder (const gchar *name, nodePtr parent)
{
	nodePtr		folder = NULL;

	folder = feedlist_find_node (parent, FOLDER_BY_TITLE, name);
	if (!folder) {
		folder = node_new (folder_get_node_type ());
		node_set_title (folder, name);
		node_set_parent (folder, parent, -1);
		feedlist_node_imported (folder);
		subscription_update (folder->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
	}
	
	return folder;
}
static void
ttrss_source_merge_feed (ttrssSourcePtr source, const gchar *url, const gchar *title, gint64 id)
{
	nodePtr		node;
	gchar		*tmp;

	/* check if node to be merged already exists */
	node = feedlist_find_node (source->root, NODE_BY_URL, url);
	
	if (!node) {
		debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
		node = node_new (feed_get_node_type ());
		node_set_title (node, title);
		node_set_data (node, feed_new ());
		
		node_set_subscription (node, subscription_new (url, NULL, NULL));
		node->subscription->type = &ttrssSourceFeedSubscriptionType;
	
		/* Save tt-rss feed id which we need to fetch items... */
		tmp = g_strdup_printf ("%" G_GINT64_FORMAT, id);
		metadata_list_set (&node->subscription->metadata, "ttrss-feed-id", tmp);
		g_free (tmp);
	
		node_set_parent (node, source->root, -1);
		feedlist_node_imported (node);
		
		/**
		 * @todo mark the ones as read immediately after this is done
		 * the feed as retrieved by this has the read and unread
		 * status inherently.
		 */
		subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
		subscription_update_favicon (node->subscription);
	
		/* Important: we must not loose the feed id! */
		db_subscription_update (node->subscription);
	}
	
	debug2 (DEBUG_UPDATE, "updating folder for %s (%s)", title, url);
	ttrss_source_update_folder (source, node);
}