mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-21 21:55:15 -05:00
- ported commit from v0.4.x to integrate new RsAvatarItem code
- suppressed compatibility with old avatar transmition code - added code for storing and sending a custom status string (for e.g. saying "I'm not here now") in p3ChatService - added code for sending group chat status messages "peer is typing". Not fully functionnal yet. Warnings: - this commit breaks the compatibility for avatar transmission - the new avatar transmission is not fully working yet git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1696 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
dfee01d4d4
commit
396058c665
@ -200,7 +200,8 @@ class NotifyBase
|
|||||||
virtual void notifyListChange(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 notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
|
||||||
virtual void notifyChat() { return; }
|
virtual void notifyChat() { return; }
|
||||||
virtual void notifyChatStatus(const std::string& peer_id,const std::string& status_string) {}
|
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(std::string fileinfo) { (void)fileinfo; return ; }
|
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 notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files) { (void)files; }
|
||||||
};
|
};
|
||||||
|
@ -132,6 +132,10 @@ virtual bool chatAvailable() = 0;
|
|||||||
virtual bool ChatSend(ChatInfo &ci) = 0;
|
virtual bool ChatSend(ChatInfo &ci) = 0;
|
||||||
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
||||||
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
|
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
|
||||||
|
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||||
|
|
||||||
|
virtual void setCustomStateString(const std::string& status_string) = 0 ;
|
||||||
|
virtual std::string getCustomStateString() = 0 ;
|
||||||
|
|
||||||
// get avatar data for peer pid
|
// get avatar data for peer pid
|
||||||
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;
|
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;
|
||||||
|
@ -109,6 +109,10 @@ bool p3Msgs::ChatSend(ChatInfo &ci)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
@ -188,4 +192,12 @@ void p3Msgs::getAvatarData(std::string pid,unsigned char *& data,int& size)
|
|||||||
mChatSrv->getAvatarJpegData(pid,data,size) ;
|
mChatSrv->getAvatarJpegData(pid,data,size) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string p3Msgs::getCustomStateString()
|
||||||
|
{
|
||||||
|
return mChatSrv->getCustomStateString() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3Msgs::setCustomStateString(const std::string& state_string)
|
||||||
|
{
|
||||||
|
mChatSrv->setCustomStateString(state_string) ;
|
||||||
|
}
|
||||||
|
@ -57,12 +57,18 @@ class p3Msgs: public RsMsgs
|
|||||||
virtual void setOwnAvatarData(const unsigned char *data,int size);
|
virtual void setOwnAvatarData(const unsigned char *data,int size);
|
||||||
virtual void getOwnAvatarData(unsigned char *& data,int& size);
|
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 std::string getCustomStateString() ;
|
||||||
|
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/* Chat */
|
/* Chat */
|
||||||
virtual bool chatAvailable();
|
virtual bool chatAvailable();
|
||||||
virtual bool ChatSend(ChatInfo &ci);
|
virtual bool ChatSend(ChatInfo &ci);
|
||||||
virtual bool getNewChat(std::list<ChatInfo> &chats);
|
virtual bool getNewChat(std::list<ChatInfo> &chats);
|
||||||
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) ;
|
||||||
|
virtual void sendGroupChatStatusString(const std::string& status_string) ;
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
|
||||||
|
@ -62,11 +62,22 @@ std::ostream& RsChatStatusItem::print(std::ostream &out, uint16_t indent)
|
|||||||
uint16_t int_Indent = indent + 2;
|
uint16_t int_Indent = indent + 2;
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
out << "Status string: " << status_string << std::endl;
|
out << "Status string: " << status_string << std::endl;
|
||||||
|
out << "Flags : " << (void*)flags << std::endl;
|
||||||
|
|
||||||
printRsItemEnd(out, "RsChatStatusItem", indent);
|
printRsItemEnd(out, "RsChatStatusItem", indent);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& RsChatAvatarItem::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsChatAvatarItem", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << "Image size: " << image_size << std::endl;
|
||||||
|
printRsItemEnd(out, "RsChatStatusItem", indent);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize)
|
RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||||
{
|
{
|
||||||
uint32_t rstype = getRsItemId(data);
|
uint32_t rstype = getRsItemId(data);
|
||||||
@ -101,6 +112,7 @@ RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||||||
{
|
{
|
||||||
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem(data,*pktsize) ;
|
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem(data,*pktsize) ;
|
||||||
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem(data,*pktsize) ;
|
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem(data,*pktsize) ;
|
||||||
|
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem(data,*pktsize) ;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Unknown packet type in chat!" << std::endl ;
|
std::cerr << "Unknown packet type in chat!" << std::endl ;
|
||||||
return NULL ;
|
return NULL ;
|
||||||
@ -120,11 +132,27 @@ uint32_t RsChatMsgItem::serial_size()
|
|||||||
uint32_t RsChatStatusItem::serial_size()
|
uint32_t RsChatStatusItem::serial_size()
|
||||||
{
|
{
|
||||||
uint32_t s = 8; /* header */
|
uint32_t s = 8; /* header */
|
||||||
|
s += 4 ; // flags
|
||||||
s += GetTlvStringSize(status_string); /* status */
|
s += GetTlvStringSize(status_string); /* status */
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t RsChatAvatarItem::serial_size()
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
s += 4 ; // size
|
||||||
|
s += image_size ; // data
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsChatAvatarItem::~RsChatAvatarItem()
|
||||||
|
{
|
||||||
|
free(image_data) ;
|
||||||
|
image_data = NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
/* serialise the data to the buffer */
|
/* serialise the data to the buffer */
|
||||||
bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
@ -191,6 +219,7 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
offset += 8;
|
offset += 8;
|
||||||
|
|
||||||
/* add mandatory parts first */
|
/* add mandatory parts first */
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, flags);
|
||||||
ok &= SetTlvString(data, tlvsize, &offset,TLV_TYPE_STR_MSG, status_string);
|
ok &= SetTlvString(data, tlvsize, &offset,TLV_TYPE_STR_MSG, status_string);
|
||||||
|
|
||||||
if (offset != tlvsize)
|
if (offset != tlvsize)
|
||||||
@ -207,6 +236,48 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
|
||||||
|
{
|
||||||
|
uint32_t tlvsize = serial_size() ;
|
||||||
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
if (pktsize < tlvsize)
|
||||||
|
return false; /* not enough space */
|
||||||
|
|
||||||
|
pktsize = tlvsize;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
||||||
|
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "RsChatSerialiser serialising chat avatar item." << std::endl;
|
||||||
|
std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl;
|
||||||
|
std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
/* add mandatory parts first */
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset,image_size);
|
||||||
|
|
||||||
|
memcpy((void*)( (unsigned char *)data + offset),image_data,image_size) ;
|
||||||
|
offset += image_size ;
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
RsChatMsgItem::RsChatMsgItem(void *data,uint32_t size)
|
RsChatMsgItem::RsChatMsgItem(void *data,uint32_t size)
|
||||||
: RsChatItem(RS_PKT_SUBTYPE_DEFAULT)
|
: RsChatItem(RS_PKT_SUBTYPE_DEFAULT)
|
||||||
{
|
{
|
||||||
@ -239,6 +310,7 @@ RsChatStatusItem::RsChatStatusItem(void *data,uint32_t size)
|
|||||||
std::cerr << "Building new chat status item." << std::endl ;
|
std::cerr << "Building new chat status item." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
/* get mandatory parts first */
|
/* get mandatory parts first */
|
||||||
|
ok &= getRawUInt32(data, rssize, &offset, &flags);
|
||||||
ok &= GetTlvString(data, rssize, &offset,TLV_TYPE_STR_MSG, status_string);
|
ok &= GetTlvString(data, rssize, &offset,TLV_TYPE_STR_MSG, status_string);
|
||||||
|
|
||||||
if (offset != rssize)
|
if (offset != rssize)
|
||||||
@ -247,6 +319,30 @@ RsChatStatusItem::RsChatStatusItem(void *data,uint32_t size)
|
|||||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t size)
|
||||||
|
: RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS)
|
||||||
|
{
|
||||||
|
uint32_t offset = 8; // skip the header
|
||||||
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
bool ok = true ;
|
||||||
|
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "Building new chat status item." << std::endl ;
|
||||||
|
#endif
|
||||||
|
/* get mandatory parts first */
|
||||||
|
ok &= getRawUInt32(data, rssize, &offset,&image_size);
|
||||||
|
|
||||||
|
image_data = (unsigned char *)malloc(image_size*sizeof(unsigned char)) ;
|
||||||
|
memcpy(image_data,(void*)((unsigned char*)data+offset),image_size) ;
|
||||||
|
offset += image_size ;
|
||||||
|
|
||||||
|
if (offset != rssize)
|
||||||
|
std::cerr << "Size error while deserializing." << std::endl ;
|
||||||
|
if (!ok)
|
||||||
|
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,8 +39,11 @@ const uint32_t RS_CHAT_FLAG_PRIVATE = 0x0001;
|
|||||||
const uint32_t RS_CHAT_FLAG_REQUESTS_AVATAR = 0x0002;
|
const uint32_t RS_CHAT_FLAG_REQUESTS_AVATAR = 0x0002;
|
||||||
const uint32_t RS_CHAT_FLAG_CONTAINS_AVATAR = 0x0004;
|
const uint32_t RS_CHAT_FLAG_CONTAINS_AVATAR = 0x0004;
|
||||||
const uint32_t RS_CHAT_FLAG_AVATAR_AVAILABLE = 0x0008;
|
const uint32_t RS_CHAT_FLAG_AVATAR_AVAILABLE = 0x0008;
|
||||||
|
const uint32_t RS_CHAT_FLAG_CUSTOM_STATE = 0x0010; // used for transmitting peer status string
|
||||||
|
const uint32_t RS_CHAT_FLAG_PUBLIC = 0x0020;
|
||||||
|
|
||||||
const uint8_t RS_PKT_SUBTYPE_CHAT_STATUS = 0x02 ; // default is 0x01
|
const uint8_t RS_PKT_SUBTYPE_CHAT_AVATAR = 0x03 ; // default is 0x01
|
||||||
|
const uint8_t RS_PKT_SUBTYPE_CHAT_STATUS = 0x04 ; // default is 0x01
|
||||||
|
|
||||||
class RsChatItem: public RsItem
|
class RsChatItem: public RsItem
|
||||||
{
|
{
|
||||||
@ -90,9 +93,29 @@ class RsChatStatusItem: public RsChatItem
|
|||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
||||||
|
|
||||||
|
uint32_t flags ;
|
||||||
std::string status_string;
|
std::string status_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This class contains avatar images in Qt format.
|
||||||
|
//
|
||||||
|
class RsChatAvatarItem: public RsChatItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {}
|
||||||
|
RsChatAvatarItem(void *data,uint32_t size) ; // deserialization
|
||||||
|
|
||||||
|
virtual ~RsChatAvatarItem() ;
|
||||||
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
|
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
||||||
|
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
||||||
|
|
||||||
|
uint32_t image_size ; // size of data in bytes
|
||||||
|
unsigned char *image_data ; // image
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class RsChatSerialiser: public RsSerialType
|
class RsChatSerialiser: public RsSerialType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -42,11 +42,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
||||||
:p3Service(RS_SERVICE_TYPE_CHAT), pqiConfig(CONFIG_TYPE_CHAT), mConnMgr(cm)
|
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mConnMgr(cm)
|
||||||
{
|
{
|
||||||
addSerialType(new RsChatSerialiser());
|
addSerialType(new RsChatSerialiser());
|
||||||
|
|
||||||
_own_avatar = NULL ;
|
_own_avatar = NULL ;
|
||||||
|
_custom_status_string = "" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int p3ChatService::tick()
|
int p3ChatService::tick()
|
||||||
@ -116,12 +117,34 @@ class p3ChatService::AvatarInfo
|
|||||||
public:
|
public:
|
||||||
AvatarInfo()
|
AvatarInfo()
|
||||||
{
|
{
|
||||||
|
_image_size = 0 ;
|
||||||
|
_image_data = NULL ;
|
||||||
_peer_is_new = false ; // true when the peer has a new avatar
|
_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.
|
_own_is_new = false ; // true when I myself a new avatar to send to this peer.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~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) ;
|
||||||
|
}
|
||||||
AvatarInfo(const unsigned char *jpeg_data,int size)
|
AvatarInfo(const unsigned char *jpeg_data,int size)
|
||||||
{
|
{
|
||||||
|
init(jpeg_data,size) ;
|
||||||
|
#ifdef TO_REMOVE
|
||||||
int n_c = size ;
|
int n_c = size ;
|
||||||
int p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
|
int p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
|
||||||
int n = n_c/p + 1 ;
|
int n = n_c/p + 1 ;
|
||||||
@ -139,13 +162,42 @@ class p3ChatService::AvatarInfo
|
|||||||
}
|
}
|
||||||
_jpeg_wstring[i] = h ;
|
_jpeg_wstring[i] = h ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
AvatarInfo(const std::wstring& s) : _jpeg_wstring(s) {}
|
#ifdef AVATAR_KEEP_BACKWRD_COMP
|
||||||
|
AvatarInfo(const std::wstring& s)
|
||||||
const std::wstring& toStdWString() const { return _jpeg_wstring; }
|
|
||||||
|
|
||||||
void toUnsignedChar(unsigned char *& data,int& size) const
|
|
||||||
{
|
{
|
||||||
|
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 p = 2 ;// minimum value for sizeof(wchar_t) over win/mac/linux ;
|
||||||
int n = _jpeg_wstring.size() ;
|
int n = _jpeg_wstring.size() ;
|
||||||
int n_c = p*n ;
|
int n_c = p*n ;
|
||||||
@ -163,19 +215,47 @@ class p3ChatService::AvatarInfo
|
|||||||
h = h >> 8 ;
|
h = h >> 8 ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t _image_size ;
|
||||||
|
unsigned char *_image_data ;
|
||||||
|
#ifdef TO_REMOVE
|
||||||
std::wstring _jpeg_wstring;
|
std::wstring _jpeg_wstring;
|
||||||
|
#endif
|
||||||
int _peer_is_new ; // true when the peer has a new avatar
|
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.
|
int _own_is_new ; // true when I myself a new avatar to send to this peer.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
||||||
|
{
|
||||||
|
std::list<std::string> ids;
|
||||||
|
mConnMgr->getOnlineList(ids);
|
||||||
|
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "p3ChatService::sendChat()";
|
||||||
|
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)
|
void p3ChatService::sendStatusString( const std::string& id , const std::string& status_string)
|
||||||
{
|
{
|
||||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||||
|
|
||||||
cs->status_string = status_string ;
|
cs->status_string = status_string ;
|
||||||
|
cs->flags = RS_CHAT_FLAG_PRIVATE ;
|
||||||
cs->PeerId(id);
|
cs->PeerId(id);
|
||||||
|
|
||||||
#ifdef CHAT_DEBUG
|
#ifdef CHAT_DEBUG
|
||||||
@ -244,7 +324,7 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
|||||||
#endif
|
#endif
|
||||||
RsChatMsgItem *ci = dynamic_cast<RsChatMsgItem*>(item) ;
|
RsChatMsgItem *ci = dynamic_cast<RsChatMsgItem*>(item) ;
|
||||||
|
|
||||||
if(ci != NULL)
|
if(ci != NULL) // real chat message
|
||||||
{
|
{
|
||||||
#ifdef CHAT_DEBUG
|
#ifdef CHAT_DEBUG
|
||||||
std::cerr << "p3ChatService::getChatQueue() Item:";
|
std::cerr << "p3ChatService::getChatQueue() Item:";
|
||||||
@ -255,9 +335,17 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(ci->chatFlags & RS_CHAT_FLAG_CONTAINS_AVATAR) // no msg here. Just an avatar.
|
if(ci->chatFlags & RS_CHAT_FLAG_CONTAINS_AVATAR) // no msg here. Just an avatar.
|
||||||
receiveAvatarJpegData(ci) ;
|
{
|
||||||
|
#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.
|
else if(ci->chatFlags & RS_CHAT_FLAG_REQUESTS_AVATAR) // no msg here. Just an avatar request.
|
||||||
|
{
|
||||||
sendAvatarJpegData(ci->PeerId()) ;
|
sendAvatarJpegData(ci->PeerId()) ;
|
||||||
|
delete item ;
|
||||||
|
}
|
||||||
else // normal msg. Return it normally.
|
else // normal msg. Return it normally.
|
||||||
{
|
{
|
||||||
// Check if new avatar is available at peer's. If so, send a request to get the avatar.
|
// Check if new avatar is available at peer's. If so, send a request to get the avatar.
|
||||||
@ -280,9 +368,11 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ci->recvTime = now;
|
ci->recvTime = now;
|
||||||
ilist.push_back(ci);
|
ilist.push_back(ci); // don't delete the item !!
|
||||||
}
|
}
|
||||||
|
continue ;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsChatStatusItem *cs = dynamic_cast<RsChatStatusItem*>(item) ;
|
RsChatStatusItem *cs = dynamic_cast<RsChatStatusItem*>(item) ;
|
||||||
|
|
||||||
if(cs != NULL)
|
if(cs != NULL)
|
||||||
@ -291,15 +381,42 @@ std::list<RsChatMsgItem *> p3ChatService::getChatQueue()
|
|||||||
#ifdef CHAT_DEBUG
|
#ifdef CHAT_DEBUG
|
||||||
std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ;
|
std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string) ;
|
if(cs->flags & RS_CHAT_FLAG_PRIVATE)
|
||||||
|
rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,true) ;
|
||||||
|
|
||||||
|
if(cs->flags & RS_CHAT_FLAG_PUBLIC)
|
||||||
|
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) ;
|
||||||
|
|
||||||
delete item ;
|
delete item ;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsChatAvatarItem *ca = dynamic_cast<RsChatAvatarItem*>(item) ;
|
||||||
|
|
||||||
|
if(ca != NULL)
|
||||||
|
{
|
||||||
|
receiveAvatarJpegData(ca) ;
|
||||||
|
delete item ;
|
||||||
|
continue ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ilist;
|
return ilist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3ChatService::setCustomStateString(const std::string& s)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
_custom_status_string = s ;
|
||||||
|
}
|
||||||
|
IndicateConfigChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
|
void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -319,6 +436,8 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
|
|||||||
std::cerr << "p3chatservice:setOwnAvatarJpegData() done." << std::endl ;
|
std::cerr << "p3chatservice:setOwnAvatarJpegData() done." << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AVATAR_KEEP_BACKWRD_COMP
|
||||||
|
// This one is kept for compatibility
|
||||||
void p3ChatService::receiveAvatarJpegData(RsChatMsgItem *ci)
|
void p3ChatService::receiveAvatarJpegData(RsChatMsgItem *ci)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
@ -330,17 +449,34 @@ void p3ChatService::receiveAvatarJpegData(RsChatMsgItem *ci)
|
|||||||
_avatars[ci->PeerId()]->_peer_is_new = true ;
|
_avatars[ci->PeerId()]->_peer_is_new = true ;
|
||||||
_avatars[ci->PeerId()]->_own_is_new = new_peer ;
|
_avatars[ci->PeerId()]->_own_is_new = new_peer ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void p3ChatService::receiveAvatarJpegData(RsChatAvatarItem *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->image_data,ci->image_size) ;
|
||||||
|
_avatars[ci->PeerId()]->_peer_is_new = true ;
|
||||||
|
_avatars[ci->PeerId()]->_own_is_new = new_peer ;
|
||||||
|
}
|
||||||
|
|
||||||
void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size)
|
void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size)
|
||||||
{
|
{
|
||||||
// should be a Mutex here.
|
// should be a Mutex here.
|
||||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
uint32_t s = 0 ;
|
||||||
std::cerr << "p3chatservice:: own avatar requested from above. " << std::endl ;
|
std::cerr << "p3chatservice:: own avatar requested from above. " << std::endl ;
|
||||||
// has avatar. Return it strait away.
|
// has avatar. Return it strait away.
|
||||||
//
|
//
|
||||||
if(_own_avatar != NULL)
|
if(_own_avatar != NULL)
|
||||||
_own_avatar->toUnsignedChar(data,size) ;
|
{
|
||||||
|
_own_avatar->toUnsignedChar(data,s) ;
|
||||||
|
size = s ;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data=NULL ;
|
data=NULL ;
|
||||||
@ -359,7 +495,9 @@ void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *
|
|||||||
//
|
//
|
||||||
if(it!=_avatars.end())
|
if(it!=_avatars.end())
|
||||||
{
|
{
|
||||||
it->second->toUnsignedChar(data,size) ;
|
uint32_t s=0 ;
|
||||||
|
it->second->toUnsignedChar(data,s) ;
|
||||||
|
size = s ;
|
||||||
it->second->_peer_is_new = false ;
|
it->second->_peer_is_new = false ;
|
||||||
std::cerr << "Already has avatar. Returning it" << std::endl ;
|
std::cerr << "Already has avatar. Returning it" << std::endl ;
|
||||||
return ;
|
return ;
|
||||||
@ -387,14 +525,21 @@ void p3ChatService::sendAvatarRequest(const std::string& peer_id)
|
|||||||
sendItem(ci);
|
sendItem(ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsChatMsgItem *p3ChatService::makeOwnAvatarItem()
|
RsChatAvatarItem *p3ChatService::makeOwnAvatarItem()
|
||||||
{
|
{
|
||||||
|
#ifdef TO_REMOVE
|
||||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
RsChatMsgItem *ci = new RsChatMsgItem();
|
RsChatMsgItem *ci = new RsChatMsgItem();
|
||||||
|
|
||||||
ci->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CONTAINS_AVATAR ;
|
ci->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CONTAINS_AVATAR ;
|
||||||
ci->sendTime = time(NULL);
|
ci->sendTime = time(NULL);
|
||||||
ci->message = _own_avatar->toStdWString() ;
|
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 ;
|
return ci ;
|
||||||
}
|
}
|
||||||
@ -406,12 +551,12 @@ void p3ChatService::sendAvatarJpegData(const std::string& peer_id)
|
|||||||
|
|
||||||
if(_own_avatar != NULL)
|
if(_own_avatar != NULL)
|
||||||
{
|
{
|
||||||
RsChatMsgItem *ci = makeOwnAvatarItem();
|
RsChatAvatarItem *ci = makeOwnAvatarItem();
|
||||||
ci->PeerId(peer_id);
|
ci->PeerId(peer_id);
|
||||||
|
|
||||||
// take avatar, and embed it into a std::wstring.
|
// take avatar, and embed it into a std::wstring.
|
||||||
//
|
//
|
||||||
std::cerr << "p3ChatService::sending avatar image to peer" << peer_id << ", string size = " << ci->message.size() << std::endl ;
|
std::cerr << "p3ChatService::sending avatar image to peer" << peer_id << ", image size = " << ci->image_size << std::endl ;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
sendItem(ci) ;
|
sendItem(ci) ;
|
||||||
@ -420,89 +565,64 @@ void p3ChatService::sendAvatarJpegData(const std::string& peer_id)
|
|||||||
std::cerr << "Doing nothing" << std::endl ;
|
std::cerr << "Doing nothing" << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ChatService::loadConfiguration(std::string &loadHash)
|
bool p3ChatService::loadList(std::list<RsItem*> load)
|
||||||
{
|
{
|
||||||
std::list<std::string>::iterator it;
|
for(std::list<RsItem*>::const_iterator it(load.begin());it!=load.end();++it)
|
||||||
std::string msgfile = Filename();
|
|
||||||
|
|
||||||
RsSerialiser *rss = new RsSerialiser();
|
|
||||||
rss->addSerialType(new RsChatSerialiser());
|
|
||||||
|
|
||||||
BinFileInterface *in = new BinFileInterface(msgfile.c_str(), BIN_FLAGS_READABLE | BIN_FLAGS_HASH_DATA);
|
|
||||||
pqistore *pa_in = new pqistore(rss, "CHATCONFIG", in, BIN_FLAGS_READABLE);
|
|
||||||
RsItem *item;
|
|
||||||
RsChatMsgItem *mitem;
|
|
||||||
|
|
||||||
while((item = pa_in -> GetItem()))
|
|
||||||
{
|
{
|
||||||
if(NULL != (mitem = dynamic_cast<RsChatMsgItem *>(item)))
|
RsChatAvatarItem *ai = NULL ;
|
||||||
|
|
||||||
|
if(NULL != (ai = dynamic_cast<RsChatAvatarItem *>(*it)))
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
_own_avatar = new AvatarInfo(mitem->message) ;
|
_own_avatar = new AvatarInfo(ai->image_data,ai->image_size) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete item;
|
RsChatStatusItem *mitem = NULL ;
|
||||||
}
|
|
||||||
|
|
||||||
std::string hashin = in->gethash();
|
if(NULL != (mitem = dynamic_cast<RsChatStatusItem *>(*it)))
|
||||||
delete pa_in;
|
|
||||||
|
|
||||||
if (hashin != loadHash)
|
|
||||||
{
|
{
|
||||||
/* big error message! */
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
std::cerr << "p3ChatService::loadConfiguration() FAILED! avatar Tampered" << std::endl;
|
|
||||||
std::string msgfileold = msgfile + ".failed";
|
|
||||||
|
|
||||||
rename(msgfile.c_str(), msgfileold.c_str());
|
_custom_status_string = mitem->status_string ;
|
||||||
|
|
||||||
std::cerr << "Moving Old file to: " << msgfileold << std::endl;
|
|
||||||
std::cerr << "removing dodgey msgs" << std::endl;
|
|
||||||
|
|
||||||
_own_avatar = NULL ;
|
|
||||||
|
|
||||||
setHash("");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setHash(hashin);
|
|
||||||
|
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ChatService::saveConfiguration()
|
std::list<RsItem*> p3ChatService::saveList(bool& cleanup)
|
||||||
{
|
{
|
||||||
|
cleanup = true ;
|
||||||
/* now we create a pqistore, and stream all the msgs into it */
|
/* now we create a pqistore, and stream all the msgs into it */
|
||||||
|
|
||||||
std::string msgfile = Filename();
|
std::list<RsItem*> list ;
|
||||||
std::string msgfiletmp = Filename()+".tmp";
|
|
||||||
|
|
||||||
RsSerialiser *rss = new RsSerialiser();
|
|
||||||
rss->addSerialType(new RsChatSerialiser());
|
|
||||||
|
|
||||||
BinFileInterface *out = new BinFileInterface(msgfiletmp.c_str(), BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
|
|
||||||
pqistore *pa_out = new pqistore(rss, "CHATCONFIG", out, BIN_FLAGS_WRITEABLE);
|
|
||||||
|
|
||||||
if(_own_avatar != NULL)
|
if(_own_avatar != NULL)
|
||||||
{
|
{
|
||||||
std::cerr << "Saving avatar config to file " << msgfile << std::endl ;
|
RsChatAvatarItem *ci = makeOwnAvatarItem() ;
|
||||||
RsChatMsgItem *ci = makeOwnAvatarItem() ;
|
|
||||||
ci->PeerId(mConnMgr->getOwnId());
|
ci->PeerId(mConnMgr->getOwnId());
|
||||||
|
|
||||||
if(!pa_out -> SendItem(ci))
|
list.push_back(ci) ;
|
||||||
return false ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setHash(out->gethash());
|
RsChatStatusItem *di = new RsChatStatusItem ;
|
||||||
delete pa_out;
|
di->status_string = _custom_status_string ;
|
||||||
|
di->flags = RS_CHAT_FLAG_CUSTOM_STATE ;
|
||||||
|
|
||||||
if(!RsDirUtil::renameFile(msgfiletmp,msgfile))
|
list.push_back(di) ;
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsSerialiser *p3ChatService::setupSerialiser()
|
||||||
{
|
{
|
||||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + msgfile) ;
|
RsSerialiser *rss = new RsSerialiser ;
|
||||||
return false ;
|
rss->addSerialType(new RsChatSerialiser) ;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return rss ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,9 @@
|
|||||||
#include "services/p3service.h"
|
#include "services/p3service.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3connmgr.h"
|
||||||
|
|
||||||
class p3ChatService: public p3Service, public pqiConfig
|
//#define AVATAR_KEEP_BACKWRD_COMP
|
||||||
|
|
||||||
|
class p3ChatService: public p3Service, public p3Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3ChatService(p3ConnectMgr *cm);
|
p3ChatService(p3ConnectMgr *cm);
|
||||||
@ -51,6 +53,9 @@ class p3ChatService: public p3Service, public pqiConfig
|
|||||||
int sendChat(std::wstring msg);
|
int sendChat(std::wstring msg);
|
||||||
int sendPrivateChat(std::wstring msg, std::string id);
|
int sendPrivateChat(std::wstring msg, std::string id);
|
||||||
void sendStatusString(const std::string& peer_id,const std::string& status_str) ;
|
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 ; }
|
||||||
|
|
||||||
/// gets the peer's avatar in jpeg format, if available. Null otherwise. Also asks the peer to send
|
/// 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
|
/// its avatar, if not already available. Creates a new unsigned char array. It's the caller's
|
||||||
@ -64,9 +69,10 @@ class p3ChatService: public p3Service, public pqiConfig
|
|||||||
|
|
||||||
std::list<RsChatMsgItem *> getChatQueue();
|
std::list<RsChatMsgItem *> getChatQueue();
|
||||||
|
|
||||||
/*** Overloaded from pqiConfig ****/
|
/************* from p3Config *******************/
|
||||||
virtual bool loadConfiguration(std::string &loadHash);
|
virtual RsSerialiser *setupSerialiser() ;
|
||||||
virtual bool saveConfiguration();
|
virtual std::list<RsItem*> saveList(bool& cleanup) ;
|
||||||
|
virtual bool loadList(std::list<RsItem*> load) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RsMutex mChatMtx;
|
RsMutex mChatMtx;
|
||||||
@ -77,17 +83,21 @@ class p3ChatService: public p3Service, public pqiConfig
|
|||||||
void sendAvatarJpegData(const std::string& peer_id) ;
|
void sendAvatarJpegData(const std::string& peer_id) ;
|
||||||
|
|
||||||
/// Receive the avatar in a chat item, with RS_CHAT_RECEIVE_AVATAR flag.
|
/// Receive the avatar in a chat item, with RS_CHAT_RECEIVE_AVATAR flag.
|
||||||
void receiveAvatarJpegData(RsChatMsgItem *ci) ;
|
#ifdef AVATAR_KEEP_BACKWRD_COMP
|
||||||
|
void receiveAvatarJpegData(RsChatMsgItem *ci) ; // old method
|
||||||
|
#endif
|
||||||
|
void receiveAvatarJpegData(RsChatAvatarItem *ci) ; // new method
|
||||||
|
|
||||||
/// Sends a request for an avatar to the peer of given id
|
/// Sends a request for an avatar to the peer of given id
|
||||||
void sendAvatarRequest(const std::string& peer_id) ;
|
void sendAvatarRequest(const std::string& peer_id) ;
|
||||||
|
|
||||||
RsChatMsgItem *makeOwnAvatarItem() ;
|
RsChatAvatarItem *makeOwnAvatarItem() ;
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3ConnectMgr *mConnMgr;
|
||||||
|
|
||||||
AvatarInfo *_own_avatar ;
|
AvatarInfo *_own_avatar ;
|
||||||
std::map<std::string,AvatarInfo *> _avatars ;
|
std::map<std::string,AvatarInfo *> _avatars ;
|
||||||
|
std::string _custom_status_string ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVICE_CHAT_HEADER
|
#endif // SERVICE_CHAT_HEADER
|
||||||
|
@ -683,14 +683,18 @@ void PeersDialog::configurefriend()
|
|||||||
ConfCertDialog::show(getPeerRsCertId(getCurrentPeer()));
|
ConfCertDialog::show(getPeerRsCertId(getCurrentPeer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeersDialog::updatePeerStatusString(const QString& peer_id,const QString& status_string)
|
void PeersDialog::updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat)
|
||||||
|
{
|
||||||
|
if(is_private_chat)
|
||||||
{
|
{
|
||||||
RshareSettings settings;
|
|
||||||
// uint chatflags = settings.getChatFlags();
|
|
||||||
|
|
||||||
PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
|
PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0);
|
||||||
pcd->updateStatusString(status_string);
|
pcd->updateStatusString(status_string);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Updating public chat msg from peer " << rsPeers->getPeerName(peer_id.toStdString()) << ": " << status_string.toStdString() << std::endl ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PeersDialog::insertChat()
|
void PeersDialog::insertChat()
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ public slots:
|
|||||||
void on_actionClearChat_triggered();
|
void on_actionClearChat_triggered();
|
||||||
void displayInfoChatMenu(const QPoint& pos);
|
void displayInfoChatMenu(const QPoint& pos);
|
||||||
|
|
||||||
void updatePeerStatusString(const QString& peer_id,const QString& status_string) ;
|
void updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat) ;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -144,7 +144,7 @@ int main(int argc, char *argv[])
|
|||||||
QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ;
|
QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ;
|
||||||
QObject::connect(notify,SIGNAL(configChanged()) ,w->messagesDialog ,SLOT(displayConfig() )) ;
|
QObject::connect(notify,SIGNAL(configChanged()) ,w->messagesDialog ,SLOT(displayConfig() )) ;
|
||||||
|
|
||||||
QObject::connect(notify,SIGNAL(chatStatusChanged(const QString&,const QString&)),w->peersDialog,SLOT(updatePeerStatusString(const QString&,const QString&)));
|
QObject::connect(notify,SIGNAL(chatStatusChanged(const QString&,const QString&,bool)),w->peersDialog,SLOT(updatePeerStatusString(const QString&,const QString&,bool)));
|
||||||
QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)),w->networkDialog,SLOT(setLogInfo(QString))) ;
|
QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)),w->networkDialog,SLOT(setLogInfo(QString))) ;
|
||||||
|
|
||||||
QObject::connect(ConfCertDialog::instance(),SIGNAL(configChanged()),w->networkDialog,SLOT(insertConnect())) ;
|
QObject::connect(ConfCertDialog::instance(),SIGNAL(configChanged()),w->networkDialog,SLOT(insertConnect())) ;
|
||||||
|
@ -39,10 +39,16 @@ void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyQt::notifyChatStatus(const std::string& peer_id,const std::string& status_string)
|
void NotifyQt::notifyCustomState(const std::string& peer_id,const std::string& custom_state_string)
|
||||||
{
|
{
|
||||||
std::cerr << "Received chat status string: " << status_string << std::endl ;
|
std::cerr << "notifyQt: Received custom status string: " << custom_state_string << std::endl ;
|
||||||
emit chatStatusChanged(QString::fromStdString(peer_id),QString::fromStdString(status_string)) ;
|
emit peerCustomStateStringChanged(QString::fromStdString(peer_id),QString::fromStdString(custom_state_string)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotifyQt::notifyChatStatus(const std::string& peer_id,const std::string& status_string,bool is_private)
|
||||||
|
{
|
||||||
|
std::cerr << "notifyQt: Received chat status string: " << status_string << std::endl ;
|
||||||
|
emit chatStatusChanged(QString::fromStdString(peer_id),QString::fromStdString(status_string),is_private) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyQt::notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files)
|
void NotifyQt::notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files)
|
||||||
|
@ -24,29 +24,17 @@ class NotifyQt: public QObject, public NotifyBase
|
|||||||
public:
|
public:
|
||||||
NotifyQt()
|
NotifyQt()
|
||||||
: cDialog(NULL)
|
: cDialog(NULL)
|
||||||
//, pDialog(NULL),
|
|
||||||
// dDialog(NULL), tDialog(NULL),
|
|
||||||
// hDialog(NULL), mDialog(NULL),
|
|
||||||
// sDialog(NULL), mWindow(NULL)
|
|
||||||
{ return; }
|
{ return; }
|
||||||
|
|
||||||
virtual ~NotifyQt() { return; }
|
virtual ~NotifyQt() { return; }
|
||||||
|
|
||||||
void setNetworkDialog(NetworkDialog *c) { cDialog = c; }
|
void setNetworkDialog(NetworkDialog *c) { cDialog = c; }
|
||||||
// void setPeersDialog(PeersDialog *p) { pDialog = p; }
|
|
||||||
// void setDirDialog(SharedFilesDialog *d) { dDialog = d; }
|
|
||||||
// void setTransfersDialog(TransfersDialog *t) { tDialog = t; }
|
|
||||||
// void setChatDialog(ChatDialog *m) { hDialog = m; }
|
|
||||||
// void setMessagesDialog(MessagesDialog *m) { mDialog = m; }
|
|
||||||
// void setChannelsDialog(ChannelsDialog *s) { sDialog = s; }
|
|
||||||
// void setMessengerWindow(MessengerWindow *mw) { mWindow = mw; }
|
|
||||||
// void setRsIface(RsIface *i) { iface = i; }
|
|
||||||
|
|
||||||
virtual void notifyListPreChange(int list, int type);
|
virtual void notifyListPreChange(int list, int type);
|
||||||
virtual void notifyListChange(int list, int type);
|
virtual void notifyListChange(int list, int type);
|
||||||
virtual void notifyErrorMsg(int list, int sev, std::string msg);
|
virtual void notifyErrorMsg(int list, int sev, std::string msg);
|
||||||
// virtual void notifyChat();
|
virtual void notifyChatStatus(const std::string& peer_id,const std::string& status_string,bool is_private);
|
||||||
virtual void notifyChatStatus(const std::string& peer_id,const std::string& status_string);
|
virtual void notifyCustomState(const std::string& peer_id,const std::string& status_string);
|
||||||
virtual void notifyHashingInfo(std::string fileinfo);
|
virtual void notifyHashingInfo(std::string fileinfo);
|
||||||
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files);
|
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& found_files);
|
||||||
|
|
||||||
@ -63,7 +51,8 @@ class NotifyQt: public QObject, public NotifyBase
|
|||||||
void messagesChanged() const ;
|
void messagesChanged() const ;
|
||||||
void configChanged() const ;
|
void configChanged() const ;
|
||||||
void logInfoChanged(const QString&) const ;
|
void logInfoChanged(const QString&) const ;
|
||||||
void chatStatusChanged(const QString&,const QString&) const ;
|
void chatStatusChanged(const QString&,const QString&,bool) const ;
|
||||||
|
void peerCustomStateStringChanged(const QString&,const QString&) const ;
|
||||||
void gotTurtleSearchResult(qulonglong search_id,FileDetail file) const ;
|
void gotTurtleSearchResult(qulonglong search_id,FileDetail file) const ;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -200,7 +200,8 @@ class NotifyBase
|
|||||||
virtual void notifyListChange(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 notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
|
||||||
virtual void notifyChat() { return; }
|
virtual void notifyChat() { return; }
|
||||||
virtual void notifyChatStatus(const std::string& peer_id,const std::string& status_string) {}
|
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(std::string fileinfo) { (void)fileinfo; return ; }
|
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 notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files) { (void)files; }
|
||||||
};
|
};
|
||||||
|
@ -132,6 +132,10 @@ virtual bool chatAvailable() = 0;
|
|||||||
virtual bool ChatSend(ChatInfo &ci) = 0;
|
virtual bool ChatSend(ChatInfo &ci) = 0;
|
||||||
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
||||||
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
|
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
|
||||||
|
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||||
|
|
||||||
|
virtual void setCustomStateString(const std::string& status_string) = 0 ;
|
||||||
|
virtual std::string getCustomStateString() = 0 ;
|
||||||
|
|
||||||
// get avatar data for peer pid
|
// get avatar data for peer pid
|
||||||
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;
|
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;
|
||||||
|
Loading…
Reference in New Issue
Block a user