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
d659fcc1
Commit
d659fcc1
authored
Sep 15, 2017
by
Roger Braun
Browse files
MastoAPI: Fix date in account view.
parent
eb248cf8
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/common_api/utils.ex
View file @
d659fcc1
...
...
@@ -119,6 +119,23 @@ def date_to_asctime(date) do
end
end
def
to_masto_date
(%
NaiveDateTime
{}
=
date
)
do
date
|>
NaiveDateTime
.
to_iso8601
|>
String
.
replace
(
~r/(\.\d+)?$/
,
".000Z"
,
global:
false
)
end
def
to_masto_date
(
date
)
do
try
do
date
|>
NaiveDateTime
.
from_iso8601!
|>
NaiveDateTime
.
to_iso8601
|>
String
.
replace
(
~r/(\.\d+)?$/
,
".000Z"
,
global:
false
)
rescue
_e
->
""
end
end
defp
shortname
(
name
)
do
if
String
.
length
(
name
)
<
30
do
name
...
...
lib/pleroma/web/mastodon_api/views/account_view.ex
View file @
d659fcc1
...
...
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
use
Pleroma
.
Web
,
:view
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
MastodonAPI
.
AccountView
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
defp
image_url
(%{
"url"
=>
[
%{
"href"
=>
href
}
|
t
]}),
do
:
href
defp
image_url
(
_
),
do
:
nil
...
...
@@ -22,7 +23,7 @@ def render("account.json", %{user: user}) do
acct:
user
.
nickname
,
display_name:
user
.
name
,
locked:
false
,
created_at:
user
.
inserted_at
,
created_at:
Utils
.
to_masto_date
(
user
.
inserted_at
)
,
followers_count:
user_info
.
follower_count
,
following_count:
user_info
.
following_count
,
statuses_count:
user_info
.
note_count
,
...
...
lib/pleroma/web/mastodon_api/views/status_view.ex
View file @
d659fcc1
...
...
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
use
Pleroma
.
Web
,
:view
alias
Pleroma
.
Web
.
MastodonAPI
.
{
AccountView
,
StatusView
}
alias
Pleroma
.
{
User
,
Activity
}
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
def
render
(
"index.json"
,
opts
)
do
render_many
(
opts
.
activities
,
StatusView
,
"status.json"
,
opts
)
...
...
@@ -26,10 +27,7 @@ def render("status.json", %{activity: %{data: %{"object" => object}} = activity}
attachments
=
render_many
(
object
[
"attachment"
]
||
[],
StatusView
,
"attachment.json"
,
as:
:attachment
)
created_at
=
(
object
[
"published"
]
||
""
)
|>
NaiveDateTime
.
from_iso8601!
|>
NaiveDateTime
.
to_iso8601
|>
String
.
replace
(
~r/(\.\d+)?$/
,
".000Z"
,
global:
false
)
created_at
=
Utils
.
to_masto_date
(
object
[
"published"
])
# TODO: Add cached version.
reply_to
=
Activity
.
get_create_activity_by_object_ap_id
(
object
[
"inReplyTo"
])
...
...
test/web/mastodon_api/account_view_test.exs
View file @
d659fcc1
...
...
@@ -5,7 +5,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
alias
Pleroma
.
User
test
"Represent a user account"
do
user
=
insert
(
:user
,
%{
info:
%{
"note_count"
=>
5
,
"follower_count"
=>
3
},
nickname:
"shp@shitposter.club"
})
user
=
insert
(
:user
,
%{
info:
%{
"note_count"
=>
5
,
"follower_count"
=>
3
},
nickname:
"shp@shitposter.club"
,
inserted_at:
~N[2017-08-15 15:47:06.597036]
})
expected
=
%{
id:
user
.
id
,
...
...
@@ -13,7 +13,7 @@ test "Represent a user account" do
acct:
user
.
nickname
,
display_name:
user
.
name
,
locked:
false
,
created_at:
user
.
inserted_at
,
created_at:
"2017-08-15T15:47:06.000Z"
,
followers_count:
3
,
following_count:
0
,
statuses_count:
5
,
...
...
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