add unread conversation count api endpoint

fixes CNVS-5780

test plan
- ensure that /api/v1/conversations/unread_count correctly reports
 a user's unread conversation message count

Change-Id: I9999b5c43b249c1db1ca003d84b1e06c7ac9e434
Reviewed-on: https://gerrit.instructure.com/20769
Reviewed-by: Jon Willesen <jonw@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Adam Phillipps <adam@instructure.com>
Product-Review: Joel Hough <joel@instructure.com>
This commit is contained in:
Joel Hough 2013-05-20 14:43:22 -06:00
parent 42888839b1
commit 008df729be
3 changed files with 19 additions and 0 deletions

View File

@ -604,6 +604,15 @@ class ConversationsController < ApplicationController
# Deprecated, see the {api:SearchController#recipients Find recipients endpoint} in the Search API
def find_recipients; end
# @API Unread count
# Get the number of unread conversations for the current user
#
# @example_response
# {'unread_count': '7'}
def unread_count
render(:json => {'unread_count' => @current_user.unread_conversations_count.to_json})
end
def public_feed
return unless get_feed_context(:only => [:user])
@current_user = @context

View File

@ -927,6 +927,7 @@ ActionController::Routing::Routes.draw do |map|
conversations.post 'conversations', :action => :create
conversations.post 'conversations/mark_all_as_read', :action => :mark_all_as_read
conversations.get 'conversations/batches', :action => :batches, :path_name => 'conversations_batches'
conversations.get 'conversations/unread_count', :action => :unread_count
conversations.get 'conversations/:id', :action => :show
conversations.put 'conversations/:id', :action => :update # stars, subscribed-ness, workflow_state
conversations.delete 'conversations/:id', :action => :destroy

View File

@ -1469,4 +1469,13 @@ describe ConversationsController, :type => :integration do
end
end
describe 'unread_count' do
it 'should return the number of unread conversations for the current user' do
conversation(student_in_course, :workflow_state => 'unread')
json = api_call(:get, '/api/v1/conversations/unread_count.json',
{:controller => 'conversations', :action => 'unread_count', :format => 'json'})
json.should eql({'unread_count' => '1'})
end
end
end