2007-12-11 20:43:17 -05:00
|
|
|
/*
|
|
|
|
* "$Id: p3ChatService.cc,v 1.24 2007-05-05 16:10:06 rmf24 Exp $"
|
|
|
|
*
|
|
|
|
* Other Bits for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2006 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-03-29 09:58:28 -04:00
|
|
|
#include "util/rsdir.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsiface.h"
|
2009-03-20 16:41:31 -04:00
|
|
|
#include "pqi/pqibin.h"
|
2009-03-29 09:58:28 -04:00
|
|
|
#include "pqi/pqinotify.h"
|
2009-05-08 20:19:54 -04:00
|
|
|
#include "pqi/pqistore.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
#include "services/p3chatservice.h"
|
|
|
|
|
2008-03-02 09:25:59 -05:00
|
|
|
/****
|
|
|
|
* #define CHAT_DEBUG 1
|
|
|
|
****/
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
/************ NOTE *********************************
|
|
|
|
* This Service is so simple that there is no
|
|
|
|
* mutex protection required!
|
|
|
|
*
|
|
|
|
*/
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
2009-09-29 16:37:20 -04:00
|
|
|
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mConnMgr(cm)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
addSerialType(new RsChatSerialiser());
|
2009-01-30 14:52:47 -05:00
|
|
|
|
|
|
|
_own_avatar = NULL ;
|
2009-09-29 16:37:20 -04:00
|
|
|
_custom_status_string = "" ;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int p3ChatService::tick()
|
|
|
|
{
|
2010-08-31 13:13:52 -04:00
|
|
|
if (receivedItems()) {
|
|
|
|
receiveChatQueue();
|
|
|
|
}
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int p3ChatService::status()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************** Chat Stuff **********************/
|
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
int p3ChatService::sendPublicChat(std::wstring &msg)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
/* go through all the peers */
|
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
std::list<std::string> ids;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
mConnMgr->getOnlineList(ids);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
/* add in own id -> so get reflection */
|
|
|
|
ids.push_back(mConnMgr->getOwnId());
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "p3ChatService::sendChat()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
for(it = ids.begin(); it != ids.end(); it++)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2009-05-05 09:18:53 -04:00
|
|
|
RsChatMsgItem *ci = new RsChatMsgItem();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
ci->PeerId(*it);
|
2007-12-11 20:43:17 -05:00
|
|
|
ci->chatFlags = 0;
|
|
|
|
ci->sendTime = time(NULL);
|
|
|
|
ci->message = msg;
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "p3ChatService::sendChat() Item:";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
ci->print(std::cerr);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
sendItem(ci);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
class p3ChatService::StateStringInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StateStringInfo()
|
|
|
|
{
|
|
|
|
_custom_status_string = "" ; // the custom status string of the peer
|
|
|
|
_peer_is_new = false ; // true when the peer has a new avatar
|
|
|
|
_own_is_new = false ; // true when I myself a new avatar to send to this peer.
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string _custom_status_string ;
|
|
|
|
int _peer_is_new ; // true when the peer has a new avatar
|
|
|
|
int _own_is_new ; // true when I myself a new avatar to send to this peer.
|
|
|
|
};
|
2009-01-30 14:52:47 -05:00
|
|
|
class p3ChatService::AvatarInfo
|
|
|
|
{
|
|
|
|
public:
|
2009-02-22 12:36:39 -05:00
|
|
|
AvatarInfo()
|
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
_image_size = 0 ;
|
|
|
|
_image_data = NULL ;
|
2009-02-22 12:36:39 -05:00
|
|
|
_peer_is_new = false ; // true when the peer has a new avatar
|
|
|
|
_own_is_new = false ; // true when I myself a new avatar to send to this peer.
|
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
~AvatarInfo()
|
|
|
|
{
|
|
|
|
delete[] _image_data ;
|
|
|
|
_image_data = NULL ;
|
|
|
|
_image_size = 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
AvatarInfo(const AvatarInfo& ai)
|
|
|
|
{
|
|
|
|
init(ai._image_data,ai._image_size) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(const unsigned char *jpeg_data,int size)
|
|
|
|
{
|
|
|
|
_image_size = size ;
|
|
|
|
_image_data = new unsigned char[size] ;
|
|
|
|
memcpy(_image_data,jpeg_data,size) ;
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
AvatarInfo(const unsigned char *jpeg_data,int size)
|
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
init(jpeg_data,size) ;
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
void toUnsignedChar(unsigned char *& data,uint32_t& size) const
|
2009-01-30 14:52:47 -05:00
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
data = new unsigned char[_image_size] ;
|
|
|
|
size = _image_size ;
|
|
|
|
memcpy(data,_image_data,size*sizeof(unsigned char)) ;
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
uint32_t _image_size ;
|
|
|
|
unsigned char *_image_data ;
|
2009-01-30 14:52:47 -05:00
|
|
|
int _peer_is_new ; // true when the peer has a new avatar
|
2009-09-29 16:37:20 -04:00
|
|
|
int _own_is_new ; // true when I myself a new avatar to send to this peer.
|
2009-01-30 14:52:47 -05:00
|
|
|
};
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
|
|
|
{
|
|
|
|
std::list<std::string> ids;
|
|
|
|
mConnMgr->getOnlineList(ids);
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-10-04 18:27:42 -04:00
|
|
|
std::cerr << "p3ChatService::sendChat(): sending group chat status string: " << status_string << std::endl ;
|
2009-09-29 16:37:20 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(std::list<std::string>::iterator it = ids.begin(); it != ids.end(); ++it)
|
|
|
|
{
|
|
|
|
RsChatStatusItem *cs = new RsChatStatusItem ;
|
|
|
|
|
|
|
|
cs->status_string = status_string ;
|
|
|
|
cs->flags = RS_CHAT_FLAG_PUBLIC ;
|
|
|
|
|
|
|
|
cs->PeerId(*it);
|
|
|
|
|
|
|
|
sendItem(cs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3ChatService::sendStatusString( const std::string& id , const std::string& status_string)
|
2009-05-05 09:18:53 -04:00
|
|
|
{
|
|
|
|
RsChatStatusItem *cs = new RsChatStatusItem ;
|
|
|
|
|
|
|
|
cs->status_string = status_string ;
|
2009-09-29 16:37:20 -04:00
|
|
|
cs->flags = RS_CHAT_FLAG_PRIVATE ;
|
2009-05-05 09:18:53 -04:00
|
|
|
cs->PeerId(id);
|
|
|
|
|
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "sending chat status packet:" << std::endl ;
|
|
|
|
cs->print(std::cerr) ;
|
|
|
|
#endif
|
|
|
|
sendItem(cs);
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
int p3ChatService::sendPrivateChat(std::string &id, std::wstring &msg)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
// make chat item....
|
2008-02-04 16:40:34 -05:00
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "p3ChatService::sendPrivateChat()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
RsChatMsgItem *ci = new RsChatMsgItem();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
ci->PeerId(id);
|
|
|
|
ci->chatFlags = RS_CHAT_FLAG_PRIVATE;
|
|
|
|
ci->sendTime = time(NULL);
|
|
|
|
ci->message = msg;
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
{
|
2009-10-04 18:27:42 -04:00
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
std::map<std::string,AvatarInfo*>::iterator it = _avatars.find(id) ;
|
|
|
|
|
|
|
|
if(it == _avatars.end())
|
|
|
|
{
|
|
|
|
_avatars[id] = new AvatarInfo ;
|
|
|
|
it = _avatars.find(id) ;
|
|
|
|
}
|
|
|
|
if(it->second->_own_is_new)
|
|
|
|
{
|
2009-02-22 12:36:39 -05:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-10-04 18:27:42 -04:00
|
|
|
std::cerr << "p3ChatService::sendPrivateChat: new avatar never sent to peer " << id << ". Setting <new> flag to packet." << std::endl;
|
2009-02-22 12:36:39 -05:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
|
|
|
it->second->_own_is_new = false ;
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-02-22 12:36:39 -05:00
|
|
|
std::cerr << "Sending msg to peer " << id << ", flags = " << ci->chatFlags << std::endl ;
|
2008-02-04 16:40:34 -05:00
|
|
|
std::cerr << "p3ChatService::sendPrivateChat() Item:";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
ci->print(std::cerr);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
sendItem(ci);
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
// Check if custom state string has changed, in which case it should be sent to the peer.
|
|
|
|
bool should_send_state_string = false ;
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
std::map<std::string,StateStringInfo>::iterator it = _state_strings.find(id) ;
|
|
|
|
|
2010-02-09 15:20:29 -05:00
|
|
|
if(it == _state_strings.end())
|
2009-10-04 18:27:42 -04:00
|
|
|
{
|
|
|
|
_state_strings[id] = StateStringInfo() ;
|
|
|
|
it = _state_strings.find(id) ;
|
|
|
|
it->second._own_is_new = true ;
|
|
|
|
}
|
|
|
|
if(it->second._own_is_new)
|
|
|
|
{
|
|
|
|
should_send_state_string = true ;
|
|
|
|
it->second._own_is_new = false ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(should_send_state_string)
|
|
|
|
{
|
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "own status string is new for peer " << id << ": sending it." << std::endl ;
|
|
|
|
#endif
|
|
|
|
RsChatStatusItem *cs = makeOwnCustomStateStringItem() ;
|
|
|
|
cs->PeerId(id) ;
|
|
|
|
sendItem(cs) ;
|
|
|
|
}
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
void p3ChatService::receiveChatQueue()
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2010-09-01 13:56:15 -04:00
|
|
|
bool publicChanged = false;
|
|
|
|
bool privateChanged = false;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
time_t now = time(NULL);
|
2009-05-05 09:18:53 -04:00
|
|
|
RsItem *item ;
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
while(NULL != (item=recvItem()))
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2008-04-04 08:19:50 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2010-08-31 13:13:52 -04:00
|
|
|
std::cerr << "p3ChatService::receiveChatQueue() Item:" << (void*)item << std::endl ;
|
2009-02-22 12:36:39 -05:00
|
|
|
#endif
|
2009-05-05 09:18:53 -04:00
|
|
|
RsChatMsgItem *ci = dynamic_cast<RsChatMsgItem*>(item) ;
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
if(ci != NULL) // real chat message
|
2009-01-30 14:52:47 -05:00
|
|
|
{
|
2009-05-05 09:18:53 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2010-08-31 13:13:52 -04:00
|
|
|
std::cerr << "p3ChatService::receiveChatQueue() Item:";
|
2009-05-05 09:18:53 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
ci->print(std::cerr);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "Got msg. Flags = " << ci->chatFlags << std::endl ;
|
|
|
|
#endif
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
if(ci->chatFlags & RS_CHAT_FLAG_REQUESTS_AVATAR) // no msg here. Just an avatar request.
|
2009-09-29 16:37:20 -04:00
|
|
|
{
|
2009-05-05 09:18:53 -04:00
|
|
|
sendAvatarJpegData(ci->PeerId()) ;
|
2009-09-29 16:37:20 -04:00
|
|
|
delete item ;
|
|
|
|
}
|
2009-05-05 09:18:53 -04:00
|
|
|
else // normal msg. Return it normally.
|
2009-01-30 14:52:47 -05:00
|
|
|
{
|
2009-05-05 09:18:53 -04:00
|
|
|
// Check if new avatar is available at peer's. If so, send a request to get the avatar.
|
|
|
|
if(ci->chatFlags & RS_CHAT_FLAG_AVATAR_AVAILABLE)
|
|
|
|
{
|
|
|
|
std::cerr << "New avatar is available for peer " << ci->PeerId() << ", sending request" << std::endl ;
|
|
|
|
sendAvatarRequest(ci->PeerId()) ;
|
|
|
|
ci->chatFlags &= ~RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(ci->PeerId()) ;
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-05-05 09:18:53 -04:00
|
|
|
std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ;
|
2010-08-31 13:13:52 -04:00
|
|
|
#endif
|
2009-05-05 09:18:53 -04:00
|
|
|
// has avatar. Return it strait away.
|
|
|
|
//
|
|
|
|
if(it!=_avatars.end() && it->second->_peer_is_new)
|
|
|
|
{
|
2010-04-24 06:33:12 -04:00
|
|
|
std::cerr << "Avatar is new for peer. ending info above" << std::endl ;
|
2009-05-05 09:18:53 -04:00
|
|
|
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
|
|
|
}
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
if ((ci->chatFlags & RS_CHAT_FLAG_PRIVATE) == 0) {
|
2010-09-01 13:56:15 -04:00
|
|
|
/* notify public chat message */
|
2010-08-31 13:13:52 -04:00
|
|
|
std::string message;
|
|
|
|
message.assign(ci->message.begin(), ci->message.end());
|
|
|
|
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId(), message, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
ci->recvTime = now;
|
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) {
|
|
|
|
privateChanged = true;
|
|
|
|
privateList.push_back(ci); // don't delete the item !!
|
|
|
|
} else {
|
|
|
|
publicChanged = true;
|
|
|
|
publicList.push_back(ci); // don't delete the item !!
|
|
|
|
}
|
|
|
|
} /* UNLOCK */
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
continue ;
|
2009-05-05 09:18:53 -04:00
|
|
|
}
|
2009-09-29 16:37:20 -04:00
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
RsChatStatusItem *cs = dynamic_cast<RsChatStatusItem*>(item) ;
|
|
|
|
|
2010-04-24 06:33:12 -04:00
|
|
|
if(cs != NULL){
|
|
|
|
|
2009-05-05 09:18:53 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ;
|
|
|
|
#endif
|
2009-09-29 16:37:20 -04:00
|
|
|
|
2010-04-24 06:33:12 -04:00
|
|
|
if(cs->flags & RS_CHAT_FLAG_REQUEST_CUSTOM_STATE){ // no state here just a request.
|
|
|
|
sendCustomState(cs->PeerId()) ;
|
2009-09-29 16:37:20 -04:00
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
}
|
2010-04-24 06:33:12 -04:00
|
|
|
else // Check if new custom string is available at peer's. If so, send a request to get the custom string.
|
|
|
|
if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE){
|
|
|
|
|
|
|
|
receiveStateString(cs->PeerId(),cs->status_string) ; // store it
|
2010-09-02 06:15:13 -04:00
|
|
|
rsicontrol->getNotify().notifyCustomState(cs->PeerId(), cs->status_string) ;
|
2010-04-24 06:33:12 -04:00
|
|
|
}else
|
|
|
|
if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE_AVAILABLE){
|
|
|
|
|
|
|
|
std::cerr << "New custom state is available for peer " << cs->PeerId() << ", sending request" << std::endl ;
|
|
|
|
sendCustomStateRequest(cs->PeerId()) ;
|
|
|
|
}else
|
|
|
|
if(cs->flags & RS_CHAT_FLAG_PRIVATE)
|
|
|
|
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,true) ;
|
|
|
|
else
|
|
|
|
if(cs->flags & RS_CHAT_FLAG_PUBLIC)
|
|
|
|
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,false) ;
|
|
|
|
|
|
|
|
delete item;
|
2009-09-29 16:37:20 -04:00
|
|
|
continue ;
|
2010-04-24 06:33:12 -04:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
RsChatAvatarItem *ca = dynamic_cast<RsChatAvatarItem*>(item) ;
|
|
|
|
|
|
|
|
if(ca != NULL)
|
|
|
|
{
|
|
|
|
receiveAvatarJpegData(ca) ;
|
2009-09-30 16:53:18 -04:00
|
|
|
|
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "Received avatar data for peer " << ca->PeerId() << ". Notifying." << std::endl ;
|
|
|
|
#endif
|
|
|
|
rsicontrol->getNotify().notifyPeerHasNewAvatar(ca->PeerId()) ;
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
delete item ;
|
|
|
|
continue ;
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
if (publicChanged) {
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PUBLIC_CHAT, NOTIFY_TYPE_ADD);
|
|
|
|
}
|
|
|
|
if (privateChanged) {
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PRIVATE_CHAT, NOTIFY_TYPE_ADD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int p3ChatService::getChatQueueCount(bool privateQueue)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
if (privateQueue) {
|
|
|
|
return privateList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return publicList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3ChatService::getPublicChatQueue(std::list<ChatInfo> &chats)
|
|
|
|
{
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
// get the items from the public list.
|
|
|
|
if (publicList.size() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<RsChatMsgItem *>::iterator it;
|
|
|
|
while (publicList.size()) {
|
|
|
|
RsChatMsgItem *c = publicList.front();
|
|
|
|
publicList.pop_front();
|
|
|
|
|
|
|
|
ChatInfo ci;
|
|
|
|
initRsChatInfo(c, ci);
|
|
|
|
chats.push_back(ci);
|
|
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
} /* UNLOCKED */
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
if (changed) {
|
2010-09-01 13:56:15 -04:00
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PUBLIC_CHAT, NOTIFY_TYPE_DEL);
|
2010-08-31 13:13:52 -04:00
|
|
|
}
|
2010-09-01 13:56:15 -04:00
|
|
|
|
|
|
|
return true;
|
2010-08-31 13:13:52 -04:00
|
|
|
}
|
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
bool p3ChatService::getPrivateChatQueueIds(std::list<std::string> &ids)
|
2010-08-31 13:13:52 -04:00
|
|
|
{
|
2010-09-01 13:56:15 -04:00
|
|
|
ids.clear();
|
2010-08-31 13:13:52 -04:00
|
|
|
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
// get the items from the private list.
|
|
|
|
if (privateList.size() == 0) {
|
2010-08-31 13:13:52 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<RsChatMsgItem *>::iterator it;
|
2010-09-01 13:56:15 -04:00
|
|
|
for (it = privateList.begin(); it != privateList.end(); it++) {
|
|
|
|
RsChatMsgItem *c = *it;
|
|
|
|
|
|
|
|
if (std::find(ids.begin(), ids.end(), c->PeerId()) == ids.end()) {
|
|
|
|
ids.push_back(c->PeerId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3ChatService::getPrivateChatQueue(std::string id, std::list<ChatInfo> &chats)
|
|
|
|
{
|
|
|
|
bool changed = false;
|
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
{
|
2010-09-01 13:56:15 -04:00
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
// get the items from the private list.
|
|
|
|
if (privateList.size() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<RsChatMsgItem *>::iterator it = privateList.begin();
|
|
|
|
while (it != privateList.end()) {
|
|
|
|
RsChatMsgItem *c = *it;
|
|
|
|
|
|
|
|
if (c->PeerId() == id) {
|
|
|
|
ChatInfo ci;
|
|
|
|
initRsChatInfo(c, ci);
|
|
|
|
chats.push_back(ci);
|
|
|
|
|
|
|
|
changed = true;
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
delete c;
|
2010-08-31 13:13:52 -04:00
|
|
|
|
2010-09-01 13:56:15 -04:00
|
|
|
std::list<RsChatMsgItem *>::iterator it1 = it;
|
|
|
|
it++;
|
|
|
|
privateList.erase(it1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
} /* UNLOCKED */
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PRIVATE_CHAT, NOTIFY_TYPE_DEL);
|
2010-08-31 13:13:52 -04:00
|
|
|
}
|
2010-09-01 13:56:15 -04:00
|
|
|
|
2010-08-31 13:13:52 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
|
|
|
|
{
|
|
|
|
i.rsid = c -> PeerId();
|
|
|
|
i.chatflags = 0 ;
|
|
|
|
i.msg = c -> message;
|
|
|
|
|
|
|
|
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
|
|
|
{
|
|
|
|
i.chatflags |= RS_CHAT_PRIVATE;
|
|
|
|
//std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i.chatflags |= RS_CHAT_PUBLIC;
|
|
|
|
//std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
void p3ChatService::setOwnCustomStateString(const std::string& s)
|
2009-09-29 16:37:20 -04:00
|
|
|
{
|
2010-04-24 06:33:12 -04:00
|
|
|
std::list<std::string> onlineList;
|
2009-09-29 16:37:20 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "p3chatservice: Setting own state string to new value : " << s << std::endl ;
|
|
|
|
#endif
|
2009-09-29 16:37:20 -04:00
|
|
|
_custom_status_string = s ;
|
2009-10-04 18:27:42 -04:00
|
|
|
|
|
|
|
for(std::map<std::string,StateStringInfo>::iterator it(_state_strings.begin());it!=_state_strings.end();++it)
|
|
|
|
it->second._own_is_new = true ;
|
2010-04-24 06:33:12 -04:00
|
|
|
|
|
|
|
mConnMgr->getOnlineList(onlineList);
|
2009-09-29 16:37:20 -04:00
|
|
|
}
|
2009-10-05 15:55:17 -04:00
|
|
|
|
|
|
|
rsicontrol->getNotify().notifyOwnStatusMessageChanged() ;
|
2010-04-24 06:33:12 -04:00
|
|
|
|
|
|
|
// alert your online peers to your newly set status
|
|
|
|
std::list<std::string>::iterator it(onlineList.begin());
|
|
|
|
for(; it != onlineList.end(); it++){
|
|
|
|
|
|
|
|
RsChatStatusItem *cs = new RsChatStatusItem();
|
|
|
|
cs->flags = RS_CHAT_FLAG_CUSTOM_STATE_AVAILABLE;
|
|
|
|
cs->status_string = "";
|
|
|
|
cs->PeerId(*it);
|
|
|
|
sendItem(cs);
|
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
IndicateConfigChanged();
|
|
|
|
}
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
|
|
|
|
{
|
2009-03-20 16:41:31 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-03-20 16:41:31 -04:00
|
|
|
std::cerr << "p3chatservice: Setting own avatar to new image." << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-03-20 16:41:31 -04:00
|
|
|
if(_own_avatar != NULL)
|
|
|
|
delete _own_avatar ;
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-03-20 16:41:31 -04:00
|
|
|
_own_avatar = new AvatarInfo(data,size) ;
|
|
|
|
|
|
|
|
// set the info that our avatar is new, for all peers
|
|
|
|
for(std::map<std::string,AvatarInfo *>::iterator it(_avatars.begin());it!=_avatars.end();++it)
|
|
|
|
it->second->_own_is_new = true ;
|
|
|
|
}
|
|
|
|
IndicateConfigChanged();
|
2009-10-04 18:27:42 -04:00
|
|
|
|
|
|
|
rsicontrol->getNotify().notifyOwnAvatarChanged() ;
|
|
|
|
|
|
|
|
#ifdef CHAT_DEBUG
|
2009-05-08 19:07:08 -04:00
|
|
|
std::cerr << "p3chatservice:setOwnAvatarJpegData() done." << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
void p3ChatService::receiveStateString(const std::string& id,const std::string& s)
|
2009-01-30 14:52:47 -05:00
|
|
|
{
|
2009-03-20 16:41:31 -04:00
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2010-04-24 06:33:12 -04:00
|
|
|
std::cerr << "p3chatservice: received custom state string for peer " << id << ". Storing it." << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
bool new_peer = (_state_strings.find(id) == _state_strings.end()) ;
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
_state_strings[id]._custom_status_string = s ;
|
|
|
|
_state_strings[id]._peer_is_new = true ;
|
|
|
|
_state_strings[id]._own_is_new = new_peer ;
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
2009-09-29 16:37:20 -04:00
|
|
|
void p3ChatService::receiveAvatarJpegData(RsChatAvatarItem *ci)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-09-29 16:37:20 -04:00
|
|
|
std::cerr << "p3chatservice: received avatar jpeg data for peer " << ci->PeerId() << ". Storing it." << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2009-09-29 16:37:20 -04:00
|
|
|
|
|
|
|
bool new_peer = (_avatars.find(ci->PeerId()) == _avatars.end()) ;
|
|
|
|
|
|
|
|
_avatars[ci->PeerId()] = new AvatarInfo(ci->image_data,ci->image_size) ;
|
|
|
|
_avatars[ci->PeerId()]->_peer_is_new = true ;
|
|
|
|
_avatars[ci->PeerId()]->_own_is_new = new_peer ;
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
std::string p3ChatService::getOwnCustomStateString()
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
return _custom_status_string ;
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size)
|
|
|
|
{
|
|
|
|
// should be a Mutex here.
|
2009-03-20 16:41:31 -04:00
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
uint32_t s = 0 ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-01-30 14:52:47 -05:00
|
|
|
std::cerr << "p3chatservice:: own avatar requested from above. " << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
// has avatar. Return it strait away.
|
|
|
|
//
|
|
|
|
if(_own_avatar != NULL)
|
2009-09-29 16:37:20 -04:00
|
|
|
{
|
|
|
|
_own_avatar->toUnsignedChar(data,s) ;
|
|
|
|
size = s ;
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
data=NULL ;
|
|
|
|
size=0 ;
|
|
|
|
}
|
|
|
|
}
|
2009-10-04 18:27:42 -04:00
|
|
|
|
|
|
|
std::string p3ChatService::getCustomStateString(const std::string& peer_id)
|
|
|
|
{
|
|
|
|
// should be a Mutex here.
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
std::map<std::string,StateStringInfo>::iterator it = _state_strings.find(peer_id) ;
|
|
|
|
|
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "p3chatservice:: status string for peer " << peer_id << " requested from above. " << std::endl ;
|
|
|
|
#endif
|
|
|
|
// has it. Return it strait away.
|
|
|
|
//
|
|
|
|
if(it!=_state_strings.end())
|
|
|
|
{
|
|
|
|
it->second._peer_is_new = false ;
|
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "Already has status string. Returning it" << std::endl ;
|
|
|
|
#endif
|
|
|
|
return it->second._custom_status_string ;
|
|
|
|
}
|
2010-04-24 06:33:12 -04:00
|
|
|
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2010-04-24 06:33:12 -04:00
|
|
|
std::cerr << "No status string for this peer. requesting it." << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2010-04-24 06:33:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
sendCustomStateRequest(peer_id);
|
|
|
|
return std::string() ;
|
2009-10-04 18:27:42 -04:00
|
|
|
}
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size)
|
|
|
|
{
|
|
|
|
// should be a Mutex here.
|
2009-03-20 16:41:31 -04:00
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(peer_id) ;
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-09-30 16:53:18 -04:00
|
|
|
std::cerr << "p3chatservice:: avatar for peer " << peer_id << " requested from above. " << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2010-04-24 06:33:12 -04:00
|
|
|
// has avatar. Return it straight away.
|
2009-01-30 14:52:47 -05:00
|
|
|
//
|
|
|
|
if(it!=_avatars.end())
|
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
uint32_t s=0 ;
|
|
|
|
it->second->toUnsignedChar(data,s) ;
|
|
|
|
size = s ;
|
2009-01-30 14:52:47 -05:00
|
|
|
it->second->_peer_is_new = false ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-01-30 14:52:47 -05:00
|
|
|
std::cerr << "Already has avatar. Returning it" << std::endl ;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
return ;
|
2010-02-10 05:56:54 -05:00
|
|
|
} else {
|
|
|
|
#ifdef CHAT_DEBUG
|
2009-01-30 14:52:47 -05:00
|
|
|
std::cerr << "No avatar for this peer. Requesting it by sending request packet." << std::endl ;
|
2010-02-10 05:56:54 -05:00
|
|
|
#endif
|
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2010-02-10 05:56:54 -05:00
|
|
|
sendAvatarRequest(peer_id);
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void p3ChatService::sendAvatarRequest(const std::string& peer_id)
|
|
|
|
{
|
|
|
|
// Doesn't have avatar. Request it.
|
|
|
|
//
|
2009-05-05 09:18:53 -04:00
|
|
|
RsChatMsgItem *ci = new RsChatMsgItem();
|
2009-01-30 14:52:47 -05:00
|
|
|
|
|
|
|
ci->PeerId(peer_id);
|
|
|
|
ci->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_REQUESTS_AVATAR ;
|
|
|
|
ci->sendTime = time(NULL);
|
2010-08-06 17:14:25 -04:00
|
|
|
ci->message.erase();
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-01-30 14:52:47 -05:00
|
|
|
std::cerr << "p3ChatService::sending request for avatar, to peer " << peer_id << std::endl ;
|
|
|
|
std::cerr << std::endl;
|
2009-10-04 18:27:42 -04:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
|
|
|
|
sendItem(ci);
|
|
|
|
}
|
|
|
|
|
2010-04-24 06:33:12 -04:00
|
|
|
void p3ChatService::sendCustomStateRequest(const std::string& peer_id){
|
|
|
|
|
|
|
|
RsChatStatusItem* cs = new RsChatStatusItem;
|
|
|
|
|
|
|
|
cs->PeerId(peer_id);
|
|
|
|
cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_REQUEST_CUSTOM_STATE ;
|
2010-08-06 17:14:25 -04:00
|
|
|
cs->status_string.erase();
|
2010-04-24 06:33:12 -04:00
|
|
|
|
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "p3ChatService::sending request for status, to peer " << peer_id << std::endl ;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sendItem(cs);
|
|
|
|
}
|
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
RsChatStatusItem *p3ChatService::makeOwnCustomStateStringItem()
|
2009-03-20 16:41:31 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
2009-10-04 18:27:42 -04:00
|
|
|
RsChatStatusItem *ci = new RsChatStatusItem();
|
2009-03-20 16:41:31 -04:00
|
|
|
|
2009-10-04 18:27:42 -04:00
|
|
|
ci->flags = RS_CHAT_FLAG_CUSTOM_STATE ;
|
|
|
|
ci->status_string = _custom_status_string ;
|
|
|
|
|
|
|
|
return ci ;
|
|
|
|
}
|
|
|
|
RsChatAvatarItem *p3ChatService::makeOwnAvatarItem()
|
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
RsChatAvatarItem *ci = new RsChatAvatarItem();
|
|
|
|
|
|
|
|
_own_avatar->toUnsignedChar(ci->image_data,ci->image_size) ;
|
2009-03-20 16:41:31 -04:00
|
|
|
|
|
|
|
return ci ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-30 14:52:47 -05:00
|
|
|
void p3ChatService::sendAvatarJpegData(const std::string& peer_id)
|
|
|
|
{
|
2010-02-10 05:56:54 -05:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-01-30 14:52:47 -05:00
|
|
|
std::cerr << "p3chatservice: sending requested for peer " << peer_id << ", data=" << (void*)_own_avatar << std::endl ;
|
2010-02-10 05:56:54 -05:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
|
|
|
|
if(_own_avatar != NULL)
|
2009-03-20 16:41:31 -04:00
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
RsChatAvatarItem *ci = makeOwnAvatarItem();
|
2009-03-20 16:41:31 -04:00
|
|
|
ci->PeerId(peer_id);
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-03-20 16:41:31 -04:00
|
|
|
// take avatar, and embed it into a std::wstring.
|
|
|
|
//
|
2010-03-28 16:46:45 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2009-09-29 16:37:20 -04:00
|
|
|
std::cerr << "p3ChatService::sending avatar image to peer" << peer_id << ", image size = " << ci->image_size << std::endl ;
|
2009-03-20 16:41:31 -04:00
|
|
|
std::cerr << std::endl;
|
2010-03-28 16:46:45 -04:00
|
|
|
#endif
|
2009-01-30 14:52:47 -05:00
|
|
|
|
2009-03-20 16:41:31 -04:00
|
|
|
sendItem(ci) ;
|
|
|
|
}
|
2010-02-10 05:56:54 -05:00
|
|
|
else {
|
2010-03-28 16:46:45 -04:00
|
|
|
#ifdef CHAT_DEBUG
|
2010-02-10 05:56:54 -05:00
|
|
|
std::cerr << "Doing nothing" << std::endl ;
|
2010-03-28 16:46:45 -04:00
|
|
|
#endif
|
2010-02-10 05:56:54 -05:00
|
|
|
}
|
2009-01-30 14:52:47 -05:00
|
|
|
}
|
|
|
|
|
2010-04-24 06:33:12 -04:00
|
|
|
void p3ChatService::sendCustomState(const std::string& peer_id){
|
|
|
|
|
|
|
|
#ifdef CHAT_DEBUG
|
|
|
|
std::cerr << "p3chatservice: sending requested status string for peer " << peer_id << std::endl ;
|
|
|
|
#endif
|
|
|
|
|
2010-07-20 15:45:07 -04:00
|
|
|
RsChatStatusItem *cs = makeOwnCustomStateStringItem();
|
|
|
|
cs->PeerId(peer_id);
|
2010-04-24 06:33:12 -04:00
|
|
|
|
2010-07-20 15:45:07 -04:00
|
|
|
sendItem(cs);
|
2010-04-24 06:33:12 -04:00
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
bool p3ChatService::loadList(std::list<RsItem*> load)
|
2009-03-20 16:41:31 -04:00
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
for(std::list<RsItem*>::const_iterator it(load.begin());it!=load.end();++it)
|
2009-03-20 16:41:31 -04:00
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
RsChatAvatarItem *ai = NULL ;
|
|
|
|
|
|
|
|
if(NULL != (ai = dynamic_cast<RsChatAvatarItem *>(*it)))
|
2009-03-20 16:41:31 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
_own_avatar = new AvatarInfo(ai->image_data,ai->image_size) ;
|
2009-03-20 16:41:31 -04:00
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
RsChatStatusItem *mitem = NULL ;
|
2009-03-20 16:41:31 -04:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
if(NULL != (mitem = dynamic_cast<RsChatStatusItem *>(*it)))
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
2009-03-20 16:41:31 -04:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
_custom_status_string = mitem->status_string ;
|
|
|
|
}
|
2009-03-20 16:41:31 -04:00
|
|
|
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
delete *it;
|
2009-03-20 16:41:31 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
std::list<RsItem*> p3ChatService::saveList(bool& cleanup)
|
2009-03-20 16:41:31 -04:00
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
cleanup = true ;
|
2009-05-08 20:19:54 -04:00
|
|
|
/* now we create a pqistore, and stream all the msgs into it */
|
2009-03-20 16:41:31 -04:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
std::list<RsItem*> list ;
|
2009-03-20 16:41:31 -04:00
|
|
|
|
|
|
|
if(_own_avatar != NULL)
|
|
|
|
{
|
2009-09-29 16:37:20 -04:00
|
|
|
RsChatAvatarItem *ci = makeOwnAvatarItem() ;
|
2009-03-20 16:41:31 -04:00
|
|
|
ci->PeerId(mConnMgr->getOwnId());
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
list.push_back(ci) ;
|
2009-03-20 16:41:31 -04:00
|
|
|
}
|
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
RsChatStatusItem *di = new RsChatStatusItem ;
|
|
|
|
di->status_string = _custom_status_string ;
|
|
|
|
di->flags = RS_CHAT_FLAG_CUSTOM_STATE ;
|
2009-03-20 16:41:31 -04:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
list.push_back(di) ;
|
2009-03-20 16:41:31 -04:00
|
|
|
|
2009-09-29 16:37:20 -04:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsSerialiser *p3ChatService::setupSerialiser()
|
|
|
|
{
|
|
|
|
RsSerialiser *rss = new RsSerialiser ;
|
|
|
|
rss->addSerialType(new RsChatSerialiser) ;
|
|
|
|
|
|
|
|
return rss ;
|
2009-03-20 16:41:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
|