Revert "Merge branch 'features/hashtag-column' into 'develop'"

This reverts merge request !2824
This commit is contained in:
Haelwenn 2020-12-28 12:02:16 +00:00
commit 3966add048
24 changed files with 70 additions and 163 deletions

View file

@ -128,57 +128,6 @@ defmodule Mix.Tasks.Pleroma.Database do
|> Stream.run()
end
def run(["fill_old_hashtags", month_limit]) do
import Ecto.Query
start_pleroma()
month_limit = String.to_integer(month_limit)
if month_limit < 1 do
shell_error("Invalid `month_limit` argument, needs to be greater than 1")
else
time_limit = DateTime.utc_now() |> Timex.shift(months: -month_limit)
from(
o in Object,
where: fragment("(?)->>'hashtags' is null", o.data),
where: fragment("(?)->>'tag' != '[]'", o.data),
where: o.inserted_at < ^time_limit,
select: %{id: o.id, tag: fragment("(?)->>'tag'", o.data)}
)
|> Pleroma.Repo.chunk_stream(200, :batches)
|> Stream.each(fn objects ->
Repo.transaction(fn ->
objects_first = objects |> List.first()
objects_last = objects |> List.last()
Logger.info(
"fill_old_hashtags: #{objects_first.id} (#{objects_first.inserted_at}) -- #{
objects_last.id
} (#{objects_last.inserted_at})"
)
objects
|> Enum.map(fn object ->
tags =
object.tag
|> Jason.decode!()
|> Enum.filter(&is_bitstring(&1))
Object
|> where([o], o.id == ^object.id)
|> update([o],
set: [data: fragment("safe_jsonb_set(?, '{hashtags}', ?, true)", o.data, ^tags)]
)
|> Repo.update_all([], timeout: :infinity)
end)
end)
end)
|> Stream.run()
end
end
def run(["vacuum", args]) do
start_pleroma()

View file

@ -48,12 +48,14 @@ defmodule Pleroma.Activity.Ir.Topics do
tags
end
defp hashtags_to_topics(object) do
object
|> Object.hashtags()
defp hashtags_to_topics(%{data: %{"tag" => tags}}) do
tags
|> Enum.filter(&is_bitstring(&1))
|> Enum.map(fn tag -> "hashtag:" <> tag end)
end
defp hashtags_to_topics(_), do: []
defp remote_topics(%{local: true}), do: []
defp remote_topics(%{actor: actor}) when is_binary(actor),

View file

@ -18,8 +18,7 @@ defmodule Pleroma.Constants do
"emoji",
"context_id",
"deleted_activity_id",
"pleroma_internal",
"hashtags"
"pleroma_internal"
]
)

View file

@ -346,8 +346,4 @@ defmodule Pleroma.Object do
def self_replies(object, opts \\ []),
do: replies(object, Keyword.put(opts, :self_only, true))
def hashtags(%Object{data: %{"hashtags" => hashtags}}), do: hashtags || []
def hashtags(%Object{data: %{"tag" => tags}}), do: Enum.filter(tags, &is_bitstring(&1))
def hashtags(_), do: []
end

View file

@ -669,7 +669,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_tag_reject(query, %{tag_reject: [_ | _] = tag_reject}) do
from(
[_activity, object] in query,
where: fragment("not (?)->'hashtags' \\?| (?)", object.data, ^tag_reject)
where: fragment("not (?)->'tag' \\?| (?)", object.data, ^tag_reject)
)
end
@ -682,7 +682,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_tag_all(query, %{tag_all: [_ | _] = tag_all}) do
from(
[_activity, object] in query,
where: fragment("(?)->'hashtags' \\?& (?)", object.data, ^tag_all)
where: fragment("(?)->'tag' \\?& (?)", object.data, ^tag_all)
)
end
@ -695,14 +695,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp restrict_tag(query, %{tag: tag}) when is_list(tag) do
from(
[_activity, object] in query,
where: fragment("(?)->'hashtags' \\?| (?)", object.data, ^tag)
where: fragment("(?)->'tag' \\?| (?)", object.data, ^tag)
)
end
defp restrict_tag(query, %{tag: tag}) when is_binary(tag) do
from(
[_activity, object] in query,
where: fragment("(?)->'hashtags' \\? (?)", object.data, ^tag)
where: fragment("(?)->'tag' \\? (?)", object.data, ^tag)
)
end

View file

