Search in sources :

Example 1 with Watchable

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();
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) Watchable(org.mamute.model.interfaces.Watchable) Watcher(org.mamute.model.watch.Watcher) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Example 2 with Watchable

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);
}
Also used : Watchable(org.mamute.model.interfaces.Watchable) Watcher(org.mamute.model.watch.Watcher) org.mamute.model(org.mamute.model) EmailAction(org.mamute.mail.action.EmailAction) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 3 with Watchable

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);
        }
    });
}
Also used : Watchable(org.mamute.model.interfaces.Watchable) Watcher(org.mamute.model.watch.Watcher)

Aggregations

Watchable (org.mamute.model.interfaces.Watchable)3 Watcher (org.mamute.model.watch.Watcher)3 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)2 Post (br.com.caelum.vraptor.Post)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 EmailAction (org.mamute.mail.action.EmailAction)1 org.mamute.model (org.mamute.model)1 LoggedUser (org.mamute.model.LoggedUser)1 User (org.mamute.model.User)1