logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20190124131141_update_activity_visibility_again.exs (1110B)


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