diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index f2be8faa233..105f75cc023 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 1ae4b004e5d..b0101ed4d18 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/apis/v1/conversations_api_spec.rb b/spec/apis/v1/conversations_api_spec.rb index accc29dd536..957e43159b3 100644 --- a/spec/apis/v1/conversations_api_spec.rb +++ b/spec/apis/v1/conversations_api_spec.rb @@ -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