diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index e446bfdef..67ca8f210 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -341,7 +341,7 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg) message.incoming = false; message.online = true; - if(!isOnline(vpid)) + if(!isOnline(vpid) && !destination.isDistantChatId()) { message.online = false; RsServer::notify()->notifyChatMessage(message); @@ -352,11 +352,15 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg) RsGxsTransId tId = RSRandom::random_u64(); +#ifdef SUSPENDED_CODE + // this part of the code was formerly used to send the traffic over GxsTransport. The problem is that + // gxstunnel takes care of reaching the peer already, so GxsTransport would only be needed when the + // current peer is offline. So we need to fin a way to quickly push the items to friends when quitting RS. + if(destination.isDistantChatId()) { RS_STACK_MUTEX(mDGMutex); - DIDEMap::const_iterator it = - mDistantGxsMap.find(destination.toDistantChatId()); + DIDEMap::const_iterator it = mDistantGxsMap.find(destination.toDistantChatId()); if(it != mDistantGxsMap.end()) { const DistantEndpoints& de(it->second); @@ -371,6 +375,7 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg) << "chat id in mDistantGxsMap this is unxpected!" << std::endl; } +#endif // peer is offline, add to outgoing list { @@ -412,10 +417,10 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg) RsServer::notify()->notifyChatMessage(message); - // cyril: history is temporarily diabled for distant chat, since we need to store the full tunnel ID, but then + // cyril: history is temporarily disabled for distant chat, since we need to store the full tunnel ID, but then // at loading time, the ID is not known so that chat window shows 00000000 as a peer. - if(!message.chat_id.isDistantChatId()) + //if(!message.chat_id.isDistantChatId()) mHistoryMgr->addMessage(message); checkSizeAndSendMessage(ci); @@ -871,10 +876,6 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *& ci) cm.online = true; RsServer::notify()->notifyChatMessage(cm); - // cyril: history is temporarily diabled for distant chat, since we need to store the full tunnel ID, but then - // at loading time, the ID is not known so that chat window shows 00000000 as a peer. - - if(!cm.chat_id.isDistantChatId()) mHistoryMgr->addMessage(cm); return true ; diff --git a/libretroshare/src/gxstunnel/p3gxstunnel.cc b/libretroshare/src/gxstunnel/p3gxstunnel.cc index ba8bcede2..5f75c633b 100644 --- a/libretroshare/src/gxstunnel/p3gxstunnel.cc +++ b/libretroshare/src/gxstunnel/p3gxstunnel.cc @@ -112,6 +112,8 @@ int p3GxsTunnelService::tick() #endif flush() ; + + rstime::rs_usleep(1000*500); return 0 ; } @@ -1294,8 +1296,7 @@ bool p3GxsTunnelService::locked_sendEncryptedTunnelData(RsGxsTunnelItem *item) } if(it->second.status != RS_GXS_TUNNEL_STATUS_CAN_TALK) { - std::cerr << "(EE) Cannot talk to tunnel id " << tunnel_id - << ". Tunnel status is: " << it->second.status << std::endl; + std::cerr << "(EE) Cannot talk to tunnel id " << tunnel_id << ". Tunnel status is: " << it->second.status << std::endl; return false; } diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index fba1711ce..b546da76c 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -48,10 +48,13 @@ p3HistoryMgr::p3HistoryMgr() mPublicEnable = false; mPrivateEnable = true; mLobbyEnable = true; + mDistantEnable = true; mPublicSaveCount = 0; mLobbySaveCount = 0; mPrivateSaveCount = 0; + mDistantSaveCount = 0; + mLastCleanTime = 0 ; mMaxStorageDurationSeconds = 10*86400 ; // store for 10 days at most. @@ -99,11 +102,25 @@ void p3HistoryMgr::addMessage(const ChatMessage& cm) enabled = true; } - if(cm.chat_id.isDistantChatId()) + if(cm.chat_id.isDistantChatId()&& mDistantEnable == true) { DistantChatPeerInfo dcpinfo; if (rsMsgs->getDistantChatStatus(cm.chat_id.toDistantChatId(), dcpinfo)) - peerName = cm.chat_id.toPeerId().toStdString(); + { + RsIdentityDetails det; + RsGxsId writer_id = cm.incoming?(dcpinfo.to_id):(dcpinfo.own_id); + + if(rsIdentity->getIdDetails(writer_id,det)) + peerName = det.mNickname; + else + peerName = writer_id.toStdString(); + } + else + { + RsErr() << "Cannot retrieve friend name for distant chat " << cm.chat_id.toDistantChatId() << std::endl; + peerName = ""; + } + enabled = true; } @@ -258,6 +275,10 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list& saveData) kv.key = "LOBBY_ENABLE"; kv.value = mLobbyEnable ? "TRUE" : "FALSE"; vitem->tlvkvs.pairs.push_back(kv); + + kv.key = "DISTANT_ENABLE"; + kv.value = mDistantEnable ? "TRUE" : "FALSE"; + vitem->tlvkvs.pairs.push_back(kv); kv.key = "MAX_STORAGE_TIME"; rs_sprintf(kv.value,"%d",mMaxStorageDurationSeconds) ; @@ -274,6 +295,10 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list& saveData) kv.key = "PRIVATE_SAVECOUNT"; rs_sprintf(kv.value, "%lu", mPrivateSaveCount); vitem->tlvkvs.pairs.push_back(kv); + + kv.key = "DISTANT_SAVECOUNT"; + rs_sprintf(kv.value, "%lu", mDistantSaveCount); + vitem->tlvkvs.pairs.push_back(kv); saveData.push_back(vitem); saveCleanupList.push_back(vitem); @@ -343,6 +368,11 @@ bool p3HistoryMgr::loadList(std::list& load) mLobbyEnable = (kit->value == "TRUE") ? true : false; continue; } + + if (kit->key == "DISTANT_ENABLE") { + mDistantEnable = (kit->value == "TRUE") ? true : false; + continue; + } if (kit->key == "MAX_STORAGE_TIME") { uint32_t val ; @@ -367,6 +397,10 @@ bool p3HistoryMgr::loadList(std::list& load) mLobbySaveCount = atoi(kit->value.c_str()); continue; } + if (kit->key == "DISTANT_SAVECOUNT") { + mDistantSaveCount = atoi(kit->value.c_str()); + continue; + } } delete (*it); @@ -444,7 +478,7 @@ bool p3HistoryMgr::getMessages(const ChatId &chatId, std::list &msgs if (chatId.isLobbyId() && mLobbyEnable == true) { enabled = true; } - if (chatId.isDistantChatId() && mPrivateEnable == true) { + if (chatId.isDistantChatId() && mDistantEnable == true) { enabled = true; } @@ -586,6 +620,7 @@ bool p3HistoryMgr::getEnable(uint32_t chat_type) case RS_HISTORY_TYPE_PUBLIC : return mPublicEnable ; case RS_HISTORY_TYPE_LOBBY : return mLobbyEnable ; case RS_HISTORY_TYPE_PRIVATE: return mPrivateEnable ; + case RS_HISTORY_TYPE_DISTANT: return mDistantEnable ; default: std::cerr << "Unexpected value " << chat_type<< " in p3HistoryMgr::getEnable(): this is a bug." << std::endl; return 0 ; @@ -623,6 +658,9 @@ void p3HistoryMgr::setEnable(uint32_t chat_type, bool enable) case RS_HISTORY_TYPE_PRIVATE: oldValue = mPrivateEnable ; mPrivateEnable = enable ; break ; + case RS_HISTORY_TYPE_DISTANT: oldValue = mDistantEnable ; + mDistantEnable = enable ; + break ; default: return; } diff --git a/libretroshare/src/pqi/p3historymgr.h b/libretroshare/src/pqi/p3historymgr.h index d18dc5a45..5f4ac0d98 100644 --- a/libretroshare/src/pqi/p3historymgr.h +++ b/libretroshare/src/pqi/p3historymgr.h @@ -82,10 +82,12 @@ private: bool mPublicEnable; bool mLobbyEnable; bool mPrivateEnable; + bool mDistantEnable; uint32_t mPublicSaveCount; uint32_t mLobbySaveCount; uint32_t mPrivateSaveCount; + uint32_t mDistantSaveCount; uint32_t mMaxStorageDurationSeconds ; rstime_t mLastCleanTime ; diff --git a/libretroshare/src/retroshare/rshistory.h b/libretroshare/src/retroshare/rshistory.h index eff72e237..16f942339 100644 --- a/libretroshare/src/retroshare/rshistory.h +++ b/libretroshare/src/retroshare/rshistory.h @@ -39,6 +39,7 @@ extern RsHistory *rsHistory; 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 ; +static const uint32_t RS_HISTORY_TYPE_DISTANT = 3 ; class HistoryMsg { diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index bb7352ffd..cca487b59 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -363,8 +363,8 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title) QString customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(chatId.toPeerId()).c_str()); updatePeersCustomStateString(QString::fromStdString(chatId.toPeerId().toStdString()), customStateString); } else if (chatType() == CHATTYPE_DISTANT){ - hist_chat_type = RS_HISTORY_TYPE_PRIVATE ; - messageCount = Settings->getPrivateChatHistoryCount(); + hist_chat_type = RS_HISTORY_TYPE_DISTANT ; + messageCount = Settings->getDistantChatHistoryCount(); } else if(chatId.isBroadcast()){ hist_chat_type = RS_HISTORY_TYPE_PUBLIC; messageCount = Settings->getPublicChatHistoryCount(); @@ -435,8 +435,8 @@ ChatWidget::ChatType ChatWidget::chatType() void ChatWidget::blockSending(QString msg) { #ifndef RS_ASYNC_CHAT - sendingBlocked = true; - ui->sendButton->setEnabled(false); +// sendingBlocked = true; +// ui->sendButton->setEnabled(false); #endif ui->sendButton->setToolTip(msg); } diff --git a/retroshare-gui/src/gui/settings/ChatPage.cpp b/retroshare-gui/src/gui/settings/ChatPage.cpp index 1c54000bc..a17aa57d4 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.cpp +++ b/retroshare-gui/src/gui/settings/ChatPage.cpp @@ -166,14 +166,18 @@ void ChatPage::updateHistoryParams() Settings->setPublicChatHistoryCount(ui.publicChatLoadCount->value()); Settings->setPrivateChatHistoryCount(ui.privateChatLoadCount->value()); Settings->setLobbyChatHistoryCount(ui.lobbyChatLoadCount->value()); + Settings->setDistantChatHistoryCount(ui.distantChatLoadCount->value()); 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->setEnable(RS_HISTORY_TYPE_DISTANT, ui.distantChatEnable->isChecked()); 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()); + rsHistory->setSaveCount(RS_HISTORY_TYPE_DISTANT, ui.distantChatSaveCount->value()); + } void ChatPage::updatePublicStyle() @@ -247,13 +251,19 @@ ChatPage::ChatPage(QWidget * parent, Qt::WindowFlags flags) connect(ui.publicChatLoadCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); connect(ui.privateChatLoadCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); + connect(ui.distantChatLoadCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); connect(ui.lobbyChatLoadCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); + connect(ui.publicChatEnable, SIGNAL(toggled(bool)), this, SLOT(updateHistoryParams())); connect(ui.privateChatEnable, SIGNAL(toggled(bool)), this, SLOT(updateHistoryParams())); + connect(ui.distantChatEnable, SIGNAL(toggled(bool)), this, SLOT(updateHistoryParams())); connect(ui.lobbyChatEnable, SIGNAL(toggled(bool)), this, SLOT(updateHistoryParams())); + connect(ui.publicChatSaveCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); connect(ui.privateChatSaveCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); connect(ui.lobbyChatSaveCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); + connect(ui.distantChatSaveCount, SIGNAL(valueChanged(int)), this, SLOT(updateHistoryParams())); + connect(ui.publicStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePublicStyle())) ; connect(ui.publicComboBoxVariant, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePublicStyle())) ; @@ -349,14 +359,18 @@ ChatPage::load() whileBlocking(ui.publicChatLoadCount)->setValue(Settings->getPublicChatHistoryCount()); whileBlocking(ui.privateChatLoadCount)->setValue(Settings->getPrivateChatHistoryCount()); whileBlocking(ui.lobbyChatLoadCount)->setValue(Settings->getLobbyChatHistoryCount()); + whileBlocking(ui.distantChatLoadCount)->setValue(Settings->getDistantChatHistoryCount()); whileBlocking(ui.publicChatEnable)->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_PUBLIC)); whileBlocking(ui.privateChatEnable)->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_PRIVATE)); whileBlocking(ui.lobbyChatEnable)->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_LOBBY)); + whileBlocking(ui.distantChatEnable)->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_DISTANT)); whileBlocking(ui.publicChatSaveCount)->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PUBLIC)); whileBlocking(ui.privateChatSaveCount)->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PRIVATE)); whileBlocking(ui.lobbyChatSaveCount)->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_LOBBY)); + whileBlocking(ui.distantChatSaveCount)->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_DISTANT)); + // using fontTempChat.rawname() does not always work! // see http://doc.qt.digia.com/qt-maemo/qfont.html#rawName diff --git a/retroshare-gui/src/gui/settings/ChatPage.ui b/retroshare-gui/src/gui/settings/ChatPage.ui index 1d18eb42f..9484cc4c6 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.ui +++ b/retroshare-gui/src/gui/settings/ChatPage.ui @@ -6,8 +6,8 @@ 0 0 - 1216 - 1127 + 800 + 600 @@ -598,8 +598,21 @@ - - + + + + Qt::LeftToRight + + + Enabled: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + 75 @@ -607,7 +620,7 @@ - Group chat + Chatlobbies @@ -624,8 +637,8 @@ - - + + 75 @@ -633,20 +646,7 @@ - Chatlobbies - - - - - - - Qt::LeftToRight - - - Enabled: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Group chat @@ -657,20 +657,6 @@ - - - - - - - - - - - - - - @@ -681,6 +667,13 @@ + + + + + + + @@ -700,27 +693,15 @@ - - - - - 60 - 16777215 - - - + + + - - - - - 1000000000 - - - + + 60 @@ -761,6 +742,25 @@ + + + + + 60 + 16777215 + + + + + + + + + + 1000000000 + + + @@ -774,7 +774,7 @@ - + @@ -787,6 +787,32 @@ + + + + + 75 + true + + + + Distant chat + + + + + + + + + + + + + + + + @@ -866,7 +892,7 @@ QTabWidget::North - 2 + 0 diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index f63341e7a..873438d70 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -728,6 +728,16 @@ void RshareSettings::setPrivateChatHistoryCount(int value) setValueToGroup("Chat", "PrivateChatHistoryCount", value); } +int RshareSettings::getDistantChatHistoryCount() +{ + return valueFromGroup("Chat", "DistantChatHistoryCount", 20).toInt(); +} + +void RshareSettings::setDistantChatHistoryCount(int value) +{ + setValueToGroup("Chat", "DistantChatHistoryCount", value); +} + /** Returns true if RetroShare is set to run on system boot. */ bool RshareSettings::runRetroshareOnBoot(bool &minimized) diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index 1102fe28b..32f9f169f 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -273,6 +273,9 @@ public: int getLobbyChatHistoryCount(); void setLobbyChatHistoryCount(int value); + + int getDistantChatHistoryCount(); + void setDistantChatHistoryCount(int value); //! Save placement, state and size information of a window. void saveWidgetInformation(QWidget *widget);