diff --git a/db/manifest b/db/manifest index 46eecb8d1..61df1be7d 100755 --- a/db/manifest +++ b/db/manifest @@ -381,4 +381,5 @@ sms_index_optimize.sql amazon_signup.sql age_out_sessions.sql alter_crash_dumps.sql -onboarding.sql \ No newline at end of file +onboarding.sql +better_lesson_notices.sql \ No newline at end of file diff --git a/db/up/better_lesson_notices.sql b/db/up/better_lesson_notices.sql new file mode 100644 index 000000000..43096e8d0 --- /dev/null +++ b/db/up/better_lesson_notices.sql @@ -0,0 +1 @@ +ALTER TABLE lesson_sessions ADD COLUMN sent_counter_reminder_at TIMESTAMP without time zone; \ No newline at end of file diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.html.erb index f437bd8ad..fc48a9251 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.html.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.html.erb @@ -3,7 +3,7 @@ <% content_for :note do %>
- <%= @teacher.name %> proposed a different time 24 hours ago.
+ <%= @teacher.name %> proposed a different time a while back.
Please click the button below to respond.
diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.text.erb
index e05617102..92d19964d 100644
--- a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.text.erb
+++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_counter_reminder.text.erb
@@ -1,3 +1,3 @@
-<%= @teacher.name %> has proposed a different time 24 hours ago. Please respond.
+<%= @teacher.name %> has proposed a different time a while back. Please respond.
To see this lesson, click here: <%= @lesson_session.web_url %>
\ No newline at end of file
diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.html.erb
index 5b5efd606..f40ae17ae 100644
--- a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.html.erb
+++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.html.erb
@@ -3,7 +3,7 @@
<% content_for :note do %>
- <%= @student.name %> has proposed a different time 24 hours ago.
+ <%= @student.name %> has proposed a different time a while back.
Please click the button below to respond.
diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.text.erb
index 4a781de93..4f896b550 100644
--- a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.text.erb
+++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_counter_reminder.text.erb
@@ -1,3 +1,3 @@
-<%= @student.name %> has proposed a different time 24 hours ago. Please respond.
+<%= @student.name %> has proposed a different time a while back. Please respond.
To see this lesson, click here: <%= @lesson_session.web_url %>
\ No newline at end of file
diff --git a/ruby/lib/jam_ruby/models/lesson_session.rb b/ruby/lib/jam_ruby/models/lesson_session.rb
index df95fc99e..2fa288174 100644
--- a/ruby/lib/jam_ruby/models/lesson_session.rb
+++ b/ruby/lib/jam_ruby/models/lesson_session.rb
@@ -142,16 +142,20 @@ module JamRuby
def self.remind_counters
MusicSession.joins(lesson_session: :lesson_booking)
- .where('lesson_sessions.sent_counter_reminder = false AND lesson_bookings.recurring = FALSE')
+ .where('lesson_bookings.recurring = FALSE')
.where('lesson_sessions.status = ? OR lesson_sessions.status = ?', LessonSession::STATUS_REQUESTED, LessonSession::STATUS_COUNTERED)
- .where("? > (COALESCE(lesson_sessions.countered_at, lesson_bookings.sent_notices_at) + (INTERVAL '24 hours'))", Time.now).each do |music_session|
+ .where("? > (COALESCE(lesson_sessions.sent_counter_reminder_at, lesson_sessions.countered_at, lesson_bookings.sent_notices_at) + (INTERVAL '24 hours'))", Time.now).each do |music_session|
lesson_session = music_session.lesson_session
if lesson_session.student_last_proposed?
+ relevant_time = [lesson_session.countered_at, lesson_session.lesson_booking.sent_notices_at].find{|x|!x.nil?}
+
+ UserMailer.student_no_comm_other(lesson_session.lesson_booking, relevant_time < Time.now - 3.days).deliver_now
UserMailer.teacher_counter_reminder(lesson_session).deliver_now
else
+ UserMailer.teacher_no_comm_other(lesson_session.lesson_booking).deliver_now
UserMailer.student_counter_reminder(lesson_session).deliver_now
end
- lesson_session.sent_counter_reminder = true
+ lesson_session.sent_counter_reminder_at = Time.now
lesson_session.save(validate: false)
end
end
diff --git a/ruby/spec/jam_ruby/models/lesson_session_spec.rb b/ruby/spec/jam_ruby/models/lesson_session_spec.rb
index d418a9fbd..9c4b984bc 100644
--- a/ruby/spec/jam_ruby/models/lesson_session_spec.rb
+++ b/ruby/spec/jam_ruby/models/lesson_session_spec.rb
@@ -291,18 +291,19 @@ describe LessonSession do
lesson_session1.sent_counter_reminder.should be_false
lesson_session1.status.should eql LessonSession::STATUS_REQUESTED
mailer = mock
- mailer.should_receive(:deliver_now).once
+ mailer.should_receive(:deliver_now).twice
UserMailer.should_receive(:teacher_counter_reminder).and_return(mailer)
+ UserMailer.should_receive(:student_no_comm_other).and_return(mailer)
LessonSession.remind_counters
lesson_session1.reload
- lesson_session1.sent_counter_reminder.should be_false
+ lesson_session1.sent_counter_reminder_at.should be_nil
Timecop.travel(Date.today + 10)
LessonSession.remind_counters
lesson_session1.reload
- lesson_session1.sent_counter_reminder.should be_true
+ lesson_session1.sent_counter_reminder_at.should_not be_nil
LessonSession.remind_counters
end
@@ -311,36 +312,38 @@ describe LessonSession do
lesson_session1 = normal_lesson(user, teacher, {counter: true, counterer: user})
mailer = mock
- mailer.should_receive(:deliver_now).once
+ mailer.should_receive(:deliver_now).twice
UserMailer.should_receive(:teacher_counter_reminder).and_return(mailer)
+ UserMailer.should_receive(:student_no_comm_other).and_return(mailer)
LessonSession.remind_counters
lesson_session1.reload
- lesson_session1.sent_counter_reminder.should be_false
+ lesson_session1.sent_counter_reminder_at.should be_nil
Timecop.travel(Date.today + 10)
LessonSession.remind_counters
lesson_session1.reload
- lesson_session1.sent_counter_reminder.should be_true
+ lesson_session1.sent_counter_reminder_at.should_not be_nil
end
it "finds old counter and pokes teacher" do
lesson_session1 = normal_lesson(user, teacher, {counter: true, counterer: teacher})
mailer = mock
- mailer.should_receive(:deliver_now).once
+ mailer.should_receive(:deliver_now).twice
UserMailer.should_receive(:student_counter_reminder).and_return(mailer)
+ UserMailer.should_receive(:teacher_no_comm_other).and_return(mailer)
LessonSession.remind_counters
lesson_session1.reload
- lesson_session1.sent_counter_reminder.should be_false
+ lesson_session1.sent_counter_reminder_at.should be_nil
Timecop.travel(Date.today + 10)
LessonSession.remind_counters
lesson_session1.reload
- lesson_session1.sent_counter_reminder.should be_true
+ lesson_session1.sent_counter_reminder_at.should_not be_nil
end
end