Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
939B

  1. defmodule Pleroma.Repo.Migrations.UpdateActivityVisibility do
  2. use Ecto.Migration
  3. @disable_ddl_transaction true
  4. def up do
  5. definition = """
  6. create or replace function activity_visibility(actor varchar, recipients varchar[], data jsonb) returns varchar as $$
  7. DECLARE
  8. fa varchar;
  9. public varchar := 'https://www.w3.org/ns/activitystreams#Public';
  10. BEGIN
  11. SELECT COALESCE(users.follower_address, '') into fa from users where users.ap_id = actor;
  12. IF data->'to' ? public THEN
  13. RETURN 'public';
  14. ELSIF data->'cc' ? public THEN
  15. RETURN 'unlisted';
  16. ELSIF ARRAY[fa] && recipients THEN
  17. RETURN 'private';
  18. ELSIF not(ARRAY[fa, public] && recipients) THEN
  19. RETURN 'direct';
  20. ELSE
  21. RETURN 'unknown';
  22. END IF;
  23. END;
  24. $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE SECURITY DEFINER;
  25. """
  26. execute(definition)
  27. end
  28. def down do
  29. end
  30. end