Class ActivityMcpTool
java.lang.Object
io.meeds.mcp.server.tool.ActivityMcpTool
- All Implemented Interfaces:
io.meeds.mcp.server.plugin.McpToolPlugin
@Service
public class ActivityMcpTool
extends Object
implements io.meeds.mcp.server.plugin.McpToolPlugin
-
Field Summary
Fields inherited from interface io.meeds.mcp.server.plugin.McpToolPlugin
DEFAULT_LIMIT, DEFAULT_OFFSET -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattachImageToActivity(long activityId, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) Attaches an image to an activity the current user may edit.attachImageToComment(long commentId, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) Attaches an image to an activity comment the current user may edit.createActivity(Long spaceId, String htmlContent, String publicationStartTime) Posts an activity as the current user, in a space or in the user's stream.createActivityComment(long activityId, String comment, Long parentCommentId) Posts a comment on an activity as the current user.createActivityCommentWithImage(long activityId, String comment, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) Posts a top-level comment carrying an image, as the current user.createActivityWithImage(Long spaceId, String htmlContent, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) Posts an activity carrying an image, as the current user; when the image can't be attached the post is deleted again.voiddeleteActivity(long activityId) getActivities(Long spaceId, Integer offset, Integer limit) Lists a page of the activities of a space, or of every stream the user sees.getActivitiesSinceDays(Long spaceId, Long days) Lists the activities updated since a number of days, reading the stream newest first, by pages ofMcpToolPlugin.DEFAULT_LIMIT, and stopping at the first page holding none of them or onceMAX_TO_LOADactivities were read.getActivity(long activityId) getActivityAttachments(long activityId) getActivityComment(long activityCommentId) getActivityComments(long activityId, Integer offset, Integer limit) Reads the discussion under an activity as the current user: its top-level comments and the replies threaded under them, in thread order.getActivityLikers(long activityId, Integer offset, Integer limit) getCommentAttachments(long commentId) getScheduledActivities(Long spaceId, Integer offset, Integer limit) Lists the activities the current user has scheduled but not yet published.protected LonggetUserActivityStream(String username, Integer offset, Integer limit) Lists a page of the activity stream of a user, as the current user sees it.voidlikeTheActivity(long activityId) pinActivity(long activityId) Pins an activity to its space stream as the current user.publishScheduledActivityNow(long activityId) Publishes a scheduled activity immediately instead of waiting for its publication time.removeImageFromActivity(long activityId, String fileId) removeImageFromComment(long commentId, String fileId) Searches the activities the current user sees by text, or lists the favorite ones, or, with neither, lists the stream likegetActivities(Long, Integer, Integer).shareActivityToSpace(long activityId, long spaceId) voidunlikeTheActivity(long activityId) unpinActivity(long activityId) Unpins an activity from its space stream as the current user.updateActivity(long activityId, String htmlContent, String publicationStartTime) Changes the text of an activity the current user can edit, or the publication time of one still scheduled.updateComment(long activityCommentId, String comment) Replaces the text of an activity comment, as the current user.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.meeds.mcp.server.plugin.McpToolPlugin
getCurrentUserAclIdentity, getCurrentUserLocale, getCurrentUserLocale, getCurrentUserName, getLocale
-
Constructor Details
-
ActivityMcpTool
public ActivityMcpTool()
-
-
Method Details
-
getActivitiesSinceDays
public ActivityCollectionModel getActivitiesSinceDays(Long spaceId, Long days) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Lists the activities updated since a number of days, reading the stream newest first, by pages ofMcpToolPlugin.DEFAULT_LIMIT, and stopping at the first page holding none of them or onceMAX_TO_LOADactivities were read. When it stops on that bound, it reads the next activity of the stream and sayshas_moreonly when that one exists and is updated since then too. An activity deleted between the listing of its id and its read is skipped, and each activity is read once, so none is listed empty.- Parameters:
spaceId- restrict to one space, or null for every stream the user seesdays- the number of days to look back- Returns:
- the activities updated since then, at most
MAX_TO_LOAD - Throws:
IllegalAccessException- when the user can't view the spaceorg.exoplatform.commons.exception.ObjectNotFoundException- when the space doesn't exist
-
getActivities
public List<ActivitySummaryModel> getActivities(Long spaceId, Integer offset, Integer limit) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Lists a page of the activities of a space, or of every stream the user sees.- Parameters:
spaceId- restrict to one space, or null for every stream the user seesoffset- index of the first activity to retrievelimit- maximum number of activities to retrieve, at mostMcpToolPluginUtils.MAX_LIMIT- Returns:
- the activities, each one with its author and space reduced to what names them
- Throws:
IllegalAccessException- when the user can't view the spaceorg.exoplatform.commons.exception.ObjectNotFoundException- when the space doesn't exist
-
getUserActivityStream
public List<ActivitySummaryModel> getUserActivityStream(String username, Integer offset, Integer limit) throws org.exoplatform.commons.exception.ObjectNotFoundException Lists a page of the activity stream of a user, as the current user sees it.- Parameters:
username- the user whose stream to read, with or without a leading@offset- index of the first activity to retrievelimit- maximum number of activities to retrieve, at mostMcpToolPluginUtils.MAX_LIMIT- Returns:
- the activities, each one with its author and space reduced to what names them
- Throws:
org.exoplatform.commons.exception.ObjectNotFoundException- when the user doesn't exist
-
getActivity
public ActivityModel getActivity(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
getActivityComment
public ActivityCommentModel getActivityComment(long activityCommentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
createActivity
public ActivityModel createActivity(Long spaceId, String htmlContent, String publicationStartTime) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Posts an activity as the current user, in a space or in the user's stream. In a call limited to a space, a post must not name anyone outside that space: every user the text mentions must be a member or a super manager of it.- Parameters:
spaceId- the space to post in, or null for the user's streamhtmlContent- the post, in HTML or MarkdownpublicationStartTime- the scheduled publication time, or null to post now- Returns:
- the posted activity
- Throws:
IllegalAccessException- when the user can't post there, or the text mentions a user outside the space the call is limited toorg.exoplatform.commons.exception.ObjectNotFoundException- when the space doesn't exist
-
createActivityWithImage
public ActivityModel createActivityWithImage(Long spaceId, String htmlContent, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Posts an activity carrying an image, as the current user; when the image can't be attached the post is deleted again. In a call limited to a space, every user the text mentions must be a member or a super manager of that space, checked before the image is staged.- Parameters:
spaceId- the space to post in, or null for the user's streamhtmlContent- the post, in HTML or MarkdownimageUrl- URL of the image, may be nullimageBase64- base64 content of the image, may be nullattachmentObjectType- type of the object an existing attachment is copied from, may be nullattachmentObjectId- identifier of the object an existing attachment is copied from, may be nulluploadId- upload id of an image the current user sent with start_upload, may be null; consumed by the callaltText- alternative text of the image, may be null- Returns:
- the posted activity
- Throws:
IllegalAccessException- when the user can't post there, or the text mentions a user outside the space the call is limited toorg.exoplatform.commons.exception.ObjectNotFoundException- when the space doesn't exist
-
attachImageToActivity
public ActivityModel attachImageToActivity(long activityId, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Attaches an image to an activity the current user may edit.- Parameters:
activityId- identifier of the activityimageUrl- URL of the image, may be nullimageBase64- base64 content of the image, may be nullattachmentObjectType- type of the object an existing attachment is copied from, may be nullattachmentObjectId- identifier of the object an existing attachment is copied from, may be nulluploadId- upload id of an image the current user sent with start_upload, may be null; consumed by the callaltText- alternative text of the image, may be null- Returns:
- the updated activity
- Throws:
IllegalAccessException- when the user can't edit the activity, or read the attachmentorg.exoplatform.commons.exception.ObjectNotFoundException- when the activity, the attachment or the upload doesn't exist
-
getScopeSpaceId
- Returns:
- the space the current call is limited to, null when it isn't
- Throws:
IllegalStateException- when the call's identity can't be read
-
updateActivity
public ActivityModel updateActivity(long activityId, String htmlContent, String publicationStartTime) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Changes the text of an activity the current user can edit, or the publication time of one still scheduled. In a call limited to a space, the new text must not name anyone outside that space: every user it mentions must be a member or a super manager of it.- Parameters:
activityId- the activityhtmlContent- the new text, in HTML or Markdown, or blank to keep itpublicationStartTime- the new publication time of a scheduled activity, or blank to keep it- Returns:
- the updated activity
- Throws:
IllegalAccessException- when the user can't edit the activity, or the new text mentions a user outside the space the call is limited toorg.exoplatform.commons.exception.ObjectNotFoundException- when the activity doesn't exist
-
getScheduledActivities
public List<ActivitySummaryModel> getScheduledActivities(Long spaceId, Integer offset, Integer limit) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Lists the activities the current user has scheduled but not yet published. These are deliberately absent from streams and from search_activities, so this is their only discovery path.- Parameters:
spaceId- restrict to one space, or null for every space the user seesoffset- index of the first activity to retrievelimit- maximum number of activities to retrieve- Returns:
- the list of pending scheduled activities, soonest first
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
publishScheduledActivityNow
public ActivityModel publishScheduledActivityNow(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Publishes a scheduled activity immediately instead of waiting for its publication time. Publication is idempotent on the social side: publishing an already published activity simply returns its current state.- Parameters:
activityId- id of the scheduled activity to publish now- Returns:
- the published activity
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
deleteActivity
public void deleteActivity(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
pinActivity
public ActivityModel pinActivity(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Pins an activity to its space stream as the current user. The activity must be viewable by the user before the pin permission is even evaluated, as the REST layer does.- Parameters:
activityId- identifier of the activity to pin- Returns:
- the activity as stored after the pin, so that the caller reports the post it acted on and its pinned state rather than assuming them
- Throws:
IllegalAccessException- when the activity isn't viewable by the current user or the user can't pin itorg.exoplatform.commons.exception.ObjectNotFoundException- when the activity doesn't exist
-
unpinActivity
public ActivityModel unpinActivity(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Unpins an activity from its space stream as the current user. The activity must be viewable by the user before the pin permission is even evaluated, as the REST layer does.- Parameters:
activityId- identifier of the activity to unpin- Returns:
- the activity as stored after the unpin, so that the caller reports the post it acted on and its pinned state rather than assuming them
- Throws:
IllegalAccessException- when the activity isn't viewable by the current user or the user can't unpin itorg.exoplatform.commons.exception.ObjectNotFoundException- when the activity doesn't exist
-
getActivityComments
public List<ActivityCommentModel> getActivityComments(long activityId, Integer offset, Integer limit) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Reads the discussion under an activity as the current user: its top-level comments and the replies threaded under them, in thread order. Social places every reply right after the comment it answers and the reply carries that comment asparentCommentId, so a flat list keeps the thread structure visible; a top-level comment has noparentCommentId. Social threads one level deep, so a reply is always the child of a top-level comment.offsetandlimitpage the top-level comments only: each page carries the replies of the comments it holds, so the number of rows returned can exceedlimit.- Parameters:
activityId- identifier of the activity (post) whose thread is readoffset- index of the first top-level comment, defaults toMcpToolPlugin.DEFAULT_OFFSETlimit- number of top-level comments per page, defaults toMcpToolPlugin.DEFAULT_LIMIT- Returns:
- the comments of the page with their replies, in thread order
- Throws:
IllegalAccessException- when the current user can't view the activityorg.exoplatform.commons.exception.ObjectNotFoundException- when no activity has that identifier
-
createActivityComment
public ActivityCommentModel createActivityComment(long activityId, String comment, Long parentCommentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Posts a comment on an activity as the current user. With aparentCommentIdthe comment is posted as a threaded reply to that comment, exactly as the "Reply" action of the activity stream does; without one it is a top-level comment, as before this parameter existed. The ACL check is the activity's own view check in both cases: a reply is a comment of the same activity and inherits its visibility, so no second check is needed and none is added. The text is rendered from Markdown to HTML, as a post's is, unless it contains one of the markersMcpToolUtils.markdownToHtml(String)reads as "already HTML" (<p>,<ul>,<li>,<div>,<img). Any other text is rendered as CommonMark, which keeps raw HTML as written and leaves Markdown inside a raw HTML block unrendered. In a call limited to a space, a comment must not name anyone outside that space: every user the rendered comment mentions must be a member or a super manager of it. The mentions are read from the HTML that is saved, as Social reads them, so Markdown around a mention (**@user**) cannot hide it from the check.- Parameters:
activityId- identifier of the activity to comment oncomment- comment text, Markdown or HTMLparentCommentId- identifier of the comment to reply to, or null for a top-level comment- Returns:
- the created comment
- Throws:
IllegalAccessException- when the activity isn't viewable by the current user, or the comment mentions a user outside the space the call is limited toorg.exoplatform.commons.exception.ObjectNotFoundException- when the activity or the parent comment doesn't exist
-
createActivityCommentWithImage
public ActivityCommentModel createActivityCommentWithImage(long activityId, String comment, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Posts a top-level comment carrying an image, as the current user. The comment is created throughcreateActivityComment(long, String, Long)without a parent, then the image is attached to it; when the attachment fails the comment is deleted again so nothing half-posted remains.- Parameters:
activityId- identifier of the activity to comment oncomment- comment text, Markdown or HTMLimageUrl- URL of the image to attach, may be nullimageBase64- base64 content of the image to attach, may be nullattachmentObjectType- type of the object an existing attachment is copied from, may be nullattachmentObjectId- identifier of the object an existing attachment is copied from, may be nulluploadId- upload id of an image the current user sent with start_upload, may be null; consumed by the callaltText- alternative text of the image, may be null- Returns:
- the created comment
- Throws:
IllegalAccessException- when the activity isn't viewable by the current user, or the comment mentions a user outside the space the call is limited to (checked before the image is staged)org.exoplatform.commons.exception.ObjectNotFoundException- when the activity doesn't exist
-
attachImageToComment
public ActivityCommentModel attachImageToComment(long commentId, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String uploadId, String altText) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Attaches an image to an activity comment the current user may edit.- Parameters:
commentId- identifier of the comment, without its "comment" prefiximageUrl- URL of the image, may be nullimageBase64- base64 content of the image, may be nullattachmentObjectType- type of the object an existing attachment is copied from, may be nullattachmentObjectId- identifier of the object an existing attachment is copied from, may be nulluploadId- upload id of an image the current user sent with start_upload, may be null; consumed by the callaltText- alternative text of the image, may be null- Returns:
- the updated comment
- Throws:
IllegalAccessException- when the user can't edit the comment, or read the attachmentorg.exoplatform.commons.exception.ObjectNotFoundException- when the comment, the attachment or the upload doesn't exist
-
getActivityAttachments
public List<AttachmentModel> getActivityAttachments(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
getCommentAttachments
public List<AttachmentModel> getCommentAttachments(long commentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
removeImageFromActivity
public ActivityModel removeImageFromActivity(long activityId, String fileId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
removeImageFromComment
public ActivityCommentModel removeImageFromComment(long commentId, String fileId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
updateComment
public ActivityCommentModel updateComment(long activityCommentId, String comment) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Replaces the text of an activity comment, as the current user. The permission is Social's own edit check for a comment,ActivityManager.isActivityEditable(ExoSocialActivity, Identity), the one its comment update REST endpoint applies: being able to view the comment is not enough, so a reader of the activity cannot rewrite another member's comment, which would keep showing that member as its author. The new text is rendered from Markdown to HTML exactly ascreateActivityComment(long, String, Long)renders it, with the same "already HTML" markers left untouched; the previous text is kept in theoriginal_commenttemplate parameter.- Parameters:
activityCommentId- identifier of the comment to updatecomment- new comment text, Markdown or HTML- Returns:
- the updated comment
- Throws:
IllegalAccessException- when the current user can't edit the commentorg.exoplatform.commons.exception.ObjectNotFoundException- when the comment doesn't exist
-
getActivityLikers
public List<UserModel> getActivityLikers(long activityId, Integer offset, Integer limit) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
likeTheActivity
public void likeTheActivity(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
unlikeTheActivity
public void unlikeTheActivity(long activityId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException - Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
searchActivities
public List<ActivitySummaryModel> searchActivities(String query, Long spaceId, Boolean isFavorite, Integer offset, Integer limit) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Searches the activities the current user sees by text, or lists the favorite ones, or, with neither, lists the stream likegetActivities(Long, Integer, Integer).- Parameters:
query- the text to searchspaceId- restrict to one space, or null for every streamisFavorite- whether to return the favorite activities onlyoffset- index of the first activity to retrievelimit- maximum number of activities to retrieve, at mostMcpToolPluginUtils.MAX_LIMIT- Returns:
- the activities, each one with its author and space reduced to what names them
- Throws:
IllegalAccessException- when the user can't view the spaceorg.exoplatform.commons.exception.ObjectNotFoundException- when the space doesn't exist
-