1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.AddVisibilityFunction do
7 @disable_ddl_transaction true
11 create or replace function activity_visibility(actor varchar, recipients varchar[], data jsonb) returns varchar as $$
14 public varchar := 'https://www.w3.org/ns/activitystreams#Public';
16 SELECT COALESCE(users.follower_address, '') into fa from users where users.ap_id = actor;
18 IF data->'to' ? public THEN
20 ELSIF data->'cc' ? public THEN
22 ELSIF ARRAY[fa] && recipients THEN
24 ELSIF not(ARRAY[fa, public] && recipients) THEN
30 $$ LANGUAGE plpgsql IMMUTABLE;
36 index(:activities, ["activity_visibility(actor, recipients, data)"],
37 name: :activities_visibility_index,
45 index(:activities, ["activity_visibility(actor, recipients, data)"],
46 name: :activities_visibility_index
51 "drop function if exists activity_visibility(actor varchar, recipients varchar[], data jsonb)"