Fix Channels Mark All as Un/Read.

This commit is contained in:
Phenom 2020-05-22 12:30:46 +02:00
parent d6748b17d5
commit ee0cc25b13
3 changed files with 39 additions and 25 deletions

View File

@ -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()

View File

@ -62,10 +62,13 @@ public:
QString getMsgLabel();
const std::list<SubFileItem *> &getFileItems() {return mFileItems; }
bool isUnread() const ;
const std::set<RsGxsMessageId>& 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<RsGxsMessageId>& 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<RsGxsMessageId>& older_versions);
@ -112,7 +115,6 @@ private:
void setup();
void fill();
void fillExpandFrame();
void setReadStatus(bool isNew, bool isUnread);
private:
bool mInFill;

View File

@ -144,18 +144,24 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEven
if(!e)
return;
switch(e->mChannelEventCode)
{
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<GxsChannelPostItem*>(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());