Commit 302eaf6b by wajeeha-khalid

Merge pull request #152 from edx/jia/MA-1748

jia/MA-1748 update read states for users
parents 2fb3086e ff00ac9c
...@@ -57,8 +57,9 @@ put "#{APIPREFIX}/threads/:thread_id" do |thread_id| ...@@ -57,8 +57,9 @@ put "#{APIPREFIX}/threads/:thread_id" do |thread_id|
filter_blocked_content params["body"] filter_blocked_content params["body"]
thread.update_attributes(params.slice(*%w[title body pinned closed commentable_id group_id thread_type])) thread.update_attributes(params.slice(*%w[title body pinned closed commentable_id group_id thread_type]))
if params["user_id"] and value_to_boolean(params["read"]) # user_id is the owner for a thread, requested_user_id is the user requesting to update said thread
user = User.only([:id, :username, :read_states]).find_by(external_id: params["user_id"]) if params["requested_user_id"] and value_to_boolean(params["read"])
user = User.only([:id, :username, :read_states]).find_by(external_id: params["requested_user_id"])
user.mark_as_read(thread) if user user.mark_as_read(thread) if user
end end
......
...@@ -606,10 +606,24 @@ describe "app" do ...@@ -606,10 +606,24 @@ describe "app" do
comment.endorsement.should == nil comment.endorsement.should == nil
check_unread_thread_result_json(changed_thread, parse(last_response.body)) check_unread_thread_result_json(changed_thread, parse(last_response.body))
end end
it "update information of comment thread and mark thread as read" do it "update information of comment thread and mark thread as read for owner user" do
thread = CommentThread.first
put "/api/v1/threads/#{thread.id}", body: "new body", title: "new title", commentable_id: "new_commentable_id", thread_type: "question", read: true, requested_user_id: thread.author.id
last_response.should be_ok
changed_thread = CommentThread.find(thread.id)
changed_thread.body.should == "new body"
changed_thread.title.should == "new title"
changed_thread.commentable_id.should == "new_commentable_id"
changed_thread.thread_type.should == "question"
user = User.find_by(external_id: thread.author.id)
json_response = parse(last_response.body)
check_thread_result_json(user, changed_thread, json_response)
json_response["read"].should == true
end
it "update information of comment thread and mark thread as read for non-owner user" do
thread = CommentThread.first thread = CommentThread.first
user = create_test_user(42) user = create_test_user(42)
put "/api/v1/threads/#{thread.id}", body: "new body", title: "new title", commentable_id: "new_commentable_id", thread_type: "question", read: true, user_id: user.id put "/api/v1/threads/#{thread.id}", body: "new body", title: "new title", commentable_id: "new_commentable_id", thread_type: "question", read: true, requested_user_id: user.id
last_response.should be_ok last_response.should be_ok
changed_thread = CommentThread.find(thread.id) changed_thread = CommentThread.find(thread.id)
changed_thread.body.should == "new body" changed_thread.body.should == "new body"
......
...@@ -265,7 +265,7 @@ def check_thread_result(user, thread, hash, is_json=false) ...@@ -265,7 +265,7 @@ def check_thread_result(user, thread, hash, is_json=false)
read_date = read_states.first.last_read_times[thread.id.to_s] read_date = read_states.first.last_read_times[thread.id.to_s]
if read_date if read_date
thread.comments.each do |c| thread.comments.each do |c|
if c.author != user and c.updated_at < read_date if c.updated_at < read_date
expected_unread_cnt -= 1 expected_unread_cnt -= 1
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment