mirror of
https://github.com/RetroShare/RetroShare.git
synced 2026-09-12 19:50:17 +05:00
Added "Mark all as read" feature
This commit is contained in:
parent
6810da41f9
commit
e6e7340da6
@ -533,7 +533,14 @@ void WireDialog::addGroup(const RsWireGroup &group)
|
||||
std::cerr << "WireDialog::addGroup() GroupId : " << group.mMeta.mGroupId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
addGroup(new WireGroupItem(this, group));
|
||||
WireGroupItem *item = new WireGroupItem(this, group);
|
||||
|
||||
// Apply cached unread count so the badge is correct from the moment the item appears
|
||||
auto sit = mCachedGroupStats.find(group.mMeta.mGroupId);
|
||||
if (sit != mCachedGroupStats.end())
|
||||
item->setUnreadCount(sit->second.mNumThreadMsgsUnread);
|
||||
|
||||
addGroup(item);
|
||||
}
|
||||
|
||||
void WireDialog::deleteGroups()
|
||||
@ -578,6 +585,12 @@ void WireDialog::updateGroups(const std::vector<RsWireGroup>& groups)
|
||||
for(auto &it : groups) {
|
||||
// save list of all groups.
|
||||
mAllGroups[it.mMeta.mGroupId] = it;
|
||||
|
||||
if (it.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED) {
|
||||
mOwnGroups.push_back(it);
|
||||
}
|
||||
|
||||
addGroup(it);
|
||||
|
||||
if (it.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
|
||||
{
|
||||
@ -1382,13 +1395,13 @@ void WireDialog::updateGroupStatisticsReal(const RsGxsGroupId &groupId)
|
||||
* Qt::QueuedConnection is important!
|
||||
*/
|
||||
|
||||
// QTreeWidgetItem *item = ui.scrollAreaWidgetContents->getItemFromId(QString::fromStdString(stats.mGrpId.toStdString()));
|
||||
|
||||
// if (item)
|
||||
// ui.scrollAreaWidgetContents->setUnreadCount(item, mCountChildMsgs ? (stats.mNumThreadMsgsUnread + stats.mNumChildMsgsUnread) : stats.mNumThreadMsgsUnread);
|
||||
|
||||
mCachedGroupStats[groupId] = stats;
|
||||
|
||||
// Update the unread count badge on the matching WireGroupItem
|
||||
WireGroupItem *groupItem = findGroupItemWidget(groupId);
|
||||
if (groupItem)
|
||||
groupItem->setUnreadCount(stats.mNumThreadMsgsUnread);
|
||||
|
||||
getUserNotify()->updateIcon();
|
||||
|
||||
}, this );
|
||||
@ -1455,6 +1468,20 @@ GxsMessageFrameWidget *WireDialog::messageWidget(const RsGxsGroupId &groupId)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WireGroupItem *WireDialog::findGroupItemWidget(const RsGxsGroupId &groupId)
|
||||
{
|
||||
QLayout *alayout = ui.groupsWidget->layout();
|
||||
for (int i = 0; i < alayout->count(); ++i)
|
||||
{
|
||||
QLayoutItem *item = alayout->itemAt(i);
|
||||
if (!item) continue;
|
||||
WireGroupItem *groupItem = dynamic_cast<WireGroupItem *>(item->widget());
|
||||
if (groupItem && groupItem->groupId() == groupId)
|
||||
return groupItem;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//void GxsGroupFrameDialog::changedCurrentGroup(const QString& groupId)
|
||||
//{
|
||||
// if (mInFill) {
|
||||
@ -1494,3 +1521,31 @@ GxsMessageFrameWidget *WireDialog::messageWidget(const RsGxsGroupId &groupId)
|
||||
// currentWidget()->setGroupId(mGroupId);
|
||||
// }
|
||||
//}
|
||||
|
||||
void WireDialog::markGroupAsRead(const RsGxsGroupId &groupId)
|
||||
{
|
||||
// Fetch all message summaries in the background and mark each as read.
|
||||
RsThread::async([this, groupId]()
|
||||
{
|
||||
std::vector<RsMsgMetaData> summaries;
|
||||
if (!rsWire->getContentSummaries(groupId, summaries))
|
||||
{
|
||||
std::cerr << "WireDialog::markGroupAsRead() failed to get summaries for group "
|
||||
<< groupId << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &meta : summaries)
|
||||
{
|
||||
uint32_t token;
|
||||
RsGxsGrpMsgIdPair msgIdPair(groupId, meta.mMsgId);
|
||||
rsWire->setMessageReadStatus(token, msgIdPair, true);
|
||||
}
|
||||
|
||||
// Refresh statistics and notify icon from the GUI thread.
|
||||
RsQThreadUtils::postToObject([this, groupId]()
|
||||
{
|
||||
updateGroupStatisticsReal(groupId);
|
||||
}, this);
|
||||
});
|
||||
}
|
||||
|
||||
@ -125,6 +125,8 @@ public:
|
||||
void getServiceStatistics(GxsServiceStatistic& stats) const override;
|
||||
|
||||
virtual bool navigate(const RsGxsGroupId &groupId, const RsGxsMessageId& msgId);
|
||||
|
||||
virtual void markGroupAsRead(const RsGxsGroupId &groupId) override;
|
||||
|
||||
protected:
|
||||
|
||||
@ -132,6 +134,7 @@ protected:
|
||||
UserNotify *createUserNotify(QObject *parent) override;
|
||||
virtual void updateGroupStatistics(const RsGxsGroupId &groupId);
|
||||
virtual void updateGroupStatisticsReal(const RsGxsGroupId &groupId);
|
||||
std::map<RsGxsGroupId, GxsGroupStatistic> mGroupStats;
|
||||
|
||||
private slots:
|
||||
|
||||
@ -178,6 +181,7 @@ private:
|
||||
void requestGroupData();
|
||||
|
||||
GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId);
|
||||
WireGroupItem *findGroupItemWidget(const RsGxsGroupId &groupId);
|
||||
|
||||
int mGroupSet;
|
||||
|
||||
|
||||
@ -77,7 +77,11 @@ RsGxsGroupId &WireGroupItem::groupId()
|
||||
|
||||
void WireGroupItem::setup()
|
||||
{
|
||||
label_groupName->setText(QString::fromStdString(mGroup.mMeta.mGroupName));
|
||||
// Initialize cached members from group data
|
||||
mGroupId = mGroup.mMeta.mGroupId;
|
||||
mGroupName = QString::fromStdString(mGroup.mMeta.mGroupName);
|
||||
|
||||
label_groupName->setText(mGroupName);
|
||||
label_authorId->setId(mGroup.mMeta.mAuthorId);
|
||||
frame_details->setVisible(false);
|
||||
|
||||
@ -119,6 +123,7 @@ void WireGroupItem::setup()
|
||||
connect(toolButton_show, SIGNAL(clicked()), this, SLOT(show()));
|
||||
connect(toolButton_subscribe, SIGNAL(clicked()), this, SLOT(subscribe()));
|
||||
connect(editButton, SIGNAL(clicked()), this, SLOT(editGroupDetails()));
|
||||
toolButton_readAll->hide(); // hidden until we know there are unread messages
|
||||
setGroupSet();
|
||||
}
|
||||
|
||||
@ -234,3 +239,21 @@ void WireGroupItem::editGroupDetails()
|
||||
WireGroupDialog wireEdit(GxsGroupDialog::MODE_EDIT, groupId, this);
|
||||
wireEdit.exec ();
|
||||
}
|
||||
|
||||
void WireGroupItem::setUnreadCount(uint32_t count)
|
||||
{
|
||||
if (count > 0) {
|
||||
// Make text bold and show count
|
||||
label_groupName->setText(QString("<b>%1 (%2)</b>").arg(mGroupName).arg(count));
|
||||
toolButton_readAll->show();
|
||||
} else {
|
||||
// Regular text
|
||||
label_groupName->setText(mGroupName);
|
||||
toolButton_readAll->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void WireGroupItem::on_toolButton_readAll_clicked()
|
||||
{
|
||||
mHolder->markGroupAsRead(mGroup.mMeta.mGroupId);
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ public:
|
||||
virtual void unsubscribe(RsGxsGroupId &groupId) = 0;
|
||||
|
||||
virtual void notifyGroupSelection(WireGroupItem *item) = 0;
|
||||
virtual void markGroupAsRead(const RsGxsGroupId &groupId) = 0;
|
||||
};
|
||||
|
||||
class WireGroupItem : public QWidget, private Ui::WireGroupItem
|
||||
@ -52,11 +53,13 @@ public:
|
||||
const QPixmap *getPixmap();
|
||||
RsGxsGroupId &groupId();
|
||||
bool matchesFilter(const QString &filterText) const;
|
||||
void setUnreadCount(uint32_t count);
|
||||
|
||||
private slots:
|
||||
void show();
|
||||
void subscribe();
|
||||
void editGroupDetails();
|
||||
void on_toolButton_readAll_clicked();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
@ -66,6 +69,8 @@ private:
|
||||
void setGroupSet();
|
||||
void setBackground(QColor color);
|
||||
|
||||
RsGxsGroupId mGroupId;
|
||||
QString mGroupName;
|
||||
WireGroupHolder *mHolder;
|
||||
RsWireGroup mGroup;
|
||||
bool mSelected;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>292</width>
|
||||
<width>302</width>
|
||||
<height>115</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -153,6 +153,20 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_readAll">
|
||||
<property name="toolTip">
|
||||
<string>Mark all as read all</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../icons.qrc">
|
||||
<normaloff>:/icons/png/correct.png</normaloff>:/icons/png/correct.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_subscribe">
|
||||
<property name="text">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user