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