Class LikeScriptService

  • All Implemented Interfaces:
    org.xwiki.script.service.ScriptService

    @Component
    @Singleton
    @Named("like")
    public class LikeScriptService
    extends Object
    implements org.xwiki.script.service.ScriptService
    Script service for manipulating Like informations.
    Since:
    12.7RC1
    Version:
    $Id: 57644d90838603a88197a6f698a0582febdf4d0c $
    • Constructor Detail

      • LikeScriptService

        public LikeScriptService()
    • Method Detail

      • isAuthorized

        public boolean isAuthorized​(EntityReference entityReference)
        Check if current user is allowed to use Like on the given reference. Note that we explicitely deny the right for guests.
        Parameters:
        entityReference - the reference on which to use like.
        Returns:
        true only if current user is not guest and has Like right on the reference.
      • isEnabled

        public boolean isEnabled()
        Returns:
        true if the Like feature is enabled.
        Since:
        13.1RC1
      • like

        public Optional<Long> like​(EntityReference entityReference)
        Perform a like on the given reference with the current user, only if allowed.
        Parameters:
        entityReference - the reference on which to perform a like.
        Returns:
        the new number of likes if the operation succeeded, else return an empty optional.
      • unlike

        public Optional<Long> unlike​(EntityReference entityReference)
        Perform a unlike on the given reference with the current user, only if allowed.
        Parameters:
        entityReference - the reference on which to perform a like.
        Returns:
        the new number of likes if the operation succeeded, else return an empty optional.
      • getLikes

        public Optional<Long> getLikes​(EntityReference entityReference)
        Retrieve like information for the given reference.
        Parameters:
        entityReference - the reference for which to retrieve like information.
        Returns:
        the number of likes, or an empty optional in case of problem.
      • getUserLikes

        public List<EntityReference> getUserLikes​(UserReference userReference,
                                                  int offset,
                                                  int limit)
        Retrieve likes performed by the given user.
        Parameters:
        userReference - the user for whom to retrieve likes.
        offset - the offset used for pagination.
        limit - the limit used for pagination.
        Returns:
        a list of liked references.
      • countUserLikes

        public Optional<Long> countUserLikes​(UserReference userReference)
        Count the number of likes performed by the given user.
        Parameters:
        userReference - the user for whom to count likes.
        Returns:
        the number of likes performed.
        Since:
        12.9RC1
      • isLiked

        public boolean isLiked​(EntityReference entityReference)
        Determine if the current user already liked the given reference.
        Parameters:
        entityReference - the reference for which to check if the current liked it or not already.
        Returns:
        true if the entity has been already liked.
      • getLikers

        public List<UserReference> getLikers​(EntityReference target,
                                             int offset,
                                             int limit)
        Return the likers of a reference.
        Parameters:
        target - the reference being liked.
        offset - the start offset for pagination.
        limit - the limit of results for pagination.
        Returns:
        a list of user references who liked the reference.
        Since:
        12.8RC1