Moved the chat history into the libretroshare.

Now the history is saved encrypted. Please delete all files with "chat*.xml" in your profile folder.
Added new config p3HistoryMgr and interface p3History.
Added new option to limit the count of the saved history items.
Added new simple html optimizer "RsHtml::optimizeHtml" to reduce the size of the html strings.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4623 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-09-29 09:20:09 +00:00
parent c6a68fe05e
commit 29c090fb44
45 changed files with 1721 additions and 1406 deletions

View file

@ -48,7 +48,7 @@
class p3PeerMgrIMPL;
class p3LinkMgrIMPL;
class p3NetMgrIMPL;
class p3HistoryMgr;
/* The Main Interface Class - for controlling the server */
@ -157,6 +157,7 @@ class RsServer: public RsControl, public RsThread
p3PeerMgrIMPL *mPeerMgr;
p3LinkMgrIMPL *mLinkMgr;
p3NetMgrIMPL *mNetMgr;
p3HistoryMgr *mHistoryMgr;
pqipersongrp *pqih;

View file

@ -0,0 +1,77 @@
/*
* libretroshare/src/rsserver: p3history.h
*
* RetroShare C++ Interface.
*
* Copyright 2011 by Thunder.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "p3history.h"
#include "pqi/p3historymgr.h"
p3History::p3History(p3HistoryMgr* historyMgr)
: mHistoryMgr(historyMgr)
{
}
p3History::~p3History()
{
}
bool p3History::getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, const uint32_t loadCount)
{
return mHistoryMgr->getMessages(chatPeerId, msgs, loadCount);
}
bool p3History::getMessage(uint32_t msgId, HistoryMsg &msg)
{
return mHistoryMgr->getMessage(msgId, msg);
}
void p3History::removeMessages(const std::list<uint32_t> &msgIds)
{
mHistoryMgr->removeMessages(msgIds);
}
void p3History::clear(const std::string &chatPeerId)
{
mHistoryMgr->clear(chatPeerId);
}
bool p3History::getEnable(bool ofPublic)
{
return mHistoryMgr->getEnable(ofPublic);
}
void p3History::setEnable(bool forPublic, bool enable)
{
mHistoryMgr->setEnable(forPublic, enable);
}
uint32_t p3History::getSaveCount(bool ofPublic)
{
return mHistoryMgr->getSaveCount(ofPublic);
}
void p3History::setSaveCount(bool forPublic, uint32_t count)
{
mHistoryMgr->setSaveCount(forPublic, count);
}

View file

@ -0,0 +1,57 @@
#ifndef RS_P3HISTORY_INTERFACE_H
#define RS_P3HISTORY_INTERFACE_H
/*
* libretroshare/src/rsserver: p3history.h
*
* RetroShare C++ Interface.
*
* Copyright 2011 by Thunder.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "retroshare/rshistory.h"
class p3HistoryMgr;
//! Implements abstract interface rsHistory
/*!
* Interfaces with p3HistoryMsg
*/
class p3History : public RsHistory
{
public:
p3History(p3HistoryMgr* historyMgr);
virtual ~p3History();
virtual bool getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
virtual bool getMessage(uint32_t msgId, HistoryMsg &msg);
virtual void removeMessages(const std::list<uint32_t> &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);
private:
p3HistoryMgr* mHistoryMgr;
};
#endif /* RS_P3HISTORY_INTERFACE_H */

View file

