Forum Discussion

mfeltscher's avatar
10 years ago

REST API call to mark notification as read

Hi

 

We are currently fetching the user notification feed from the API using

/restapi/vc/users/id/{userid}/notifications

 

I am now looking for a way to mark a notification as read using the REST API. This means, the result of the request mentioned above should also contain a "read" flag. Since I'm not entirely sure, how this is handled by Lithium internally, I don't even know, if this is possible somehow. Could you please let me know, how this works in the built-in component displaying the notifications?

 

 

Thanks

Moreno

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi mfeltscher 

     

    I don't think there is an API available to mark a notification as 'read' right now. As there isn't a similar functionality in the UI, I am assuming that the REST call is something which could be introduced as a future improvement, if it is seen as a need by a significant group. What I suggest is to have a look on our Idea board and add a new idea about this - or add the suggestion to this existing idea which is hinting to similar features.

     

    Cheers,

    • mfeltscher's avatar
      mfeltscher
      Expert

      PaoloT As far as I can see there is a similar functionality in the frontend. First, I see the unread notification count and second, if I go to the notification page, I see which notifications got read and which are unread. How is this handled internally?

       

      Moreno

      • PaoloT's avatar
        PaoloT
        Lithium Alumni (Retired)

        Hi mfeltscher 

         

        I wouldn't be able to illustrate the inner workings of the platform, this would be more a question for our engineering department. Even so, I am not sure they would be sharing internal platform implementation details, unless they form part of a standard platform customization point.

         

        I understand what you say, however there is no explicit feature in the UI that allows a user to mark a notification read or unread. Also, the REST API does not currently offer a call to retrieve unread notifications (the question was also asked here).

         

        Kind Regards,

         

         

  • HI mfeltscher 

     

    As per my knowledge its not possible to set user notification using rest api but it can be achiveable using jquery. I have done the same part. i.e. facebook shows notification on top of the page. I achived it using jquery. Following is the code. Hope it may help you:

     

    ;( function( $, undefined )
    {
        $.fn.UserNotifications = function()
        {
            var $item   = $( '#user-notifications-menu-top' )
              , $list   = $item.find( '#notification-list' )
              , unread  = parseInt( $item.find( '.user-navigation-combine-notification-feed .lia-header-nav-component-unread-count' ).text() )
              , pageURL = $item.find( '.user-navigation-combine-notification-feed .lia-link-navigation' ).attr( 'href' );

            $item.find( '#alerts-count' ).text( unread );
            $item.find( '#notifications-page-link' ).attr( 'href', pageURL );
        
            if( unread > 0 )
            {
                $item.addClass( 'new-notifications' );
                $list.find( 'li:lt( ' + unread + ' )' ).addClass( 'unread' );
            }
            else
            {
                $item.addClass( 'no-new-notifications' );
            }
        };

    } )( jQuery );

     

    Note: Also you need to make some css per code.

    • mfeltscher's avatar
      mfeltscher
      Expert

      Hi bhupen 

       

      Thank you for your reply. Since we want to use the notification count in a third party software we cannot solve this by using Frontend technologies such as Javascript / jQuery.

       

       

      Thanks anyway for sharing your code

      Moreno

      • bhupen's avatar
        bhupen
        Advisor

        mfeltscher  I think you want when some one rank/like/mention/reply/ on your post then notification will comeup as unread. Once you click on view all notification the it will convert into read. Thats what exactly this code does. I don't think lithium provide third party api etc.. Hope this will help you.. also there is api for notification count

        restapi/vc/users/id/youruserid/notifications/count