Remerge of hashtag following #341
2 changed files with 28 additions and 1 deletions
|
@ -10,6 +10,7 @@ defmodule Pleroma.Hashtag do
|
|||
|
||||
alias Ecto.Multi
|
||||
alias Pleroma.Hashtag
|
||||
alias Pleroma.User.HashtagFollow
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
|
||||
|
@ -111,4 +112,19 @@ def delete_unreferenced(ids) do
|
|||
{:ok, deleted_count}
|
||||
end
|
||||
end
|
||||
|
||||
def get_followers(%Hashtag{id: hashtag_id}) do
|
||||
from(hf in HashtagFollow)
|
||||
|> where([hf], hf.hashtag_id == ^hashtag_id)
|
||||
|> join(:inner, [hf], u in assoc(hf, :user))
|
||||
|> select([hf, u], u.id)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def get_recipients_for_activity(%Pleroma.Activity{object: %{hashtags: tags}}) do
|
||||
tags
|
||||
|> Enum.map(&get_followers/1)
|
||||
|> List.flatten()
|
||||
|> Enum.uniq()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,7 @@ defmodule Pleroma.Web.Streamer do
|
|||
alias Pleroma.Web.OAuth.Token
|
||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.Web.StreamerView
|
||||
require Pleroma.Constants
|
||||
|
||||
@mix_env Mix.env()
|
||||
@registry Pleroma.Web.StreamerRegistry
|
||||
|
@ -252,7 +253,17 @@ defp do_stream("user", item) do
|
|||
User.get_recipients_from_activity(item)
|
||||
|> Enum.map(fn %{id: id} -> "user:#{id}" end)
|
||||
|
||||
Enum.each(recipient_topics, fn topic ->
|
||||
hashtag_recipients =
|
||||
if Pleroma.Constants.as_public() in item.recipients do
|
||||
Pleroma.Hashtag.get_recipients_for_activity(item)
|
||||
|> Enum.map(fn id -> "user:#{id}" end)
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
all_recipients = Enum.uniq(recipient_topics ++ hashtag_recipients)
|
||||
|
||||
Enum.each(all_recipients, fn topic ->
|
||||
push_to_socket(topic, item)
|
||||
end)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue