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.ScriptService
Script service for manipulating Like informations.
- Since:
- 12.7RC1
- Version:
- $Id: 57644d90838603a88197a6f698a0582febdf4d0c $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncountUserLikes
(UserReference userReference) Count the number of likes performed by the given user.boolean
displayButton
(EntityReference entityReference) Check if the display button should be displayed: should betrue
if 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()
).getLikers
(EntityReference target, int offset, int limit) Return the likers of a reference.getLikes
(EntityReference entityReference) Retrieve like information for the given reference.getUserLikes
(UserReference userReference, int offset, int limit) Retrieve likes performed by the given user.boolean
isAuthorized
(EntityReference entityReference) Check if current user is allowed to use Like on the given reference.boolean
boolean
isLiked
(EntityReference entityReference) Determine if the current user already liked the given reference.like
(EntityReference entityReference) Perform a like on the given reference with the current user, only if allowed.unlike
(EntityReference entityReference) Perform a unlike on the given reference with the current user, only if allowed.
-
Constructor Details
-
LikeScriptService
public LikeScriptService()
-
-
Method Details
-
isAuthorized
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.
-
displayButton
Check if the display button should be displayed: should betrue
if 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:
true
only if the button should be displayed.
-
isEnabled
public boolean isEnabled()- Returns:
true
if the Like feature is enabled.- Since:
- 13.1RC1
-
like
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
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
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
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
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
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
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
-