File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -360,6 +360,12 @@ def mark_all_read(user_id)
360360 post ( 'channels/read' , data : payload )
361361 end
362362
363+ # Get unread count for a user.
364+ sig { params ( user_id : String ) . returns ( StreamChat ::StreamResponse ) }
365+ def get_unread_count ( user_id )
366+ get ( "/unread" , params : { user_id : user_id } )
367+ end
368+
363369 # Pins a message.
364370 #
365371 # Pinned messages allow users to highlight important messages, make announcements, or temporarily
Original file line number Diff line number Diff line change @@ -546,6 +546,39 @@ def loop_times(times)
546546 end
547547 end
548548
549+ describe 'unread count' do
550+ before ( :all ) do
551+ @user_id = SecureRandom . uuid
552+ @client . update_users ( [ { id : @user_id } ] )
553+ @channel . add_members ( [ @user_id ] )
554+ end
555+
556+ before ( :each ) do
557+ @client . mark_all_read ( @user_id )
558+ end
559+
560+ it 'gets unread count' do
561+ resp = @client . get_unread_count ( @user_id )
562+ expect ( resp [ 'total_unread_count' ] ) . to eq 0
563+ end
564+
565+ it "gets unread count if there are unread messages" do
566+ @channel . send_message ( { text : 'Hello world' } , @random_user [ :id ] )
567+ resp = @client . get_unread_count ( @user_id )
568+ expect ( resp [ 'total_unread_count' ] ) . to eq 1
569+ end
570+
571+ it "gets unread count for a channel" do
572+ @message = @channel . send_message ( { text : 'Hello world' } , @random_user [ :id ] )
573+ resp = @client . get_unread_count ( @user_id )
574+ expect ( resp [ 'total_unread_count' ] ) . to eq 1
575+ expect ( resp [ 'channels' ] . length ) . to eq 1
576+ expect ( resp [ 'channels' ] [ 0 ] [ 'channel_id' ] ) . to eq @channel . cid
577+ expect ( resp [ 'channels' ] [ 0 ] [ 'unread_count' ] ) . to eq 1
578+ expect ( resp [ 'channels' ] [ 0 ] [ 'last_read' ] ) . not_to be_nil
579+ end
580+ end
581+
549582 describe 'blocklist' do
550583 before ( :all ) do
551584 @blocklist = SecureRandom . uuid
You can’t perform that action at this time.
0 commit comments