alias Pleroma.{Repo, User, Web, Object, Activity}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.{WebFinger, Websub}
+ alias Pleroma.Web.OStatus.FollowHandler
def feed_path(user) do
"#{user.ap_id}/feed.atom"
{:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
case verb do
+ 'http://activitystrea.ms/schema/1.0/follow' ->
+ with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
'http://activitystrea.ms/schema/1.0/share' ->
with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity]
'http://activitystrea.ms/schema/1.0/favorite' ->
def make_share(entry, doc, retweeted_activity) do
with {:ok, actor} <- find_make_or_update_user(doc),
- %Object{} = object <- Object.get_cached_by_ap_id(retweeted_activity.data["object"]["id"]),
+ %Object{} = object <- Object.get_by_ap_id(retweeted_activity.data["object"]["id"]),
id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
{:ok, activity, _object} = ActivityPub.announce(actor, object, id, false) do
{:ok, activity}
def make_favorite(entry, doc, favorited_activity) do
with {:ok, actor} <- find_make_or_update_user(doc),
- %Object{} = object <- Object.get_cached_by_ap_id(favorited_activity.data["object"]["id"]),
+ %Object{} = object <- Object.get_by_ap_id(favorited_activity.data["object"]["id"]),
id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
{:ok, activity, _object} = ActivityPub.like(actor, object, id, false) do
{:ok, activity}
|> Enum.filter(&(&1))
end
+ def get_content(entry) do
+ base_content = string_from_xpath("/entry/content", entry)
+
+ with scope when not is_nil(scope) <- string_from_xpath("//mastodon:scope", entry),
+ cw when not is_nil(cw) <- string_from_xpath("/entry/summary", entry) do
+ "<span class='mastodon-cw'>#{cw}</span><br>#{base_content}"
+ else _e -> base_content
+ end
+ end
+
def handle_note(entry, doc \\ nil) do
- content_html = string_from_xpath("//content[1]", entry)
+ content_html = get_content(entry)
[author] = :xmerl_xpath.string('//author[1]', doc)
{:ok, actor} = find_make_or_update_user(author)
# TODO: Bail out sooner and use transaction.
if Object.get_by_ap_id(id) do
- {:error, "duplicate activity"}
+ {:ok, Activity.get_create_activity_by_object_ap_id(id)}
else
ActivityPub.create(to, actor, context, object, %{}, date, false)
end
def make_user(uri) do
with {:ok, info} <- gather_user_info(uri) do
data = %{
- local: false,
name: info["name"],
nickname: info["nickname"] <> "@" <> info["host"],
ap_id: info["uri"],
info: info,
avatar: info["avatar"]
}
- # TODO: Make remote user changeset
- # SHould enforce fqn nickname
- Repo.insert(Ecto.Changeset.change(%User{}, data))
+ cs = User.remote_user_creation(data)
+ Repo.insert(cs)
end
end