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
360c51f1
Commit
360c51f1
authored
Apr 02, 2018
by
lain
Browse files
Use context_ids directly if we have them.
parent
bc31bee7
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/twitter_api/twitter_api.ex
View file @
360c51f1
...
...
@@ -212,6 +212,7 @@ defp make_date do
DateTime
.
utc_now
()
|>
DateTime
.
to_iso8601
()
end
# DEPRECATED mostly, context objects are now created at insertion time.
def
context_to_conversation_id
(
context
)
do
with
%
Object
{
id:
id
}
<-
Object
.
get_cached_by_ap_id
(
context
)
do
id
...
...
lib/pleroma/web/twitter_api/views/activity_view.ex
View file @
360c51f1
...
...
@@ -13,6 +13,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
import
Ecto
.
Query
defp
query_context_ids
([]),
do
:
[]
defp
query_context_ids
(
contexts
)
do
query
=
from
o
in
Object
,
where:
fragment
(
"(?)->>'id' = ANY(?)"
,
o
.
data
,
^
contexts
)
...
...
@@ -22,6 +23,7 @@ defp query_context_ids(contexts) do
defp
collect_context_ids
(
activities
)
do
contexts
=
activities
|>
Enum
.
reject
(
&
(
&1
.
data
[
"context_id"
]))
|>
Enum
.
map
(
fn
(%{
data:
data
})
->
data
[
"context"
]
end
)
...
...
@@ -32,6 +34,7 @@ defp collect_context_ids(activities) do
end
)
end
defp
get_context_id
(%{
data:
%{
"context_id"
=>
context_id
}},
_
)
when
not
is_nil
(
context_id
),
do
:
context_id
defp
get_context_id
(%{
data:
%{
"context"
=>
nil
}},
_
),
do
:
nil
defp
get_context_id
(%{
data:
%{
"context"
=>
context
}},
options
)
do
cond
do
...
...
@@ -210,12 +213,4 @@ def render(
"possibly_sensitive"
=>
possibly_sensitive
}
end
defp
conversation_id
(
activity
)
do
with
context
when
not
is_nil
(
context
)
<-
activity
.
data
[
"context"
]
do
TwitterAPI
.
context_to_conversation_id
(
context
)
else
_e
->
nil
end
end
end
test/web/twitter_api/twitter_api_controller_test.exs
View file @
360c51f1
...
...
@@ -160,15 +160,13 @@ test "gets a user for a logged in user", %{conn: conn} do
describe
"GET /statusnet/conversation/:id.json"
do
test
"returns the statuses in the conversation"
,
%{
conn:
conn
}
do
{
:ok
,
_user
}
=
UserBuilder
.
insert
()
{
:ok
,
_
activity
}
=
ActivityBuilder
.
insert
(%{
"type"
=>
"Create"
,
"context"
=>
"2hu"
})
{
:ok
,
activity
}
=
ActivityBuilder
.
insert
(%{
"type"
=>
"Create"
,
"context"
=>
"2hu"
})
{
:ok
,
_activity_two
}
=
ActivityBuilder
.
insert
(%{
"type"
=>
"Create"
,
"context"
=>
"2hu"
})
{
:ok
,
_activity_three
}
=
ActivityBuilder
.
insert
(%{
"type"
=>
"Create"
,
"context"
=>
"3hu"
})
{
:ok
,
object
}
=
Object
.
context_mapping
(
"2hu"
)
|>
Repo
.
insert
()
conn
=
conn
|>
get
(
"/api/statusnet/conversation/
#{
object
.
id
}
.json"
)
|>
get
(
"/api/statusnet/conversation/
#{
activity
.
data
[
"context_id"
]
}
.json"
)
response
=
json_response
(
conn
,
200
)
...
...
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