simplified the code in feeds GxsForumItem, making sure that group msg and parent msg data are all loaded correctly (avoids blank feed items)

This commit is contained in:
csoler 2021-02-25 17:52:43 +01:00
parent 2cdad9ea66
commit f4bc964ac5
2 changed files with 87 additions and 111 deletions

View File

@ -125,16 +125,6 @@ void GxsForumMsgItem::setup()
ui->parentFrame->hide();
}
bool GxsForumMsgItem::isTop()
{
// if (mMessage.mMeta.mMsgId == mMessage.mMeta.mThreadId || mMessage.mMeta.mThreadId.isNull()) {
if (mMessage.mMeta.mParentId.isNull()) {
return true;
}
return false;
}
bool GxsForumMsgItem::setGroup(const RsGxsForumGroup &group, bool doFill)
{
if (groupId() != group.mMeta.mGroupId) {
@ -145,9 +135,8 @@ bool GxsForumMsgItem::setGroup(const RsGxsForumGroup &group, bool doFill)
mGroup = group;
if (doFill) {
fill();
}
if (doFill)
fillGroup();
return true;
}
@ -162,10 +151,11 @@ bool GxsForumMsgItem::setMessage(const RsGxsForumMsg &msg, bool doFill)
mMessage = msg;
if (!isTop())
loadParentMessage(mMessage.mMeta.mParentId);
else if(doFill)
fill();
if(! mMessage.mMeta.mParentId.isNull())
loadParentMessage(mMessage.mMeta.mParentId);
if(doFill)
fillMessage();
return true;
}
@ -299,112 +289,97 @@ void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg)
* after a blocking call to RetroShare API complete */
mParentMessage = msg;
fill();
fillParentMessage();
}, this );
});
}
void GxsForumMsgItem::fill()
void GxsForumMsgItem::fillParentMessage()
{
/* fill in */
mInFill = true;
// if (isLoading()) {
// /* Wait for all requests */
// return;
// }
ui->parentFrame->hide();
RetroShareLink linkParent = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_FORUM, mParentMessage.mMeta.mGroupId, mParentMessage.mMeta.mMsgId, QString::fromUtf8(mParentMessage.mMeta.mMsgName.c_str()));
ui->parentSubLabel->setText(linkParent.toHtml());
ui->parentMsgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mParentMessage.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
ui->parentNameLabel->setId(mParentMessage.mMeta.mAuthorId);
RsIdentityDetails idDetails ;
rsIdentity->getIdDetails(mParentMessage.mMeta.mAuthorId,idDetails);
QPixmap pixmap ;
if(idDetails.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idDetails.mAvatar.mData, idDetails.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
pixmap = GxsIdDetails::makeDefaultIcon(mParentMessage.mMeta.mAuthorId,GxsIdDetails::SMALL);
ui->parentAvatar->setPixmap(pixmap);
mInFill = false;
}
void GxsForumMsgItem::fillMessage()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsForumMsgItem::fill()";
std::cerr << std::endl;
std::cerr << "GxsForumMsgItem::fill()";
std::cerr << std::endl;
#endif
mInFill = true;
if(!mIsHome && mCloseOnRead && !IS_MSG_NEW(mMessage.mMeta.mMsgStatus))
removeItem();
QString title = tr("Forum Feed") + ": ";
RetroShareLink link = RetroShareLink::createGxsGroupLink(RetroShareLink::TYPE_FORUM, mMessage.mMeta.mGroupId, groupName());
title += link.toHtml();
ui->titleLabel->setText(title);
setReadStatus(IS_MSG_NEW(mMessage.mMeta.mMsgStatus), IS_MSG_UNREAD(mMessage.mMeta.mMsgStatus) || IS_MSG_NEW(mMessage.mMeta.mMsgStatus));
if (!mIsHome && IS_MSG_NEW(mMessage.mMeta.mMsgStatus))
mCloseOnRead = true;
RsIdentityDetails idDetails ;
rsIdentity->getIdDetails(mMessage.mMeta.mAuthorId,idDetails);
QPixmap pixmap ;
if(idDetails.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idDetails.mAvatar.mData, idDetails.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
pixmap = GxsIdDetails::makeDefaultIcon(mMessage.mMeta.mAuthorId,GxsIdDetails::SMALL);
ui->avatar->setPixmap(pixmap);
ui->nameLabel->setId(mMessage.mMeta.mAuthorId);
RetroShareLink msgLink = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_FORUM, mMessage.mMeta.mGroupId, mMessage.mMeta.mMsgId, messageName());
ui->subLabel->setText(msgLink.toHtml());
if (wasExpanded() || ui->expandFrame->isVisible())
fillExpandFrame();
ui->timestamplabel->setText(DateTime::formatLongDateTime(mMessage.mMeta.mPublishTs));
/* header stuff */
ui->subjectLabel->setText(msgLink.toHtml());
if (mIsHome)
{
/* disable buttons */
ui->clearButton->setEnabled(false);
ui->clearButton->hide();
}
mInFill = false;
}
void GxsForumMsgItem::fillGroup()
{
mInFill = true;
if (!mIsHome)
{
if (mCloseOnRead && !IS_MSG_NEW(mMessage.mMeta.mMsgStatus)) {
removeItem();
}
}
ui->unsubscribeButton->setEnabled(IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags)) ;
QString title = tr("Forum Feed") + ": ";
RetroShareLink link = RetroShareLink::createGxsGroupLink(RetroShareLink::TYPE_FORUM, mMessage.mMeta.mGroupId, groupName());
title += link.toHtml();
ui->titleLabel->setText(title);
if (IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags)) {
ui->unsubscribeButton->setEnabled(true);
setReadStatus(IS_MSG_NEW(mMessage.mMeta.mMsgStatus), IS_MSG_UNREAD(mMessage.mMeta.mMsgStatus) || IS_MSG_NEW(mMessage.mMeta.mMsgStatus));
} else {
ui->unsubscribeButton->setEnabled(false);
}
if (IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags)) {
if (IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags))
ui->iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/forums.png"));
} else {
else
ui->iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/forums-default.png"));
}
if (!mIsHome) {
if (IS_MSG_NEW(mMessage.mMeta.mMsgStatus)) {
mCloseOnRead = true;
}
}
RsIdentityDetails idDetails ;
rsIdentity->getIdDetails(mMessage.mMeta.mAuthorId,idDetails);
QPixmap pixmap ;
if(idDetails.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idDetails.mAvatar.mData, idDetails.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
pixmap = GxsIdDetails::makeDefaultIcon(mMessage.mMeta.mAuthorId,GxsIdDetails::SMALL);
ui->avatar->setPixmap(pixmap);
ui->nameLabel->setId(mMessage.mMeta.mAuthorId);
RetroShareLink msgLink = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_FORUM, mMessage.mMeta.mGroupId, mMessage.mMeta.mMsgId, messageName());
ui->subLabel->setText(msgLink.toHtml());
if (wasExpanded() || ui->expandFrame->isVisible()) {
fillExpandFrame();
}
ui->timestamplabel->setText(DateTime::formatLongDateTime(mMessage.mMeta.mPublishTs));
if (isTop()) {
ui->parentFrame->hide();
} else {
RetroShareLink linkParent = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_FORUM, mParentMessage.mMeta.mGroupId, mParentMessage.mMeta.mMsgId, QString::fromUtf8(mParentMessage.mMeta.mMsgName.c_str()));
ui->parentSubLabel->setText(linkParent.toHtml());
ui->parentMsgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mParentMessage.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
ui->parentNameLabel->setId(mParentMessage.mMeta.mAuthorId);
RsIdentityDetails idDetails ;
rsIdentity->getIdDetails(mParentMessage.mMeta.mAuthorId,idDetails);
QPixmap pixmap ;
if(idDetails.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idDetails.mAvatar.mData, idDetails.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
pixmap = GxsIdDetails::makeDefaultIcon(mParentMessage.mMeta.mAuthorId,GxsIdDetails::SMALL);
ui->parentAvatar->setPixmap(pixmap);
}
/* header stuff */
ui->subjectLabel->setText(msgLink.toHtml());
if (mIsHome)
{
/* disable buttons */
ui->clearButton->setEnabled(false);
ui->clearButton->hide();
}
mInFill = false;
}

View File

@ -77,11 +77,12 @@ signals:
private:
void setup();
void fill();
void fillExpandFrame();
void fillGroup();
void fillMessage();
void fillParentMessage();
void fillExpandFrame();
void setReadStatus(bool isNew, bool isUnread);
void setAsRead();
bool isTop();
private:
bool mInFill;