From 7fa0ff96631ec02208c29f6510f7ac45f0a3b56f Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Mon, 29 Aug 2011 13:48:45 -0600 Subject: [PATCH] conversations are teacher interactions, fixes #5437 Change-Id: I03aebdee626ae8300acf0973a97d0ba69f5098f5 Reviewed-on: https://gerrit.instructure.com/5326 Reviewed-by: Cody Cutrer Tested-by: Hudson --- app/controllers/users_controller.rb | 9 +++++++++ spec/integration/users_controller_spec.rb | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e86c6e0d768..5817812b384 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -835,6 +835,15 @@ class UsersController < ApplicationController next unless student = data[user_id] student[:last_interaction] = [student[:last_interaction], date].compact.max end + last_message_dates = ConversationMessage.maximum( + :created_at, + :joins => 'INNER JOIN conversation_participants ON conversation_participants.conversation_id=conversation_messages.conversation_id', + :group => ['conversation_participants.user_id', 'conversation_messages.author_id'], + :conditions => [ 'conversation_messages.author_id = ? AND conversation_participants.user_id IN (?) AND NOT conversation_messages.generated', teacher.id, ids ]) + last_message_dates.each do |key, date| + next unless student = data[key.first.to_i] + student[:last_interaction] = [student[:last_interaction], date].compact.max + end # find all ungraded submissions in one query ungraded_submissions = course.submissions.all( diff --git a/spec/integration/users_controller_spec.rb b/spec/integration/users_controller_spec.rb index 2dd93f46081..e12f1929fff 100644 --- a/spec/integration/users_controller_spec.rb +++ b/spec/integration/users_controller_spec.rb @@ -34,6 +34,17 @@ describe UsersController do @e2.update_attribute(:course_section, @s2) end + it "should count conversations as interaction" do + get user_student_teacher_activity_url(@teacher, @e1.user) + Nokogiri::HTML(response.body).at_css('table.report tr:first td:nth(2)').text.should match(/never/) + + @conversation = Conversation.initiate([@e1.user_id, @teacher.id], false) + @conversation.add_message(@teacher, "hello") + + get user_student_teacher_activity_url(@teacher, @e1.user) + Nokogiri::HTML(response.body).at_css('table.report tr:first td:nth(2)').text.should match(/less than 1 day/) + end + it "should only include students the teacher can view" do get user_course_teacher_activity_url(@teacher, @course) response.should be_success