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());
}
}
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);
}
});
}
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);
}
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());
}
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());
}
Aggregations