fixed a few glitches in Mail GUI

This commit is contained in:
csoler 2022-11-22 23:08:42 +01:00
parent 3ac97b24a8
commit 8bcb531cd3
4 changed files with 35 additions and 104 deletions

View File

@ -660,61 +660,20 @@ void MessageComposer::addConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId
std::list<MsgInfoSummary> msgList;
std::list<MsgInfoSummary>::const_iterator it;
rsMail->getMessageSummaries(msgList);
for(it = msgList.begin(); it != msgList.end(); ++it) {
if (it->msgflags & RS_MSG_TRASH) {
continue;
}
if ((it->msgflags & RS_MSG_BOXMASK) != RS_MSG_INBOX) {
continue;
}
if ((it->msgflags & RS_MSG_USER_REQUEST) == 0) {
continue;
}
if (it->title == title.toUtf8().constData()) {
rsMail->getMessageSummaries(Rs::Msgs::BoxName::BOX_INBOX,msgList);
// do not re-add an existing request.
// note: the test with name() is very unsecure. We should use the ID instead.
for(it = msgList.begin(); it != msgList.end(); ++it)
if((it->msgflags & RS_MSG_USER_REQUEST) && it->title == title.toUtf8().constData())
return;
}
}
/* create a message */
QString msgText = tr("Hi %1,<br><br>%2 wants to be friends with you on RetroShare.<br><br>Respond now:<br>%3<br><br>Thanks,<br>The RetroShare Team").arg(QString::fromUtf8(rsPeers->getGPGName(rsPeers->getGPGOwnId()).c_str()), link.name(), link.toHtml());
rsMail->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_USER_REQUEST);
}
#ifdef UNUSED_CODE
void MessageComposer::sendChannelPublishKey(RsGxsChannelGroup &group)
{
// QString channelName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
// RetroShareLink link;
// if (!link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, group.mMeta.mGroupId, channelName)) {
// return;
// }
// QString title = tr("Publish key for channel %1").arg(channelName);
// /* create a message */
// QString msgText = tr("... %1 ...<br>%2").arg(channelName, link.toHtml());
// rsMail->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_PUBLISH_KEY);
}
void MessageComposer::sendForumPublishKey(RsGxsForumGroup &group)
{
// QString forumName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
// RetroShareLink link;
// if (!link.createGxsGroupLink(RetroShareLink::TYPE_FORUM, group.mMeta.mGroupId, forumName)) {
// return;
// }
// QString title = tr("Publish key for forum %1").arg(forumName);
// /* create a message */
// QString msgText = tr("... %1 ...<br>%2").arg(forumName, link.toHtml());
// rsMail->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_PUBLISH_KEY);
}
#endif
void MessageComposer::closeEvent (QCloseEvent * event)
{
bool bClose = true;

View File

@ -53,7 +53,7 @@ const QString RsMessageModel::FilterString("filtered");
RsMessageModel::RsMessageModel(QObject *parent)
: QAbstractItemModel(parent)
{
mCurrentBox = BOX_NONE;
mCurrentBox = Rs::Msgs::BoxName::BOX_NONE;
mQuickViewFilter = QUICK_VIEW_ALL;
mFilterType = FILTER_TYPE_NONE;
mFilterStrings.clear();
@ -647,7 +647,7 @@ void RsMessageModel::setMessages(const std::list<Rs::Msgs::MsgInfoSummary>& msgs
emit messagesLoaded();
}
void RsMessageModel::setCurrentBox(BoxName bn)
void RsMessageModel::setCurrentBox(Rs::Msgs::BoxName bn)
{
if(mCurrentBox != bn)
{
@ -669,45 +669,13 @@ void RsMessageModel::setQuickViewFilter(QuickViewFilter fn)
}
}
void RsMessageModel::getMessageSummaries(BoxName box,std::list<Rs::Msgs::MsgInfoSummary>& msgs)
{
rsMsgs->getMessageSummaries(msgs);
std::cerr << "Get msg summaries. Box=" << box << ":" << std::endl;
// filter out messages that are not in the right box.
for(auto it(msgs.begin());it!=msgs.end();)
{
bool ok = false;
switch(box)
{
case BOX_INBOX : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX && !(it->msgflags & RS_MSG_TRASH); break ;
case BOX_SENT : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_SENTBOX && !(it->msgflags & RS_MSG_TRASH); break ;
case BOX_OUTBOX : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX && !(it->msgflags & RS_MSG_TRASH); break ;
case BOX_DRAFTS : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_DRAFTBOX && !(it->msgflags & RS_MSG_TRASH); break ;
case BOX_TRASH : ok = (it->msgflags & RS_MSG_TRASH) ; break ;
default:
++it;
continue;
}
std::cerr << " msg id " << it->msgId << " flags=" << (it->msgflags & RS_MSG_BOXMASK) << " ok: " << ok << std::endl;
if(ok)
++it;
else
it = msgs.erase(it) ;
}
}
void RsMessageModel::updateMessages()
{
emit messagesAboutToLoad();
std::list<Rs::Msgs::MsgInfoSummary> msgs;
getMessageSummaries(mCurrentBox,msgs);
rsMsgs->getMessageSummaries(mCurrentBox,msgs);
setMessages(msgs);
emit messagesLoaded();

View File

@ -43,15 +43,6 @@ public:
explicit RsMessageModel(QObject *parent = NULL);
~RsMessageModel(){}
enum BoxName {
BOX_NONE = 0x00,
BOX_INBOX = 0x01,
BOX_OUTBOX = 0x02,
BOX_DRAFTS = 0x03,
BOX_SENT = 0x04,
BOX_TRASH = 0x05
};
enum Columns {
COLUMN_THREAD_STAR = 0x00,
COLUMN_THREAD_ATTACHMENT = 0x01,
@ -105,11 +96,10 @@ public:
QModelIndex getIndexOfMessage(const std::string &mid) const;
static const QString FilterString ;
static void getMessageSummaries(BoxName box, std::list<Rs::Msgs::MsgInfoSummary>& msgs);
// This method will asynchroneously update the data
void setCurrentBox(BoxName bn) ;
void setCurrentBox(Rs::Msgs::BoxName bn) ;
void setQuickViewFilter(QuickViewFilter fn) ;
void setFilter(FilterType filter_type, const QStringList& strings) ;
@ -189,7 +179,7 @@ private:
QColor mTextColorNotSubscribed ;
QColor mTextColorMissing ;
BoxName mCurrentBox ;
Rs::Msgs::BoxName mCurrentBox ;
QuickViewFilter mQuickViewFilter ;
QStringList mFilterStrings;
FilterType mFilterType;

View File

@ -897,18 +897,18 @@ void MessagesDialog::changeBox(int box_row)
QString placeholderText = tr("No message available in your %1.").arg(item->text());
switch(box_row)
{
case ROW_INBOX: mMessageModel->setCurrentBox(RsMessageModel::BOX_INBOX );
case ROW_INBOX: mMessageModel->setCurrentBox(Rs::Msgs::BoxName::BOX_INBOX );
break;
case ROW_OUTBOX: mMessageModel->setCurrentBox(RsMessageModel::BOX_OUTBOX);
case ROW_OUTBOX: mMessageModel->setCurrentBox(Rs::Msgs::BoxName::BOX_OUTBOX);
break;
case ROW_DRAFTBOX: mMessageModel->setCurrentBox(RsMessageModel::BOX_DRAFTS);
case ROW_DRAFTBOX: mMessageModel->setCurrentBox(Rs::Msgs::BoxName::BOX_DRAFTS);
break;
case ROW_SENTBOX: mMessageModel->setCurrentBox(RsMessageModel::BOX_SENT );
case ROW_SENTBOX: mMessageModel->setCurrentBox(Rs::Msgs::BoxName::BOX_SENT );
break;
case ROW_TRASHBOX: mMessageModel->setCurrentBox(RsMessageModel::BOX_TRASH );
case ROW_TRASHBOX: mMessageModel->setCurrentBox(Rs::Msgs::BoxName::BOX_TRASH );
break;
default:
mMessageModel->setCurrentBox(RsMessageModel::BOX_NONE);
mMessageModel->setCurrentBox(Rs::Msgs::BoxName::BOX_NONE);
}
insertMsgTxtAndFiles(ui.messageTreeWidget->currentIndex());
@ -916,7 +916,7 @@ void MessagesDialog::changeBox(int box_row)
}
else
{
mMessageModel->setCurrentBox(RsMessageModel::BOX_NONE);
mMessageModel->setCurrentBox(Rs::Msgs::BoxName::BOX_NONE);
}
inChange = false;
@ -1263,8 +1263,22 @@ void MessagesDialog::updateMessageSummaryList()
/* calculating the new messages */
Rs::Msgs::BoxName box;
int box_row = ui.listWidget->currentRow();
switch(box_row)
{
case ROW_INBOX: box = Rs::Msgs::BoxName::BOX_INBOX ; break;
case ROW_OUTBOX: box = Rs::Msgs::BoxName::BOX_OUTBOX; break;
case ROW_DRAFTBOX: box = Rs::Msgs::BoxName::BOX_DRAFTS; break;
case ROW_SENTBOX: box = Rs::Msgs::BoxName::BOX_SENT ; break;
case ROW_TRASHBOX: box = Rs::Msgs::BoxName::BOX_TRASH ; break;
default:
box = Rs::Msgs::BoxName::BOX_NONE;
}
std::list<MsgInfoSummary> msgList;
rsMail->getMessageSummaries(msgList);
rsMail->getMessageSummaries(box,msgList);
QMap<int, int> tagCount;
@ -1513,7 +1527,7 @@ void MessagesDialog::tagSet(int tagId, bool set)
void MessagesDialog::emptyTrash()
{
std::list<Rs::Msgs::MsgInfoSummary> msgs ;
mMessageModel->getMessageSummaries(RsMessageModel::BOX_TRASH,msgs);
rsMsgs->getMessageSummaries(Rs::Msgs::BoxName::BOX_TRASH,msgs);
for(auto it(msgs.begin());it!=msgs.end();++it)
rsMail->MessageDelete(it->msgId);