Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
8672d4d1
Commit
8672d4d1
authored
Sep 10, 2017
by
lain
Browse files
Add context to mastodonAPI.
parent
fc108758
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
8672d4d1
...
...
@@ -61,6 +61,19 @@ def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
end
end
def
get_context
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"id"
=>
id
})
do
with
%
Activity
{}
=
activity
<-
Repo
.
get
(
Activity
,
id
),
activities
<-
ActivityPub
.
fetch_activities_for_context
(
activity
.
data
[
"object"
][
"context"
]),
%{
true:
ancestors
,
false:
descendants
}
<-
Enum
.
group_by
(
activities
,
fn
(%{
id:
id
})
->
id
<
activity
.
id
end
)
do
result
=
%{
ancestors:
StatusView
.
render
(
"index.json"
,
for:
user
,
activities:
ancestors
,
as:
:activity
)
|>
Enum
.
reverse
,
descendants:
StatusView
.
render
(
"index.json"
,
for:
user
,
activities:
descendants
,
as:
:activity
)
|>
Enum
.
reverse
,
}
json
(
conn
,
result
)
end
end
def
post_status
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"status"
=>
status
}
=
params
)
do
l
=
status
|>
String
.
trim
|>
String
.
length
...
...
lib/pleroma/web/router.ex
View file @
8672d4d1
...
...
@@ -47,6 +47,7 @@ def user_fetcher(username) do
get
"/timelines/public"
,
MastodonAPIController
,
:public_timeline
get
"/statuses/:id"
,
MastodonAPIController
,
:get_status
get
"/statuses/:id/context"
,
MastodonAPIController
,
:get_context
end
scope
"/api/v1"
,
Pleroma
.
Web
.
MastodonAPI
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment