activitypub: transmogrifier: unify mention extraction
This commit is contained in:
parent
0a2c1a3419
commit
6b4064fa5d
|
@ -482,7 +482,10 @@ def get_notified_from_activity_query(to, true) do
|
||||||
|
|
||||||
def get_notified_from_activity(activity, local_only \\ true)
|
def get_notified_from_activity(activity, local_only \\ true)
|
||||||
|
|
||||||
def get_notified_from_activity(%Activity{data: %{"type" => "Announce", "to" => to} = data}, local_only) do
|
def get_notified_from_activity(
|
||||||
|
%Activity{data: %{"type" => "Announce", "to" => to} = data},
|
||||||
|
local_only
|
||||||
|
) do
|
||||||
object = Object.normalize(data["object"])
|
object = Object.normalize(data["object"])
|
||||||
actor = User.get_cached_by_ap_id(data["actor"])
|
actor = User.get_cached_by_ap_id(data["actor"])
|
||||||
|
|
||||||
|
|
|
@ -693,12 +693,9 @@ def add_hashtags(object) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_mention_tags(object) do
|
def add_mention_tags(object) do
|
||||||
recipients = object["to"] || []
|
|
||||||
|
|
||||||
mentions =
|
mentions =
|
||||||
recipients
|
object
|
||||||
|> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
|
|> Utils.get_notified_from_object()
|
||||||
|> Enum.filter(& &1)
|
|
||||||
|> Enum.map(fn user ->
|
|> Enum.map(fn user ->
|
||||||
%{"type" => "Mention", "href" => user.ap_id, "name" => "@#{user.nickname}"}
|
%{"type" => "Mention", "href" => user.ap_id, "name" => "@#{user.nickname}"}
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -95,6 +95,10 @@ def generate_id(type) do
|
||||||
"#{Web.base_url()}/#{type}/#{UUID.generate()}"
|
"#{Web.base_url()}/#{type}/#{UUID.generate()}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_notified_from_object(object) do
|
||||||
|
User.get_notified_from_activity(%Activity{data: object}, false)
|
||||||
|
end
|
||||||
|
|
||||||
def create_context(context) do
|
def create_context(context) do
|
||||||
context = context || generate_id("contexts")
|
context = context || generate_id("contexts")
|
||||||
changeset = Object.context_mapping(context)
|
changeset = Object.context_mapping(context)
|
||||||
|
|
Loading…
Reference in New Issue