From b1129df0771d6c64d7ad8857204fd033ca08e112 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 7 Nov 2020 18:09:50 +0100 Subject: [PATCH] Change Chat History Dialog to no modal. It will be updated when new message comes. --- libretroshare/src/pqi/p3historymgr.cc | 2 +- libretroshare/src/pqi/p3historymgr.h | 4 +- libretroshare/src/pqi/p3peermgr.cc | 2 + libretroshare/src/retroshare/rshistory.h | 10 +-- libretroshare/src/rsserver/p3history.cc | 5 ++ libretroshare/src/rsserver/p3history.h | 15 +++-- retroshare-gui/src/gui/chat/ChatWidget.cpp | 12 ++-- retroshare-gui/src/gui/chat/ChatWidget.h | 19 +++--- .../src/gui/im_history/ImHistoryBrowser.cpp | 66 +++++++++++-------- .../src/gui/im_history/ImHistoryBrowser.h | 2 +- 10 files changed, 81 insertions(+), 56 deletions(-) diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index b546da76c..a53acb678 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -416,7 +416,7 @@ bool p3HistoryMgr::loadList(std::list& load) } // have to convert to virtual peer id, to be able to use existing serialiser and file format -bool p3HistoryMgr::chatIdToVirtualPeerId(ChatId chat_id, RsPeerId &peer_id) +bool p3HistoryMgr::chatIdToVirtualPeerId(const ChatId& chat_id, RsPeerId &peer_id) { if (chat_id.isBroadcast()) { peer_id = RsPeerId(); diff --git a/libretroshare/src/pqi/p3historymgr.h b/libretroshare/src/pqi/p3historymgr.h index 5f4ac0d98..a74eff67e 100644 --- a/libretroshare/src/pqi/p3historymgr.h +++ b/libretroshare/src/pqi/p3historymgr.h @@ -68,9 +68,9 @@ public: virtual void saveDone(); virtual bool loadList(std::list& load); -private: - static bool chatIdToVirtualPeerId(ChatId chat_id, RsPeerId& peer_id); + static bool chatIdToVirtualPeerId(const ChatId& chat_id, RsPeerId& peer_id); +private: uint32_t nextMsgId; std::map > mMessages; diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 07eb180d4..55b1eb041 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1876,7 +1876,9 @@ bool p3PeerMgrIMPL::getExtAddressReportedByFriends(sockaddr_storage &addr, uint8 static bool cleanIpList(std::list& lst,const RsPeerId& pid,p3LinkMgr *link_mgr) { bool changed = false ; +#ifdef PEER_DEBUG rstime_t now = time(NULL) ; +#endif for(std::list::iterator it2(lst.begin());it2 != lst.end();) { diff --git a/libretroshare/src/retroshare/rshistory.h b/libretroshare/src/retroshare/rshistory.h index 16f942339..f8eb7ecaa 100644 --- a/libretroshare/src/retroshare/rshistory.h +++ b/libretroshare/src/retroshare/rshistory.h @@ -70,15 +70,17 @@ public: class RsHistory { public: - virtual bool getMessages(const ChatId &chatPeerId, std::list &msgs, uint32_t loadCount) = 0; + virtual bool chatIdToVirtualPeerId(const ChatId &chat_id, RsPeerId &peer_id) = 0; + virtual bool getMessages(const ChatId &chatPeerId, std::list &msgs, uint32_t loadCount) = 0; virtual bool getMessage(uint32_t msgId, HistoryMsg &msg) = 0; virtual void removeMessages(const std::list &msgIds) = 0; - virtual void clear(const ChatId &chatPeerId) = 0; + virtual void clear(const ChatId &chatPeerId) = 0; virtual bool getEnable(uint32_t chat_type) = 0; virtual void setEnable(uint32_t chat_type, bool enable) = 0; - virtual uint32_t getMaxStorageDuration() = 0 ; - virtual void setMaxStorageDuration(uint32_t seconds) = 0 ; + + virtual uint32_t getMaxStorageDuration() = 0; + virtual void setMaxStorageDuration(uint32_t seconds) = 0; // 0 = no limit, >0 count of saved messages virtual uint32_t getSaveCount(uint32_t chat_type) = 0; diff --git a/libretroshare/src/rsserver/p3history.cc b/libretroshare/src/rsserver/p3history.cc index 9492a09f0..2818d9339 100644 --- a/libretroshare/src/rsserver/p3history.cc +++ b/libretroshare/src/rsserver/p3history.cc @@ -31,6 +31,11 @@ p3History::~p3History() { } +bool p3History::chatIdToVirtualPeerId(const ChatId &chat_id, RsPeerId &peer_id) +{ + return mHistoryMgr->chatIdToVirtualPeerId(chat_id, peer_id); +} + void p3History::setMaxStorageDuration(uint32_t seconds) { mHistoryMgr->setMaxStorageDuration(seconds) ; diff --git a/libretroshare/src/rsserver/p3history.h b/libretroshare/src/rsserver/p3history.h index 73d009657..2a75d328d 100644 --- a/libretroshare/src/rsserver/p3history.h +++ b/libretroshare/src/rsserver/p3history.h @@ -37,16 +37,21 @@ public: p3History(p3HistoryMgr* historyMgr); virtual ~p3History(); - virtual bool getMessages(const ChatId &chatPeerId, std::list &msgs, uint32_t loadCount); + virtual bool chatIdToVirtualPeerId(const ChatId &chat_id, RsPeerId &peer_id); + virtual bool getMessages(const ChatId &chatPeerId, std::list &msgs, uint32_t loadCount); virtual bool getMessage(uint32_t msgId, HistoryMsg &msg); virtual void removeMessages(const std::list &msgIds); - virtual void clear(const ChatId &chatPeerId); + virtual void clear(const ChatId &chatPeerId); + virtual bool getEnable(uint32_t chat_type); virtual void setEnable(uint32_t chat_type, bool enable); + + virtual uint32_t getMaxStorageDuration(); + virtual void setMaxStorageDuration(uint32_t seconds); + + // 0 = no limit, >0 count of saved messages virtual uint32_t getSaveCount(uint32_t chat_type); - virtual void setSaveCount(uint32_t chat_type, uint32_t count); - virtual void setMaxStorageDuration(uint32_t seconds) ; - virtual uint32_t getMaxStorageDuration() ; + virtual void setSaveCount(uint32_t chat_type, uint32_t count); private: p3HistoryMgr* mHistoryMgr; diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 7b8c532d0..a28d0943d 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -42,7 +42,6 @@ #include "gui/settings/rsharesettings.h" #include "gui/settings/rsettingswin.h" #include "gui/settings/RsharePeerSettings.h" -#include "gui/im_history/ImHistoryBrowser.h" #include "gui/common/StatusDefs.h" #include "gui/common/FilesDefs.h" #include "gui/common/Emoticons.h" @@ -78,7 +77,7 @@ ChatWidget::ChatWidget(QWidget *parent) , lastStatusSendTime(0) , firstShow(true), inChatCharFormatChanged(false), firstSearch(true) , lastUpdateCursorPos(0), lastUpdateCursorEnd(0) - , completer(NULL), notify(NULL) + , completer(NULL), imBrowser(NULL), notify(NULL) , ui(new Ui::ChatWidget) { ui->setupUi(this); @@ -87,8 +86,8 @@ ChatWidget::ChatWidget(QWidget *parent) double fmm = iconHeight > FMM_THRESHOLD ? FMM : FMM_SMALLER; iconHeight *= fmm; QSize iconSize = QSize(iconHeight, iconHeight); - int butt_size(iconSize.height() + fmm); - QSize buttonSize = QSize(butt_size, butt_size); + //int butt_size(iconSize.height() + fmm); + //QSize buttonSize = QSize(butt_size, butt_size); lastMsgDate = QDate::currentDate(); @@ -1607,8 +1606,9 @@ void ChatWidget::deleteChatHistory() void ChatWidget::messageHistory() { - ImHistoryBrowser imBrowser(chatId, ui->chatTextEdit, window()); - imBrowser.exec(); + if (!imBrowser) + imBrowser = new ImHistoryBrowser(chatId, ui->chatTextEdit, this->title, window()); + imBrowser->show(); } void ChatWidget::addExtraFile() diff --git a/retroshare-gui/src/gui/chat/ChatWidget.h b/retroshare-gui/src/gui/chat/ChatWidget.h index 535636ddd..2e64dce75 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.h +++ b/retroshare-gui/src/gui/chat/ChatWidget.h @@ -23,20 +23,22 @@ #ifndef CHATWIDGET_H #define CHATWIDGET_H -#include -#include -#include -#include -#include +#include "ChatLobbyUserNotify.h" +#include "ChatStyle.h" #include "gui/common/HashBox.h" #include "gui/common/RsButtonOnText.h" -#include "ChatStyle.h" +#include "gui/im_history/ImHistoryBrowser.h" #include "gui/style/RSStyle.h" -#include "ChatLobbyUserNotify.h" #include #include +#include +#include +#include +#include +#include + //For PersonId anchor. #define PERSONID "PersonId:" @@ -258,7 +260,8 @@ private: TransferRequestFlags mDefaultExtraFileFlags ; // flags for extra files shared in this chat. Will be 0 by default, but might be ANONYMOUS for chat lobbies. QDate lastMsgDate ; - QCompleter *completer; + QCompleter *completer; + ImHistoryBrowser* imBrowser; QList mChatWidgetHolder; ChatLobbyUserNotify* notify; diff --git a/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp b/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp index 70b5b4b0d..9f84f6856 100644 --- a/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp +++ b/retroshare-gui/src/gui/im_history/ImHistoryBrowser.cpp @@ -91,14 +91,15 @@ void ImHistoryBrowserCreateItemsThread::run() } /** Default constructor */ -ImHistoryBrowser::ImHistoryBrowser(const ChatId &chatId, QTextEdit *edit, QWidget *parent) +ImHistoryBrowser::ImHistoryBrowser(const ChatId &chatId, QTextEdit *edit,const QString &chatTitle, QWidget *parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint) { /* Invoke Qt Designer generated QObject setup routine */ ui.setupUi(this); + setWindowTitle(tr("%1 's Message History").arg(chatTitle)); ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/user/agt_forum64.png")); - ui.headerFrame->setHeaderText(tr("Message History")); + ui.headerFrame->setHeaderText(windowTitle()); m_chatId = chatId; textEdit = edit; @@ -225,36 +226,43 @@ void ImHistoryBrowser::historyAdd(HistoryMsg& msg) void ImHistoryBrowser::historyChanged(uint msgId, int type) { - if (type == NOTIFY_TYPE_ADD) { - /* history message added */ - HistoryMsg msg; - if (rsHistory->getMessage(msgId, msg) == false) { - return; - } + if (type == NOTIFY_TYPE_ADD) { + /* history message added */ + HistoryMsg msg; + if (rsHistory->getMessage(msgId, msg) == false) { + return; + } + RsPeerId virtChatId; + if ( rsHistory->chatIdToVirtualPeerId(m_chatId ,virtChatId) + && virtChatId == msg.chatPeerId) + historyAdd(msg); - historyAdd(msg); + return; + } - return; - } + if (type == NOTIFY_TYPE_DEL) { + /* history message removed */ + int count = ui.listWidget->count(); + for (int i = 0; i < count; ++i) { + QListWidgetItem *itemWidget = ui.listWidget->item(i); + if (itemWidget->data(ROLE_MSGID).toString().toUInt() == msgId) { + delete(ui.listWidget->takeItem(i)); + break; + } + } + return; + } - if (type == NOTIFY_TYPE_DEL) { - /* history message removed */ - int count = ui.listWidget->count(); - for (int i = 0; i < count; ++i) { - QListWidgetItem *itemWidget = ui.listWidget->item(i); - if (itemWidget->data(ROLE_MSGID).toString().toUInt() == msgId) { - delete(ui.listWidget->takeItem(i)); - break; - } - } - return; - } - - if (type == NOTIFY_TYPE_MOD) { - /* clear history */ - ui.listWidget->clear(); - return; - } + if (type == NOTIFY_TYPE_MOD) { + /* clear history */ + // As no ChatId nor msgId are send via Notify, + // only check if history of this chat is empty before clear our list. + std::list historyMsgs; + rsHistory->getMessages(m_chatId, historyMsgs, 1); + if (historyMsgs.empty()) + ui.listWidget->clear(); + return; + } } void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg) diff --git a/retroshare-gui/src/gui/im_history/ImHistoryBrowser.h b/retroshare-gui/src/gui/im_history/ImHistoryBrowser.h index 0cfeb9a45..6888594a5 100644 --- a/retroshare-gui/src/gui/im_history/ImHistoryBrowser.h +++ b/retroshare-gui/src/gui/im_history/ImHistoryBrowser.h @@ -41,7 +41,7 @@ class ImHistoryBrowser : public QDialog public: /** Default constructor */ - ImHistoryBrowser(const ChatId &chatId, QTextEdit *edit, QWidget *parent = 0); + ImHistoryBrowser(const ChatId &chatId, QTextEdit *edit,const QString &chatTitle, QWidget *parent = 0); /** Default destructor */ virtual ~ImHistoryBrowser();