示例#1
0
文件: User.cpp 项目: starius/thechess
void User::send_message(UserPtr from, UserPtr to, const Wt::WString& text) {
    if (!to || from == to) {
        return;
    }
    CommentPtr base = to->comment_base();
    if (!base) {
        to.reread();
        base = to.modify()->comment_base();
        base.flush();
    }
    CommentPtr from_base;
    if (from) {
        from_base = from->comment_base();
        if (!from_base) {
            from.reread();
            from_base = from.modify()->comment_base();
            from_base.flush();
        }
    }
    CommentPtr message = to.session()->add(new Comment(true));
    message.modify()->set_text(text);
    message.modify()->set_init(from);
    message.modify()->set_parent(base);
    message.modify()->set_root(base);
    message.modify()->set_type(Comment::PRIVATE_MESSAGE);
    message.flush();
    t_emit_after(COMMENT, base.id());
    t_emit(COMMENT, from_base.id());
    if (from) {
        t_emit(new NewMessage(to.id(), from.id()));
    }
}
示例#2
0
void Footer::refresh() {
    int comment_id = Options::instance()->footer_content_id();
    if (comment_id > 0) {
        dbo::Transaction t(tApp->session());
        try {
            CommentPtr comment = tApp->session().load<Comment>(comment_id,
                                 /* forceReread */ true);
            if (comment->type() == Comment::FORUM_COMMENT ||
                    comment->type() == Comment::FORUM_POST_TEXT) {
                setText(comment->text());
            }
        } catch (...)
        { }
    }
}
示例#3
0
ChatCommentWidget::ChatCommentWidget(const CommentPtr& comment) {
    dbo::Transaction t(tApp->session());
    if (comment->type() != Comment::CHAT_MESSAGE &&
            comment->type() != Comment::PRIVATE_MESSAGE) {
        return;
    }
    if (!comment->can_read_chat_logs(tApp->user())) {
        return;
    }
    new Header(tr("tc.forum.Comment"), this);
    new Wt::WText(forum_comment_text(comment), this);
    UserPtr user = comment->init();
    if (user) {
        new Wt::WBreak(this);
        user_anchor(user, this);
    }
    Wt::WAnchor* a = anchor_to_host(comment);
    if (a) {
        new Wt::WBreak(this);
        addWidget(a);
    }
    add_remover_buttons(comment, this);
    addWidget(new MessageForm(user));
}
示例#4
0
 void add_handler_() {
     Wt::WValidator::State V = Wt::WValidator::Valid;
     if (username_->validate() != V) {
         error_->setText(tr("facts.comment.Incorrect_username"));
         return;
     }
     if (email_->validate() != V) {
         error_->setText(tr("facts.comment.Incorrect_email"));
         return;
     }
     int input_length = text_->text().value().size();
     if (input_length < MIN_INPUT_SIZE || input_length > MAX_TEXT_SIZE) {
         error_->setText(tr("facts.comment.Incorrect_text"));
         return;
     }
     dbo::Transaction t(fApp->session());
     if (fApp->is_banned()) {
         error_->setText(tr("facts.common.BannedIp"));
         return;
     }
     int index;
     if (comments_->fact()->comments().size()) {
         index = 1 + fApp->session()
                 .query<int>("select max(comment_index) from facts_comment where fact_id=?")
                 .bind(comments_->fact().id());
     } else {
         index = 1;
     }
     CommentPtr c = fApp->session().add(new Comment(CommentId(comments_->fact(), index)));
     c.modify()->set_username(username_->text());
     c.modify()->set_email(email_->text().toUTF8());
     c.modify()->set_text(text_->text());
     c.modify()->set_ip(fApp->environment().clientAddress());
     comments_->comment_added_handler_(); // delete this
     t.commit();
 }
