Package org.xwiki.like.script
Class LikeScriptService
- java.lang.Object
-
- org.xwiki.like.script.LikeScriptService
-
- All Implemented Interfaces:
org.xwiki.script.service.ScriptService
@Component @Singleton @Named("like") public class LikeScriptService extends Object implements org.xwiki.script.service.ScriptServiceScript service for manipulating Like informations.- Since:
- 12.7RC1
- Version:
- $Id: 57644d90838603a88197a6f698a0582febdf4d0c $
-
-
Constructor Summary
Constructors Constructor Description LikeScriptService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<Long>countUserLikes(UserReference userReference)Count the number of likes performed by the given user.booleandisplayButton(EntityReference entityReference)Check if the display button should be displayed: should betrueif the like feature is enabled (seeLikeConfiguration.isEnabled()) and if current user is authorized to use like (seeisAuthorized(EntityReference)) or if the configuration is set to always display it (seeLikeConfiguration.alwaysDisplayButton()).List<UserReference>getLikers(EntityReference target, int offset, int limit)Return the likers of a reference.Optional<Long>getLikes(EntityReference entityReference)Retrieve like information for the given reference.List<EntityReference>getUserLikes(UserReference userReference, int offset, int limit)Retrieve likes performed by the given user.booleanisAuthorized(EntityReference entityReference)Check if current user is allowed to use Like on the given reference.booleanisEnabled()booleanisLiked(EntityReference entityReference)Determine if the current user already liked the given reference.Optional<Long>like(EntityReference entityReference)Perform a like on the given reference with the current user, only if allowed.Optional<Long>unlike(EntityReference entityReference)Perform a unlike on the given reference with the current user, only if allowed.
-
-
-
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:
trueonly if current user is not guest and has Like right on the reference.
-
displayButton
public boolean displayButton(EntityReference entityReference)
Check if the display button should be displayed: should betrueif the like feature is enabled (seeLikeConfiguration.isEnabled()) and if current user is authorized to use like (seeisAuthorized(EntityReference)) or if the configuration is set to always display it (seeLikeConfiguration.alwaysDisplayButton()).- Parameters:
entityReference- the reference for which to display the button- Returns:
trueonly if the button should be displayed.
-
isEnabled
public boolean isEnabled()
- Returns:
trueif 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:
trueif 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
-
-