Search in sources :

Example 6 with Watcher

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

the class AnswerController method newAnswer.

@Post
@CustomBrutauthRules({ LoggedRule.class, InputRule.class, InactiveQuestionRequiresMoreKarmaRule.class })
public void newAnswer(@Load Question question, MarkedText description, boolean watching, List<Long> attachmentsIds) {
    User current = currentUser.getCurrent();
    boolean canAnswer = answeredByValidator.validate(question);
    boolean isUserWithKarma = current.hasKarma();
    AnswerInformation information = new AnswerInformation(description, currentUser, "new answer");
    Answer answer = new Answer(information, question, current);
    List<Attachment> attachmentsLoaded = attachments.load(attachmentsIds);
    answer.add(attachmentsLoaded);
    if (canAnswer) {
        question.touchedBy(current);
        answers.save(answer);
        ReputationEvent reputationEvent = new ReputationEvent(EventType.CREATED_ANSWER, question, current);
        reputationEvents.save(reputationEvent);
        if (isUserWithKarma) {
            current.increaseKarma(reputationEvent.getKarmaReward());
        }
        result.redirectTo(QuestionController.class).showQuestion(question, question.getSluggedTitle());
        notificationManager.sendEmailsAndInactivate(new EmailAction(answer, question));
        if (watching) {
            watchers.add(question, new Watcher(current));
        }
    } else {
        result.include("answer", answer);
        answeredByValidator.onErrorRedirectTo(QuestionController.class).showQuestion(question, question.getSluggedTitle());
    }
}
Also used : Watcher(org.mamute.model.watch.Watcher) EmailAction(org.mamute.mail.action.EmailAction) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Example 7 with Watcher

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

Example 8 with Watcher

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

the class SubscribeUsersToNewQuestion method subscribeUsers.

public void subscribeUsers(@Observes QuestionCreated questionCreated) {
    Question question = questionCreated.getQuestion();
    List<User> subscribed = users.findUsersSubscribedToAllQuestions();
    for (User user : subscribed) {
        watchers.add(question, new Watcher(user));
    }
    newQuestionMailer.send(subscribed, question);
}
Also used : User(org.mamute.model.User) Watcher(org.mamute.model.watch.Watcher) Question(org.mamute.model.Question)

Example 9 with Watcher

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

the class WatcherDAOTest method should_not_get_innactive_watchers_of_a_question.

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

Example 10 with Watcher

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

the class WatcherDAOTest method should_innactivate_watcher.

@Test
public void should_innactivate_watcher() {
    User subscribedWatcher = user("watcher", "watcher@watcher.com");
    session.save(subscribedWatcher);
    Watcher watch = new Watcher(subscribedWatcher);
    watch.inactivate();
    watchers.add(question, watch);
    watchers.ping(question, subscribedWatcher);
    assertTrue(watch.isActive());
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) Watcher(org.mamute.model.watch.Watcher) Test(org.junit.Test)

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