Update triggers.sql

This commit is contained in:
dullbananas 2024-06-13 14:34:09 -07:00 committed by GitHub
parent 28fafdde9b
commit 5be7daf72a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -564,8 +564,10 @@ BEGIN
IF NOT (NEW.path ~ ('*.' || id)::lquery) THEN
NEW.path = NEW.path || id;
END IF;
-- Set `ap_id`
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/comment/' || id));
-- Set local apub URLs
IF NEW.local THEN
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/comment/' || id));
END IF;
RETURN NEW;
END
$$;
@ -575,3 +577,82 @@ CREATE TRIGGER change_values
FOR EACH ROW
EXECUTE FUNCTION r.comment_change_values ();
CREATE FUNCTION r.community_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
IF NEW.local THEN
NEW.actor_id = coalesce(NEW.actor_id, r.local_url('/c/' || NEW.id::text));
NEW.followers_url = coalesce(NEW.followers_url, NEW.actor_id || '/followers');
NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
NEW.moderators_url = coalesce(NEW.moderators_url, NEW.actor_id || '/moderators');
NEW.featured_url = coalesce(NEW.featured_url, NEW.actor_id || '/featured');
NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox');
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON community
FOR EACH ROW
EXECUTE FUNCTION r.community_change_values ();
CREATE FUNCTION r.person_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
IF NEW.local THEN
NEW.actor_id = coalesce(NEW.actor_id, r.local_url('/u/' || NEW.id::text));
NEW.inbox_url = coalesce(NEW.inbox_url, NEW.actor_id || '/inbox');
NEW.shared_inbox_url = coalesce(NEW.shared_inbox_url, r.local_url('/inbox');
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON person
FOR EACH ROW
EXECUTE FUNCTION r.person_change_values ();
CREATE FUNCTION r.post_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
IF NEW.local THEN
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/post/' || NEW.id::text));
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON post
FOR EACH ROW
EXECUTE FUNCTION r.post_change_values ();
CREATE FUNCTION r.private_message_change_values ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
-- Set local apub URLs
IF NEW.local THEN
NEW.ap_id = coalesce(NEW.ap_id, r.local_url('/private_message/' || NEW.id::text));
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER change_values
BEFORE INSERT OR UPDATE ON private_message
FOR EACH ROW
EXECUTE FUNCTION r.private_message_change_values ();