Elixir 1.19: Fix typing violation on struct updates in CommonAPI.Activity*
warning: a struct for Pleroma.Web.CommonAPI.ActivityDraft is expected on struct update:
%Pleroma.Web.CommonAPI.ActivityDraft{draft | object: object}
but got type:
dynamic()
where "draft" was given the type:
# type: dynamic()
# from: lib/pleroma/web/common_api/activity_draft.ex:91:22
draft
when defining the variable "draft", you must also pattern match on "%Pleroma.Web.CommonAPI.ActivityDraft{}".
hint: given pattern matching is enough to catch typing errors, you may optionally convert the struct update into a map update. For example, instead of:
user = some_function()
%User{user | name: "John Doe"}
it is enough to write:
%User{} = user = some_function()
%{user | name: "John Doe"}
typing violation found at:
│
102 │ %__MODULE__{draft | object: object}
│ ~
│
└─ lib/pleroma/web/common_api/activity_draft.ex:102:5: Pleroma.Web.CommonAPI.ActivityDraft.listen_object/1
This commit is contained in:
parent
958d250fe5
commit
8417629b4b
1 changed files with 23 additions and 23 deletions
|
|
@ -88,7 +88,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
|> validate()
|
|> validate()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp listen_object(draft) do
|
defp listen_object(%__MODULE__{} = draft) do
|
||||||
object =
|
object =
|
||||||
draft.params
|
draft.params
|
||||||
|> Map.take([:album, :artist, :title, :length])
|
|> Map.take([:album, :artist, :title, :length])
|
||||||
|
|
@ -102,20 +102,20 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
%__MODULE__{draft | object: object}
|
%__MODULE__{draft | object: object}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_params(draft, params) do
|
defp put_params(%__MODULE__{} = draft, params) do
|
||||||
params = Map.put_new(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
params = Map.put_new(params, :in_reply_to_status_id, params[:in_reply_to_id])
|
||||||
%__MODULE__{draft | params: params}
|
%__MODULE__{draft | params: params}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp status(%{params: %{status: status}} = draft) do
|
defp status(%__MODULE__{params: %{status: status}} = draft) do
|
||||||
%__MODULE__{draft | status: String.trim(status)}
|
%__MODULE__{draft | status: String.trim(status)}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp summary(%{params: params} = draft) do
|
defp summary(%__MODULE__{params: params} = draft) do
|
||||||
%__MODULE__{draft | summary: Map.get(params, :spoiler_text, "")}
|
%__MODULE__{draft | summary: Map.get(params, :spoiler_text, "")}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp full_payload(%{status: status, summary: summary} = draft) do
|
defp full_payload(%__MODULE__{status: status, summary: summary} = draft) do
|
||||||
full_payload = String.trim(status <> summary)
|
full_payload = String.trim(status <> summary)
|
||||||
|
|
||||||
case Utils.validate_character_limit(full_payload, draft.attachments) do
|
case Utils.validate_character_limit(full_payload, draft.attachments) do
|
||||||
|
|
@ -124,7 +124,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp attachments(%{params: params} = draft) do
|
defp attachments(%__MODULE__{params: params} = draft) do
|
||||||
attachments = Utils.attachments_from_ids(params, draft.user)
|
attachments = Utils.attachments_from_ids(params, draft.user)
|
||||||
draft = %__MODULE__{draft | attachments: attachments}
|
draft = %__MODULE__{draft | attachments: attachments}
|
||||||
|
|
||||||
|
|
@ -134,9 +134,9 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp in_reply_to(%{params: %{in_reply_to_status_id: ""}} = draft), do: draft
|
defp in_reply_to(%__MODULE__{params: %{in_reply_to_status_id: ""}} = draft), do: draft
|
||||||
|
|
||||||
defp in_reply_to(%{params: %{in_reply_to_status_id: id}} = draft) when is_binary(id) do
|
defp in_reply_to(%__MODULE__{params: %{in_reply_to_status_id: id}} = draft) when is_binary(id) do
|
||||||
# If a post was deleted all its activities (except the newly added Delete) are purged too,
|
# If a post was deleted all its activities (except the newly added Delete) are purged too,
|
||||||
# thus lookup by Create db ID will yield nil just as if it never existed in the first place.
|
# thus lookup by Create db ID will yield nil just as if it never existed in the first place.
|
||||||
#
|
#
|
||||||
|
|
@ -166,13 +166,13 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp in_reply_to(%{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}} = draft) do
|
defp in_reply_to(%__MODULE__{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}} = draft) do
|
||||||
%__MODULE__{draft | in_reply_to: in_reply_to}
|
%__MODULE__{draft | in_reply_to: in_reply_to}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp in_reply_to(draft), do: draft
|
defp in_reply_to(draft), do: draft
|
||||||
|
|
||||||
defp quote_post(%{params: %{quoted_status_id: id}} = draft) when not_empty_string(id) do
|
defp quote_post(%__MODULE__{params: %{quoted_status_id: id}} = draft) when not_empty_string(id) do
|
||||||
case Activity.get_by_id_with_object(id) do
|
case Activity.get_by_id_with_object(id) do
|
||||||
%Activity{} = activity ->
|
%Activity{} = activity ->
|
||||||
%__MODULE__{draft | quote_post: activity}
|
%__MODULE__{draft | quote_post: activity}
|
||||||
|
|
@ -188,12 +188,12 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
|
|
||||||
defp quote_post(draft), do: draft
|
defp quote_post(draft), do: draft
|
||||||
|
|
||||||
defp in_reply_to_conversation(draft) do
|
defp in_reply_to_conversation(%__MODULE__{} = draft) do
|
||||||
in_reply_to_conversation = Participation.get(draft.params[:in_reply_to_conversation_id])
|
in_reply_to_conversation = Participation.get(draft.params[:in_reply_to_conversation_id])
|
||||||
%__MODULE__{draft | in_reply_to_conversation: in_reply_to_conversation}
|
%__MODULE__{draft | in_reply_to_conversation: in_reply_to_conversation}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp visibility(%{params: params} = draft) do
|
defp visibility(%__MODULE__{params: params} = draft) do
|
||||||
case CommonAPI.get_visibility(params, draft.in_reply_to, draft.in_reply_to_conversation) do
|
case CommonAPI.get_visibility(params, draft.in_reply_to, draft.in_reply_to_conversation) do
|
||||||
{visibility, "direct"} when visibility != "direct" ->
|
{visibility, "direct"} when visibility != "direct" ->
|
||||||
add_error(draft, dgettext("errors", "The message visibility must be direct"))
|
add_error(draft, dgettext("errors", "The message visibility must be direct"))
|
||||||
|
|
@ -226,14 +226,14 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
|
|
||||||
defp quoting_visibility(draft), do: draft
|
defp quoting_visibility(draft), do: draft
|
||||||
|
|
||||||
defp expires_at(draft) do
|
defp expires_at(%__MODULE__{} = draft) do
|
||||||
case CommonAPI.check_expiry_date(draft.params[:expires_in]) do
|
case CommonAPI.check_expiry_date(draft.params[:expires_in]) do
|
||||||
{:ok, expires_at} -> %__MODULE__{draft | expires_at: expires_at}
|
{:ok, expires_at} -> %__MODULE__{draft | expires_at: expires_at}
|
||||||
{:error, message} -> add_error(draft, message)
|
{:error, message} -> add_error(draft, message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp poll(draft) do
|
defp poll(%__MODULE__{} = draft) do
|
||||||
case Utils.make_poll_data(draft.params) do
|
case Utils.make_poll_data(draft.params) do
|
||||||
{:ok, {poll, poll_emoji}} ->
|
{:ok, {poll, poll_emoji}} ->
|
||||||
%__MODULE__{draft | extra: poll, emoji: Map.merge(draft.emoji, poll_emoji)}
|
%__MODULE__{draft | extra: poll, emoji: Map.merge(draft.emoji, poll_emoji)}
|
||||||
|
|
@ -243,7 +243,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp content(%{mentions: mentions} = draft) do
|
defp content(%__MODULE__{mentions: mentions} = draft) do
|
||||||
{content_html, mentioned_users, tags} = Utils.make_content_html(draft)
|
{content_html, mentioned_users, tags} = Utils.make_content_html(draft)
|
||||||
|
|
||||||
mentioned_ap_ids =
|
mentioned_ap_ids =
|
||||||
|
|
@ -257,22 +257,22 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
%__MODULE__{draft | content_html: content_html, mentions: mentions, tags: tags}
|
%__MODULE__{draft | content_html: content_html, mentions: mentions, tags: tags}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp to_and_cc(draft) do
|
defp to_and_cc(%__MODULE__{} = draft) do
|
||||||
{to, cc} = Utils.get_to_and_cc(draft)
|
{to, cc} = Utils.get_to_and_cc(draft)
|
||||||
%__MODULE__{draft | to: to, cc: cc}
|
%__MODULE__{draft | to: to, cc: cc}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp context(draft) do
|
defp context(%__MODULE__{} = draft) do
|
||||||
context = Utils.make_context(draft.in_reply_to, draft.in_reply_to_conversation)
|
context = Utils.make_context(draft.in_reply_to, draft.in_reply_to_conversation)
|
||||||
%__MODULE__{draft | context: context}
|
%__MODULE__{draft | context: context}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp sensitive(draft) do
|
defp sensitive(%__MODULE__{} = draft) do
|
||||||
sensitive = draft.params[:sensitive]
|
sensitive = draft.params[:sensitive]
|
||||||
%__MODULE__{draft | sensitive: sensitive}
|
%__MODULE__{draft | sensitive: sensitive}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp language(draft) do
|
defp language(%__MODULE__{} = draft) do
|
||||||
language =
|
language =
|
||||||
with language <- draft.params[:language],
|
with language <- draft.params[:language],
|
||||||
true <- good_locale_code?(language) do
|
true <- good_locale_code?(language) do
|
||||||
|
|
@ -284,7 +284,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
%__MODULE__{draft | language: language}
|
%__MODULE__{draft | language: language}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp object(draft) do
|
defp object(%__MODULE__{} = draft) do
|
||||||
emoji = Map.merge(Pleroma.Emoji.Formatter.get_emoji_map(draft.full_payload), draft.emoji)
|
emoji = Map.merge(Pleroma.Emoji.Formatter.get_emoji_map(draft.full_payload), draft.emoji)
|
||||||
|
|
||||||
# Sometimes people create posts with subject containing emoji,
|
# Sometimes people create posts with subject containing emoji,
|
||||||
|
|
@ -328,12 +328,12 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
%__MODULE__{draft | object: object}
|
%__MODULE__{draft | object: object}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp preview?(draft) do
|
defp preview?(%__MODULE__{} = draft) do
|
||||||
preview? = Pleroma.Web.Utils.Params.truthy_param?(draft.params[:preview])
|
preview? = Pleroma.Web.Utils.Params.truthy_param?(draft.params[:preview])
|
||||||
%__MODULE__{draft | preview?: preview?}
|
%__MODULE__{draft | preview?: preview?}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp changes(draft) do
|
defp changes(%__MODULE__{} = draft) do
|
||||||
direct? = draft.visibility == "direct"
|
direct? = draft.visibility == "direct"
|
||||||
additional = %{"cc" => draft.cc, "directMessage" => direct?}
|
additional = %{"cc" => draft.cc, "directMessage" => direct?}
|
||||||
|
|
||||||
|
|
@ -359,7 +359,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
defp with_valid(%{valid?: true} = draft, func), do: func.(draft)
|
defp with_valid(%{valid?: true} = draft, func), do: func.(draft)
|
||||||
defp with_valid(draft, _func), do: draft
|
defp with_valid(draft, _func), do: draft
|
||||||
|
|
||||||
defp add_error(draft, message) do
|
defp add_error(%__MODULE__{} = draft, message) do
|
||||||
%__MODULE__{draft | valid?: false, errors: [message | draft.errors]}
|
%__MODULE__{draft | valid?: false, errors: [message | draft.errors]}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue