Fix NaN statuses per day.

This commit is contained in:
Roger Braun 2017-06-05 15:47:37 +02:00
parent 436d538b36
commit 00c032783d
4 changed files with 20 additions and 9 deletions

View File

@ -2,7 +2,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter} alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
alias Pleroma.{Activity, User, Formatter} alias Pleroma.{Activity, User, Formatter}
alias Calendar.Strftime
alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.TwitterAPI
defp user_by_ap_id(user_list, ap_id) do defp user_by_ap_id(user_list, ap_id) do
@ -130,14 +129,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
end end
end end
defp date_to_asctime(date) do
with {:ok, date, _offset} <- date |> DateTime.from_iso8601 do
Strftime.strftime!(date, "%a %b %d %H:%M:%S %z %Y")
else _e ->
""
end
end
defp to_boolean(false) do defp to_boolean(false) do
false false
end end

View File

@ -1,6 +1,7 @@
defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
defmacro __using__(_opts) do defmacro __using__(_opts) do
quote do quote do
alias Calendar.Strftime
def to_json(object) do to_json(object, %{}) end def to_json(object) do to_json(object, %{}) end
def to_json(object, options) do def to_json(object, options) do
object object
@ -23,6 +24,18 @@ defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
|> enum_to_list(options) |> enum_to_list(options)
|> Poison.encode! |> Poison.encode!
end end
def format_asctime(date) do
Strftime.strftime!(date, "%a %b %d %H:%M:%S %z %Y")
end
def date_to_asctime(date) do
with {:ok, date, _offset} <- date |> DateTime.from_iso8601 do
format_asctime(date)
else _e ->
""
end
end
end end
end end
end end

View File

@ -12,6 +12,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
end end
user_info = User.get_cached_user_info(user) user_info = User.get_cached_user_info(user)
created_at = user.inserted_at |> DateTime.from_naive!("Etc/UTC") |> format_asctime
map = %{ map = %{
"id" => user.id, "id" => user.id,
@ -19,6 +20,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
"screen_name" => user.nickname, "screen_name" => user.nickname,
"description" => user.bio, "description" => user.bio,
"following" => following, "following" => following,
"created_at" => created_at,
# Fake fields # Fake fields
"favourites_count" => 0, "favourites_count" => 0,
"statuses_count" => user_info[:note_count], "statuses_count" => user_info[:note_count],

View File

@ -33,11 +33,14 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
image = "https://placehold.it/48x48" image = "https://placehold.it/48x48"
created_at = user.inserted_at |> DateTime.from_naive!("Etc/UTC") |> UserRepresenter.format_asctime
represented = %{ represented = %{
"id" => user.id, "id" => user.id,
"name" => user.name, "name" => user.name,
"screen_name" => user.nickname, "screen_name" => user.nickname,
"description" => user.bio, "description" => user.bio,
"created_at" => created_at,
# Fake fields # Fake fields
"favourites_count" => 0, "favourites_count" => 0,
"statuses_count" => 1, "statuses_count" => 1,
@ -58,11 +61,13 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
test "A user for a given other follower", %{user: user} do test "A user for a given other follower", %{user: user} do
{:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]}) {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
image = "https://placehold.it/48x48" image = "https://placehold.it/48x48"
created_at = user.inserted_at |> DateTime.from_naive!("Etc/UTC") |> UserRepresenter.format_asctime
represented = %{ represented = %{
"id" => user.id, "id" => user.id,
"name" => user.name, "name" => user.name,
"screen_name" => user.nickname, "screen_name" => user.nickname,
"description" => user.bio, "description" => user.bio,
"created_at" => created_at,
# Fake fields # Fake fields
"favourites_count" => 0, "favourites_count" => 0,
"statuses_count" => 0, "statuses_count" => 0,