2011-09-29 05:20:09 -04:00
|
|
|
#ifndef RS_P3_HISTORY_MGR_H
|
|
|
|
#define RS_P3_HISTORY_MGR_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* libretroshare/src/services: p3historymgr.h
|
|
|
|
*
|
|
|
|
* RetroShare C++
|
|
|
|
*
|
|
|
|
* 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 <map>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#include "serialiser/rshistoryitems.h"
|
|
|
|
#include "retroshare/rshistory.h"
|
|
|
|
#include "pqi/p3cfgmgr.h"
|
|
|
|
|
|
|
|
class RsChatMsgItem;
|
|
|
|
|
|
|
|
//! handles history
|
|
|
|
/*!
|
|
|
|
* The is a retroshare service which allows peers
|
|
|
|
* to store the history of the chat messages
|
|
|
|
*/
|
|
|
|
class p3HistoryMgr: public p3Config
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
p3HistoryMgr();
|
|
|
|
virtual ~p3HistoryMgr();
|
|
|
|
|
|
|
|
/******** p3HistoryMgr *********/
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
void addMessage(bool incoming, const RsPeerId &chatPeerId, const RsPeerId &peerId, const RsChatMsgItem *chatItem);
|
2011-09-29 05:20:09 -04:00
|
|
|
|
|
|
|
/********* RsHistory ***********/
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool getMessages(const RsPeerId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
2011-09-29 05:20:09 -04:00
|
|
|
bool getMessage(uint32_t msgId, HistoryMsg &msg);
|
2014-03-17 16:56:06 -04:00
|
|
|
void clear(const RsPeerId &chatPeerId);
|
2011-09-29 05:20:09 -04:00
|
|
|
void removeMessages(const std::list<uint32_t> &msgIds);
|
2013-09-27 17:18:44 -04:00
|
|
|
|
|
|
|
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() ;
|
2011-09-29 05:20:09 -04:00
|
|
|
|
|
|
|
/********* p3config ************/
|
|
|
|
|
|
|
|
virtual RsSerialiser *setupSerialiser();
|
|
|
|
virtual bool saveList(bool& cleanup, std::list<RsItem*>& saveData);
|
|
|
|
virtual void saveDone();
|
|
|
|
virtual bool loadList(std::list<RsItem*>& load);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t nextMsgId;
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> > mMessages;
|
2011-09-29 05:20:09 -04:00
|
|
|
|
2013-09-27 17:18:44 -04:00
|
|
|
// Removes messages stored for more than mMaxMsgStorageDurationSeconds seconds.
|
|
|
|
// This avoids the stored list to grow crazy with time.
|
|
|
|
//
|
|
|
|
void cleanOldMessages() ;
|
|
|
|
|
2011-09-29 05:20:09 -04:00
|
|
|
bool mPublicEnable;
|
2013-09-27 17:18:44 -04:00
|
|
|
bool mLobbyEnable;
|
2011-09-29 05:20:09 -04:00
|
|
|
bool mPrivateEnable;
|
|
|
|
|
|
|
|
uint32_t mPublicSaveCount;
|
2013-09-27 17:18:44 -04:00
|
|
|
uint32_t mLobbySaveCount;
|
2011-09-29 05:20:09 -04:00
|
|
|
uint32_t mPrivateSaveCount;
|
|
|
|
|
2013-09-27 17:18:44 -04:00
|
|
|
uint32_t mMaxStorageDurationSeconds ;
|
|
|
|
time_t mLastCleanTime ;
|
|
|
|
|
2011-09-29 05:20:09 -04:00
|
|
|
std::list<RsItem*> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
|
|
|
|
|
|
|
|
RsMutex mHistoryMtx;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|