mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
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:
parent
c6a68fe05e
commit
29c090fb44
45 changed files with 1721 additions and 1406 deletions
|
@ -139,6 +139,7 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
|
|||
retroshare/rsexpr.h \
|
||||
retroshare/rsfiles.h \
|
||||
retroshare/rsforums.h \
|
||||
retroshare/rshistory.h \
|
||||
retroshare/rsiface.h \
|
||||
retroshare/rsinit.h \
|
||||
retroshare/rsplugin.h \
|
||||
|
@ -368,6 +369,7 @@ HEADERS += pqi/authssl.h \
|
|||
pqi/pqibin.h \
|
||||
pqi/pqihandler.h \
|
||||
pqi/pqihash.h \
|
||||
pqi/p3historymgr.h \
|
||||
pqi/pqiindic.h \
|
||||
pqi/pqiipset.h \
|
||||
pqi/pqilistener.h \
|
||||
|
@ -391,6 +393,7 @@ HEADERS += pqi/authssl.h \
|
|||
|
||||
HEADERS += rsserver/p3discovery.h \
|
||||
rsserver/p3face.h \
|
||||
rsserver/p3history.h \
|
||||
rsserver/p3msgs.h \
|
||||
rsserver/p3peers.h \
|
||||
rsserver/p3photo.h \
|
||||
|
@ -406,6 +409,7 @@ HEADERS += serialiser/rsbaseitems.h \
|
|||
serialiser/rsdistribitems.h \
|
||||
serialiser/rsforumitems.h \
|
||||
serialiser/rsgameitems.h \
|
||||
serialiser/rshistoryitems.h \
|
||||
serialiser/rsmsgitems.h \
|
||||
serialiser/rsphotoitems.h \
|
||||
serialiser/rsserial.h \
|
||||
|
@ -490,6 +494,7 @@ SOURCES += pqi/authgpg.cc \
|
|||
pqi/pqiarchive.cc \
|
||||
pqi/pqibin.cc \
|
||||
pqi/pqihandler.cc \
|
||||
pqi/p3historymgr.cc \
|
||||
pqi/pqiipset.cc \
|
||||
pqi/pqiloopback.cc \
|
||||
pqi/pqimonitor.cc \
|
||||
|
@ -512,6 +517,7 @@ SOURCES += rsserver/p3discovery.cc \
|
|||
rsserver/p3face-config.cc \
|
||||
rsserver/p3face-msgs.cc \
|
||||
rsserver/p3face-server.cc \
|
||||
rsserver/p3history.cc \
|
||||
rsserver/p3msgs.cc \
|
||||
rsserver/p3peers.cc \
|
||||
rsserver/p3photo.cc \
|
||||
|
@ -535,6 +541,7 @@ SOURCES += serialiser/rsbaseitems.cc \
|
|||
serialiser/rsdistribitems.cc \
|
||||
serialiser/rsforumitems.cc \
|
||||
serialiser/rsgameitems.cc \
|
||||
serialiser/rshistoryitems.cc \
|
||||
serialiser/rsmsgitems.cc \
|
||||
serialiser/rsphotoitems.cc \
|
||||
serialiser/rsserial.cc \
|
||||
|
|
|
@ -81,6 +81,7 @@ const uint32_t CONFIG_TYPE_AUTHSSL = 0x000C;
|
|||
const uint32_t CONFIG_TYPE_CHAT = 0x0012;
|
||||
const uint32_t CONFIG_TYPE_STATUS = 0x0013;
|
||||
const uint32_t CONFIG_TYPE_PLUGINS = 0x0014;
|
||||
const uint32_t CONFIG_TYPE_HISTORY = 0x0015;
|
||||
|
||||
/// turtle router
|
||||
const uint32_t CONFIG_TYPE_TURTLE = 0x0020;
|
||||
|
|
417
libretroshare/src/pqi/p3historymgr.cc
Normal file
417
libretroshare/src/pqi/p3historymgr.cc
Normal file
|
@ -0,0 +1,417 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3HistoryMgr.cc
|
||||
*
|
||||
* 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 "p3historymgr.h"
|
||||
#include "serialiser/rshistoryitems.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
|
||||
RsHistory *rsHistory = NULL;
|
||||
|
||||
p3HistoryMgr::p3HistoryMgr()
|
||||
: p3Config(CONFIG_TYPE_HISTORY), mHistoryMtx("p3HistoryMgr")
|
||||
{
|
||||
nextMsgId = 1;
|
||||
|
||||
mPublicEnable = false;
|
||||
mPrivateEnable = true;
|
||||
|
||||
mPublicSaveCount = 0;
|
||||
mPrivateSaveCount = 0;
|
||||
}
|
||||
|
||||
p3HistoryMgr::~p3HistoryMgr()
|
||||
{
|
||||
}
|
||||
|
||||
/***** p3HistoryMgr *****/
|
||||
|
||||
void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem)
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (mPublicEnable == false && chatPeerId.empty()) {
|
||||
// public chat not enabled
|
||||
return;
|
||||
}
|
||||
|
||||
if (mPrivateEnable == false && chatPeerId.empty() == false) {
|
||||
// private chat not enabled
|
||||
return;
|
||||
}
|
||||
|
||||
RsHistoryMsgItem* item = new RsHistoryMsgItem;
|
||||
item->chatPeerId = chatPeerId;
|
||||
item->incoming = incoming;
|
||||
item->peerId = peerId;
|
||||
item->peerName = rsPeers->getPeerName(item->peerId);
|
||||
item->sendTime = chatItem->sendTime;
|
||||
item->recvTime = chatItem->recvTime;
|
||||
item->message.assign(chatItem->message.begin(), chatItem->message.end());
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(item->chatPeerId);
|
||||
if (mit != mMessages.end()) {
|
||||
item->msgId = nextMsgId++;
|
||||
mit->second.insert(std::make_pair(item->msgId, item));
|
||||
|
||||
// check the limit
|
||||
uint32_t limit;
|
||||
if (chatPeerId.empty()) {
|
||||
limit = mPublicSaveCount;
|
||||
} else {
|
||||
limit = mPrivateSaveCount;
|
||||
}
|
||||
|
||||
if (limit) {
|
||||
while (mit->second.size() > limit) {
|
||||
delete(mit->second.begin()->second);
|
||||
mit->second.erase(mit->second.begin());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::map<uint32_t, RsHistoryMsgItem*> msgs;
|
||||
item->msgId = nextMsgId++;
|
||||
msgs.insert(std::make_pair(item->msgId, item));
|
||||
mMessages.insert(std::make_pair(item->chatPeerId, msgs));
|
||||
|
||||
// no need to check the limit
|
||||
}
|
||||
|
||||
IndicateConfigChanged();
|
||||
|
||||
rsicontrol->getNotify().notifyHistoryChanged(item->msgId, NOTIFY_TYPE_ADD);
|
||||
}
|
||||
|
||||
/***** p3Config *****/
|
||||
|
||||
RsSerialiser* p3HistoryMgr::setupSerialiser()
|
||||
{
|
||||
RsSerialiser *rss = new RsSerialiser;
|
||||
rss->addSerialType(new RsHistorySerialiser);
|
||||
rss->addSerialType(new RsGeneralConfigSerialiser());
|
||||
|
||||
return rss;
|
||||
}
|
||||
|
||||
bool p3HistoryMgr::saveList(bool& cleanup, std::list<RsItem*>& saveData)
|
||||
{
|
||||
cleanup = false;
|
||||
|
||||
mHistoryMtx.lock(); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit;
|
||||
for (mit = mMessages.begin(); mit != mMessages.end(); mit++) {
|
||||
for (lit = mit->second.begin(); lit != mit->second.end(); lit++) {
|
||||
saveData.push_back(lit->second);
|
||||
}
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet;
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "PUBLIC_ENABLE";
|
||||
kv.value = mPublicEnable ? "TRUE" : "FALSE";
|
||||
vitem->tlvkvs.pairs.push_back(kv);
|
||||
|
||||
kv.key = "PRIVATE_ENABLE";
|
||||
kv.value = mPrivateEnable ? "TRUE" : "FALSE";
|
||||
vitem->tlvkvs.pairs.push_back(kv);
|
||||
|
||||
kv.key = "PUBLIC_SAVECOUNT";
|
||||
std::ostringstream s1;
|
||||
s1 << mPublicSaveCount;
|
||||
kv.value = s1.str();
|
||||
vitem->tlvkvs.pairs.push_back(kv);
|
||||
|
||||
kv.key = "PRIVATE_SAVECOUNT";
|
||||
std::ostringstream s2;
|
||||
s2 << mPrivateSaveCount;
|
||||
kv.value = s2.str();
|
||||
vitem->tlvkvs.pairs.push_back(kv);
|
||||
|
||||
saveData.push_back(vitem);
|
||||
saveCleanupList.push_back(vitem);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3HistoryMgr::saveDone()
|
||||
{
|
||||
/* clean up the save List */
|
||||
std::list<RsItem*>::iterator it;
|
||||
for (it = saveCleanupList.begin(); it != saveCleanupList.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
saveCleanupList.clear();
|
||||
|
||||
/* unlock mutex */
|
||||
mHistoryMtx.unlock(); /****** MUTEX UNLOCKED *******/
|
||||
}
|
||||
|
||||
bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
RsHistoryMsgItem *msgItem;
|
||||
std::list<RsItem*>::iterator it;
|
||||
|
||||
for (it = load.begin(); it != load.end(); it++) {
|
||||
if (NULL != (msgItem = dynamic_cast<RsHistoryMsgItem*>(*it))) {
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(msgItem->chatPeerId);
|
||||
msgItem->msgId = nextMsgId++;
|
||||
if (mit != mMessages.end()) {
|
||||
mit->second.insert(std::make_pair(msgItem->msgId, msgItem));
|
||||
} else {
|
||||
std::map<uint32_t, RsHistoryMsgItem*> msgs;
|
||||
msgs.insert(std::make_pair(msgItem->msgId, msgItem));
|
||||
mMessages.insert(std::make_pair(msgItem->chatPeerId, msgs));
|
||||
}
|
||||
|
||||
// don't delete the item !!
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *rskv ;
|
||||
if (NULL != (rskv = dynamic_cast<RsConfigKeyValueSet*>(*it))) {
|
||||
for (std::list<RsTlvKeyValue>::const_iterator kit = rskv->tlvkvs.pairs.begin(); kit != rskv->tlvkvs.pairs.end(); kit++) {
|
||||
if (kit->key == "PUBLIC_ENABLE") {
|
||||
mPublicEnable = (kit->value == "TRUE") ? TRUE : FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kit->key == "PRIVATE_ENABLE") {
|
||||
mPrivateEnable = (kit->value == "TRUE") ? TRUE : FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kit->key == "PUBLIC_SAVECOUNT") {
|
||||
mPublicSaveCount = atoi(kit->value.c_str());
|
||||
continue;
|
||||
}
|
||||
if (kit->key == "PRIVATE_SAVECOUNT") {
|
||||
mPrivateSaveCount = atoi(kit->value.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
delete (*it);
|
||||
continue;
|
||||
}
|
||||
|
||||
// delete unknown items
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/***** p3History *****/
|
||||
|
||||
static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg)
|
||||
{
|
||||
msg.msgId = item->msgId;
|
||||
msg.chatPeerId = item->chatPeerId;
|
||||
msg.incoming = item->incoming;
|
||||
msg.peerId = item->peerId;
|
||||
msg.peerName = item->peerName;
|
||||
msg.sendTime = item->sendTime;
|
||||
msg.recvTime = item->recvTime;
|
||||
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<HistoryMsg> &msgs, uint32_t loadCount)
|
||||
{
|
||||
msgs.clear();
|
||||
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (mPublicEnable == false && chatPeerId.empty()) {
|
||||
// public chat not enabled
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mPrivateEnable == false && chatPeerId.empty() == false) {
|
||||
// private chat not enabled
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t foundCount = 0;
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||
if (mit != mMessages.end()) {
|
||||
std::map<uint32_t, RsHistoryMsgItem*>::reverse_iterator lit;
|
||||
for (lit = mit->second.rbegin(); lit != mit->second.rend(); lit++) {
|
||||
HistoryMsg msg;
|
||||
convertMsg(lit->second, msg);
|
||||
msgs.insert(msgs.begin(), msg);
|
||||
foundCount++;
|
||||
if (loadCount && foundCount >= loadCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3HistoryMgr::getMessage(uint32_t msgId, HistoryMsg &msg)
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
for (mit = mMessages.begin(); mit != mMessages.end(); mit++) {
|
||||
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit = mit->second.find(msgId);
|
||||
if (lit != mit->second.end()) {
|
||||
convertMsg(lit->second, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void p3HistoryMgr::clear(const std::string &chatPeerId)
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||
if (mit == mMessages.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit;
|
||||
for (lit = mit->second.begin(); lit != mit->second.end(); lit++) {
|
||||
delete(lit->second);
|
||||
}
|
||||
mit->second.clear();
|
||||
mMessages.erase(mit);
|
||||
|
||||
IndicateConfigChanged();
|
||||
|
||||
rsicontrol->getNotify().notifyHistoryChanged(0, NOTIFY_TYPE_MOD);
|
||||
}
|
||||
|
||||
void p3HistoryMgr::removeMessages(const std::list<uint32_t> &msgIds)
|
||||
{
|
||||
std::list<uint32_t> ids = msgIds;
|
||||
std::list<uint32_t> removedIds;
|
||||
std::list<uint32_t>::iterator iit;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit;
|
||||
for (mit = mMessages.begin(); mit != mMessages.end(); ++mit) {
|
||||
iit = ids.begin();
|
||||
while (iit != ids.end()) {
|
||||
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit = mit->second.find(*iit);
|
||||
if (lit != mit->second.end()) {
|
||||
delete(lit->second);
|
||||
mit->second.erase(lit);
|
||||
|
||||
removedIds.push_back(*iit);
|
||||
iit = ids.erase(iit);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
++iit;
|
||||
}
|
||||
|
||||
if (ids.empty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (removedIds.empty() == false) {
|
||||
IndicateConfigChanged();
|
||||
|
||||
for (iit = removedIds.begin(); iit != removedIds.end(); ++iit) {
|
||||
rsicontrol->getNotify().notifyHistoryChanged(*iit, NOTIFY_TYPE_DEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool p3HistoryMgr::getEnable(bool ofPublic)
|
||||
{
|
||||
return ofPublic ? mPublicEnable : mPrivateEnable;
|
||||
}
|
||||
|
||||
void p3HistoryMgr::setEnable(bool forPublic, bool enable)
|
||||
{
|
||||
bool oldValue;
|
||||
|
||||
if (forPublic) {
|
||||
oldValue = mPublicEnable;
|
||||
mPublicEnable = enable;
|
||||
} else {
|
||||
oldValue = mPrivateEnable;
|
||||
mPrivateEnable = enable;
|
||||
}
|
||||
|
||||
if (oldValue != enable) {
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t p3HistoryMgr::getSaveCount(bool ofPublic)
|
||||
{
|
||||
return ofPublic ? mPublicSaveCount : mPrivateSaveCount;
|
||||
}
|
||||
|
||||
void p3HistoryMgr::setSaveCount(bool forPublic, uint32_t count)
|
||||
{
|
||||
uint32_t oldValue;
|
||||
|
||||
if (forPublic) {
|
||||
oldValue = mPublicSaveCount;
|
||||
mPublicSaveCount = count;
|
||||
} else {
|
||||
oldValue = mPrivateSaveCount;
|
||||
mPrivateSaveCount = count;
|
||||
}
|
||||
|
||||
if (oldValue != count) {
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
86
libretroshare/src/pqi/p3historymgr.h
Normal file
86
libretroshare/src/pqi/p3historymgr.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
#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 *********/
|
||||
|
||||
void addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem);
|
||||
|
||||
/********* RsHistory ***********/
|
||||
|
||||
bool getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
|
||||
bool getMessage(uint32_t msgId, HistoryMsg &msg);
|
||||
void clear(const std::string &chatPeerId);
|
||||
void removeMessages(const std::list<uint32_t> &msgIds);
|
||||
bool getEnable(bool ofPublic);
|
||||
void setEnable(bool forPublic, bool enable);
|
||||
uint32_t getSaveCount(bool ofPublic);
|
||||
void setSaveCount(bool forPublic, uint32_t count);
|
||||
|
||||
/********* 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;
|
||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> > mMessages;
|
||||
|
||||
bool mPublicEnable;
|
||||
bool mPrivateEnable;
|
||||
|
||||
uint32_t mPublicSaveCount;
|
||||
uint32_t mPrivateSaveCount;
|
||||
|
||||
std::list<RsItem*> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
|
||||
|
||||
RsMutex mHistoryMtx;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -30,6 +30,7 @@
|
|||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
#include "pqi/p3historymgr.h"
|
||||
|
||||
//#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||
//#include "tcponudp/tou.h"
|
||||
|
@ -109,6 +110,10 @@ p3PeerMgrIMPL::p3PeerMgrIMPL()
|
|||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
mLinkMgr = NULL;
|
||||
mNetMgr = NULL;
|
||||
mHistoryMgr = NULL;
|
||||
|
||||
/* setup basics of own state */
|
||||
mOwnState.id = AuthSSL::getAuthSSL()->OwnId();
|
||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
|
@ -130,10 +135,11 @@ p3PeerMgrIMPL::p3PeerMgrIMPL()
|
|||
return;
|
||||
}
|
||||
|
||||
void p3PeerMgrIMPL::setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr)
|
||||
void p3PeerMgrIMPL::setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr, p3HistoryMgr *historyMgr)
|
||||
{
|
||||
mLinkMgr = linkMgr;
|
||||
mNetMgr = netMgr;
|
||||
mHistoryMgr = historyMgr;
|
||||
}
|
||||
|
||||
void p3PeerMgrIMPL::setOwnNetworkMode(uint32_t netMode)
|
||||
|
@ -537,6 +543,7 @@ bool p3PeerMgrIMPL::removeFriend(const std::string &id)
|
|||
{
|
||||
if (mFriendList.end() != (it = mFriendList.find(*rit)))
|
||||
{
|
||||
mHistoryMgr->clear(it->second.id);
|
||||
mFriendList.erase(it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ class p3NetMgr;
|
|||
|
||||
class p3LinkMgrIMPL;
|
||||
class p3NetMgrIMPL;
|
||||
class p3HistoryMgr;
|
||||
|
||||
class p3PeerMgr
|
||||
{
|
||||
|
@ -279,7 +280,7 @@ virtual bool haveOnceConnected();
|
|||
|
||||
p3PeerMgrIMPL();
|
||||
|
||||
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr);
|
||||
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr, p3HistoryMgr *historyMgr);
|
||||
|
||||
void tick();
|
||||
|
||||
|
@ -314,7 +315,7 @@ void printPeerLists(std::ostream &out);
|
|||
|
||||
p3LinkMgrIMPL *mLinkMgr;
|
||||
p3NetMgrIMPL *mNetMgr;
|
||||
|
||||
p3HistoryMgr *mHistoryMgr;
|
||||
|
||||
private:
|
||||
RsMutex mPeerMtx; /* protects below */
|
||||
|
|
83
libretroshare/src/retroshare/rshistory.h
Normal file
83
libretroshare/src/retroshare/rshistory.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
#ifndef RS_HISTORY_INTERFACE_H
|
||||
#define RS_HISTORY_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/retroshare: rshistory.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".
|
||||
*
|
||||
*/
|
||||
|
||||
class RsHistory;
|
||||
|
||||
extern RsHistory *rsHistory;
|
||||
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
#include <list>
|
||||
|
||||
//! data object for message history
|
||||
/*!
|
||||
* data object used for message history
|
||||
*/
|
||||
class HistoryMsg
|
||||
{
|
||||
public:
|
||||
HistoryMsg()
|
||||
{
|
||||
msgId = 0;
|
||||
incoming = false;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
uint32_t msgId;
|
||||
std::string chatPeerId;
|
||||
bool incoming;
|
||||
std::string peerId;
|
||||
std::string peerName;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
//! Interface to retroshare for message history
|
||||
/*!
|
||||
* Provides an interface for retroshare's message history functionality
|
||||
*/
|
||||
class RsHistory
|
||||
{
|
||||
public:
|
||||
virtual bool getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount) = 0;
|
||||
virtual bool getMessage(uint32_t msgId, HistoryMsg &msg) = 0;
|
||||
virtual void removeMessages(const std::list<uint32_t> &msgIds) = 0;
|
||||
virtual void clear(const std::string &chatPeerId) = 0;
|
||||
|
||||
virtual bool getEnable(bool ofPublic) = 0;
|
||||
virtual void setEnable(bool forPublic, bool enable) = 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;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -185,7 +185,6 @@ class NotifyBase
|
|||
virtual void notifyListPreChange(int list, int type) { (void) list; (void) type; return; }
|
||||
virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; }
|
||||
virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
|
||||
virtual void notifyChat() { return; }
|
||||
virtual void notifyChatStatus(const std::string& /* peer_id */, const std::string& /* status_string */ ,bool /* is_private */) {}
|
||||
virtual void notifyCustomState(const std::string& /* peer_id */, const std::string& /* status_string */) {}
|
||||
virtual void notifyHashingInfo(uint32_t type, const std::string& fileinfo) { (void) type; (void)fileinfo; }
|
||||
|
@ -202,6 +201,7 @@ class NotifyBase
|
|||
virtual void notifyDiscInfoChanged() {}
|
||||
virtual void notifyDownloadComplete(const std::string& /* fileHash */) {};
|
||||
virtual void notifyDownloadCompleteCount(uint32_t /* count */) {};
|
||||
virtual void notifyHistoryChanged(uint32_t /* msgId */, int /* type */) {}
|
||||
|
||||
virtual bool askForPassword(const std::string& /* key_details */, bool /* prev_is_bad */, std::string& /* password */ ) { return false ;}
|
||||
};
|
||||
|
|
|
@ -125,7 +125,7 @@ public:
|
|||
#define RS_CHAT_PRIVATE 0x0002
|
||||
#define RS_CHAT_AVATAR_AVAILABLE 0x0004
|
||||
|
||||
class ChatInfo
|
||||
class ChatInfo
|
||||
{
|
||||
public:
|
||||
std::string rsid;
|
||||
|
@ -140,6 +140,7 @@ std::ostream &operator<<(std::ostream &out, const ChatInfo &info);
|
|||
//std::ostream &operator<<(std::ostream &out, const MsgTagInfo);
|
||||
//std::ostream &operator<<(std::ostream &out, const MsgTagType);
|
||||
|
||||
bool operator==(const ChatInfo&, const ChatInfo&);
|
||||
|
||||
class RsMsgs;
|
||||
extern RsMsgs *rsMsgs;
|
||||
|
@ -183,14 +184,14 @@ virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0;
|
|||
|
||||
/****************************************/
|
||||
/* Chat */
|
||||
virtual bool sendPublicChat(std::wstring msg) = 0;
|
||||
virtual bool sendPrivateChat(std::string id, std::wstring msg) = 0;
|
||||
virtual bool sendPublicChat(const std::wstring& msg) = 0;
|
||||
virtual bool sendPrivateChat(const std::string& id, const std::wstring& msg) = 0;
|
||||
virtual int getPublicChatQueueCount() = 0;
|
||||
virtual bool getPublicChatQueue(std::list<ChatInfo> &chats) = 0;
|
||||
virtual int getPrivateChatQueueCount(bool incoming) = 0;
|
||||
virtual bool getPrivateChatQueueIds(bool incoming, std::list<std::string> &ids) = 0;
|
||||
virtual bool getPrivateChatQueue(bool incoming, std::string id, std::list<ChatInfo> &chats) = 0;
|
||||
virtual bool clearPrivateChatQueue(bool incoming, std::string id) = 0;
|
||||
virtual bool getPrivateChatQueue(bool incoming, const std::string& id, std::list<ChatInfo> &chats) = 0;
|
||||
virtual bool clearPrivateChatQueue(bool incoming, const std::string& id) = 0;
|
||||
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
|
||||
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||
|
||||
|
@ -199,7 +200,7 @@ virtual std::string getCustomStateString() = 0 ;
|
|||
virtual std::string getCustomStateString(const std::string& peer_id) = 0 ;
|
||||
|
||||
// get avatar data for peer pid
|
||||
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;
|
||||
virtual void getAvatarData(const std::string& pid,unsigned char *& data,int& size) = 0 ;
|
||||
// set own avatar data
|
||||
virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ;
|
||||
virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
77
libretroshare/src/rsserver/p3history.cc
Normal file
77
libretroshare/src/rsserver/p3history.cc
Normal 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);
|
||||
}
|
57
libretroshare/src/rsserver/p3history.h
Normal file
57
libretroshare/src/rsserver/p3history.h
Normal 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 */
|
|
@ -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) ;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -42,6 +42,7 @@ const uint8_t RS_PKT_TYPE_PEER_CONFIG = 0x02;
|
|||
const uint8_t RS_PKT_TYPE_CACHE_CONFIG = 0x03;
|
||||
const uint8_t RS_PKT_TYPE_FILE_CONFIG = 0x04;
|
||||
const uint8_t RS_PKT_TYPE_PLUGIN_CONFIG = 0x05;
|
||||
const uint8_t RS_PKT_TYPE_HISTORY_CONFIG = 0x06;
|
||||
|
||||
/* GENERAL CONFIG SUBTYPES */
|
||||
const uint8_t RS_PKT_SUBTYPE_KEY_VALUE = 0x01;
|
||||
|
|
266
libretroshare/src/serialiser/rshistoryitems.cc
Normal file
266
libretroshare/src/serialiser/rshistoryitems.cc
Normal file
|
@ -0,0 +1,266 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rshistoryitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* 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 "serialiser/rshistoryitems.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG, RS_PKT_SUBTYPE_DEFAULT)
|
||||
{
|
||||
incoming = false;
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
msgId = 0;
|
||||
}
|
||||
|
||||
RsHistoryMsgItem::~RsHistoryMsgItem()
|
||||
{
|
||||
}
|
||||
|
||||
void RsHistoryMsgItem::clear()
|
||||
{
|
||||
incoming = false;
|
||||
peerId.clear();
|
||||
peerName.clear();
|
||||
sendTime = 0;
|
||||
recvTime = 0;
|
||||
message.clear();
|
||||
msgId = 0;
|
||||
}
|
||||
|
||||
std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsHistoryMsgItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "chatPeerid: " << chatPeerId << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "incoming: " << (incoming ? "1" : "0") << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "peerId: " << peerId << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "peerName: " << peerName << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "sendTime: " << sendTime << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "recvTime: " << recvTime << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_message(message.begin(), message.end());
|
||||
out << "message: " << cnv_message << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsHistoryMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
RsHistorySerialiser::RsHistorySerialiser() : RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_HISTORY_CONFIG)
|
||||
{
|
||||
}
|
||||
|
||||
RsHistorySerialiser::~RsHistorySerialiser()
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += 2; /* version */
|
||||
s += GetTlvStringSize(item->chatPeerId);
|
||||
s += 1; /* incoming */
|
||||
s += GetTlvStringSize(item->peerId);
|
||||
s += GetTlvStringSize(item->peerName);
|
||||
s += 4; /* sendTime */
|
||||
s += 4; /* recvTime */
|
||||
s += GetTlvStringSize(item->message);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeHistoryMsgItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Header: " << ok << std::endl;
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt16(data, tlvsize, &offset, 0); // version
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->chatPeerId);
|
||||
uint8_t dummy = item->incoming ? 1 : 0;
|
||||
ok &= setRawUInt8(data, tlvsize, &offset, dummy);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->peerId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->peerName);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_WSTR_MSG, item->message);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsHistorySerialiser::serialiseItem() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsHistoryMsgItem *RsHistorySerialiser::deserialiseHistoryMsgItem(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsHistoryMsgItem *item = new RsHistoryMsgItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
uint16_t version = 0;
|
||||
ok &= getRawUInt16(data, rssize, &offset, &version);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->chatPeerId);
|
||||
uint8_t dummy;
|
||||
ok &= getRawUInt8(data, rssize, &offset, &dummy);
|
||||
item->incoming = (dummy == 1);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->peerId);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->peerName);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime));
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_WSTR_MSG, item->message);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsHistorySerialiser::size(RsItem *item)
|
||||
{
|
||||
RsHistoryMsgItem* hi;
|
||||
|
||||
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
|
||||
{
|
||||
return sizeHistoryMsgItem(hi);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsHistorySerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsHistoryMsgItem* hi;
|
||||
|
||||
if (NULL != (hi = dynamic_cast<RsHistoryMsgItem*>(item)))
|
||||
{
|
||||
return serialiseHistoryMsgItem(hi, data, pktsize);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
|
||||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
|
||||
(RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DEFAULT:
|
||||
return deserialiseHistoryMsgItem(data, pktsize);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
75
libretroshare/src/serialiser/rshistoryitems.h
Normal file
75
libretroshare/src/serialiser/rshistoryitems.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
#ifndef RS_HISTORY_ITEMS_H
|
||||
#define RS_HISTORY_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rshistoryitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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 "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsHistoryMsgItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsHistoryMsgItem();
|
||||
virtual ~RsHistoryMsgItem();
|
||||
|
||||
virtual void clear();
|
||||
std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string chatPeerId; // empty for global chat
|
||||
bool incoming;
|
||||
std::string peerId;
|
||||
std::string peerName;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
std::string message;
|
||||
|
||||
/* not serialised */
|
||||
uint32_t msgId;
|
||||
};
|
||||
|
||||
class RsHistorySerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsHistorySerialiser();
|
||||
virtual ~RsHistorySerialiser();
|
||||
|
||||
virtual uint32_t size(RsItem*);
|
||||
virtual bool serialise(RsItem* item, void* data, uint32_t* size);
|
||||
virtual RsItem* deserialise(void* data, uint32_t* size);
|
||||
|
||||
private:
|
||||
virtual uint32_t sizeHistoryMsgItem(RsHistoryMsgItem*);
|
||||
virtual bool serialiseHistoryMsgItem (RsHistoryMsgItem* item, void* data, uint32_t* size);
|
||||
virtual RsHistoryMsgItem* deserialiseHistoryMsgItem(void* data, uint32_t* size);
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_HISTORY_ITEMS_H */
|
||||
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
#include "pqi/pqinotify.h"
|
||||
#include "pqi/pqistore.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3historymgr.h"
|
||||
|
||||
#include "services/p3chatservice.h"
|
||||
|
||||
|
@ -42,8 +43,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
p3ChatService::p3ChatService(p3LinkMgr *lm)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm)
|
||||
p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr)
|
||||
{
|
||||
addSerialType(new RsChatSerialiser());
|
||||
|
||||
|
@ -67,7 +68,7 @@ int p3ChatService::status()
|
|||
|
||||
/***************** Chat Stuff **********************/
|
||||
|
||||
int p3ChatService::sendPublicChat(std::wstring &msg)
|
||||
int p3ChatService::sendPublicChat(const std::wstring &msg)
|
||||
{
|
||||
/* go through all the peers */
|
||||
|
||||
|
@ -76,7 +77,8 @@ int p3ChatService::sendPublicChat(std::wstring &msg)
|
|||
mLinkMgr->getOnlineList(ids);
|
||||
|
||||
/* add in own id -> so get reflection */
|
||||
ids.push_back(mLinkMgr->getOwnId());
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
ids.push_back(ownId);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendChat()";
|
||||
|
@ -92,7 +94,7 @@ int p3ChatService::sendPublicChat(std::wstring &msg)
|
|||
ci->sendTime = time(NULL);
|
||||
ci->recvTime = ci->sendTime;
|
||||
ci->message = msg;
|
||||
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendChat() Item:";
|
||||
std::cerr << std::endl;
|
||||
|
@ -100,6 +102,9 @@ int p3ChatService::sendPublicChat(std::wstring &msg)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (*it == ownId) {
|
||||
mHistoryMgr->addMessage(false, "", ownId, ci);
|
||||
}
|
||||
sendItem(ci);
|
||||
}
|
||||
|
||||
|
@ -220,7 +225,7 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
|||
sendItem(msg) ;
|
||||
}
|
||||
|
||||
bool p3ChatService::sendPrivateChat(std::string &id, std::wstring &msg)
|
||||
bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstring &msg)
|
||||
{
|
||||
// make chat item....
|
||||
#ifdef CHAT_DEBUG
|
||||
|
@ -278,6 +283,8 @@ bool p3ChatService::sendPrivateChat(std::string &id, std::wstring &msg)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mHistoryMgr->addMessage(false, id, mLinkMgr->getOwnId(), ci);
|
||||
|
||||
checkSizeAndSendMessage(ci);
|
||||
|
||||
// Check if custom state string has changed, in which case it should be sent to the peer.
|
||||
|
@ -428,9 +435,16 @@ void p3ChatService::receiveChatQueue()
|
|||
if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) {
|
||||
privateChanged = true;
|
||||
privateIncomingList.push_back(ci); // don't delete the item !!
|
||||
|
||||
mHistoryMgr->addMessage(true, ci->PeerId(), ci->PeerId(), ci);
|
||||
} else {
|
||||
publicChanged = true;
|
||||
publicList.push_back(ci); // don't delete the item !!
|
||||
|
||||
if (ci->PeerId() != mLinkMgr->getOwnId()) {
|
||||
/* not from loop back */
|
||||
mHistoryMgr->addMessage(true, "", ci->PeerId(), ci);
|
||||
}
|
||||
}
|
||||
} /* UNLOCK */
|
||||
}
|
||||
|
@ -1088,12 +1102,16 @@ void p3ChatService::statusChange(const std::list<pqipeer> &plist)
|
|||
if (privateOutgoingList.size()) {
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
|
||||
std::list<RsChatMsgItem *>::iterator cit = privateOutgoingList.begin();
|
||||
while (cit != privateOutgoingList.end()) {
|
||||
RsChatMsgItem *c = *cit;
|
||||
|
||||
if (c->PeerId() == it->id) {
|
||||
sendItem(c); // delete item
|
||||
mHistoryMgr->addMessage(false, c->PeerId(), ownId, c);
|
||||
|
||||
checkSizeAndSendMessage(c); // delete item
|
||||
|
||||
changed = true;
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "retroshare/rsmsgs.h"
|
||||
|
||||
class p3LinkMgr;
|
||||
class p3HistoryMgr;
|
||||
|
||||
//!The basic Chat service.
|
||||
/**
|
||||
|
@ -46,7 +47,7 @@ class p3LinkMgr;
|
|||
class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
{
|
||||
public:
|
||||
p3ChatService(p3LinkMgr *cm);
|
||||
p3ChatService(p3LinkMgr *cm, p3HistoryMgr *historyMgr);
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
/*!
|
||||
|
@ -65,14 +66,14 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
|||
/*!
|
||||
* public chat sent to all peers
|
||||
*/
|
||||
int sendPublicChat(std::wstring &msg);
|
||||
int sendPublicChat(const std::wstring &msg);
|
||||
|
||||
/********* RsMsgs ***********/
|
||||
/*!
|
||||
* chat is sent to specifc peer
|
||||
* @param id peer to send chat msg to
|
||||
*/
|
||||
bool sendPrivateChat(std::string &id, std::wstring &msg);
|
||||
bool sendPrivateChat(const std::string &id, const std::wstring &msg);
|
||||
|
||||
/*!
|
||||
* can be used to send 'immediate' status msgs, these status updates are meant for immediate use by peer (not saved by rs)
|
||||
|
@ -201,6 +202,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
|||
RsChatStatusItem *makeOwnCustomStateStringItem() ;
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
p3HistoryMgr *mHistoryMgr;
|
||||
|
||||
std::list<RsChatMsgItem *> publicList;
|
||||
std::list<RsChatMsgItem *> privateIncomingList;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue