Search in sources :

Example 1 with Watcher

use of org.mamute.model.watch.Watcher in project mamute by caelum.

the class QuestionController method newQuestion.

@Post
@CustomBrutauthRules({ LoggedRule.class, InputRule.class })
public void newQuestion(String title, MarkedText description, String tagNames, boolean watching, List<Long> attachmentsIds) {
    List<Attachment> attachments = this.attachments.load(attachmentsIds);
    attachmentsValidator.validate(attachments);
    List<String> splitedTags = splitter.splitTags(tagNames);
    List<Tag> foundTags = tagsManager.findOrCreate(splitedTags);
    validate(foundTags, splitedTags);
    QuestionInformation information = new QuestionInformation(title, description, currentUser, foundTags, "new question");
    brutalValidator.validate(information);
    User author = currentUser.getCurrent();
    Question question = new Question(information, author);
    result.include("question", question);
    validator.onErrorUse(Results.page()).of(this.getClass()).questionForm();
    questions.save(question);
    index.indexQuestion(question);
    question.add(attachments);
    ReputationEvent reputationEvent = new ReputationEvent(EventType.CREATED_QUESTION, question, author);
    author.increaseKarma(reputationEvent.getKarmaReward());
    reputationEvents.save(reputationEvent);
    if (watching) {
        watchers.add(question, new Watcher(author));
    }
    questionCreated.fire(new QuestionCreated(question));
    result.include("mamuteMessages", asList(messageFactory.build("alert", "question.quality_reminder")));
    result.redirectTo(this).showQuestion(question, question.getSluggedTitle());
}
Also used : Watcher(org.mamute.model.watch.Watcher) QuestionCreated(org.mamute.event.QuestionCreated) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Example 2 with Watcher

use of org.mamute.model.watch.Watcher in project mamute by caelum.

the class WatcherDAOTest method should_get_subscribed_users_of_a_question.

@Test
public void should_get_subscribed_users_of_a_question() {
    User subscribedWatcher = user("watcher", "watcher@watcher.com");
    session.save(subscribedWatcher);
    watchers.add(question, new Watcher(subscribedWatcher));
    assertThat(watchers.of(question), not(empty()));
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) Watcher(org.mamute.model.watch.Watcher) Test(org.junit.Test)

Example 3 with Watcher

use of org.mamute.model.watch.Watcher in project mamute by caelum.

the class NotificationManager method buildMails.

private List<NotificationMail> buildMails(EmailAction emailAction, List<Watcher> watchList) {
    List<NotificationMail> mails = new ArrayList<NotificationMail>();
    for (Watcher watcher : watchList) {
        boolean sameAuthor = watcher.getWatcher().getId().equals(emailAction.getWhat().getAuthor().getId());
        if (!sameAuthor) {
            mails.add(new NotificationMail(emailAction, watcher.getWatcher()));
            watcher.inactivate();
        }
    }
    return mails;
}
Also used : ArrayList(java.util.ArrayList) Watcher(org.mamute.model.watch.Watcher)

Example 4 with Watcher

use of org.mamute.model.watch.Watcher 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 5 with Watcher

use of org.mamute.model.watch.Watcher 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)

Aggregations

Watcher (org.mamute.model.watch.Watcher)10 User (org.mamute.model.User)5 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)4 Post (br.com.caelum.vraptor.Post)4 LoggedUser (org.mamute.model.LoggedUser)4 Test (org.junit.Test)3 Watchable (org.mamute.model.interfaces.Watchable)3 EmailAction (org.mamute.mail.action.EmailAction)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 ArrayList (java.util.ArrayList)1 QuestionCreated (org.mamute.event.QuestionCreated)1 org.mamute.model (org.mamute.model)1 Question (org.mamute.model.Question)1