From 006f4c53be3d42ba0c9f872b9417f705f24ba14f Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 30 Nov 2022 15:25:38 +0100 Subject: [PATCH] removed mMsgTagIds since tags are not in RsMailStorageItem struct --- .../src/gui/msgs/MessageComposer.cpp | 47 +++++++++---------- retroshare-gui/src/gui/msgs/MessageComposer.h | 2 +- retroshare-gui/src/gui/msgs/MessageModel.cpp | 7 ++- retroshare-gui/src/gui/msgs/MessageWidget.cpp | 8 ++-- retroshare-gui/src/gui/msgs/MessageWindow.cpp | 2 +- retroshare-gui/src/gui/msgs/TagsMenu.cpp | 4 +- retroshare-gui/src/gui/msgs/TagsMenu.h | 2 +- 7 files changed, 35 insertions(+), 37 deletions(-) diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 97c28a9e5..c90e6cba9 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -1081,7 +1081,7 @@ MessageComposer *MessageComposer::newMsg(const std::string &msgId /* = ""*/) MsgTagInfo tagInfo; rsMail->getMessageTag(msgId, tagInfo); - msgComposer->m_tagIds = tagInfo.tagIds; + msgComposer->m_tagIds = tagInfo; msgComposer->showTagLabels(); std::cerr << "Setting modified 005 = false" << std::endl; msgComposer->ui.msgText->document()->setModified(false); @@ -1267,7 +1267,7 @@ MessageComposer *MessageComposer::replyMsg(const std::string &msgId, bool all) MsgTagInfo tagInfo; rsMail->getMessageTag(msgId, tagInfo); - msgComposer->m_tagIds = tagInfo.tagIds; + msgComposer->m_tagIds = tagInfo; msgComposer->showTagLabels(); msgComposer->calculateTitle(); @@ -1563,18 +1563,15 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox) /* insert new tags */ std::list::iterator tag; - for (tag = m_tagIds.begin(); tag != m_tagIds.end(); ++tag) { - if (std::find(tagInfo.tagIds.begin(), tagInfo.tagIds.end(), *tag) == tagInfo.tagIds.end()) { - rsMail->setMessageTag(mi.msgId, *tag, true); - } else { - tagInfo.tagIds.remove(*tag); - } - } + for (auto tag:m_tagIds) + if (tagInfo.find(tag) == tagInfo.end()) + rsMail->setMessageTag(mi.msgId, tag, true); + else + tagInfo.erase(tag); /* remove deleted tags */ - for (tag = tagInfo.tagIds.begin(); tag != tagInfo.tagIds.end(); ++tag) { - rsMail->setMessageTag(mi.msgId, *tag, false); - } + for (auto tag:tagInfo) + rsMail->setMessageTag(mi.msgId, tag, false); } std::cerr << "Setting modified 001 = false" << std::endl; ui.msgText->document()->setModified(false); @@ -2801,17 +2798,17 @@ void MessageComposer::tagSet(int tagId, bool set) return; } - std::list::iterator tag = std::find(m_tagIds.begin(), m_tagIds.end(), tagId); - if (tag == m_tagIds.end()) { - if (set) { - m_tagIds.push_back(tagId); - /* Keep the list sorted */ - m_tagIds.sort(); - } - } else { - if (set == false) { - m_tagIds.remove(tagId); - } + auto tag = m_tagIds.find(tagId); + + if (tag == m_tagIds.end()) + { + if (set) + m_tagIds.insert(tagId); + } + else + { + if (set == false) + m_tagIds.erase(tagId); } showTagLabels(); @@ -2838,8 +2835,8 @@ void MessageComposer::showTagLabels() rsMail->getMessageTagTypes(tags); std::map >::iterator tag; - for (std::list::iterator tagId = m_tagIds.begin(); tagId != m_tagIds.end(); ++tagId) { - tag = tags.types.find(*tagId); + for (auto tagId:m_tagIds) { + tag = tags.types.find(tagId); if (tag != tags.types.end()) { QLabel *tagLabel = new QLabel(TagDefs::name(tag->first, tag->second.first), this); tagLabel->setMaximumHeight(QFontMetrics(tagLabel->font()).height()*1.2); diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index dbc13d431..0df2dbd8e 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -251,7 +251,7 @@ private: std::string m_msgParentId; // parent message id std::string m_sDraftMsgId; // existing message id enumMessageType m_msgType; - std::list m_tagIds; + std::set m_tagIds; QList tagLabels; // needed to send system flags with reply diff --git a/retroshare-gui/src/gui/msgs/MessageModel.cpp b/retroshare-gui/src/gui/msgs/MessageModel.cpp index 3696d6f33..a0a33853b 100644 --- a/retroshare-gui/src/gui/msgs/MessageModel.cpp +++ b/retroshare-gui/src/gui/msgs/MessageModel.cpp @@ -508,15 +508,14 @@ QVariant RsMessageModel::displayRole(const Rs::Msgs::MsgInfoSummary& fmpe,int co QString text; // build tag names - for (auto tagit = tagInfo.tagIds.begin(); tagit != tagInfo.tagIds.end(); ++tagit) + for (auto tag:tagInfo) { if (!text.isNull()) text += ","; - auto Tag = Tags.types.find(*tagit); - - if (Tag != Tags.types.end()) if (Tag != Tags.types.end()) + auto Tag = Tags.types.find(tag); + if (Tag != Tags.types.end()) text += TagDefs::name(Tag->first, Tag->second.first); else RS_WARN("Unknown tag ", (int)Tag->first, " in message ", fmpe.msgId); diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index 54266c3fa..9bf3dcc35 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -475,15 +475,17 @@ void MessageWidget::showTagLabels() MsgTagInfo tagInfo; rsMail->getMessageTag(currMsgId, tagInfo); - if (tagInfo.tagIds.empty() == false) { + if (!tagInfo.empty()) + { ui.tagsLabel->setVisible(true); MsgTagType Tags; rsMail->getMessageTagTypes(Tags); std::map >::iterator Tag; - for (std::list::iterator tagId = tagInfo.tagIds.begin(); tagId != tagInfo.tagIds.end(); ++tagId) { - Tag = Tags.types.find(*tagId); + for (auto tag:tagInfo) + { + Tag = Tags.types.find(tag); if (Tag != Tags.types.end()) { QLabel *tagLabel = new QLabel(TagDefs::name(Tag->first, Tag->second.first), this); tagLabel->setMaximumHeight(16); diff --git a/retroshare-gui/src/gui/msgs/MessageWindow.cpp b/retroshare-gui/src/gui/msgs/MessageWindow.cpp index ad1067367..0c9abf2a2 100644 --- a/retroshare-gui/src/gui/msgs/MessageWindow.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWindow.cpp @@ -150,7 +150,7 @@ void MessageWindow::tagAboutToShow() MsgTagInfo tagInfo; rsMail->getMessageTag(msgWidget->msgId(), tagInfo); - menu->activateActions(tagInfo.tagIds); + menu->activateActions(tagInfo); } void MessageWindow::tagRemoveAll() diff --git a/retroshare-gui/src/gui/msgs/TagsMenu.cpp b/retroshare-gui/src/gui/msgs/TagsMenu.cpp index 8ef4f7d93..881ec268d 100644 --- a/retroshare-gui/src/gui/msgs/TagsMenu.cpp +++ b/retroshare-gui/src/gui/msgs/TagsMenu.cpp @@ -170,7 +170,7 @@ void TagsMenu::fillTags() addAction(action); } -void TagsMenu::activateActions(std::list& tagIds) +void TagsMenu::activateActions(std::set& tagIds) { foreach(QObject *object, children()) { QAction *action = qobject_cast (object); @@ -186,7 +186,7 @@ void TagsMenu::activateActions(std::list& tagIds) continue; } - std::list::iterator tagId = std::find(tagIds.begin(), tagIds.end(), values [ACTION_TAGSINDEX_ID]); + auto tagId = std::find(tagIds.begin(), tagIds.end(), values [ACTION_TAGSINDEX_ID]); action->setChecked(tagId != tagIds.end()); } } diff --git a/retroshare-gui/src/gui/msgs/TagsMenu.h b/retroshare-gui/src/gui/msgs/TagsMenu.h index a3f2cdd55..1cccb7e5f 100644 --- a/retroshare-gui/src/gui/msgs/TagsMenu.h +++ b/retroshare-gui/src/gui/msgs/TagsMenu.h @@ -34,7 +34,7 @@ public: TagsMenu(const QString &title, QWidget *parent); virtual ~TagsMenu(); - void activateActions(std::list& tagIds); + void activateActions(std::set &tagIds); signals: void tagSet(int tagId, bool set);