-- Republish activities from a user outbox feed into guest-visible public feeds.
-- Default outbox = foss (adjust OUTBOX_FEED if needed).
-- Run:
--   podman exec -i koopa-bonfire-db psql -U postgres -d bonfire_db < publish-outbox-to-public.sql

\set OUTBOX_FEED '019f487a-df20-4ed0-a334-40ec3eac23e7'
\set FEED_INTERNET '0aab414c-eb0a-ac1d-8c81-ef0d74ec55da'
\set FEED_LOCAL_USERS '797632fc-029e-06f0-1031-410d73a5558e'

INSERT INTO bonfire_data_social_feed_publish (id, feed_id)
SELECT fp.id, :'FEED_INTERNET'::uuid
FROM bonfire_data_social_feed_publish fp
WHERE fp.feed_id = :'OUTBOX_FEED'::uuid
ON CONFLICT DO NOTHING;

INSERT INTO bonfire_data_social_feed_publish (id, feed_id)
SELECT fp.id, :'FEED_LOCAL_USERS'::uuid
FROM bonfire_data_social_feed_publish fp
WHERE fp.feed_id = :'OUTBOX_FEED'::uuid
ON CONFLICT DO NOTHING;

SELECT n.name, count(*)
FROM bonfire_data_social_feed_publish fp
LEFT JOIN bonfire_data_social_named n ON n.id = fp.feed_id
GROUP BY 1
ORDER BY 2 DESC
LIMIT 15;
