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