Skip to content

Commit f408123

Browse files
committed
rework activity views
1 parent 5eb7d4d commit f408123

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

lib/algora/activities/activities.ex

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ defmodule Algora.Activities do
279279
def notify_users(_activity, []), do: :ok
280280

281281
def notify_users(activity, users_to_notify) do
282-
title = activity_email_title(activity)
283-
body = activity_email_body(activity)
282+
title = Views.render(activity, :title)
283+
body = Views.render(activity, :txt)
284284

285285
users_to_notify
286286
|> Enum.reduce([], fn
@@ -305,21 +305,13 @@ defmodule Algora.Activities do
305305
|> Oban.insert_all()
306306
end
307307

308-
def activity_email_title(activity) do
309-
apply(Views, :"#{activity.type}_title", [])
310-
end
311-
312-
def activity_email_body(activity) do
313-
apply(Views, :"#{activity.type}_txt", [activity, activity.assoc])
314-
end
315-
316308
def redirect_url_for_activity(activity) do
317309
slug =
318310
activity.assoc_name
319311
|> to_string()
320312
|> String.replace("_activities", "")
321313

322-
"/a/#{slug}/#{activity.id}"
314+
"a/#{slug}/#{activity.id}"
323315
end
324316

325317
def external_url(activity) do

lib/algora/activities/views.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ defmodule Algora.Activities.Views do
77

88
@base_path Path.join([File.cwd!(), "lib", "algora", "activities", "views"])
99

10+
def render(activity, kind) when kind in ~w(title txt)a do
11+
apply(__MODULE__, :"#{activity.type}_#{kind}", [activity, activity.assoc])
12+
end
13+
1014
Enum.each(Activity.types(), fn type ->
1115
base_type = type |> to_string() |> String.split("_") |> List.first() |> String.to_atom()
12-
EEx.function_from_file(:def, :"#{type}_title", Path.join(@base_path, "#{type}.title.eex"), [])
16+
EEx.function_from_file(:def, :"#{type}_title", Path.join(@base_path, "#{type}.title.eex"), [:activity, base_type])
1317
EEx.function_from_file(:def, :"#{type}_txt", Path.join(@base_path, "#{type}.txt.eex"), [:activity, base_type])
1418
end)
1519
end

0 commit comments

Comments
 (0)