@ -50,6 +50,28 @@ RsMsgs *rsMsgs = NULL;
/****************************************/
/****************************************/
std::ostream &operator<<(std::ostream &out, const ChatInfo &info)
{
out << "ChatInfo: rsid: " << info.rsid << std::endl;
out << "chatflags: " << info.chatflags << std::endl;
out << "sendTime: " << info.sendTime << std::endl;
out << "recvTime: " << info.recvTime << std::endl;
std::string message;
message.assign(info.msg.begin(), info.msg.end());
out << "msg: " << message;
return out;
}
bool operator==(const ChatInfo& info1, const ChatInfo& info2)
{
return info1.rsid == info2.rsid &&
info1.chatflags == info2.chatflags &&
info1.sendTime == info2.sendTime &&
info1.recvTime == info2.recvTime &&
info1.msg == info2.msg;
}
bool p3Msgs::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
{
return mMsgSrv->getMessageSummaries(msgList);
@ -156,13 +178,13 @@ bool p3Msgs::resetMessageStandardTagTypes(MsgTagType& tags)
/****************************************/
/****************************************/
bool p3Msgs::sendPublicChat(std::wstring msg)
bool p3Msgs::sendPublicChat(const std::wstring& msg)
{
/* send a message to all for now */
return mChatSrv -> sendPublicChat(msg);
}
bool p3Msgs::sendPrivateChat(std::string id, std::wstring msg)
bool p3Msgs::sendPrivateChat(const std::string& id, const std::wstring& msg)
{
/* send a message to peer */
return mChatSrv -> sendPrivateChat(id, msg);
@ -172,9 +194,10 @@ void p3Msgs::sendGroupChatStatusString(const std::string& status_string)
{
mChatSrv->sendGroupChatStatusString(status_string);
}
void p3Msgs::sendStatusString(const std::string& peer_id,const std::string& status_string)
void p3Msgs::sendStatusString(const std::string& peer_id, const std::string& status_string)
{
mChatSrv->sendStatusString(peer_id,status_string);
mChatSrv->sendStatusString(peer_id, status_string);
}
int p3Msgs::getPublicChatQueueCount()
@ -197,12 +220,12 @@ bool p3Msgs::getPrivateChatQueueIds(bool incoming, std::list<std::string> &ids
return mChatSrv->getPrivateChatQueueIds(incoming, ids);
}
bool p3Msgs::getPrivateChatQueue(bool incoming, std::string id, std::list<ChatInfo> &chats)
bool p3Msgs::getPrivateChatQueue(bool incoming, const std::string& id, std::list<ChatInfo> &chats)
{
return mChatSrv->getPrivateChatQueue(incoming, id, chats);
}
bool p3Msgs::clearPrivateChatQueue(bool incoming, std::string id)
bool p3Msgs::clearPrivateChatQueue(bool incoming, const std::string& id)
{
return mChatSrv->clearPrivateChatQueue(incoming, id);
}
@ -217,7 +240,7 @@ void p3Msgs::setOwnAvatarData(const unsigned char *data,int size)
mChatSrv->setOwnAvatarJpegData(data,size) ;
}
void p3Msgs::getAvatarData(std::string pid,unsigned char *& data,int& size)
void p3Msgs::getAvatarData(const std::string& pid,unsigned char *& data,int& size)
{
mChatSrv->getAvatarJpegData(pid,data,size) ;
}

View file

@ -80,7 +80,7 @@ class p3Msgs: public RsMsgs
/*!
* gets avatar from peer, image data in jpeg format
*/
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size);
virtual void getAvatarData(const std::string& pid,unsigned char *& data,int& size);
/*!
* sets clients avatar, image data should be in jpeg format
@ -111,13 +111,13 @@ class p3Msgs: public RsMsgs
/*!
* public chat sent to all peers
*/
virtual bool sendPublicChat(std::wstring msg);
virtual bool sendPublicChat(const std::wstring& msg);
/*!
* chat is sent to specifc peer
* @param id peer to send chat msg to
*/
virtual bool sendPrivateChat(std::string id, std::wstring msg);
virtual bool sendPrivateChat(const std::string& id, const std::wstring& msg);
/*!
* returns the count of messages in public or private queue
@ -145,19 +145,19 @@ class p3Msgs: public RsMsgs
/*!
* @param chats ref to list of received private chats is stored here
*/
virtual bool getPrivateChatQueue(bool incoming, std::string id, std::list<ChatInfo> &chats);
virtual bool getPrivateChatQueue(bool incoming, const std::string& id, std::list<ChatInfo> &chats);
/*!
* @param clear private chat queue
*/
virtual bool clearPrivateChatQueue(bool incoming, std::string id);
virtual bool clearPrivateChatQueue(bool incoming, const std::string& id);
/*!
* sends immediate status string to a specific peer, e.g. in a private chat
* @param peer_id peer to send status string to
* @param status_string immediate status to send
*/
virtual void sendStatusString(const std::string& peer_id,const std::string& status_string) ;
virtual void sendStatusString(const std::string& peer_id, const std::string& status_string) ;
/*!
* sends immediate status to all peers

View file

@ -1703,6 +1703,7 @@ RsTurtle *rsTurtle = NULL ;
#include "pqi/pqisslpersongrp.h"
#include "pqi/pqiloopback.h"
#include "pqi/p3cfgmgr.h"
#include "pqi/p3historymgr.h"
#include "util/rsdebug.h"
#include "util/rsdir.h"
@ -1741,6 +1742,7 @@ RsTurtle *rsTurtle = NULL ;
#include "rsserver/p3discovery.h"
#include "rsserver/p3photo.h"
#include "rsserver/p3status.h"
#include "rsserver/p3history.h"
#include "rsserver/p3serverconfig.h"
#include "retroshare/rsgame.h"
@ -1850,11 +1852,14 @@ int RsServer::StartupRetroShare()
/* Setup Notify Early - So we can use it. */
rsNotify = new p3Notify();
/* History Manager */
mHistoryMgr = new p3HistoryMgr();
mPeerMgr = new p3PeerMgrIMPL();
mNetMgr = new p3NetMgrIMPL();
mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr);
mPeerMgr->setManagers(mLinkMgr, mNetMgr);
mPeerMgr->setManagers(mLinkMgr, mNetMgr, mHistoryMgr);
mNetMgr->setManagers(mPeerMgr, mLinkMgr);
//load all the SSL certs as friends
@ -2048,7 +2053,7 @@ int RsServer::StartupRetroShare()
ad = new p3disc(mPeerMgr, mLinkMgr, pqih);
#ifndef MINIMAL_LIBRS
msgSrv = new p3MsgService(mLinkMgr);
chatSrv = new p3ChatService(mLinkMgr);
chatSrv = new p3ChatService(mLinkMgr, mHistoryMgr);
mStatusSrv = new p3StatusService(mLinkMgr);
#endif // MINIMAL_LIBRS
@ -2155,7 +2160,8 @@ int RsServer::StartupRetroShare()
#ifndef MINIMAL_LIBRS
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
mConfigMgr->addConfiguration("chat.cfg", chatSrv);
#ifdef RS_USE_BLOGS
mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr);
#ifdef RS_USE_BLOGS
mConfigMgr->addConfiguration("blogs.cfg", mBlogs);
#endif
mConfigMgr->addConfiguration("forums.cfg", mForums);
@ -2335,6 +2341,7 @@ int RsServer::StartupRetroShare()
rsBlogs = mBlogs;
#endif
rsStatus = new p3Status(mStatusSrv);
rsHistory = new p3History(mHistoryMgr);
#ifndef RS_RELEASE
rsGameLauncher = gameLauncher;