Implementing Auto-Watch
Developers perform this task.
Auto-watch is a feature that automatically adds a user as a watcher after performing an action on that item. For example, if a user posts a comment to an article's conversation, that user can automatically become a watcher on that article.
You implement auto-watch in actions by recasting the passed item as a Record
and then calling the sendMessage
method. The following snippet is an example taken from the ConversationWidget
class.
private static boolean processForm(ToolPageContext page, Recordable content) throws Exception { post.save(); 1 Record record = (Record) content; 2 record.sendMessage("watch.autoAdd", page.getUser()); 3 /* Return true or false */ }
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.