squash! Expose expires_at datetime in mastoAPI only for the activity actor
authorMike Verdone <spiral@arcseconds.net>
Wed, 24 Jul 2019 14:51:09 +0000 (16:51 +0200)
committerMike Verdone <spiral@arcseconds.net>
Wed, 24 Jul 2019 14:51:09 +0000 (16:51 +0200)
NOTE: rewrite the commit msg

docs/api/differences_in_mastoapi_responses.md
lib/pleroma/web/mastodon_api/views/status_view.ex
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/mastodon_api/status_view_test.exs

index 168a13f4e485733511f2aa55fede5e2664685ada..829468b1393c2efa4cf997eebeacd0c5a5c0d34a 100644 (file)
@@ -25,7 +25,7 @@ Has these additional fields under the `pleroma` object:
 - `in_reply_to_account_acct`: the `acct` property of User entity for replied user (if any)
 - `content`: a map consisting of alternate representations of the `content` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
 - `spoiler_text`: a map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`
-- `expires_on`: a datetime (iso8601) that states when the post will expire (be deleted automatically), or empty if the post won't expire
+- `expires_in`:  the number of minutes until a post will expire (be deleted automatically), or empty if the post won't expire
 
 ## Attachments
 
index 7264dcafb59c3a1f51277021a0e900561cfe33de..4a3686d72fea77704d80eead677e32cc74916e70 100644 (file)
@@ -168,11 +168,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
 
     client_posted_this_activity = opts[:for] && user.id == opts[:for].id
 
-    expires_at =
+    expires_in =
       with true <- client_posted_this_activity,
            expiration when not is_nil(expiration) <-
              ActivityExpiration.get_by_activity_id(activity.id) do
-        expiration.scheduled_at
+        expires_in_seconds =
+          expiration.scheduled_at
+          |> NaiveDateTime.diff(NaiveDateTime.utc_now(), :second)
+
+        round(expires_in_seconds / 60)
       end
 
     thread_muted? =
@@ -273,7 +277,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         in_reply_to_account_acct: reply_to_user && reply_to_user.nickname,
         content: %{"text/plain" => content_plaintext},
         spoiler_text: %{"text/plain" => summary_plaintext},
-        expires_at: expires_at
+        expires_in: expires_in
       }
     }
   end
index e599089794be6c65822629dcc7af8bd3c9a7ea29..a9d38c06e8ce987e09826969ca70db3860ad417c 100644 (file)
@@ -170,7 +170,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       assert activity = Activity.get_by_id(fourth_id)
       assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
       assert expiration.scheduled_at == expires_at
-      assert fourth_response["pleroma"]["expires_at"] == NaiveDateTime.to_iso8601(expires_at)
+      assert fourth_response["pleroma"]["expires_in"] > 0
     end
 
     test "replying to a status", %{conn: conn} do
index 073c696597f35d0c8d46a3d29b609abdf1861937..eb0874ab26b2c2b4e506cd8af2aa137707904345 100644 (file)
@@ -134,7 +134,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
         in_reply_to_account_acct: nil,
         content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
         spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
-        expires_at: nil
+        expires_in: nil
       }
     }