feat(notify): Web Push subscriptions and email/push prefs.
Prefs in user.preferences; push_subscription table; VAPID send on reminder/waitlist. Refs EventHub/EventHubBack#75
This commit is contained in:
@@ -422,10 +422,15 @@ maybe_remind(#booking{id = Id, event_id = EventId, user_id = UserId} = Booking,
|
||||
send_reminder(UserId, Title, Start, CalId, EventId) ->
|
||||
Path = <<"/c/", CalId/binary, "/e/", EventId/binary>>,
|
||||
WhenText = format_when(Start),
|
||||
case core_user:get_by_id(UserId) of
|
||||
{ok, #user{email = Email}} when is_binary(Email), Email =/= <<>> ->
|
||||
_ = logic_email:send_booking_reminder(Email, Title, Start, Path);
|
||||
_ ->
|
||||
case logic_notification_prefs:email_enabled(UserId) of
|
||||
true ->
|
||||
case core_user:get_by_id(UserId) of
|
||||
{ok, #user{email = Email}} when is_binary(Email), Email =/= <<>> ->
|
||||
_ = logic_email:send_booking_reminder(Email, Title, Start, Path);
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
false ->
|
||||
ok
|
||||
end,
|
||||
_ = logic_notification:notify_event_reminder(UserId, #{
|
||||
@@ -435,6 +440,12 @@ send_reminder(UserId, Title, Start, CalId, EventId) ->
|
||||
start_time => Start,
|
||||
when_text => WhenText
|
||||
}),
|
||||
_ = logic_web_push:send(
|
||||
UserId,
|
||||
<<"Напоминание о записи"/utf8>>,
|
||||
iolist_to_binary([<<"Скоро: «"/utf8>>, Title, <<"» — "/utf8>>, WhenText]),
|
||||
Path
|
||||
),
|
||||
ok.
|
||||
|
||||
format_when({{Y, Mo, D}, {H, Mi, _S}}) ->
|
||||
|
||||
Reference in New Issue
Block a user