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
fc85c9f0
Commit
fc85c9f0
authored
Sep 14, 2017
by
Roger Braun
Browse files
Add tag timelines.
parent
b0363e80
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
fc85c9f0
...
...
@@ -111,6 +111,12 @@ defp restrict_since(query, %{"since_id" => since_id}) do
end
defp
restrict_since
(
query
,
_
),
do
:
query
defp
restrict_tag
(
query
,
%{
"tag"
=>
tag
})
do
from
activity
in
query
,
where:
fragment
(
"? <@ (? #> '{
\"
object
\"
,
\"
tag
\"
}')"
,
^
tag
,
activity
.
data
)
end
defp
restrict_tag
(
query
,
_
),
do
:
query
defp
restrict_recipients
(
query
,
recipients
)
do
Enum
.
reduce
(
recipients
,
query
,
fn
(
recipient
,
q
)
->
map
=
%{
to:
[
recipient
]
}
...
...
@@ -148,6 +154,7 @@ def fetch_activities(recipients, opts \\ %{}) do
base_query
|>
restrict_recipients
(
recipients
)
|>
restrict_tag
(
opts
)
|>
restrict_since
(
opts
)
|>
restrict_local
(
opts
)
|>
restrict_max
(
opts
)
...
...
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
fc85c9f0
...
...
@@ -230,6 +230,18 @@ def reblogged_by(conn, %{"id" => id}) do
end
end
def
hashtag_timeline
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
params
=
params
|>
Map
.
put
(
"type"
,
"Create"
)
|>
Map
.
put
(
"local_only"
,
!!params
[
"local"
])
activities
=
ActivityPub
.
fetch_public_activities
(
params
)
|>
Enum
.
reverse
conn
|>
render
(
StatusView
,
"index.json"
,
%{
activities:
activities
,
for:
user
,
as:
:activity
})
end
def
empty_array
(
conn
,
_
)
do
Logger
.
debug
(
"Unimplemented, returning an empty array"
)
json
(
conn
,
[])
...
...
lib/pleroma/web/router.ex
View file @
fc85c9f0
...
...
@@ -65,6 +65,7 @@ def user_fetcher(username) do
post
"/apps"
,
MastodonAPIController
,
:create_app
get
"/timelines/public"
,
MastodonAPIController
,
:public_timeline
get
"/timelines/tag/:tag"
,
MastodonAPIController
,
:hashtag_timeline
get
"/statuses/:id"
,
MastodonAPIController
,
:get_status
get
"/statuses/:id/context"
,
MastodonAPIController
,
:get_context
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
fc85c9f0
...
...
@@ -186,7 +186,6 @@ test "gets a users statuses", %{conn: conn} do
test
"returns the relationships for the current user"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
other_user
=
insert
(
:user
)
{
:ok
,
user
}
=
User
.
follow
(
user
,
other_user
)
conn
=
conn
...
...
@@ -227,4 +226,18 @@ test "media upload", %{conn: conn} do
assert
media
[
"type"
]
==
"image"
end
test
"hashtag timeline"
,
%{
conn:
conn
}
do
following
=
insert
(
:user
)
{
:ok
,
activity
}
=
TwitterAPI
.
create_status
(
following
,
%{
"status"
=>
"test #2hu"
})
{
:ok
,
[
_activity
]}
=
OStatus
.
fetch_activity_from_url
(
"https://shitposter.club/notice/2827873"
)
conn
=
conn
|>
get
(
"/api/v1/timelines/tag/2hu"
)
assert
[%{
"id"
=>
id
}]
=
json_response
(
conn
,
200
)
assert
id
==
activity
.
id
end
end
Write
Preview
Supports
Markdown
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