Merge branch 'poll-notification' into 'develop'
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>
Mon, 9 Aug 2021 10:02:37 +0000 (10:02 +0000)
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>
Mon, 9 Aug 2021 10:02:37 +0000 (10:02 +0000)
MastodonAPI: Support poll notification

See merge request pleroma/pleroma!3484

1  2 
CHANGELOG.md
config/config.exs
test/support/factory.ex

diff --combined CHANGELOG.md
index 9e594f1741ef0f3136526999b55ab9425c1a513d,f9e0fe25b5f595d27457378089ab3c20e6b4589f..45a365505756860a3c5a3b272efdd5a7138b0f67
@@@ -8,18 -8,7 +8,18 @@@ The format is based on [Keep a Changelo
  
  ### Changed
  
 +### Added
 +
 +### Fixed
 +
 +### Removed
 +
 +## 2.4.0 - 2021-08-xx
 +
 +### Changed
 +
  - **Breaking:** Configuration: `:chat, enabled` moved to `:shout, enabled` and `:instance, chat_limit` moved to `:shout, limit`
 +- **Breaking** Entries for simple_policy, transparency_exclusions and quarantined_instances now list both the instance and a reason.
  - Support for Erlang/OTP 24
  - The `application` metadata returned with statuses is no longer hardcoded. Apps that want to display these details will now have valid data for new posts after this change.
  - HTTPSecurityPlug now sends a response header to opt out of Google's FLoC (Federated Learning of Cohorts) targeted advertising.
@@@ -35,6 -24,7 +35,7 @@@
  - AdminAPI: return `created_at` date with users.
  - `AnalyzeMetadata` upload filter for extracting image/video attachment dimensions and generating blurhashes for images. Blurhashes for videos are not generated at this time.
  - Attachment dimensions and blurhashes are federated when available.
+ - Mastodon API: support `poll` notification.
  - Pinned posts federation
  
  ### Fixed
  - Remote users can no longer reappear after being deleted.
  - Deactivated users may now be deleted.
  - Mix task `pleroma.database prune_objects`
 +- Fixed rendering of JSON errors on ActivityPub endpoints.
  - Linkify: Parsing crash with URLs ending in unbalanced closed paren, no path separator, and no query parameters
 -
 -### Removed
 -- **Breaking**: Remove deprecated `/api/qvitter/statuses/notifications/read` (replaced by `/api/v1/pleroma/notifications/read`)
 -
 -## Unreleased (Patch)
 -
 -### Fixed
 -
  - Try to save exported ConfigDB settings (migrate_from_db) in the system temp directory if default location is not writable.
  - Uploading custom instance thumbnail via AdminAPI/AdminFE generated invalid URL to the image
  - Applying ConcurrentLimiter settings via AdminAPI
  - MRF (`SimplePolicy`): Embedded objects are now checked. If any embedded object would be rejected, its parent is rejected. This fixes Announces leaking posts from blocked domains.
  - Fixed some Markdown issues, including trailing slash in links.
  
 -## [2.3.0] - 2020-03-01
 +### Removed
 +- **Breaking**: Remove deprecated `/api/qvitter/statuses/notifications/read` (replaced by `/api/v1/pleroma/notifications/read`)
 +
 +## [2.3.0] - 2021-03-01
  
  ### Security
  
    - Mastodon API: Support for expires_in/expires_at in the Filters.
  </details>
  
 -## [2.2.2] - 2020-01-18
 +## [2.2.2] - 2021-01-18
  
  ### Fixed
  
diff --combined config/config.exs
index b50c910b12b985ed1c8f6311fc6b8a25c6f8c550,a0a9b76e4b2c5e6995153004e4b39923c3e9cb5e..828fe00857518594c69495ae44f705c9debd8b71
@@@ -460,7 -460,7 +460,7 @@@ config :pleroma, :shout
    enabled: true,
    limit: 5_000
  
 -config :phoenix, :format_encoders, json: Jason
 +config :phoenix, :format_encoders, json: Jason, "activity+json": Jason
  
  config :phoenix, :json_library, Jason
  
@@@ -560,6 -560,7 +560,7 @@@ config :pleroma, Oban
      mailer: 10,
      transmogrifier: 20,
      scheduled_activities: 10,
+     poll_notifications: 10,
      background: 5,
      remote_fetcher: 2,
      attachments_cleanup: 1,
diff --combined test/support/factory.ex
index f31f64a503e2996ee5d9fc7130eb203dc4955b5c,d42e59dda1d73ec0548246ada980931ee1cd30d4..4a78425ce4d2e3ccb21683a032b330cdda4826ec
@@@ -142,11 -142,6 +142,11 @@@ defmodule Pleroma.Factory d
      }
    end
  
 +  def followers_only_note_factory(attrs \\ %{}) do
 +    %Pleroma.Object{data: data} = note_factory(attrs)
 +    %Pleroma.Object{data: Map.merge(data, %{"to" => [data["actor"] <> "/followers"]})}
 +  end
 +
    def audio_factory(attrs \\ %{}) do
      text = sequence(:text, &"lain radio episode #{&1}")
  
      }
    end
  
