示例#1
0
  public void delete(boolean removeFromParent) {
    AjaxServlet.invalidateFrontPageCache(getGroup().getId());
    if (parent == null) {
      // we're a toplevel post

      if (getWhiteboard() == null) {
        Iterator<PostModel> it = replies.iterator();
        while (it.hasNext()) {
          PostModel reply = it.next();
          reply.delete(false);
          it.remove();
          reply.setParent(null);
        }
      } else {
        getWhiteboard().delete();
      }
    } else {
      // we're a reply
      subject = "reply";
      intro = "parent's subject was: " + parent.getSubject();

      Calendar lReply = GregorianCalendar.getInstance();
      Calendar rCal = GregorianCalendar.getInstance();
      lReply.setTime(parent.getDate());

      for (PostModel r : parent.getReplies()) {
        rCal.setTime(r.getDate());
        if (!r.getGroup().equals(Helpers.getGroup("DeletedPosts"))
            && lReply.before(rCal)
            && !r.equals(this)) {
          lReply.setTime(r.getDate());
        }
      }

      parent.setLastReply(lReply.getTime());
      if (removeFromParent) {
        parent.getReplies().remove(this);
        parent = null;
      }
    }

    subject = "*deleted* " + subject;
    intro =
        "deleted "
            + (new Date()).toString()
            + ", original group was: "
            + group.getName()
            + "\n- - -\n"
            + intro;
    this.group = Helpers.getGroup("DeletedPosts");
    getSearchable().delete();
  }
示例#2
0
  public void sendAsWatchListEmail(String sender, List<String> emailsForReplies) throws Exception {
    String htmlMessage = doTemplateMerge(this, "emails/post.html.vm");
    String textMessage = doTemplateMerge(this, "emails/post.txt.vm");

    String shortname = Helpers.getEnShortName() + "-watchlist";
    String fullSubject = "Re: [" + shortname + "] " + parent.getSubject();

    EmailModel.sendEmail(
        sender, emailsForReplies, fullSubject, textMessage, htmlMessage, shortname, false);
  }
示例#3
0
  public PostModel reply(UserModel currentUser, String body, String tags) {
    if (!hasActiveWhiteboard()) {
      Session hibernateSession = HibernateUtil.currentSession();
      PostModel p = new PostModel();
      hibernateSession.save(p);
      AjaxServlet.invalidateFrontPageCache(getGroup().getId());

      p.setBody(body);
      addReply(p); // sets group on reply

      Logger.getLogger(this.getClass())
          .info("Post " + this.getId() + " has " + this.getReplies().size() + " replies.");

      if (this.getReplies().size() == Post.RepliesToFeature) {
        this.feature();
      }

      if (this.isFeatured()) {
        p.feature();
      }

      for (String tag : TagLogic.extractTagNames(tags)) {
        addTag(TagModel.getOrCreateTag(tag));
      }

      currentUser.addPost(p);

      setLastReply(new Date());

      hibernateSession.flush();
      Helpers.currentDailyStats().logReply();

      p.setSearchable(SearchableModel.newSearchable(p, null, null));

      return p;
    } else {
      Logger.getLogger(this.getClass()).debug("Tried to reply to a post that has a whiteboard.");
      return null;
    }
  }
示例#4
0
  public static PostModel newPost(
      UserModel currentUser,
      GroupModel targetGroup,
      String subject,
      String intro,
      String body,
      String unsplitTags,
      boolean whiteboard) {
    Session hibernateSession = HibernateUtil.currentSession();
    PostModel p = new PostModel();
    hibernateSession.save(p);
    AjaxServlet.invalidateFrontPageCache(targetGroup.getId());

    p.setSubject(subject);
    p.setIntro(intro);

    if (!body.trim().equals("")) {
      p.setBody(body);
    }

    targetGroup.addPost(p);

    for (String tag : TagLogic.extractTagNames(unsplitTags)) {
      p.addTag(TagModel.getOrCreateTag(tag));
    }

    currentUser.addPost(p);

    hibernateSession.flush();

    if (whiteboard) {
      p.setWhiteboard(WhiteboardModel.newWhiteboard(null, p, null));
    }
    Helpers.currentDailyStats().logPost();

    p.setSearchable(SearchableModel.newSearchable(p, null, null));

    return p;
  }