forked from AkkomaGang/akkoma
MastoAPI: Fix put_settings
This commit is contained in:
parent
ccf0b46dd6
commit
2ae1128d9f
3 changed files with 10 additions and 7 deletions
|
@ -62,10 +62,6 @@ def follow_changeset(struct, params \\ %{}) do
|
||||||
|> validate_required([:following])
|
|> validate_required([:following])
|
||||||
end
|
end
|
||||||
|
|
||||||
def info_changeset(struct, params \\ %{}) do
|
|
||||||
raise "NOT VALID ANYMORE"
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_info(%User{} = user) do
|
def user_info(%User{} = user) do
|
||||||
oneself = if user.local, do: 1, else: 0
|
oneself = if user.local, do: 1, else: 0
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,11 @@ def mastodon_profile_update(info, params) do
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mastodon_settings_update(info, params) do
|
||||||
|
info
|
||||||
|
|> cast(params, [:settings])
|
||||||
|
end
|
||||||
|
|
||||||
def set_source_data(info, source_data) do
|
def set_source_data(info, source_data) do
|
||||||
params = %{source_data: source_data}
|
params = %{source_data: source_data}
|
||||||
|
|
||||||
|
|
|
@ -970,9 +970,11 @@ def index(%{assigns: %{user: user}} = conn, _params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
|
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
|
||||||
with new_info <- Map.put(user.info, "settings", settings),
|
info_cng = User.Info.mastodon_settings_update(user.info, settings)
|
||||||
change <- User.info_changeset(user, %{info: new_info}),
|
|
||||||
{:ok, _user} <- User.update_and_set_cache(change) do
|
with changeset <- User.update_changeset(user),
|
||||||
|
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
||||||
|
{:ok, user} <- User.update_and_set_cache(changeset) do
|
||||||
conn
|
conn
|
||||||
|> json(%{})
|
|> json(%{})
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue