diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index 25b93ac8d..aa35fc0cc 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -141,7 +141,7 @@ GxsChannelPostItem::~GxsChannelPostItem() bool GxsChannelPostItem::isUnread() const { - return IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) ; + return IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) ; } void GxsChannelPostItem::setup() @@ -427,7 +427,7 @@ void GxsChannelPostItem::fill() QString title; - float f = QFontMetricsF(font()).height()/14.0 ; + //float f = QFontMetricsF(font()).height()/14.0 ; if(mPost.mThumbnail.mData != NULL) { @@ -629,14 +629,21 @@ QString GxsChannelPostItem::messageName() void GxsChannelPostItem::setReadStatus(bool isNew, bool isUnread) { + if (isNew) + mPost.mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_NEW; + else + mPost.mMeta.mMsgStatus &= ~GXS_SERV::GXS_MSG_STATUS_GUI_NEW; + if (isUnread) { - ui->readButton->setChecked(true); + mPost.mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; + whileBlocking(ui->readButton)->setChecked(true); ui->readButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-unread.png")); } else { - ui->readButton->setChecked(false); + mPost.mMeta.mMsgStatus &= ~GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; + whileBlocking(ui->readButton)->setChecked(false); ui->readButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-read.png")); } @@ -835,7 +842,7 @@ void GxsChannelPostItem::play() } } -void GxsChannelPostItem::readToggled(bool checked) +void GxsChannelPostItem::readToggled(bool /*checked*/) { if (mInFill) { return; @@ -845,10 +852,9 @@ void GxsChannelPostItem::readToggled(bool checked) RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); - uint32_t token; - rsGxsChannels->setMessageReadStatus(token, msgPair, !checked); + rsGxsChannels->markRead(msgPair, isUnread()); - setReadStatus(false, checked); + //setReadStatus(false, checked); // Updated by events } void GxsChannelPostItem::makeDownVote() diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 86aa20371..315972bb1 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -62,10 +62,13 @@ public: QString getMsgLabel(); const std::list &getFileItems() {return mFileItems; } - bool isUnread() const ; - const std::set& olderVersions() const { return mPost.mOlderVersions; } + bool isLoaded() const {return mLoaded;}; + bool isUnread() const ; + void setReadStatus(bool isNew, bool isUnread); - static uint64_t computeIdentifier(const RsGxsMessageId& msgid) { return hash64("GxsChannelPostItem " + msgid.toStdString()) ; } + const std::set& olderVersions() const { return mPost.mOlderVersions; } + + static uint64_t computeIdentifier(const RsGxsMessageId& msgid) { return hash64("GxsChannelPostItem " + msgid.toStdString()) ; } protected: //void init(const RsGxsMessageId& messageId,const std::set& older_versions); @@ -112,7 +115,6 @@ private: void setup(); void fill(); void fillExpandFrame(); - void setReadStatus(bool isNew, bool isUnread); private: bool mInFill; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 48b620775..d4e6192e2 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -144,18 +144,24 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptrmChannelEventCode) - { - case RsChannelEventCode::UPDATED_CHANNEL: - case RsChannelEventCode::NEW_CHANNEL: - case RsChannelEventCode::UPDATED_MESSAGE: - case RsChannelEventCode::NEW_MESSAGE: - if(e->mChannelGroupId == groupId()) + switch(e->mChannelEventCode) + { + case RsChannelEventCode::NEW_CHANNEL: // [[fallthrough]]; + case RsChannelEventCode::UPDATED_CHANNEL: // [[fallthrough]]; + case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]]; + case RsChannelEventCode::UPDATED_MESSAGE: + if(e->mChannelGroupId == groupId()) updateDisplay(true); - break; - default: - break; - } + break; + case RsChannelEventCode::READ_STATUS_CHANGED: + if (FeedItem *feedItem = ui->feedWidget->findFeedItem(GxsChannelPostItem::computeIdentifier(e->mChannelMsgId))) + if (GxsChannelPostItem *channelPostItem = dynamic_cast(feedItem)) + channelPostItem->setReadStatus(false,!channelPostItem->isUnread()); + //channelPostItem->setReadStatus(false,e->Don't get read status. Will be more easier and accurate); + break; + default: + break; + } } GxsChannelPostsWidget::~GxsChannelPostsWidget() @@ -909,9 +915,9 @@ static void setAllMessagesReadCallback(FeedItem *feedItem, void *data) } GxsChannelPostsReadData *readData = (GxsChannelPostsReadData*) data; - bool is_not_new = !channelPostItem->isUnread() ; + bool isRead = !channelPostItem->isUnread() ; - if(is_not_new == readData->mRead) + if(channelPostItem->isLoaded() && (isRead == readData->mRead)) return ; RsGxsGrpMsgIdPair msgPair = std::make_pair(channelPostItem->groupId(), channelPostItem->messageId());