Merge branch 'master' into refactoring-based-on-credo-and-dialyzer
This commit is contained in:
@@ -357,9 +357,8 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
|
||||
with {:ok, _} <- Events.delete_event(event),
|
||||
{:ok, activity} <- create_activity(data, local),
|
||||
{:ok, object} <- insert_full_object(data),
|
||||
:ok <- maybe_federate(activity) do
|
||||
{:ok, activity, object}
|
||||
{:ok, activity, event}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -542,7 +541,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
|
||||
public = is_public?(activity)
|
||||
|
||||
if public && Config.get([:instance, :allow_relay]) do
|
||||
if public && !is_delete_activity?(activity) && Config.get([:instance, :allow_relay]) do
|
||||
Logger.info(fn -> "Relaying #{activity.data["id"]} out" end)
|
||||
Mobilizon.Service.ActivityPub.Relay.publish(activity)
|
||||
end
|
||||
@@ -573,6 +572,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
end)
|
||||
end
|
||||
|
||||
defp is_delete_activity?(%Activity{data: %{"type" => "Delete"}}), do: true
|
||||
defp is_delete_activity?(_), do: false
|
||||
|
||||
@doc """
|
||||
Publish an activity to a specific inbox
|
||||
"""
|
||||
|
||||
@@ -165,14 +165,14 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
{:ok, %Report{} = report} <- Reports.create_report(data) do
|
||||
Enum.each(Users.list_moderators(), fn moderator ->
|
||||
moderator
|
||||
|> Email.Admin.report(moderator, report)
|
||||
|> Email.Admin.report(report)
|
||||
|> Email.Mailer.deliver_later()
|
||||
end)
|
||||
|
||||
{:ok, report}
|
||||
else
|
||||
err ->
|
||||
Logger.error("Error while inserting a remote comment inside database")
|
||||
Logger.error("Error while inserting report inside database")
|
||||
Logger.debug(inspect(err))
|
||||
{:error, err}
|
||||
end
|
||||
|
||||
@@ -22,9 +22,19 @@ defmodule Mobilizon.Service.Admin.ActionLogService do
|
||||
"target_type" => to_string(target.__struct__),
|
||||
"target_id" => target.id,
|
||||
"action" => action,
|
||||
"changes" => Map.from_struct(target) |> Map.take([:status, :uri, :content])
|
||||
"changes" => stringify_struct(target)
|
||||
}) do
|
||||
{:ok, create_action_log}
|
||||
end
|
||||
end
|
||||
|
||||
defp stringify_struct(%_{} = struct) do
|
||||
association_fields = struct.__struct__.__schema__(:associations)
|
||||
|
||||
struct
|
||||
|> Map.from_struct()
|
||||
|> Map.drop(association_fields ++ [:__meta__])
|
||||
end
|
||||
|
||||
defp stringify_struct(struct), do: struct
|
||||
end
|
||||
|
||||
31
lib/service/statistics.ex
Normal file
31
lib/service/statistics.ex
Normal file
@@ -0,0 +1,31 @@
|
||||
defmodule Mobilizon.Service.Statistics do
|
||||
@moduledoc """
|
||||
A module that provides cached statistics
|
||||
"""
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Users
|
||||
|
||||
def get_cached_value(key) do
|
||||
case Cachex.fetch(:statistics, key, fn key ->
|
||||
case create_cache(key) do
|
||||
value when not is_nil(value) -> {:commit, value}
|
||||
err -> {:ignore, err}
|
||||
end
|
||||
end) do
|
||||
{status, value} when status in [:ok, :commit] -> value
|
||||
_err -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp create_cache(:local_users) do
|
||||
Users.count_users()
|
||||
end
|
||||
|
||||
defp create_cache(:local_events) do
|
||||
Events.count_local_events()
|
||||
end
|
||||
|
||||
defp create_cache(:local_comments) do
|
||||
Events.count_local_comments()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user