@ -8,7 +8,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
alias Pleroma.Config
alias Pleroma.FollowingRelationship
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF
@ -75,11 +74,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
object =
if MRF.subdomain_match?(media_nsfw, actor_host) do
child_object =
child_object
|> Map.put("hashtags", Object.hashtags(%Object{data: child_object}) ++ ["nsfw"])
|> Map.put("sensitive", true)
tags = (child_object["tag"] || []) ++ ["nsfw"]
child_object = Map.put(child_object, "tag", tags)
child_object = Map.put(child_object, "sensitive", true)
Map.put(object, "object", child_object)
else
object

View file

@ -312,15 +312,16 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def fix_emoji(object), do: object
def fix_tag(%{"tag" => tag} = object) when is_list(tag) do
hashtags =
tags =
tag
|> Enum.filter(fn data -> data["type"] == "Hashtag" and data["name"] end)
|> Enum.map(fn
%{"name" => "#" <> hashtag} -> String.downcase(hashtag)
%{"name" => hashtag} -> String.downcase(hashtag)
|> Enum.map(fn %{"name" => name} ->
name
|> String.slice(1..-1)
|> String.downcase()
end)
Map.put(object, "hashtags", hashtags)
Map.put(object, "tag", tag ++ tags)
end
def fix_tag(%{"tag" => %{} = tag} = object) do
@ -863,18 +864,23 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def maybe_fix_object_url(data), do: data
def add_hashtags(object) do
hashtags =
%Object{data: object}
|> Object.hashtags()
|> Enum.map(fn tag ->
%{
"href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
"name" => "##{tag}",
"type" => "Hashtag"
}
tags =
(object["tag"] || [])
|> Enum.map(fn
# Expand internal representation tags into AS2 tags.
tag when is_binary(tag) ->
%{
"href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
"name" => "##{tag}",
"type" => "Hashtag"
}
# Do not process tags which are already AS2 tag objects.
tag when is_map(tag) ->
tag
end)
Map.put(object, "tag", hashtags ++ (object["tag"] || []))
Map.put(object, "tag", tags)
end
# TODO These should be added on our side on insertion, it doesn't make much
@ -930,7 +936,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
def set_sensitive(object) do
tags = object["hashtags"] || object["tag"] || []
tags = object["tag"] || []
Map.put(object, "sensitive", "nsfw" in tags)
end

View file

@ -310,16 +310,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
"context" => draft.context,
"attachment" => draft.attachments,
"actor" => draft.user.ap_id,
"tag" => Enum.filter(draft.tags, &is_map(&1)) |> Enum.uniq(),
"hashtags" =>
draft.tags
|> Enum.reduce([], fn
# Why so many formats
{:name, x}, acc -> if is_bitstring(x), do: [x | acc], else: acc
{"#" <> _, x}, acc -> if is_bitstring(x), do: [x | acc], else: acc
x, acc -> if is_bitstring(x), do: [x | acc], else: acc
end)
|> Enum.uniq()
"tag" => Keyword.values(draft.tags) |> Enum.uniq()
}
|> add_in_reply_to(draft.in_reply_to)
|> Map.merge(draft.extra)

View file

@ -32,7 +32,6 @@ defmodule Pleroma.Web.Feed.FeedView do
%{
activity: activity,
object: object,
data: Map.get(object, :data),
actor: actor
}

View file

@ -347,7 +347,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
media_attachments: attachments,
poll: render(PollView, "show.json", object: object, for: opts[:for]),
mentions: mentions,
tags: build_tags(Object.hashtags(object)),
tags: build_tags(tags),
application: %{
name: "Web",
website: nil

View file

@ -22,8 +22,8 @@
<link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/>
<% end %>
<%= for hashtag <- Object.hashtags(@object) do %>
<category term="<%= hashtag %>"></category>
<%= for tag <- @data["tag"] || [] do %>
<category term="<%= tag %>"></category>
<% end %>
<%= for attachment <- @data["attachment"] || [] do %>

View file

@ -21,8 +21,8 @@
<link><%= @data["external_url"] %></link>
<% end %>
<%= for hashtag <- Object.hashtags(@object) do %>
<category term="<%= hashtag %>"></category>
<%= for tag <- @data["tag"] || [] do %>
<category term="<%= tag %>"></category>
<% end %>
<%= for attachment <- @data["attachment"] || [] do %>

View file

@ -41,8 +41,8 @@
<% end %>
<% end %>
<%= for hashtag <- Object.hashtags(@object) do %>
<category term="<%= hashtag %>"></category>
<%= for tag <- @data["tag"] || [] do %>
<category term="<%= tag %>"></category>
<% end %>
<%= for {emoji, file} <- @data["emoji"] || %{} do %>