示例#5
0
std::string Application::comment_path(const CommentPtr& comment) const {
    return str(comment_path_format_ % comment.id().fact.id() % comment.id().index);
}
示例#6
0
bool VsMagnitude::setComments(Magnitude *mag, const std::string id,
                              const T value) {
    for ( size_t i = 0; i < mag->commentCount(); ++i ) {
        CommentPtr cmnt = mag->comment(i);
        if ( cmnt->id() != id )
            continue;
        cmnt->setText(Core::toString(value));
        try {
            cmnt->creationInfo().setModificationTime(_currentTime);
        } catch ( ... ) {
            CreationInfo ci;
            ci.setModificationTime(_currentTime);
            cmnt->setCreationInfo(ci);

        }
        cmnt->update();
        return true;
    }
    // Create a new one
    CommentPtr cmt = new Comment();
    cmt->setId(id);
    cmt->setText(Core::toString(value));
    CreationInfo ci;
    ci.setCreationTime(_currentTime);
    cmt->setCreationInfo(ci);

    if ( !mag->add(cmt.get()) ) {
        return false;
    }
    return true;
}
示例#7
0
ForumCommentWidget::ForumCommentWidget(const CommentPtr& comment) {
    dbo::Transaction t(tApp->session());
    if (comment->type() != Comment::FORUM_COMMENT) {
        return;
    }
    new Header(tr("tc.forum.Comment"), this);
    Wt::WText* text = new Wt::WText(forum_comment_text(comment), this);
    text->addStyleClass("thechess-forum-comments");
    UserPtr user = comment->init();
    if (user) {
        new Wt::WBreak(this);
        user_anchor(user, this);
    }
    CommentPtr post_text = comment->root();
    CommentPtr post = post_text->parent();
    new Wt::WBreak(this);
    Wt::WAnchor* a = new Wt::WAnchor(this);
    a->setLink(tApp->path().post()->get_link(post.id()));
    a->setText(tr("tc.forum.post_header")
               .arg(post.id()).arg(post->text_or_removed(tApp->user())));
    CommentPtr parent = comment->parent();
    if (parent->type() == Comment::FORUM_COMMENT) {
        new Wt::WBreak(this);
        Wt::WAnchor* g = new Wt::WAnchor(this);
        g->setLink(tApp->path().post_comment()->get_link(parent.id()));
        g->setText(tr("tc.forum.Goto_parent").arg(parent.id()));
    }
    if (comment->can_edit(tApp->user())) {
        new Wt::WBreak(this);
        Wt::WAnchor* e = new Wt::WAnchor(this);
        e->setLink(tApp->path().forum_edit()->get_link(comment.id()));
        e->setText(tr("tc.forum.Edit"));
    }
    Wt::WTextEdit* edit = new Wt::WTextEdit(this);
    patch_text_edit(edit);
    new Wt::WBreak(this);
    if (Comment::can_create(tApp->user(), Comment::FORUM_COMMENT, comment)) {
        Wt::WPushButton* add = new Wt::WPushButton(tr("tc.comment.Add"), this);
        add->clicked().connect(boost::bind(add_comment, comment, edit, this));
    }
    add_remover_buttons(comment, this);
}
示例#8
0
static void add_comment(CommentPtr comment, Wt::WTextEdit* edit,
                        ForumCommentWidget* widget) {
    dbo::Transaction t(tApp->session());
    comment.reread();
    tApp->user().reread();
    Comment::State state = Comment::state_of_new(tApp->user(),
                           Comment::FORUM_COMMENT, comment);
    if (state == Comment::DELETED) {
        return;
    }
    CommentPtr c = tApp->session().add(new Comment(true));
    c.modify()->set_parent(comment);
    c.modify()->set_type(Comment::FORUM_COMMENT);
    c.modify()->set_text(patch_text_edit_text(edit->valueText()));
    c.modify()->set_init(tApp->user());
    c.modify()->set_root(comment->root());
    c.modify()->set_state(state);
    int root_id = comment->root().id();
    CommentPtr post_text = comment->root();
    CommentPtr post = post_text->parent();
    post.reread();
    post.modify()->post_comment_added();
    c.flush();
    // private notification
    Wt::WString notification = "[auto] " + comm_a(c.id());
    User::send_message(tApp->user(), post->init(), notification);
    if (post->init() != comment->init()) {
        User::send_message(tApp->user(), comment->init(), notification);
    }
    t.commit();
    t_emit(COMMENT, root_id);
    if (state == Comment::DRAFT) {
        widget->clear();
        widget->addWidget(new Wt::WText(Wt::WString::tr(
                                            "tc.comment.draft_message")));
    } else {
        tApp->path().post()->set_integer_value(post.id());
        tApp->path().post()->open();
    }
}