From 2d327a8b2aa7fa71f1b1c777292e893186024691 Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Thu, 25 Jan 2024 08:51:25 +0000 Subject: [PATCH] https://github.com/bonfire-networks/bonfire-app/issues/831 --- lib/objects.ex | 2 +- lib/tags.ex | 51 ++++++++------------------------------------------ 2 files changed, 9 insertions(+), 44 deletions(-) diff --git a/lib/objects.ex b/lib/objects.ex index d0985391..3392e023 100644 --- a/lib/objects.ex +++ b/lib/objects.ex @@ -43,7 +43,7 @@ defmodule Bonfire.Social.Objects do # record replies & threads. preloads data that will be checked by `Acls` |> Threads.cast(attrs, creator, opts) # record tags & mentions. uses data preloaded by `PostContents` - |> Tags.cast(attrs, creator, opts) + |> Tags.maybe_cast(attrs, creator, opts) # apply boundaries on all objects, note that ORDER MATTERS, as it uses data preloaded by `Threads` and `PostContents` |> cast_acl(creator, opts) diff --git a/lib/tags.ex b/lib/tags.ex index 71c82de6..e9f2e32f 100644 --- a/lib/tags.ex +++ b/lib/tags.ex @@ -9,37 +9,12 @@ defmodule Bonfire.Social.Tags do # alias Bonfire.Data.Social.PostContent alias Ecto.Changeset - def cast(changeset, attrs, creator, opts) do - with true <- module_enabled?(Bonfire.Tag, creator), - # tag any mentions that were found in the text and injected into the changeset by PostContents (NOTE: this doesn't necessarily mean they should be included in boundaries or notified) - # tag any hashtags that were found in the text and injected into the changeset by PostContents - tags when is_list(tags) and length(tags) > 0 <- - (e(changeset, :changes, :post_content, :changes, :mentions, []) ++ - e(changeset, :changes, :post_content, :changes, :hashtags, []) ++ - e(attrs, :tags, [])) - |> Enum.map(fn - %{} = obj -> - obj - - id when is_binary(id) -> - if Types.is_ulid?(id), do: %{tag_id: id} - - other -> - warn(other, "unsupported") - nil - end) - |> filter_empty([]) - |> Enums.uniq_by_id() - # |> tags_preloads(opts) - |> debug("cast tags") do - changeset - |> Changeset.cast(%{tagged: tags}, []) - |> debug("before cast assoc") - |> Changeset.cast_assoc(:tagged, with: &Bonfire.Tag.Tagged.changeset/2) + def maybe_cast(changeset, attrs, creator, opts) do + with true <- module_enabled?(Bonfire.Tag.Tags, creator) do + Bonfire.Tag.Tags.cast(changeset, attrs, creator, opts) else _ -> changeset end - |> debug("changeset with :tagged") end def maybe_process(creator, text, opts) do @@ -133,20 +108,6 @@ defmodule Bonfire.Social.Tags do |> if(preload?, do: repo().maybe_preload(..., [:character]), else: ...) end - def maybe_tag(creator, object, tags, mentions_are_private? \\ false) do - if module_enabled?(Bonfire.Tag.Tags, creator) do - boost_category_tags = !mentions_are_private? - - Bonfire.Tag.Tags.maybe_tag(creator, object, tags, boost_category_tags) - |> debug() - - # ~> maybe_boostable_categories(creator, e(..., :tags, [])) # done in Bonfire.Tag.Tags instead - # ~> auto_boost(..., object) - else - error("No tagging extension available.") - end - end - def maybe_auto_boost(creator, category_or_categories, object) do maybe_boostable_categories(creator, category_or_categories) |> debug() @@ -159,6 +120,10 @@ defmodule Bonfire.Social.Tags do end def auto_boost(%{} = category, object) do + category = + category + |> repo().maybe_preload(:character) + if e(category, :character, nil) do # category # |> debug("auto_boost_object") @@ -174,7 +139,7 @@ defmodule Bonfire.Social.Tags do do: Bonfire.Social.FeedActivities.delete(feed_id: inbox_id, id: ulid(object)) |> debug(), else: debug("no inbox ID") else - debug("not a character") + debug("skip boosting, because not a character") end end