diff --git a/libretroshare/src/retroshare/rsiface.h b/libretroshare/src/retroshare/rsiface.h index f0147a91d..df62c16cf 100644 --- a/libretroshare/src/retroshare/rsiface.h +++ b/libretroshare/src/retroshare/rsiface.h @@ -198,6 +198,7 @@ class NotifyBase virtual void notifyPeerStatusChanged(const std::string& /* peer_id */, uint32_t /* status */) {} /* one or more peers has changed the states */ virtual void notifyPeerStatusChangedSummary() {} + virtual void notifyForumMsgReadSatusChanged(const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) {} virtual void notifyChannelMsgReadSatusChanged(const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) {} virtual void notifyDiscInfoChanged() {} virtual void notifyDownloadComplete(const std::string& /* fileHash */) {}; diff --git a/libretroshare/src/services/p3forums.cc b/libretroshare/src/services/p3forums.cc index f0bd16a86..12dcee700 100644 --- a/libretroshare/src/services/p3forums.cc +++ b/libretroshare/src/services/p3forums.cc @@ -367,6 +367,9 @@ bool p3Forums::ForumMessageSend(ForumMsgInfo &info) bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,const uint32_t status, const uint32_t statusMask) { + bool changed = false; + uint32_t newStatus = 0; + { RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/ @@ -374,8 +377,14 @@ bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,co if (mit != mReadStatus.end()) { RsForumReadStatus* rsi = mit->second; + uint32_t oldStatus = rsi->msgReadStatus[mId]; rsi->msgReadStatus[mId] &= ~statusMask; rsi->msgReadStatus[mId] |= (status & statusMask); + + newStatus = rsi->msgReadStatus[mId]; + if (oldStatus != newStatus) { + changed = true; + } } else { // if forum id does not exist create one RsForumReadStatus* rsi = new RsForumReadStatus(); @@ -383,12 +392,18 @@ bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,co rsi->msgReadStatus[mId] = status & statusMask; mReadStatus[fId] = rsi; mSaveList.push_back(rsi); + + newStatus = rsi->msgReadStatus[mId]; + changed = true; } IndicateConfigChanged(); } /******* UNLOCKED ********/ - rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_MOD); + if (changed) { + rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_MOD); + rsicontrol->getNotify().notifyForumMsgReadSatusChanged(fId, mId, newStatus); + } return true; } diff --git a/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp b/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp index fdc4bd52e..bb571bfd7 100644 --- a/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/ChanMsgItem.cpp @@ -313,9 +313,7 @@ void ChanMsgItem::toggle() expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png"))); expandButton->setToolTip(tr("Hide")); - if (!mIsHome) { - readToggled(false); - } + readToggled(false); } else { @@ -392,12 +390,25 @@ void ChanMsgItem::readToggled(bool checked) /* ... and as read by user */ statusNew &= ~CHANNEL_MSG_STATUS_UNREAD_BY_USER; } + + if (!mIsHome) { + disconnect( NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int))); + } rsChannels->setMessageStatus(mChanId, mMsgId, statusNew, CHANNEL_MSG_STATUS_READ | CHANNEL_MSG_STATUS_UNREAD_BY_USER); + if (!mIsHome) { + connect( NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int)), Qt::QueuedConnection); + } } -void ChanMsgItem::channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int /*status*/) +void ChanMsgItem::channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status) { if (channelId.toStdString() == mChanId && msgId.toStdString() == mMsgId) { + if (!mIsHome) { + if (status & CHANNEL_MSG_STATUS_READ) { + close(); + return; + } + } updateItemStatic(); } } diff --git a/retroshare-gui/src/gui/feeds/ForumMsgItem.cpp b/retroshare-gui/src/gui/feeds/ForumMsgItem.cpp index adcb98b53..e8da1ded2 100644 --- a/retroshare-gui/src/gui/feeds/ForumMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/ForumMsgItem.cpp @@ -33,6 +33,7 @@ #include "gui/forums/CreateForumMsg.h" #include "gui/chat/HandleRichText.h" #include "gui/common/AvatarDefs.h" +#include "gui/notifyqt.h" //#include "gui/settings/rsharesettings.h" /**** @@ -57,6 +58,8 @@ ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::strin connect( replyButton, SIGNAL( clicked( void ) ), this, SLOT( replyToPost ( void ) ) ); connect( sendButton, SIGNAL( clicked( ) ), this, SLOT( sendMsg() ) ); + connect(NotifyQt::getInstance(), SIGNAL(forumMsgReadSatusChanged(QString,QString,int)), this, SLOT(forumMsgReadSatusChanged(QString,QString,int)), Qt::QueuedConnection); + subjectLabel->setMinimumWidth(20); small(); @@ -277,7 +280,9 @@ void ForumMsgItem::toggle() // } if (status != statusNew) { + disconnect(NotifyQt::getInstance(), SIGNAL(forumMsgReadSatusChanged(QString,QString,int)), this, SLOT(forumMsgReadSatusChanged(QString,QString,int))); rsForums->setMessageStatus(mForumId, mPostId, statusNew, FORUM_MSG_STATUS_READ | FORUM_MSG_STATUS_UNREAD_BY_USER); + connect(NotifyQt::getInstance(), SIGNAL(forumMsgReadSatusChanged(QString,QString,int)), this, SLOT(forumMsgReadSatusChanged(QString,QString,int)), Qt::QueuedConnection); } } } @@ -402,3 +407,12 @@ void ForumMsgItem::sendMsg() } } } + +void ForumMsgItem::forumMsgReadSatusChanged(const QString &forumId, const QString &msgId, int status) +{ + if (mForumId == forumId.toStdString() && mPostId == msgId.toStdString()) { + if (status & FORUM_MSG_STATUS_READ) { + close(); + } + } +} diff --git a/retroshare-gui/src/gui/feeds/ForumMsgItem.h b/retroshare-gui/src/gui/feeds/ForumMsgItem.h index 28ebeda4c..5cc9990e8 100644 --- a/retroshare-gui/src/gui/feeds/ForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/ForumMsgItem.h @@ -48,6 +48,8 @@ private slots: void replyToPost(); void sendMsg(); + void forumMsgReadSatusChanged(const QString &forumId, const QString &msgId, int status); + void updateItem(); private: diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index a69270e3b..adf1f191b 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -200,9 +200,14 @@ void NotifyQt::notifyPeerStatusChangedSummary() emit peerStatusChangedSummary(); } +void NotifyQt::notifyForumMsgReadSatusChanged(const std::string& forumId, const std::string& msgId, uint32_t status) +{ + emit forumMsgReadSatusChanged(QString::fromStdString(forumId), QString::fromStdString(msgId), status); +} + void NotifyQt::notifyChannelMsgReadSatusChanged(const std::string& channelId, const std::string& msgId, uint32_t status) { - emit channelMsgReadSatusChanged(QString::fromStdString(channelId), QString::fromStdString(msgId), status); + emit channelMsgReadSatusChanged(QString::fromStdString(channelId), QString::fromStdString(msgId), status); } void NotifyQt::notifyOwnStatusMessageChanged() diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 2ff503320..c7362fd6b 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -48,6 +48,7 @@ class NotifyQt: public QObject, public NotifyBase virtual void notifyPeerStatusChanged(const std::string& peer_id, uint32_t state); /* one or more peers has changed the states */ virtual void notifyPeerStatusChangedSummary(); + virtual void notifyForumMsgReadSatusChanged(const std::string& forumId, const std::string& msgId, uint32_t status); virtual void notifyChannelMsgReadSatusChanged(const std::string& channelId, const std::string& msgId, uint32_t status); virtual void notifyHistoryChanged(uint32_t msgId, int type); @@ -93,6 +94,7 @@ class NotifyQt: public QObject, public NotifyBase void discInfoChanged() const ; void downloadComplete(const QString& /* fileHash */); void downloadCompleteCountChanged(int /* count */); + void forumMsgReadSatusChanged(const QString& forumId, const QString& msgId, int status); void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status); void historyChanged(uint msgId, int type); void chatLobbyInviteReceived() ; @@ -101,8 +103,7 @@ class NotifyQt: public QObject, public NotifyBase void chatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType); public slots: - - void UpdateGUI(); /* called by timer */ + void UpdateGUI(); /* called by timer */ private slots: void runningTick();