CommentsContainerWidget::CommentsContainerWidget(string videoId, Session* session, WContainerWidget* parent)
  : WContainerWidget(parent), d(videoId, session)
{
  string querysql = "select content,last_updated,\
      auth_info.email as email,\
    auth_identity.identity as identity\
    from comment\
    inner join auth_info on comment.user_id = auth_info.user_id\
    inner join auth_identity on auth_info.id = auth_identity.auth_info_id\
  ";
  wApp->log("notice") << "comments query: " << querysql;
  auto query = d->session->query<CommentTuple>(querysql);
  query.where("media_id = ?").bind(videoId);
  query.where("auth_identity.provider = 'loginname'");
  query.orderBy("last_updated DESC");
  addWidget(WW<WText>(wtr("comments.label")).css("label").setInline(false));
  
  WTextArea* newCommentContent = new WTextArea();
  newCommentContent->setRows(3);
  newCommentContent->setInline(false);
  WPushButton* insertComment = WW<WPushButton>(wtr("comments.addcomment.button")).css("btn btn-primary btn-sm").onClick([=](WMouseEvent){
    if(newCommentContent->text().empty())
      return;
    Comment *comment = new Comment(videoId, d->session->user(), newCommentContent->text().toUTF8());
    Dbo::Transaction t(*d->session);
    Dbo::ptr< Comment > newComment = d->session->add(comment);
    t.commit();
    newCommentContent->setText("");
    commentViewers.commentAdded(videoId, newComment.id());
  });
  newCommentContent->keyWentUp().connect([=](WKeyEvent){
    insertComment->setEnabled(!newCommentContent->text().empty());
  });
  insertComment->setEnabled(false);
  
//     newCommentContent->setWidth(500);
  newCommentContent->addStyleClass("col-md-8");

  addWidget(WW<WContainerWidget>().css("add-comment-box row").add(newCommentContent).add(insertComment).setContentAlignment(AlignCenter));
  
  addWidget(d->commentsContainer = WW<WContainerWidget>().css("container") );

  Dbo::Transaction t(*d->session);
  for(CommentTuple comment : query.resultList())
    d->commentsContainer->addWidget(new CommentView(comment) );
  
  auto commentAdded = [=] (string commentVideoId, long commentId) {
    if(commentVideoId != videoId) return;
    Dbo::Transaction t(*d->session);
    auto query = d->session->query<CommentTuple>(querysql).where("comment.id = ?").bind(commentId);
    query.where("auth_identity.provider = 'loginname'");
    d->commentsContainer->insertWidget(0, new CommentView(query.resultValue()));
    d->commentsContainer->refresh();
    wApp->triggerUpdate();
  };
  
  commentViewers.addClient(wApp->sessionId(), commentAdded);
}
Esempio n. 2
0
	bool operator==(const hCompositeId& other) const
	{
		return name==other.name && parent.id()==other.parent.id() ;
	}