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.
1private static boolean processForm(ToolPageContext page, Recordable content) throws Exception {23①post.save();45②Record record = (Record) content;6③record.sendMessage("watch.autoAdd", page.getUser());78/* Return true or false */9}
- ①Commits the post associated with the
contentto the database. - ②Instantiates a
recordvariable based on the passedcontent. - ③Establishes a watch on the passed
contentfor 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.