Forum Discussion

mfeltscher's avatar
11 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

10 Replies

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    11 years ago

    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
    11 years ago

    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)
    11 years ago

    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,

     

     

  • mfeltscher's avatar
    mfeltscher
    Expert
    11 years ago

    Hi PaoloT 

     

    Could you please get in touch with the engineering department to get some more information on how this is done by Lithium?

     

     

    Thanks,

    Moreno

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    11 years ago

    Hi mfeltscher 

     

    For this type of request, I suggest you get in touch with our Support department - however, as I have mentioned I am not sure whether internal implementation details will be shared externally.

     

    Kind Regards,

     

  • cblown's avatar
    cblown
    Boss
    11 years ago

    Just a question on this topic.

     

    Wouldn't it make sense for Lithium Engineering to build out a full API for Notifications first and then simply build the out-of-the-box component via this API rather than directly coding them? What is the reasoning here, other than it being much faster to program? 

     

    Custom Components and OOTB components should be 1:1. 

     

    Looking at this idea here -- http://community.lithium.com/t5/Product-ideas/quot-API-first-quot-development/idi-p/79260 it supposed to be partially delivered - and V2 looks to be going in this direction.. albeit slowly.

     

    As a principle this idea has huge merit, Lithium should be sitting up and taking note of just how many users are getting "not via the API" responses here in the Community.

     

    Thanks

  • 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
    11 years ago

    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
    11 years ago

    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

  • mfeltscher's avatar
    mfeltscher
    Expert
    11 years ago

    Yes this is what I want but I want to expose this information in another application, therefore I need to be able to access this information using Lithium's REST API. I hope Lithium will offer this functionality at some point, since it is already possible in the frontend. As cblown mentioned it would be a good approach regarding consistency to implement new functionality in the API first and afterwards develop the frontend parts.