Fix NaN statuses per day.
authorRoger Braun <roger@rogerbraun.net>
Mon, 5 Jun 2017 13:47:37 +0000 (15:47 +0200)
committerRoger Braun <roger@rogerbraun.net>
Mon, 5 Jun 2017 13:47:37 +0000 (15:47 +0200)
lib/pleroma/web/twitter_api/representers/activity_representer.ex
lib/pleroma/web/twitter_api/representers/base_representer.ex
lib/pleroma/web/twitter_api/representers/user_representer.ex
test/web/twitter_api/representers/user_representer_test.exs

index 0303739f5b9fb7e6415ab170ac14342023866a64..ade200268c0feba0fb7547c9750053ee14dc3d50 100644 (file)
@@ -2,7 +2,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
   use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
   alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
   alias Pleroma.{Activity, User, Formatter}
-  alias Calendar.Strftime
   alias Pleroma.Web.TwitterAPI.TwitterAPI
 
   defp user_by_ap_id(user_list, ap_id) do
@@ -130,14 +129,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     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
     false
   end
index a4ef245fc687195356239c4a0961d0175e978a19..f13a544129df7a6226261d5dd845fc10173e420c 100644 (file)
@@ -1,6 +1,7 @@
 defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
   defmacro __using__(_opts) do
     quote do
+      alias Calendar.Strftime
       def to_json(object) do to_json(object, %{}) end
       def to_json(object, options) do
         object
@@ -23,6 +24,18 @@ defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
         |> enum_to_list(options)
         |> Poison.encode!
       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
index 4930774138d8861f287eb48ede8a737328144001..8a7bb6f0d3199fab6ad6f81b92a1cc0d61c0b4bd 100644 (file)
@@ -12,6 +12,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
     end
 
     user_info = User.get_cached_user_info(user)
+    created_at = user.inserted_at |> DateTime.from_naive!("Etc/UTC") |> format_asctime
 
     map = %{
       "id" => user.id,
@@ -19,6 +20,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
       "screen_name" => user.nickname,
       "description" => user.bio,
       "following" => following,
+      "created_at" => created_at,
       # Fake fields
       "favourites_count" => 0,
       "statuses_count" => user_info[:note_count],
index 77f0659483f3ba1e851727d9d5bd3f82c760c0ab..d63f738a92e8f117f68c994787b15eb8ce6a77b4 100644 (file)
@@ -33,11 +33,14 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
 
     image = "https://placehold.it/48x48"
 
+    created_at = user.inserted_at |> DateTime.from_naive!("Etc/UTC") |> UserRepresenter.format_asctime
+
     represented = %{
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
       "description" => user.bio,
+      "created_at" => created_at,
       # Fake fields
       "favourites_count" => 0,
       "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
     {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
     image = "https://placehold.it/48x48"
+    created_at = user.inserted_at |> DateTime.from_naive!("Etc/UTC") |> UserRepresenter.format_asctime
     represented = %{
       "id" => user.id,
       "name" => user.name,
       "screen_name" => user.nickname,
       "description" => user.bio,
+      "created_at" => created_at,
       # Fake fields
       "favourites_count" => 0,
       "statuses_count" => 0,