Basic status creation and retrieval.
This commit is contained in:
parent
8de523c8ae
commit
9a8850eb9e
14 changed files with 272 additions and 9 deletions
|
|
@ -0,0 +1,17 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
||||
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
|
||||
alias Pleroma.Web.TwitterAPI.Representers.UserRepresenter
|
||||
|
||||
def to_map(activity, %{user: user}) do
|
||||
content = get_in(activity.data, ["object", "content"])
|
||||
%{
|
||||
"id" => activity.id,
|
||||
"user" => UserRepresenter.to_map(user),
|
||||
"attentions" => [],
|
||||
"statusnet_html" => content,
|
||||
"text" => content,
|
||||
"is_local" => true,
|
||||
"is_post_verb" => true
|
||||
}
|
||||
end
|
||||
end
|
||||
33
lib/pleroma/web/twitter_api/twitter_api.ex
Normal file
33
lib/pleroma/web/twitter_api/twitter_api.ex
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
|
||||
|
||||
def create_status(user = %User{}, data = %{}) do
|
||||
activity = %{
|
||||
type: "Create",
|
||||
to: [
|
||||
User.ap_followers(user),
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
actor: User.ap_id(user),
|
||||
object: %{
|
||||
type: "Note",
|
||||
content: data.status
|
||||
}
|
||||
}
|
||||
|
||||
ActivityPub.insert(activity)
|
||||
end
|
||||
|
||||
def fetch_public_statuses do
|
||||
activities = ActivityPub.fetch_public_activities
|
||||
|
||||
Enum.map(activities, fn(activity) ->
|
||||
actor = get_in(activity.data, ["actor"])
|
||||
user = Repo.get_by!(User, ap_id: actor)
|
||||
ActivityRepresenter.to_map(activity, %{user: user})
|
||||
end)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue