mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-21 21:55:15 -05:00
fixed exchange of custom strings.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1717 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
96d9f80d6c
commit
798f6026cc
@ -201,7 +201,7 @@ class NotifyBase
|
||||
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 notifyCustomState(const std::string& peer_id) {}
|
||||
virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; }
|
||||
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files) { (void)files; }
|
||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
|
||||
|
@ -136,6 +136,7 @@ virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||
|
||||
virtual void setCustomStateString(const std::string& status_string) = 0 ;
|
||||
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 ;
|
||||
|
@ -185,12 +185,18 @@ void p3Msgs::getAvatarData(std::string pid,unsigned char *& data,int& size)
|
||||
mChatSrv->getAvatarJpegData(pid,data,size) ;
|
||||
}
|
||||
|
||||
std::string p3Msgs::getCustomStateString(const std::string& peer_id)
|
||||
{
|
||||
return mChatSrv->getCustomStateString(peer_id) ;
|
||||
}
|
||||
|
||||
std::string p3Msgs::getCustomStateString()
|
||||
{
|
||||
return mChatSrv->getCustomStateString() ;
|
||||
return mChatSrv->getOwnCustomStateString() ;
|
||||
}
|
||||
|
||||
void p3Msgs::setCustomStateString(const std::string& state_string)
|
||||
{
|
||||
mChatSrv->setCustomStateString(state_string) ;
|
||||
mChatSrv->setOwnCustomStateString(state_string) ;
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,9 @@ class p3Msgs: public RsMsgs
|
||||
virtual void getOwnAvatarData(unsigned char *& data,int& size);
|
||||
|
||||
// gets/set avatar from peer id in jpeg format.
|
||||
virtual void setCustomStateString(const std::string& status_string) ;
|
||||
virtual void setCustomStateString(const std::string& status_string) ;
|
||||
virtual std::string getCustomStateString() ;
|
||||
virtual std::string getCustomStateString(const std::string& peer_id) ;
|
||||
|
||||
|
||||
/****************************************/
|
||||
|
@ -52,23 +52,11 @@ p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
||||
|
||||
int p3ChatService::tick()
|
||||
{
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::tick()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int p3ChatService::status()
|
||||
{
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::status()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -112,6 +100,20 @@ int p3ChatService::sendChat(std::wstring msg)
|
||||
return 1;
|
||||
}
|
||||
|
||||
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.
|
||||
};
|
||||
class p3ChatService::AvatarInfo
|
||||
{
|
||||
public:
|
||||
@ -144,85 +146,17 @@ class p3ChatService::AvatarInfo
|
||||
AvatarInfo(const unsigned char *jpeg_data,int size)
|
||||
{
|
||||
init(jpeg_data,size) ;
|
||||
#ifdef TO_REMOVE
|
||||
int n_c = size ;
|
||||
int p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
|
||||
int n = n_c/p + 1 ;
|
||||
|
||||
_jpeg_wstring = std::wstring(n,0) ;
|
||||
|
||||
for(int i=0;i<n;++i)
|
||||
{
|
||||
wchar_t h = jpeg_data[p*i+p-1] ;
|
||||
|
||||
for(int j=p-2;j>=0;--j)
|
||||
{
|
||||
h = h << 8 ;
|
||||
h += jpeg_data[p*i+j] ;
|
||||
}
|
||||
_jpeg_wstring[i] = h ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef AVATAR_KEEP_BACKWRD_COMP
|
||||
AvatarInfo(const std::wstring& s)
|
||||
{
|
||||
int p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
|
||||
int n = s.size() ;
|
||||
int n_c = p*n ;
|
||||
|
||||
_image_data = new unsigned char[n_c] ;
|
||||
_image_size = n_c ;
|
||||
|
||||
for(int i=0;i<n;++i)
|
||||
{
|
||||
wchar_t h = s[i] ;
|
||||
|
||||
for(int j=0;j<p;++j)
|
||||
{
|
||||
_image_data[p*i+j] = (unsigned char)(h & 0xff) ;
|
||||
h = h >> 8 ;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
const std::wstring& toStdWString() const { return _jpeg_wstring; }
|
||||
#endif
|
||||
|
||||
void toUnsignedChar(unsigned char *& data,uint32_t& size) const
|
||||
{
|
||||
data = new unsigned char[_image_size] ;
|
||||
size = _image_size ;
|
||||
memcpy(data,_image_data,size*sizeof(unsigned char)) ;
|
||||
#ifdef TO_REMOVE
|
||||
int p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
|
||||
int n = _jpeg_wstring.size() ;
|
||||
int n_c = p*n ;
|
||||
|
||||
data = new unsigned char[n_c] ;
|
||||
size = n_c ;
|
||||
|
||||
for(int i=0;i<n;++i)
|
||||
{
|
||||
wchar_t h = _jpeg_wstring[i] ;
|
||||
|
||||
for(int j=0;j<p;++j)
|
||||
{
|
||||
data[p*i+j] = (unsigned char)(h & 0xff) ;
|
||||
h = h >> 8 ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t _image_size ;
|
||||
unsigned char *_image_data ;
|
||||
#ifdef TO_REMOVE
|
||||
std::wstring _jpeg_wstring;
|
||||
#endif
|
||||
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.
|
||||
};
|
||||
@ -233,7 +167,7 @@ void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
||||
mConnMgr->getOnlineList(ids);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendChat()";
|
||||
std::cerr << "p3ChatService::sendChat(): sending group chat status string: " << status_string << std::endl ;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
@ -280,21 +214,24 @@ int p3ChatService::sendPrivateChat( std::wstring msg, std::string id)
|
||||
ci->sendTime = time(NULL);
|
||||
ci->message = msg;
|
||||
|
||||
std::map<std::string,AvatarInfo*>::iterator it = _avatars.find(id) ;
|
||||
{
|
||||
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 != _avatars.end() && it->second->_own_is_new)
|
||||
{
|
||||
if(it == _avatars.end())
|
||||
{
|
||||
_avatars[id] = new AvatarInfo ;
|
||||
it = _avatars.find(id) ;
|
||||
}
|
||||
if(it->second->_own_is_new)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendPrivateChat: new avatar never sent to peer " << id << ". Setting <new> flag to packet." << std::endl;
|
||||
std::cerr << "p3ChatService::sendPrivateChat: new avatar never sent to peer " << id << ". Setting <new> flag to packet." << std::endl;
|
||||
#endif
|
||||
|
||||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
it->second->_own_is_new = false ;
|
||||
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||
it->second->_own_is_new = false ;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
@ -307,6 +244,36 @@ int p3ChatService::sendPrivateChat( std::wstring msg, std::string id)
|
||||
|
||||
sendItem(ci);
|
||||
|
||||
// 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) ;
|
||||
|
||||
if(it != _state_strings.end())
|
||||
{
|
||||
_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) ;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -334,14 +301,7 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
||||
std::cerr << "Got msg. Flags = " << ci->chatFlags << std::endl ;
|
||||
#endif
|
||||
|
||||
if(ci->chatFlags & RS_CHAT_FLAG_CONTAINS_AVATAR) // no msg here. Just an avatar.
|
||||
{
|
||||
#ifdef AVATAR_KEEP_BACKWRD_COMP
|
||||
receiveAvatarJpegData(ci) ; // Do we keep this for backward compatibility ?
|
||||
#endif
|
||||
delete item ;
|
||||
}
|
||||
else if(ci->chatFlags & RS_CHAT_FLAG_REQUESTS_AVATAR) // no msg here. Just an avatar request.
|
||||
if(ci->chatFlags & RS_CHAT_FLAG_REQUESTS_AVATAR) // no msg here. Just an avatar request.
|
||||
{
|
||||
sendAvatarJpegData(ci->PeerId()) ;
|
||||
delete item ;
|
||||
@ -388,7 +348,13 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
||||
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,false) ;
|
||||
|
||||
if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE)
|
||||
rsicontrol->getNotify().notifyCustomState(cs->PeerId(),cs->status_string) ;
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cout << "Received custom status string packet from peer " << cs->PeerId() << ": " << cs->status_string << ". Storing it and notifying." << std::endl ;
|
||||
#endif
|
||||
receiveStateString(cs->PeerId(),cs->status_string) ; // store it
|
||||
rsicontrol->getNotify().notifyCustomState(cs->PeerId()) ;
|
||||
}
|
||||
|
||||
delete item ;
|
||||
continue ;
|
||||
@ -413,12 +379,18 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
||||
return ilist;
|
||||
}
|
||||
|
||||
void p3ChatService::setCustomStateString(const std::string& s)
|
||||
void p3ChatService::setOwnCustomStateString(const std::string& s)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice: Setting own state string to new value : " << s << std::endl ;
|
||||
#endif
|
||||
_custom_status_string = s ;
|
||||
|
||||
for(std::map<std::string,StateStringInfo>::iterator it(_state_strings.begin());it!=_state_strings.end();++it)
|
||||
it->second._own_is_new = true ;
|
||||
}
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
@ -427,7 +399,9 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice: Setting own avatar to new image." << std::endl ;
|
||||
#endif
|
||||
|
||||
if(_own_avatar != NULL)
|
||||
delete _own_avatar ;
|
||||
@ -439,28 +413,34 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
|
||||
it->second->_own_is_new = true ;
|
||||
}
|
||||
IndicateConfigChanged();
|
||||
|
||||
rsicontrol->getNotify().notifyOwnAvatarChanged() ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice:setOwnAvatarJpegData() done." << std::endl ;
|
||||
}
|
||||
|
||||
#ifdef AVATAR_KEEP_BACKWRD_COMP
|
||||
// This one is kept for compatibility
|
||||
void p3ChatService::receiveAvatarJpegData(RsChatMsgItem *ci)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
std::cerr << "p3chatservice: received avatar jpeg data for peer " << ci->PeerId() << ". Storing it." << std::endl ;
|
||||
|
||||
bool new_peer = (_avatars.find(ci->PeerId()) == _avatars.end()) ;
|
||||
|
||||
_avatars[ci->PeerId()] = new AvatarInfo(ci->message) ;
|
||||
_avatars[ci->PeerId()]->_peer_is_new = true ;
|
||||
_avatars[ci->PeerId()]->_own_is_new = new_peer ;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void p3ChatService::receiveStateString(const std::string& id,const std::string& s)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice: received avatar jpeg data for peer " << id << ". Storing it." << std::endl ;
|
||||
#endif
|
||||
|
||||
bool new_peer = (_state_strings.find(id) == _state_strings.end()) ;
|
||||
|
||||
_state_strings[id]._custom_status_string = s ;
|
||||
_state_strings[id]._peer_is_new = true ;
|
||||
_state_strings[id]._own_is_new = new_peer ;
|
||||
}
|
||||
void p3ChatService::receiveAvatarJpegData(RsChatAvatarItem *ci)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice: received avatar jpeg data for peer " << ci->PeerId() << ". Storing it." << std::endl ;
|
||||
#endif
|
||||
|
||||
bool new_peer = (_avatars.find(ci->PeerId()) == _avatars.end()) ;
|
||||
|
||||
@ -469,13 +449,20 @@ void p3ChatService::receiveAvatarJpegData(RsChatAvatarItem *ci)
|
||||
_avatars[ci->PeerId()]->_own_is_new = new_peer ;
|
||||
}
|
||||
|
||||
std::string p3ChatService::getOwnCustomStateString()
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
return _custom_status_string ;
|
||||
}
|
||||
void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size)
|
||||
{
|
||||
// should be a Mutex here.
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
uint32_t s = 0 ;
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice:: own avatar requested from above. " << std::endl ;
|
||||
#endif
|
||||
// has avatar. Return it strait away.
|
||||
//
|
||||
if(_own_avatar != NULL)
|
||||
@ -489,6 +476,36 @@ void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size)
|
||||
size=0 ;
|
||||
}
|
||||
}
|
||||
|
||||
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 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "No status string for this peer. Not requesting it." << std::endl ;
|
||||
#endif
|
||||
return std::string() ;
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size)
|
||||
{
|
||||
// should be a Mutex here.
|
||||
@ -496,7 +513,9 @@ void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *
|
||||
|
||||
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(peer_id) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3chatservice:: avatar for peer " << peer_id << " requested from above. " << std::endl ;
|
||||
#endif
|
||||
// has avatar. Return it strait away.
|
||||
//
|
||||
if(it!=_avatars.end())
|
||||
@ -505,7 +524,9 @@ void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *
|
||||
it->second->toUnsignedChar(data,s) ;
|
||||
size = s ;
|
||||
it->second->_peer_is_new = false ;
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Already has avatar. Returning it" << std::endl ;
|
||||
#endif
|
||||
return ;
|
||||
}
|
||||
else
|
||||
@ -525,27 +546,30 @@ void p3ChatService::sendAvatarRequest(const std::string& peer_id)
|
||||
ci->sendTime = time(NULL);
|
||||
ci->message = std::wstring() ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sending request for avatar, to peer " << peer_id << std::endl ;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
sendItem(ci);
|
||||
}
|
||||
|
||||
RsChatStatusItem *p3ChatService::makeOwnCustomStateStringItem()
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
RsChatStatusItem *ci = new RsChatStatusItem();
|
||||
|
||||
ci->flags = RS_CHAT_FLAG_CUSTOM_STATE ;
|
||||
ci->status_string = _custom_status_string ;
|
||||
|
||||
return ci ;
|
||||
}
|
||||
RsChatAvatarItem *p3ChatService::makeOwnAvatarItem()
|
||||
{
|
||||
#ifdef TO_REMOVE
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
RsChatMsgItem *ci = new RsChatMsgItem();
|
||||
|
||||
ci->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CONTAINS_AVATAR ;
|
||||
ci->sendTime = time(NULL);
|
||||
ci->message = _own_avatar->toStdWString() ;
|
||||
#else
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
RsChatAvatarItem *ci = new RsChatAvatarItem();
|
||||
|
||||
_own_avatar->toUnsignedChar(ci->image_data,ci->image_size) ;
|
||||
#endif
|
||||
|
||||
return ci ;
|
||||
}
|
||||
|
@ -39,8 +39,6 @@
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
//#define AVATAR_KEEP_BACKWRD_COMP
|
||||
|
||||
class p3ChatService: public p3Service, public p3Config
|
||||
{
|
||||
public:
|
||||
@ -54,8 +52,10 @@ class p3ChatService: public p3Service, public p3Config
|
||||
int sendPrivateChat(std::wstring msg, std::string id);
|
||||
void sendStatusString(const std::string& peer_id,const std::string& status_str) ;
|
||||
void sendGroupChatStatusString(const std::string& status_str) ;
|
||||
void setCustomStateString(const std::string&) ;
|
||||
std::string getCustomStateString() { return _custom_status_string ; }
|
||||
|
||||
std::string getCustomStateString(const std::string& peer_id) ;
|
||||
void setOwnCustomStateString(const std::string&) ;
|
||||
std::string getOwnCustomStateString() ;
|
||||
|
||||
/// gets the peer's avatar in jpeg format, if available. Null otherwise. Also asks the peer to send
|
||||
/// its avatar, if not already available. Creates a new unsigned char array. It's the caller's
|
||||
@ -78,26 +78,28 @@ class p3ChatService: public p3Service, public p3Config
|
||||
RsMutex mChatMtx;
|
||||
|
||||
class AvatarInfo ;
|
||||
class StateStringInfo ;
|
||||
|
||||
/// Send avatar info to peer in jpeg format.
|
||||
void sendAvatarJpegData(const std::string& peer_id) ;
|
||||
|
||||
/// Receive the avatar in a chat item, with RS_CHAT_RECEIVE_AVATAR flag.
|
||||
#ifdef AVATAR_KEEP_BACKWRD_COMP
|
||||
void receiveAvatarJpegData(RsChatMsgItem *ci) ; // old method
|
||||
#endif
|
||||
void receiveAvatarJpegData(RsChatAvatarItem *ci) ; // new method
|
||||
void receiveStateString(const std::string& id,const std::string& s) ;
|
||||
|
||||
/// Sends a request for an avatar to the peer of given id
|
||||
void sendAvatarRequest(const std::string& peer_id) ;
|
||||
|
||||
RsChatAvatarItem *makeOwnAvatarItem() ;
|
||||
RsChatStatusItem *makeOwnCustomStateStringItem() ;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
|
||||
AvatarInfo *_own_avatar ;
|
||||
std::map<std::string,AvatarInfo *> _avatars ;
|
||||
|
||||
std::string _custom_status_string ;
|
||||
std::map<std::string,StateStringInfo> _state_strings ;
|
||||
};
|
||||
|
||||
#endif // SERVICE_CHAT_HEADER
|
||||
|
@ -712,6 +712,18 @@ void PeersDialog::updateStatusString(const QString& status_string)
|
||||
QTimer::singleShot(5000,this,SLOT(resetStatusBar())) ;
|
||||
}
|
||||
|
||||
void PeersDialog::updatePeersCustomStateString(const QString& peer_id)
|
||||
{
|
||||
#ifdef JUST_AN_EXAMPLE
|
||||
// This is an example of how to retrieve the custom string.
|
||||
//
|
||||
std::cerr << "PeersDialog: Got notified that state string changed for peer " << peer_id.toStdString() << std::endl ;
|
||||
std::cerr << "New state string for this peer is : " << rsMsgs->getCustomStateString(peer_id.toStdString()) << std::endl ;
|
||||
|
||||
QMessageBox::information(NULL,"Notification",peer_id+" has new custom string: " + QString::fromStdString(rsMsgs->getCustomStateString(peer_id.toStdString()))) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void PeersDialog::updatePeersAvatar(const QString& peer_id)
|
||||
{
|
||||
std::cerr << "PeersDialog: Got notified of new avatar for peer " << peer_id.toStdString() << std::endl ;
|
||||
|
@ -39,134 +39,135 @@ class ChatDialog;
|
||||
|
||||
class PeersDialog : public MainPage
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Default Constructor */
|
||||
PeersDialog(QWidget *parent = 0);
|
||||
/** Default Destructor */
|
||||
|
||||
PopupChatDialog *getPrivateChat(std::string id, std::string name, uint chatflags);
|
||||
void clearOldChats();
|
||||
|
||||
void loadEmoticonsgroupchat();
|
||||
// void setChatDialog(ChatDialog *cd);
|
||||
public:
|
||||
/** Default Constructor */
|
||||
PeersDialog(QWidget *parent = 0);
|
||||
/** Default Destructor */
|
||||
|
||||
QPixmap picture;
|
||||
PopupChatDialog *getPrivateChat(std::string id, std::string name, uint chatflags);
|
||||
void clearOldChats();
|
||||
|
||||
public slots:
|
||||
void loadEmoticonsgroupchat();
|
||||
// void setChatDialog(ChatDialog *cd);
|
||||
|
||||
void insertPeers();
|
||||
void toggleSendItem( QTreeWidgetItem *item, int col );
|
||||
QPixmap picture;
|
||||
|
||||
void insertChat();
|
||||
void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
|
||||
void resetStatusBar() ;
|
||||
public slots:
|
||||
|
||||
|
||||
void smileyWidgetgroupchat();
|
||||
void addSmileys();
|
||||
|
||||
void on_actionClearChat_triggered();
|
||||
void displayInfoChatMenu(const QPoint& pos);
|
||||
void insertPeers();
|
||||
void toggleSendItem( QTreeWidgetItem *item, int col );
|
||||
|
||||
// called by notifyQt when another peer is typing (in group chant and private chat)
|
||||
void updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat) ;
|
||||
void insertChat();
|
||||
void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
|
||||
void resetStatusBar() ;
|
||||
|
||||
void updatePeersAvatar(const QString& peer_id);
|
||||
void updateAvatar(); // called by notifyQt to update the avatar when it gets changed by another component
|
||||
|
||||
private slots:
|
||||
void smileyWidgetgroupchat();
|
||||
void addSmileys();
|
||||
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void peertreeWidgetCostumPopupMenu( QPoint point );
|
||||
void on_actionClearChat_triggered();
|
||||
void displayInfoChatMenu(const QPoint& pos);
|
||||
|
||||
void updateStatusString(const QString& statusString) ; // called when a peer is typing in group chat
|
||||
void updateStatusTyping() ; // called each time a key is hit
|
||||
|
||||
//void updatePeerStatusString(const QString& peer_id,const QString& chat_status) ;
|
||||
// called by notifyQt when another peer is typing (in group chant and private chat)
|
||||
void updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat) ;
|
||||
|
||||
/** Export friend in Friends Dialog */
|
||||
void exportfriend();
|
||||
/** Remove friend */
|
||||
void removefriend();
|
||||
/** start a chat with a friend **/
|
||||
void chatfriend();
|
||||
void msgfriend();
|
||||
void updatePeersCustomStateString(const QString& peer_id) ;
|
||||
void updatePeersAvatar(const QString& peer_id);
|
||||
void updateAvatar(); // called by notifyQt to update the avatar when it gets changed by another component
|
||||
|
||||
void configurefriend();
|
||||
void viewprofile();
|
||||
private slots:
|
||||
|
||||
/** RsServer Friend Calls */
|
||||
void allowfriend();
|
||||
void connectfriend();
|
||||
void setaddressfriend();
|
||||
void trustfriend();
|
||||
|
||||
void setColor();
|
||||
void insertSendList();
|
||||
void checkChat();
|
||||
void sendMsg();
|
||||
|
||||
//void privchat();
|
||||
|
||||
void setFont();
|
||||
void getFont();
|
||||
void underline();
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void peertreeWidgetCostumPopupMenu( QPoint point );
|
||||
|
||||
void changeAvatarClicked();
|
||||
void getAvatar();
|
||||
|
||||
void on_actionAdd_Friend_activated();
|
||||
void on_actionCreate_new_Profile_activated();
|
||||
|
||||
void loadmypersonalstatus();
|
||||
void updateStatusString(const QString& statusString) ; // called when a peer is typing in group chat
|
||||
void updateStatusTyping() ; // called each time a key is hit
|
||||
|
||||
//void updatePeerStatusString(const QString& peer_id,const QString& chat_status) ;
|
||||
|
||||
/** Export friend in Friends Dialog */
|
||||
void exportfriend();
|
||||
/** Remove friend */
|
||||
void removefriend();
|
||||
/** start a chat with a friend **/
|
||||
void chatfriend();
|
||||
void msgfriend();
|
||||
|
||||
void configurefriend();
|
||||
void viewprofile();
|
||||
|
||||
/** RsServer Friend Calls */
|
||||
void allowfriend();
|
||||
void connectfriend();
|
||||
void setaddressfriend();
|
||||
void trustfriend();
|
||||
|
||||
void setColor();
|
||||
void insertSendList();
|
||||
void checkChat();
|
||||
void sendMsg();
|
||||
|
||||
//void privchat();
|
||||
|
||||
void setFont();
|
||||
void getFont();
|
||||
void underline();
|
||||
|
||||
void changeAvatarClicked();
|
||||
void getAvatar();
|
||||
|
||||
void on_actionAdd_Friend_activated();
|
||||
void on_actionCreate_new_Profile_activated();
|
||||
|
||||
void loadmypersonalstatus();
|
||||
|
||||
|
||||
signals:
|
||||
void friendsUpdated() ;
|
||||
void notifyGroupChat(const QString&,const QString&) ;
|
||||
|
||||
private:
|
||||
class QLabel *iconLabel, *textLabel;
|
||||
class QWidget *widget;
|
||||
class QWidgetAction *widgetAction;
|
||||
class QSpacerItem *spacerItem;
|
||||
void friendsUpdated() ;
|
||||
void notifyGroupChat(const QString&,const QString&) ;
|
||||
|
||||
/* Worker Functions */
|
||||
/* (1) Update Display */
|
||||
private:
|
||||
class QLabel *iconLabel, *textLabel;
|
||||
class QWidget *widget;
|
||||
class QWidgetAction *widgetAction;
|
||||
class QSpacerItem *spacerItem;
|
||||
|
||||
/* (2) Utility Fns */
|
||||
QTreeWidgetItem *getCurrentPeer();
|
||||
/* Worker Functions */
|
||||
/* (1) Update Display */
|
||||
|
||||
/** Define the popup menus for the Context menu */
|
||||
QMenu* contextMnu;
|
||||
/** Defines the actions for the context menu */
|
||||
QAction* chatAct;
|
||||
QAction* msgAct;
|
||||
QAction* connectfriendAct;
|
||||
QAction* profileviewAct;
|
||||
QAction* configurefriendAct;
|
||||
QAction* exportfriendAct;
|
||||
QAction* removefriendAct;
|
||||
/* (2) Utility Fns */
|
||||
QTreeWidgetItem *getCurrentPeer();
|
||||
|
||||
QTreeWidget *peertreeWidget;
|
||||
/** Define the popup menus for the Context menu */
|
||||
QMenu* contextMnu;
|
||||
/** Defines the actions for the context menu */
|
||||
QAction* chatAct;
|
||||
QAction* msgAct;
|
||||
QAction* connectfriendAct;
|
||||
QAction* profileviewAct;
|
||||
QAction* configurefriendAct;
|
||||
QAction* exportfriendAct;
|
||||
QAction* removefriendAct;
|
||||
|
||||
IMHistoryKeeper historyKeeper;
|
||||
|
||||
QColor _currentColor;
|
||||
bool _underline;
|
||||
time_t last_status_send_time ;
|
||||
QTreeWidget *peertreeWidget;
|
||||
|
||||
QHash<QString, QString> smileys;
|
||||
IMHistoryKeeper historyKeeper;
|
||||
|
||||
std::map<std::string, PopupChatDialog *> chatDialogs;
|
||||
QColor _currentColor;
|
||||
bool _underline;
|
||||
time_t last_status_send_time ;
|
||||
|
||||
QFont mCurrentFont; /* how the text will come out */
|
||||
|
||||
std::map<std::string, PopupChatDialog *> chatDialogs;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::PeersDialog ui;
|
||||
QFont mCurrentFont; /* how the text will come out */
|
||||
|
||||
/** A RshareSettings object used for saving/loading settings */
|
||||
RshareSettings* _settings;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::PeersDialog ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -50,10 +50,10 @@ void NotifyQt::notifyPeerHasNewAvatar(std::string peer_id)
|
||||
emit peerHasNewAvatar(QString::fromStdString(peer_id)) ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyCustomState(const std::string& peer_id,const std::string& custom_state_string)
|
||||
void NotifyQt::notifyCustomState(const std::string& peer_id)
|
||||
{
|
||||
std::cerr << "notifyQt: Received custom status string: " << custom_state_string << std::endl ;
|
||||
emit peerCustomStateStringChanged(QString::fromStdString(peer_id),QString::fromStdString(custom_state_string)) ;
|
||||
std::cerr << "notifyQt: Received custom status string notification" << std::endl ;
|
||||
emit peerHasNewCustomStateString(QString::fromStdString(peer_id)) ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyChatStatus(const std::string& peer_id,const std::string& status_string,bool is_private)
|
||||
|
@ -34,7 +34,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
virtual void notifyListChange(int list, int type);
|
||||
virtual void notifyErrorMsg(int list, int sev, std::string msg);
|
||||
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 notifyCustomState(const std::string& peer_id);
|
||||
virtual void notifyHashingInfo(std::string fileinfo);
|
||||
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files);
|
||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
|
||||
@ -54,7 +54,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
void configChanged() const ;
|
||||
void logInfoChanged(const QString&) const ;
|
||||
void chatStatusChanged(const QString&,const QString&,bool) const ;
|
||||
void peerCustomStateStringChanged(const QString&,const QString&) const ;
|
||||
void peerHasNewCustomStateString(const QString&) const ;
|
||||
void gotTurtleSearchResult(qulonglong search_id,FileDetail file) const ;
|
||||
void peerHasNewAvatar(const QString& peer_id) const ;
|
||||
void ownAvatarChanged() const ;
|
||||
|
@ -201,7 +201,7 @@ class NotifyBase
|
||||
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 notifyCustomState(const std::string& peer_id) {}
|
||||
virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; }
|
||||
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files) { (void)files; }
|
||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
|
||||
|
@ -136,6 +136,7 @@ virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||
|
||||
virtual void setCustomStateString(const std::string& status_string) = 0 ;
|
||||
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 ;
|
||||
|
Loading…
Reference in New Issue
Block a user