+   def question_factory(attrs \\ %{}) do
+     user = attrs[:user] || insert(:user)
+     data = %{
+       "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+       "type" => "Question",
+       "actor" => user.ap_id,
+       "attributedTo" => user.ap_id,
+       "attachment" => [],
+       "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+       "cc" => [user.follower_address],
+       "context" => Pleroma.Web.ActivityPub.Utils.generate_context_id(),
+       "closed" => DateTime.utc_now() |> DateTime.add(86_400) |> DateTime.to_iso8601(),
+       "oneOf" => [
+         %{
+           "type" => "Note",
+           "name" => "chocolate",
+           "replies" => %{"totalItems" => 0, "type" => "Collection"}
+         },
+         %{
+           "type" => "Note",
+           "name" => "vanilla",
+           "replies" => %{"totalItems" => 0, "type" => "Collection"}
+         }
+       ]
+     }
+     %Pleroma.Object{
+       data: merge_attributes(data, Map.get(attrs, :data, %{}))
+     }
+   end
    def direct_note_activity_factory do
      dm = insert(:direct_note)
  
      %Pleroma.Activity{
        data: data,
        actor: data["actor"],
 +      recipients: data["to"]
 +    }
 +    |> Map.merge(attrs)
 +  end
 +
 +  def followers_only_note_activity_factory(attrs \\ %{}) do
 +    user = attrs[:user] || insert(:user)
 +    note = insert(:followers_only_note, user: user)
 +
 +    data_attrs = attrs[:data_attrs] || %{}
 +    attrs = Map.drop(attrs, [:user, :note, :data_attrs])
 +
 +    data =
 +      %{
 +        "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
 +        "type" => "Create",
 +        "actor" => note.data["actor"],
 +        "to" => note.data["to"],
 +        "object" => note.data,
 +        "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
 +        "context" => note.data["context"]
 +      }
 +      |> Map.merge(data_attrs)
 +
 +    %Pleroma.Activity{
 +      data: data,
 +      actor: data["actor"],
        recipients: data["to"]
      }
      |> Map.merge(attrs)
      }
    end
  
+   def question_activity_factory(attrs \\ %{}) do
+     user = attrs[:user] || insert(:user)
+     question = attrs[:question] || insert(:question, user: user)
+     data_attrs = attrs[:data_attrs] || %{}
+     attrs = Map.drop(attrs, [:user, :question, :data_attrs])
+     data =
+       %{
+         "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+         "type" => "Create",
+         "actor" => question.data["actor"],
+         "to" => question.data["to"],
+         "object" => question.data["id"],
+         "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+         "context" => question.data["context"]
+       }
+       |> Map.merge(data_attrs)
+     %Pleroma.Activity{
+       data: data,
+       actor: data["actor"],
+       recipients: data["to"]
+     }
+     |> Map.merge(attrs)
+   end
    def oauth_app_factory do
      %Pleroma.Web.OAuth.App{
        client_name: sequence(:client_name, &"Some client #{&1}"),