Skip to main content

Implementing Auto-Watch

Auto-watch is a feature that automatically adds a user as a watcher after performing an action on that asset. For example, if an editor posts a comment to an article's conversation, that editor can automatically become a watcher on that article.

showLineNumbers {3,5,6}
1
private static boolean processForm(ToolPageContext page, Recordable content) throws Exception {
2
3
post.save();
4
5
Record record = (Record) content;
6
record.sendMessage("watch.autoAdd", page.getUser());
7
8
/* Return true or false */
9
}
  • 3. Commits the post associated with the content to the database.
  • 5. Instantiates a record variable based on the passed content.
  • 6. Establishes a watch on the passed content for the user who posted the conversation.

The first parameter for the sendMessage method is one of the following:

  • watch.autoAdd—Adds the user unless the user previously removed the watch.
  • watch.manualAdd—Adds the user regardless if user previously removed the watch.
  • watch.autoRemove—Removes the user unless the user manually created a watch.
  • watch.manualRemove—Adds a user regardless if user previously created a watch.