diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index 01d365b4b..e8ef5b8ed 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -31,6 +31,10 @@ #include "serialiser/rsmsgitems.h" #include "util/rsstring.h" +// clean too old messages every 5 minutes +// +#define MSG_HISTORY_CLEANING_PERIOD 300 + RsHistory *rsHistory = NULL; p3HistoryMgr::p3HistoryMgr() @@ -40,9 +44,14 @@ p3HistoryMgr::p3HistoryMgr() mPublicEnable = false; mPrivateEnable = true; + mLobbyEnable = true; - mPublicSaveCount = 0; + mPublicSaveCount = 0; + mLobbySaveCount = 0; mPrivateSaveCount = 0; + mLastCleanTime = 0 ; + + mMaxStorageDurationSeconds = 10*86400 ; // store for 10 days at most. } p3HistoryMgr::~p3HistoryMgr() @@ -55,6 +64,14 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons { uint32_t addMsgId = 0; + time_t now = time(NULL) ; + + if(mLastCleanTime + MSG_HISTORY_CLEANING_PERIOD < now) + { + cleanOldMessages() ; + mLastCleanTime = now ; + } + { RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ @@ -65,13 +82,15 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons const RsChatLobbyMsgItem *cli = dynamic_cast(chatItem); - if (cli) { - // there is currently no setting for chat lobbies - } else { - if (mPrivateEnable == false && chatPeerId.empty() == false) { - // private chat not enabled + if (cli) + { + if (mLobbyEnable == false && !chatPeerId.empty()) // lobby chat not enabled + return; + } + else + { + if (mPrivateEnable == false && !chatPeerId.empty()) // private chat not enabled return; - } } RsHistoryMsgItem* item = new RsHistoryMsgItem; @@ -97,16 +116,12 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons // check the limit uint32_t limit; - if (chatPeerId.empty()) { + if (chatPeerId.empty()) limit = mPublicSaveCount; - } else { - if (cli) { - // there is currently no setting for chat lobbies - limit = 0; - } else { - limit = mPrivateSaveCount; - } - } + else if (cli) + limit = mLobbySaveCount; + else + limit = mPrivateSaveCount; if (limit) { while (mit->second.size() > limit) { @@ -132,6 +147,51 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons } } +void p3HistoryMgr::cleanOldMessages() +{ + RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "****** cleaning old messages." << std::endl; + time_t now = time(NULL) ; + bool changed = false ; + + for(std::map >::iterator mit = mMessages.begin(); mit != mMessages.end();) + { + for(std::map::iterator lit = mit->second.begin();lit!=mit->second.end();) + if(lit->second->recvTime + mMaxStorageDurationSeconds < now) + { + std::map::iterator lit2 = lit ; + ++lit2 ; + + std::cerr << " removing msg id " << lit->first << ", for peer id " << mit->first << std::endl; + delete lit->second ; + + mit->second.erase(lit) ; + lit = lit2 ; + + changed = true ; + } + else + ++lit ; + + if(mit->second.empty()) + { + std::map >::iterator mit2 = mit ; + ++mit2 ; + std::cerr << " removing peer id " << mit->first << ", since it has no messages" << std::endl; + mMessages.erase(mit) ; + mit = mit2 ; + + changed = true ; + } + else + ++mit ; + } + + if(changed) + IndicateConfigChanged() ; +} + /***** p3Config *****/ RsSerialiser* p3HistoryMgr::setupSerialiser() @@ -170,6 +230,18 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list& saveData) kv.value = mPrivateEnable ? "TRUE" : "FALSE"; vitem->tlvkvs.pairs.push_back(kv); + kv.key = "LOBBY_ENABLE"; + kv.value = mLobbyEnable ? "TRUE" : "FALSE"; + vitem->tlvkvs.pairs.push_back(kv); + + kv.key = "MAX_STORAGE_TIME"; + rs_sprintf(kv.value,"%d",mMaxStorageDurationSeconds) ; + vitem->tlvkvs.pairs.push_back(kv); + + kv.key = "LOBBY_SAVECOUNT"; + rs_sprintf(kv.value, "%lu", mLobbySaveCount); + vitem->tlvkvs.pairs.push_back(kv); + kv.key = "PUBLIC_SAVECOUNT"; rs_sprintf(kv.value, "%lu", mPublicSaveCount); vitem->tlvkvs.pairs.push_back(kv); @@ -207,8 +279,12 @@ bool p3HistoryMgr::loadList(std::list& load) for (it = load.begin(); it != load.end(); it++) { if (NULL != (msgItem = dynamic_cast(*it))) { + std::map >::iterator mit = mMessages.find(msgItem->chatPeerId); msgItem->msgId = nextMsgId++; + + std::cerr << "Loading msg history item: peer id=" << msgItem->chatPeerId << "), msg id =" << msgItem->msgId << std::endl; + if (mit != mMessages.end()) { mit->second.insert(std::make_pair(msgItem->msgId, msgItem)); } else { @@ -235,6 +311,20 @@ bool p3HistoryMgr::loadList(std::list& load) continue; } + if (kit->key == "LOBBY_ENABLE") { + mLobbyEnable = (kit->value == "TRUE") ? true : false; + continue; + } + + if (kit->key == "MAX_STORAGE_TIME") { + uint32_t val ; + if (sscanf(kit->value.c_str(), "%d", &val) == 1) + mMaxStorageDurationSeconds = val ; + + std::cerr << "Loaded max storage time for history = " << val << " seconds" << std::endl; + continue; + } + if (kit->key == "PUBLIC_SAVECOUNT") { mPublicSaveCount = atoi(kit->value.c_str()); continue; @@ -243,6 +333,10 @@ bool p3HistoryMgr::loadList(std::list& load) mPrivateSaveCount = atoi(kit->value.c_str()); continue; } + if (kit->key == "LOBBY_SAVECOUNT") { + mLobbySaveCount = atoi(kit->value.c_str()); + continue; + } } delete (*it); @@ -270,40 +364,35 @@ static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg) msg.message = item->message; } -//static void convertMsg(const HistoryMsg &msg, RsHistoryMsgItem* item) -//{ -// item->msgId = msg.msgId; -// item->chatPeerId = msg.chatPeerId; -// item->incoming = msg.incoming; -// item->peerId = msg.peerId; -// item->peerName = msg.peerName; -// item->sendTime = msg.sendTime; -// item->recvTime = msg.recvTime; -// item->message = msg.message; -//} - bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list &msgs, uint32_t loadCount) { msgs.clear(); RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ - if (mPublicEnable == false && chatPeerId.empty()) { + std::cerr << "Getting history for peer " << chatPeerId << std::endl; + + if (mPublicEnable == false && chatPeerId.empty()) { // chatPeerId.empty() means it's public chat // public chat not enabled return false; } - if (mPrivateEnable == false && chatPeerId.empty() == false) { - // private chat not enabled + if (mPrivateEnable == false && chatPeerId.empty() == false) // private chat not enabled + return false; + + if (mLobbyEnable == false && chatPeerId.empty() == false) // private chat not enabled return false; - } uint32_t foundCount = 0; std::map >::iterator mit = mMessages.find(chatPeerId); - if (mit != mMessages.end()) { + + if (mit != mMessages.end()) + { std::map::reverse_iterator lit; - for (lit = mit->second.rbegin(); lit != mit->second.rend(); lit++) { + + for (lit = mit->second.rbegin(); lit != mit->second.rend(); lit++) + { HistoryMsg msg; convertMsg(lit->second, msg); msgs.insert(msgs.begin(), msg); @@ -313,6 +402,7 @@ bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list >::iterator mit = mMessages.find(chatPeerId); if (mit == mMessages.end()) { return; @@ -362,6 +454,7 @@ void p3HistoryMgr::removeMessages(const std::list &msgIds) std::list removedIds; std::list::iterator iit; + std::cerr << "********** p3History::removeMessages called()" << std::endl; { RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ @@ -374,6 +467,7 @@ void p3HistoryMgr::removeMessages(const std::list &msgIds) delete(lit->second); mit->second.erase(lit); + std::cerr << "**** Removing " << mit->first << " msg id = " << lit->first << std::endl; removedIds.push_back(*iit); iit = ids.erase(iit); @@ -398,46 +492,88 @@ void p3HistoryMgr::removeMessages(const std::list &msgIds) } } -bool p3HistoryMgr::getEnable(bool ofPublic) +bool p3HistoryMgr::getEnable(uint32_t chat_type) { - return ofPublic ? mPublicEnable : mPrivateEnable; + switch(chat_type) + { + case RS_HISTORY_TYPE_PUBLIC : return mPublicEnable ; + case RS_HISTORY_TYPE_LOBBY : return mLobbyEnable ; + case RS_HISTORY_TYPE_PRIVATE: return mPrivateEnable ; + default: + std::cerr << "Unexpected value " << chat_type<< " in p3HistoryMgr::getEnable(): this is a bug." << std::endl; + return 0 ; + } } -void p3HistoryMgr::setEnable(bool forPublic, bool enable) +uint32_t p3HistoryMgr::getMaxStorageDuration() +{ + return mMaxStorageDurationSeconds ; +} + + +void p3HistoryMgr::setMaxStorageDuration(uint32_t seconds) +{ + if(mMaxStorageDurationSeconds != seconds) + IndicateConfigChanged() ; + + mMaxStorageDurationSeconds = seconds ; +} + +void p3HistoryMgr::setEnable(uint32_t chat_type, bool enable) { bool oldValue; - if (forPublic) { - oldValue = mPublicEnable; - mPublicEnable = enable; - } else { - oldValue = mPrivateEnable; - mPrivateEnable = enable; + switch(chat_type) + { + case RS_HISTORY_TYPE_PUBLIC : oldValue = mPublicEnable ; + mPublicEnable = enable ; + break ; + + case RS_HISTORY_TYPE_LOBBY : oldValue = mLobbyEnable ; + mLobbyEnable = enable; + break ; + + case RS_HISTORY_TYPE_PRIVATE: oldValue = mPrivateEnable ; + mPrivateEnable = enable ; + break ; } - if (oldValue != enable) { + if (oldValue != enable) IndicateConfigChanged(); +} + +uint32_t p3HistoryMgr::getSaveCount(uint32_t chat_type) +{ + switch(chat_type) + { + case RS_HISTORY_TYPE_PUBLIC : return mPublicSaveCount ; + case RS_HISTORY_TYPE_LOBBY : return mLobbySaveCount ; + case RS_HISTORY_TYPE_PRIVATE: return mPrivateSaveCount ; + default: + std::cerr << "Unexpected value " << chat_type<< " in p3HistoryMgr::getSaveCount(): this is a bug." << std::endl; + return 0 ; } } -uint32_t p3HistoryMgr::getSaveCount(bool ofPublic) -{ - return ofPublic ? mPublicSaveCount : mPrivateSaveCount; -} - -void p3HistoryMgr::setSaveCount(bool forPublic, uint32_t count) +void p3HistoryMgr::setSaveCount(uint32_t chat_type, uint32_t count) { uint32_t oldValue; - if (forPublic) { - oldValue = mPublicSaveCount; - mPublicSaveCount = count; - } else { - oldValue = mPrivateSaveCount; - mPrivateSaveCount = count; + switch(chat_type) + { + case RS_HISTORY_TYPE_PUBLIC : oldValue = mPublicSaveCount ; + mPublicSaveCount = count ; + break ; + + case RS_HISTORY_TYPE_LOBBY : oldValue = mLobbySaveCount ; + mLobbySaveCount = count; + break ; + + case RS_HISTORY_TYPE_PRIVATE: oldValue = mPrivateSaveCount ; + mPrivateSaveCount = count ; + break ; } - if (oldValue != count) { + if (oldValue != count) IndicateConfigChanged(); - } } diff --git a/libretroshare/src/pqi/p3historymgr.h b/libretroshare/src/pqi/p3historymgr.h index 7a4bac10a..038d1bbac 100644 --- a/libretroshare/src/pqi/p3historymgr.h +++ b/libretroshare/src/pqi/p3historymgr.h @@ -56,10 +56,13 @@ public: bool getMessage(uint32_t msgId, HistoryMsg &msg); void clear(const std::string &chatPeerId); void removeMessages(const std::list &msgIds); - bool getEnable(bool ofPublic); - void setEnable(bool forPublic, bool enable); - uint32_t getSaveCount(bool ofPublic); - void setSaveCount(bool forPublic, uint32_t count); + + virtual bool getEnable(uint32_t chat_type); + virtual void setEnable(uint32_t chat_type, bool enable); + 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() ; /********* p3config ************/ @@ -72,12 +75,22 @@ private: uint32_t nextMsgId; std::map > mMessages; + // Removes messages stored for more than mMaxMsgStorageDurationSeconds seconds. + // This avoids the stored list to grow crazy with time. + // + void cleanOldMessages() ; + bool mPublicEnable; + bool mLobbyEnable; bool mPrivateEnable; uint32_t mPublicSaveCount; + uint32_t mLobbySaveCount; uint32_t mPrivateSaveCount; + uint32_t mMaxStorageDurationSeconds ; + time_t mLastCleanTime ; + std::list saveCleanupList; /* TEMPORARY LIST WHEN SAVING */ RsMutex mHistoryMtx; diff --git a/libretroshare/src/retroshare/rshistory.h b/libretroshare/src/retroshare/rshistory.h index 0f85143ce..2c6f8366e 100644 --- a/libretroshare/src/retroshare/rshistory.h +++ b/libretroshare/src/retroshare/rshistory.h @@ -38,6 +38,10 @@ extern RsHistory *rsHistory; /*! * data object used for message history */ +static const uint32_t RS_HISTORY_TYPE_PUBLIC = 0 ; +static const uint32_t RS_HISTORY_TYPE_PRIVATE = 1 ; +static const uint32_t RS_HISTORY_TYPE_LOBBY = 2 ; + class HistoryMsg { public: @@ -72,12 +76,14 @@ public: virtual void removeMessages(const std::list &msgIds) = 0; virtual void clear(const std::string &chatPeerId) = 0; - virtual bool getEnable(bool ofPublic) = 0; - virtual void setEnable(bool forPublic, bool enable) = 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 ; // 0 = no limit, >0 count of saved messages - virtual uint32_t getSaveCount(bool ofPublic) = 0; - virtual void setSaveCount(bool forPublic, uint32_t count) = 0; + virtual uint32_t getSaveCount(uint32_t chat_type) = 0; + virtual void setSaveCount(uint32_t chat_type, uint32_t count) = 0; }; #endif diff --git a/libretroshare/src/rsserver/p3history.cc b/libretroshare/src/rsserver/p3history.cc index 7fc1f35f0..68e4c134d 100644 --- a/libretroshare/src/rsserver/p3history.cc +++ b/libretroshare/src/rsserver/p3history.cc @@ -36,6 +36,14 @@ p3History::~p3History() { } +void p3History::setMaxStorageDuration(uint32_t seconds) +{ + mHistoryMgr->setMaxStorageDuration(seconds) ; +} +uint32_t p3History::getMaxStorageDuration() +{ + return mHistoryMgr->getMaxStorageDuration() ; +} bool p3History::getMessages(const std::string &chatPeerId, std::list &msgs, const uint32_t loadCount) { return mHistoryMgr->getMessages(chatPeerId, msgs, loadCount); @@ -56,22 +64,22 @@ void p3History::clear(const std::string &chatPeerId) mHistoryMgr->clear(chatPeerId); } -bool p3History::getEnable(bool ofPublic) +bool p3History::getEnable(uint32_t chat_type) { - return mHistoryMgr->getEnable(ofPublic); + return mHistoryMgr->getEnable(chat_type); } -void p3History::setEnable(bool forPublic, bool enable) +void p3History::setEnable(uint32_t chat_type, bool enable) { - mHistoryMgr->setEnable(forPublic, enable); + mHistoryMgr->setEnable(chat_type, enable); } -uint32_t p3History::getSaveCount(bool ofPublic) +uint32_t p3History::getSaveCount(uint32_t chat_type) { - return mHistoryMgr->getSaveCount(ofPublic); + return mHistoryMgr->getSaveCount(chat_type); } -void p3History::setSaveCount(bool forPublic, uint32_t count) +void p3History::setSaveCount(uint32_t chat_type, uint32_t count) { - mHistoryMgr->setSaveCount(forPublic, count); + mHistoryMgr->setSaveCount(chat_type, count); } diff --git a/libretroshare/src/rsserver/p3history.h b/libretroshare/src/rsserver/p3history.h index 8c76644d2..50b2b4a80 100644 --- a/libretroshare/src/rsserver/p3history.h +++ b/libretroshare/src/rsserver/p3history.h @@ -45,10 +45,12 @@ public: virtual bool getMessage(uint32_t msgId, HistoryMsg &msg); virtual void removeMessages(const std::list &msgIds); virtual void clear(const std::string &chatPeerId); - virtual bool getEnable(bool ofPublic); - virtual void setEnable(bool forPublic, bool enable); - virtual uint32_t getSaveCount(bool ofPublic); - virtual void setSaveCount(bool forPublic, uint32_t count); + virtual bool getEnable(uint32_t chat_type); + virtual void setEnable(uint32_t chat_type, bool enable); + 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() ; private: p3HistoryMgr* mHistoryMgr; diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 87e66cbbc..e42c58b5a 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -1151,12 +1151,12 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca) bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci) { // Remove too big messages - if (ci->message.length() > 2000 && (ci->chatFlags & RS_CHAT_FLAG_LOBBY)) + if (ci->message.length() > 6000 && (ci->chatFlags & RS_CHAT_FLAG_LOBBY)) { wchar_t tmp[300]; mbstowcs(tmp, rsPeers->getPeerName(ci->PeerId()).c_str(), 299); - ci->message = std::wstring(L"**** Security warning: Message bigger than 2000 characters, coming from id ") + tmp + L", dropped. ****"; + ci->message = std::wstring(L"**** Security warning: Message bigger than 6000 characters, forwarded to you by ") + tmp + L", dropped. ****"; return false; } @@ -2892,7 +2892,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id) // remove history - mHistoryMgr->clear(it->second.virtual_peer_id); + //mHistoryMgr->clear(it->second.virtual_peer_id); // remove lobby information diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 3fff5a757..a00dd8f66 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -202,17 +202,21 @@ void ChatWidget::init(const std::string &peerId, const QString &title) updateTitle(); } - if (rsHistory->getEnable(false)) { + uint32_t hist_chat_type = isChatLobby?RS_HISTORY_TYPE_LOBBY:RS_HISTORY_TYPE_PRIVATE ; + int messageCount = isChatLobby?(Settings->getLobbyChatHistoryCount()):(Settings->getPrivateChatHistoryCount()); + + if (rsHistory->getEnable(hist_chat_type)) + { // get chat messages from history std::list historyMsgs; - int messageCount = Settings->getPrivateChatHistoryCount(); - if (messageCount > 0) { + + if (messageCount > 0) + { rsHistory->getMessages(peerId, historyMsgs, messageCount); std::list::iterator historyIt; - for (historyIt = historyMsgs.begin(); historyIt != historyMsgs.end(); historyIt++) { + for (historyIt = historyMsgs.begin(); historyIt != historyMsgs.end(); historyIt++) addChatMsg(historyIt->incoming, QString::fromUtf8(historyIt->peerName.c_str()), QDateTime::fromTime_t(historyIt->sendTime), QDateTime::fromTime_t(historyIt->recvTime), QString::fromUtf8(historyIt->message.c_str()), TYPE_HISTORY); - } } } diff --git a/retroshare-gui/src/gui/settings/ChatPage.cpp b/retroshare-gui/src/gui/settings/ChatPage.cpp index b697af116..d9ec376c4 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.cpp +++ b/retroshare-gui/src/gui/settings/ChatPage.cpp @@ -266,12 +266,15 @@ ChatPage::save(QString &/*errmsg*/) Settings->setPublicChatHistoryCount(ui.publicChatLoadCount->value()); Settings->setPrivateChatHistoryCount(ui.privateChatLoadCount->value()); + Settings->setLobbyChatHistoryCount(ui.lobbyChatLoadCount->value()); - rsHistory->setEnable(true, ui.publicChatEnable->isChecked()); - rsHistory->setEnable(false, ui.privateChatEnable->isChecked()); + rsHistory->setEnable(RS_HISTORY_TYPE_PUBLIC , ui.publicChatEnable->isChecked()); + rsHistory->setEnable(RS_HISTORY_TYPE_PRIVATE, ui.privateChatEnable->isChecked()); + rsHistory->setEnable(RS_HISTORY_TYPE_LOBBY , ui.lobbyChatEnable->isChecked()); - rsHistory->setSaveCount(true, ui.publicChatSaveCount->value()); - rsHistory->setSaveCount(false, ui.privateChatSaveCount->value()); + rsHistory->setSaveCount(RS_HISTORY_TYPE_PUBLIC , ui.publicChatSaveCount->value()); + rsHistory->setSaveCount(RS_HISTORY_TYPE_PRIVATE, ui.privateChatSaveCount->value()); + rsHistory->setSaveCount(RS_HISTORY_TYPE_LOBBY , ui.lobbyChatSaveCount->value()); rsMsgs->setDefaultNickNameForChatLobby(ui.chatLobbyNick_LE->text().toUtf8().constData()) ; @@ -303,6 +306,8 @@ ChatPage::save(QString &/*errmsg*/) } } + rsHistory->setMaxStorageDuration(ui.max_storage_period->value() * 86400) ; + uint chatflags = 0; if (ui.chat_NewWindow->isChecked()) @@ -346,16 +351,21 @@ ChatPage::load() ui.publicChatLoadCount->setValue(Settings->getPublicChatHistoryCount()); ui.privateChatLoadCount->setValue(Settings->getPrivateChatHistoryCount()); + ui.lobbyChatLoadCount->setValue(Settings->getLobbyChatHistoryCount()); - ui.publicChatEnable->setChecked(rsHistory->getEnable(true)); - ui.privateChatEnable->setChecked(rsHistory->getEnable(false)); + ui.publicChatEnable->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_PUBLIC)); + ui.privateChatEnable->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_PRIVATE)); + ui.lobbyChatEnable->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_LOBBY)); - ui.publicChatSaveCount->setValue(rsHistory->getSaveCount(true)); - ui.privateChatSaveCount->setValue(rsHistory->getSaveCount(false)); + ui.publicChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PUBLIC)); + ui.privateChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PRIVATE)); + ui.lobbyChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_LOBBY)); ui.labelChatFontPreview->setText(fontTempChat.rawName()); ui.labelChatFontPreview->setFont(fontTempChat); + ui.max_storage_period->setValue(rsHistory->getMaxStorageDuration()/86400) ; + /* Load styles */ publicStylePath = loadStyleInfo(ChatStyle::TYPE_PUBLIC, ui.publicList, ui.publicComboBoxVariant, publicStyleVariant); privateStylePath = loadStyleInfo(ChatStyle::TYPE_PRIVATE, ui.privateList, ui.privateComboBoxVariant, privateStyleVariant); diff --git a/retroshare-gui/src/gui/settings/ChatPage.ui b/retroshare-gui/src/gui/settings/ChatPage.ui index c59611962..a95a538e4 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.ui +++ b/retroshare-gui/src/gui/settings/ChatPage.ui @@ -6,15 +6,15 @@ 0 0 - 646 - 412 + 606 + 477 - + - 0 + 2 @@ -420,65 +420,267 @@ - - - Group Chat + + + + 0 + 0 + - - - - - Enable - - - - - - - + + <html><head/><body><p align="justify">In this tab you can setup how many chat messages Retroshare will keep saved on the disc and how much of the previous conversation it will display, for the different chat systems. The max storage period allows to discard old messages and prevents the chat history from filling up with volatile chat (e.g. chat lobbies and distant chat).</p></body></html> + + + Qt::RichText + + + true + + + true + + + + + + + + + + + + 75 + true + + + + Group chat + + + + + + + + 75 + true + + + + Private chat + + + + + + + + 75 + true + + + + Chatlobbies + + + + + + + Qt::LeftToRight + + + Enabled: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + + + + + + + + + + + Saved messages (0 = unlimited): + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 60 + 16777215 + + + + + + + + + + 1000000000 + + + + + + + + 60 + 16777215 + + + + + + + + + + 1000000000 + + + + + + + + 60 + 16777215 + + + + + + + + + + 1000000000 + + + + + + + Number of messages restored (0 = off): + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 60 + 16777215 + + + + 20 + + + + + + + + 60 + 16777215 + + + + 20 + + + + + + + + 60 + 16777215 + + + + 20 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + General + + + + + + - Number of saved messages (0 = unlimited) + Maximum storage period, in days: - - - + + + + + + + Qt::Horizontal + + - 60 - 16777215 + 40 + 20 - - - - - - - - 1000000000 - - - - - - - - 60 - 16777215 - - - - 20 - - - - - - - Load number of messages (0 = off) - - + @@ -486,80 +688,14 @@ - - - Private Chat - - - - - - Enable - - - - - - - - - Number of saved messages (0 = unlimited) - - - - - - - - 60 - 16777215 - - - - - - - - - - 1000000000 - - - - - - - - 60 - 16777215 - - - - 20 - - - - - - - Load number of messages (0 = off) - - - - - - - - - - + Qt::Vertical - 176 - 480 + 20 + 40 diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index 972ad6762..70f991541 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -462,7 +462,15 @@ void RshareSettings::setHistoryChatStyle(const QString &stylePath, const QString setValueToGroup("Chat", "StyleHistory", stylePath); setValueToGroup("Chat", "StylePrivateVariant", styleVariant); } +int RshareSettings::getLobbyChatHistoryCount() +{ + return valueFromGroup("Chat", "LobbyChatHistoryCount", 0).toInt(); +} +void RshareSettings::setLobbyChatHistoryCount(int value) +{ + setValueToGroup("Chat", "LobbyChatHistoryCount", value); +} int RshareSettings::getPublicChatHistoryCount() { return valueFromGroup("Chat", "PublicChatHistoryCount", 0).toInt(); diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index fea1eb7db..673046c54 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -216,6 +216,9 @@ public: int getPrivateChatHistoryCount(); void setPrivateChatHistoryCount(int value); + int getLobbyChatHistoryCount(); + void setLobbyChatHistoryCount(int value); + //! Save placement, state and size information of a window. void saveWidgetInformation(QWidget *widget);