MA-2139: Mark thread as read on thread and comment creation/update/actions

This commit is contained in:
wajeeha-khalid 2016-07-19 17:50:16 +05:00
Родитель b832156039
Коммит 3d506614fe
7 изменённых файлов: 27 добавлений и 6 удалений

Просмотреть файл

@ -77,6 +77,8 @@ post "#{APIPREFIX}/threads/:thread_id/comments" do |thread_id|
error 400, comment.errors.full_messages.to_json
else
user.subscribe(thread) if bool_auto_subscribe
# Mark thread as read for owner user on comment creation
user.mark_as_read(thread)
comment.to_hash.to_json
end
end

Просмотреть файл

@ -42,11 +42,17 @@ post "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
thread.author = user
thread.save
if thread.errors.any?
error 400, thread.errors.full_messages.to_json
else
# Mark thread as read for owner user on creation
user.mark_as_read(thread)
user.subscribe(thread) if bool_auto_subscribe
presenter = ThreadPresenter.factory(thread, nil)
# Initialize ThreadPresenter; if non-null user is passed it also calculates
# user specific data on initialization such as thread "read" status
presenter = ThreadPresenter.factory(thread, user)
thread = presenter.to_hash
thread["resp_total"] = 0
thread.to_json

Просмотреть файл

@ -44,6 +44,8 @@ post "#{APIPREFIX}/comments/:comment_id" do |comment_id|
error 400, comment.errors.full_messages.to_json
else
user.subscribe(comment.comment_thread) if bool_auto_subscribe
# Mark thread as read for owner user on response creation
user.mark_as_read(comment.comment_thread)
sub_comment.to_hash.to_json
end
end

Просмотреть файл

@ -155,7 +155,7 @@ describe 'Comment API' do
end
describe 'POST /api/v1/comments/:comment_id' do
it 'creates a sub comment to the comment' do
it 'creates a sub comment to the comment and marks thread as read for user' do
comment = thread.comments.first
previous_child_count = comment.children.length
user = thread.author
@ -172,6 +172,8 @@ describe 'Comment API' do
sub_comment.course_id.should == course_id
sub_comment.author.should == user
sub_comment.child_count.should == 0
test_thread_marked_as_read(thread.id, user.id)
end
it 'returns 400 when the comment does not exist' do

Просмотреть файл

@ -666,7 +666,6 @@ describe "app" do
thread = CommentThread.first
comment = thread.comments.first
comment.endorsed = true
comment.endorsement = {:user_id => "42", :time => DateTime.now}
comment.save
put "/api/v1/threads/#{thread.id}", body: "new body", title: "new title", commentable_id: "new_commentable_id", thread_type: "question"
last_response.should be_ok
@ -716,7 +715,7 @@ describe "app" do
let :default_params do
{body: "new comment", course_id: "1", user_id: User.first.id}
end
it "create a comment to the comment thread" do
it "creates a comment to the comment thread and marks thread as read for user" do
thread = CommentThread.first
user = User.first
orig_count = thread.comment_count
@ -729,6 +728,8 @@ describe "app" do
comment.should_not be_nil
comment.author_id.should == user.id
retrieved["child_count"].should == 0
test_thread_marked_as_read(thread.id, user.id)
end
it "allows anonymous comment" do
thread = CommentThread.first

Просмотреть файл

@ -125,11 +125,11 @@ describe 'app' do
subject { post "/api/v1/#{commentable_id}/threads", parameters }
shared_examples_for 'CommentThread creation API' do |context='course'|
it 'creates a new CommentThread' do
it 'creates a new CommentThread and marks it as read for owner user' do
expect(CommentThread.count).to eq 0
body = parse(subject.body)
expect(body).to include('read' => false,
expect(body).to include('read' => true,
'unread_comments_count' => 0,
'endorsed' => false,
'resp_total' => 0)

Просмотреть файл

@ -409,3 +409,11 @@ def create_comment_thread_and_comments
thread
end
def test_thread_marked_as_read(thread_id, user_id)
# get thread to assert its "read" status
get "/api/v1/threads/#{thread_id}", user_id: user_id
last_response.should be_ok
retrieved_thread = parse last_response.body
retrieved_thread["read"].should == true
end