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
d0da40dc
Commit
d0da40dc
authored
Apr 13, 2017
by
lain
Browse files
Display like activities.
parent
834c84b5
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/twitter_api/representers/activity_representer.ex
View file @
d0da40dc
...
...
@@ -4,6 +4,25 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
alias
Pleroma
.
Activity
def
to_map
(%
Activity
{
data:
%{
"type"
=>
"Like"
}}
=
activity
,
%{
user:
user
,
liked_activity:
liked_activity
}
=
opts
)
do
created_at
=
get_in
(
activity
.
data
,
[
"published"
])
|>
date_to_asctime
text
=
"
#{
user
.
nickname
}
favorited a status."
%{
"id"
=>
activity
.
id
,
"user"
=>
UserRepresenter
.
to_map
(
user
,
opts
),
"statusnet_html"
=>
text
,
# TODO: add summary
"text"
=>
text
,
"is_local"
=>
true
,
"is_post_verb"
=>
false
,
"uri"
=>
"tag:
#{
activity
.
data
[
"id"
]
}
:objectType=Favourite"
,
"created_at"
=>
created_at
,
"in_reply_to_status_id"
=>
liked_activity
.
id
,
}
end
def
to_map
(%
Activity
{
data:
%{
"type"
=>
"Follow"
}}
=
activity
,
%{
user:
user
}
=
opts
)
do
created_at
=
get_in
(
activity
.
data
,
[
"published"
])
|>
date_to_asctime
...
...
lib/pleroma/web/twitter_api/twitter_api.ex
View file @
d0da40dc
...
...
@@ -192,6 +192,15 @@ defp activities_to_statuses(activities, opts) do
end
)
end
# For likes, fetch the liked activity, too.
defp
activity_to_status
(%
Activity
{
data:
%{
"type"
=>
"Like"
}}
=
activity
,
opts
)
do
actor
=
get_in
(
activity
.
data
,
[
"actor"
])
user
=
Repo
.
get_by!
(
User
,
ap_id:
actor
)
[
liked_activity
]
=
Activity
.
all_by_object_ap_id
(
activity
.
data
[
"object"
])
ActivityRepresenter
.
to_map
(
activity
,
Map
.
merge
(
opts
,
%{
user:
user
,
liked_activity:
liked_activity
}))
end
defp
activity_to_status
(
activity
,
opts
)
do
actor
=
get_in
(
activity
.
data
,
[
"actor"
])
user
=
Repo
.
get_by!
(
User
,
ap_id:
actor
)
...
...
test/web/twitter_api/representers/activity_representer_test.exs
View file @
d0da40dc
...
...
@@ -2,7 +2,21 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
use
Pleroma
.
DataCase
alias
Pleroma
.
{
User
,
Activity
,
Object
}
alias
Pleroma
.
Web
.
TwitterAPI
.
Representers
.
{
UserRepresenter
,
ActivityRepresenter
,
ObjectRepresenter
}
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Pleroma
.
Builders
.
UserBuilder
import
Pleroma
.
Factory
test
"a like activity"
do
user
=
insert
(
:user
)
note_activity
=
insert
(
:note_activity
)
object
=
Object
.
get_by_ap_id
(
note_activity
.
data
[
"object"
][
"id"
])
{
:ok
,
like_activity
,
object
}
=
ActivityPub
.
like
(
user
,
object
)
status
=
ActivityRepresenter
.
to_map
(
like_activity
,
%{
user:
user
,
liked_activity:
note_activity
})
assert
status
[
"id"
]
==
like_activity
.
id
assert
status
[
"in_reply_to_status_id"
]
==
note_activity
.
id
end
test
"an activity"
do
{
:ok
,
user
}
=
UserBuilder
.
insert
...
...
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