projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'feature/peertube_2' into 'develop'
[akkoma]
/
lib
/
pleroma
/
web
/
common_api
/
utils.ex
diff --git
a/lib/pleroma/web/common_api/utils.ex
b/lib/pleroma/web/common_api/utils.ex
index b142eda952a9cf13dd735dab1fa57d91e3f4b0d0..869f4c5661c5cef438ee3a3cf7b45dd7745d0d93 100644
(file)
--- a/
lib/pleroma/web/common_api/utils.ex
+++ b/
lib/pleroma/web/common_api/utils.ex
@@
-1,17
+1,20
@@
defmodule Pleroma.Web.CommonAPI.Utils do
defmodule Pleroma.Web.CommonAPI.Utils do
- alias Pleroma.{Repo, Object, Formatter,
User,
Activity}
+ alias Pleroma.{Repo, Object, Formatter, Activity}
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.User
alias Calendar.Strftime
alias Calendar.Strftime
+ alias Comeonin.Pbkdf2
# This is a hack for twidere.
def get_by_id_or_ap_id(id) do
activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id)
# This is a hack for twidere.
def get_by_id_or_ap_id(id) do
activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id)
- if activity.data["type"] == "Create" do
- activity
- else
- Activity.get_create_activity_by_object_ap_id(activity.data["object"])
- end
+ activity &&
+ if activity.data["type"] == "Create" do
+ activity
+ else
+ Activity.get_create_activity_by_object_ap_id(activity.data["object"])
+ end
end
def get_replied_to_activity(id) when not is_nil(id) do
end
def get_replied_to_activity(id) when not is_nil(id) do
@@
-61,7
+64,6
@@
defmodule Pleroma.Web.CommonAPI.Utils do
def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do
status
def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do
status
- |> String.replace("\r", "")
|> format_input(mentions, tags)
|> maybe_add_attachments(attachments, no_attachment_links)
end
|> format_input(mentions, tags)
|> maybe_add_attachments(attachments, no_attachment_links)
end
@@
-92,7
+94,7
@@
defmodule Pleroma.Web.CommonAPI.Utils do
def format_input(text, mentions, tags) do
text
|> Formatter.html_escape()
def format_input(text, mentions, tags) do
text
|> Formatter.html_escape()
- |> String.replace(
"\n"
, "<br>")
+ |> String.replace(
~r/\r?\n/
, "<br>")
|> (&{[], &1}).()
|> Formatter.add_links()
|> Formatter.add_user_links(mentions)
|> (&{[], &1}).()
|> Formatter.add_links()
|> Formatter.add_user_links(mentions)
@@
-106,7
+108,7
@@
defmodule Pleroma.Web.CommonAPI.Utils do
|> Enum.sort_by(fn {tag, _} -> -String.length(tag) end)
Enum.reduce(tags, text, fn {full, tag}, text ->
|> Enum.sort_by(fn {tag, _} -> -String.length(tag) end)
Enum.reduce(tags, text, fn {full, tag}, text ->
- url = "
#<a href='#{Pleroma.Web.base_url()}/tag/#{tag}' rel='tag'>
#{tag}</a>"
+ url = "
<a href='#{Pleroma.Web.base_url()}/tag/#{tag}' rel='tag'>#
#{tag}</a>"
String.replace(text, full, url)
end)
end
String.replace(text, full, url)
end)
end
@@
-131,7
+133,7
@@
defmodule Pleroma.Web.CommonAPI.Utils do
"context" => context,
"attachment" => attachments,
"actor" => actor,
"context" => context,
"attachment" => attachments,
"actor" => actor,
- "tag" => tags |> Enum.map(fn {_, tag} -> tag end)
+ "tag" => tags |> Enum.map(fn {_, tag} -> tag end)
|> Enum.uniq()
}
if inReplyTo do
}
if inReplyTo do
@@
-184,4
+186,13
@@
defmodule Pleroma.Web.CommonAPI.Utils do
String.slice(name, 0..30) <> "…"
end
end
String.slice(name, 0..30) <> "…"
end
end
+
+ def confirm_current_password(user, password) do
+ with %User{local: true} = db_user <- Repo.get(User, user.id),
+ true <- Pbkdf2.checkpw(password, db_user.password_hash) do
+ {:ok, db_user}
+ else
+ _ -> {:error, "Invalid password."}
+ end
+ end
end
end