diff --git a/app/mailers/maintenance_mailer.rb b/app/mailers/maintenance_mailer.rb index 2f2a3d6..adfabe7 100644 --- a/app/mailers/maintenance_mailer.rb +++ b/app/mailers/maintenance_mailer.rb @@ -14,13 +14,9 @@ class MaintenanceMailer < ApplicationMailer # Notifica que volvimos def were_back - params[:maintenance] = Maintenance.find(params[:maintenance_id]) - - Usuarie.all.find_each do |usuarie| - I18n.with_locale usuarie.lang do - mail to: usuarie.email, - subject: I18n.t('maintenance_mailer.were_back.subject') - end + I18n.with_locale params[:lang] do + mail to: params[:email], + subject: I18n.t('maintenance_mailer.were_back.subject') end end diff --git a/app/models/maintenance.rb b/app/models/maintenance.rb index a40d5cc..95b2a01 100644 --- a/app/models/maintenance.rb +++ b/app/models/maintenance.rb @@ -5,4 +5,50 @@ class Maintenance < ApplicationRecord extend Mobility translates :message, type: :string, locale_accessors: true + + # Renderiza el mensaje una sola vez + # + # @return [String] + def to_html + @renderized_message ||= {} + @renderized_message[message.hash.to_s] ||= CommonMarker.render_doc(message, %i[FOOTNOTES SMART], %i[table strikethrough autolink]).to_html.html_safe + end + + # Como no sabemos en qué zona horaria están les usuaries, generamos la + # URL para convertir el tiempo estimado a la zona local, visitando + # otro servicio. + # + # @return [String] + def estimated_from_time_is + @estimated_from_time_is ||= {} + @estimated_from_time_is[cache_key_for_attr(estimated_from)] ||= time_is(estimated_from) + end + + # @see estimated_from_time_is + # @return [String] + def estimated_to_time_is + @estimated_to_time_is ||= {} + @estimated_to_time_is[cache_key_for_attr(estimated_to)] ||= time_is(estimated_to) + end + + # @see estimated_from_time_is + # @return [String] + def updated_at_time_is + @updated_at_time_is ||= {} + @updated_at_time_is[cache_key_for_attr(updated_at)] ||= time_is(updated_at) + end + + private + + def cache_key_for_attr(attr) + attr.hash.to_s + I18n.locale.to_s + end + + # Devuelve la URL + # + # @param [Time] + # @return [String] + def time_is(time) + "https://time.is/#{I18n.locale}/compare/#{time.utc.strftime('%H%M_%d_%B_%Y_in_%Z')}" + end end diff --git a/app/views/maintenance_mailer/notice.html.haml b/app/views/maintenance_mailer/notice.html.haml index 667002b..d159db6 100644 --- a/app/views/maintenance_mailer/notice.html.haml +++ b/app/views/maintenance_mailer/notice.html.haml @@ -1,6 +1,6 @@ %p= t('.hi') %p= t('.message') %p= t('.reason') -%blockquote= params[:maintenance].message -%p= t('.estimated_from', from: params[:maintenance].estimated_from) -%p= t('.estimated_to', to: params[:maintenance].estimated_to) += params[:maintenance].to_html +%p= t('.estimated_from_html', from: params[:maintenance].estimated_from, time_is: params[:maintenance].estimated_from_time_is) +%p= t('.estimated_to_html', to: params[:maintenance].estimated_to, time_is: params[:maintenance].estimated_to_time_is) diff --git a/app/views/maintenance_mailer/notice.text.haml b/app/views/maintenance_mailer/notice.text.haml index 7e8c5f3..1767d0d 100644 --- a/app/views/maintenance_mailer/notice.text.haml +++ b/app/views/maintenance_mailer/notice.text.haml @@ -6,7 +6,7 @@ \ = params[:maintenance].message.html_safe \ -= t('.estimated_from', from: params[:maintenance].estimated_from).html_safe += t('.estimated_from', from: params[:maintenance].estimated_from, time_is: params[:maintenance].estimated_from_time_is).html_safe \ -= t('.estimated_to', to: params[:maintenance].estimated_to).html_safe += t('.estimated_to', to: params[:maintenance].estimated_to, time_is: params[:maintenance].estimated_to_time_is).html_safe \ diff --git a/app/views/maintenance_mailer/were_back.html.haml b/app/views/maintenance_mailer/were_back.html.haml index 20d0bf2..0bff7ef 100644 --- a/app/views/maintenance_mailer/were_back.html.haml +++ b/app/views/maintenance_mailer/were_back.html.haml @@ -1,3 +1,3 @@ %p= t('.hi') -%p= t('.message') -%blockquote= params[:maintenance].message +%p= t('.message_html', updated_at: params[:maintenance].updated_at, time_is: params[:maintenance].updated_at_time_is) +%p= params[:maintenance].to_html diff --git a/app/views/maintenance_mailer/were_back.text.haml b/app/views/maintenance_mailer/were_back.text.haml index 5d7d531..db6dfb4 100644 --- a/app/views/maintenance_mailer/were_back.text.haml +++ b/app/views/maintenance_mailer/were_back.text.haml @@ -1,6 +1,6 @@ = t('.hi') \ -= t('.message') += t('.message', updated_at: params[:maintenance].updated_at, time_is: params[:maintenance].updated_at_time_is) \ = params[:maintenance].message \ diff --git a/config/locales/en.yml b/config/locales/en.yml index f9e8050..f5b254e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -94,13 +94,16 @@ en: hi: 'Hi!' message: "We're getting in contact with you to let you know we'll be doing maintenance work in our servers." reason: 'The reason is:' - estimated_from: 'The maintenance period starts at %{from}' - estimated_to: 'Up to %{to} (approximately)' + estimated_from: 'The maintenance period starts at %{from} (visit %{time_is} to convert into your time zone)' + estimated_to: 'Up to %{to} (approximately, visit %{time_is} to convert into your time zone)' + estimated_from_html: 'The maintenance period starts at %{from} (convert into your time zone)' + estimated_to_html: 'Up to %{to} (approximately, convert into your time zone)' thanks: 'Thanks for your patience' were_back: subject: 'Maintenance period ended' hi: 'Hi!' - message: 'The maintenance period ended at %{created_at}' + message: 'The maintenance period ended at %{updated_at} (visit %{time_is} to convert into your time zone)' + message_html: 'The maintenance period ended at %{updated_at} (convert into your timezone)' ics: summary: 'Sutty - Maintenance' activerecord: diff --git a/config/locales/es.yml b/config/locales/es.yml index 729e9fd..b68c6a8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -94,13 +94,16 @@ es: hi: '¡Hola!' message: 'Nos comunicamos con vos para informarte que estaremos realizando mantenimiento en nuestros servidores' reason: 'La razón de esta tarea es:' - estimated_from: 'El mantenimiento se realizará a partir de %{from}' - estimated_to: 'Hasta %{to} (aproximadamente)' + estimated_from: 'El mantenimiento se realizará a partir de %{from} (%{time_is})' + estimated_to: 'Hasta %{to} (aproximadamente, %{time_is})' + estimated_from_html: 'El mantenimiento se realizará a partir de %{from} (convertir a tu zona horaria).' + estimated_to_html: 'Hasta %{to} (aproximadamente, convertir a tu zona horaria)' thanks: 'Gracias por tu paciencia' were_back: subject: 'Fin del mantenimiento' hi: '¡Hola!' - message: 'El período de mantenimiento terminó en %{created_at}' + message: 'El período de mantenimiento terminó en %{updated_at} (visita %{time_is} para convertir a tu zona horaria)' + message_html: 'El período de mantenimiento terminó en %{updated_at} (convertir a tu zona horaria)' ics: summary: 'Sutty - Mantenimiento' activerecord: