use of org.mamute.model.interfaces.Watchable in project mamute by caelum.
the class WatchController method watch.
@Post
@CustomBrutauthRules(LoggedRule.class)
public void watch(Long watchableId, String type) {
Watchable watchable = watchers.findWatchable(watchableId, mapping.getClassFor(type));
User user = currentUser.getCurrent();
Watcher watcher = new Watcher(user);
watchers.addOrRemove(watchable, watcher);
result.nothing();
}
use of org.mamute.model.interfaces.Watchable in project mamute by caelum.
the class CommentController method comment.
@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.CREATE_COMMENT)
@CustomBrutauthRules({ InputRule.class, InactiveQuestionRequiresMoreKarmaRule.class })
@Post
public void comment(Long id, String onWhat, MarkedText comment, boolean watching) {
User current = currentUser.getCurrent();
Comment newComment = new Comment(current, comment);
Class<?> type = getType(onWhat);
validator.validate(newComment);
validator.onErrorUse(Results.http()).setStatusCode(400);
org.mamute.model.Post commentable = comments.loadCommentable(type, id);
commentable.add(newComment);
comments.save(newComment);
Watchable watchable = commentable.getMainThread();
notificationManager.sendEmailsAndInactivate(new EmailAction(newComment, commentable));
if (watching) {
watchers.add(watchable, new Watcher(current));
} else {
watchers.removeIfWatching(watchable, new Watcher(current));
}
result.include("post", commentable);
result.include("type", onWhat);
result.forwardTo(BrutalTemplatesController.class).comment(newComment);
}
use of org.mamute.model.interfaces.Watchable in project mamute by caelum.
the class NotificationManager method sendEmailsAndInactivate.
public void sendEmailsAndInactivate(EmailAction emailAction) {
Watchable watchable = emailAction.getMainThread();
List<Watcher> watchList = watchers.of(watchable);
final List<NotificationMail> mails = buildMails(emailAction, watchList);
afterTransaction.execute(new Runnable() {
@Override
public void run() {
NotificationManager.this.sendMailsAsynchronously(mails);
}
});
}
Aggregations