diff --git a/libretroshare/src/rsiface/rsiface.h b/libretroshare/src/rsiface/rsiface.h index 2da891b2c..aa582e280 100644 --- a/libretroshare/src/rsiface/rsiface.h +++ b/libretroshare/src/rsiface/rsiface.h @@ -200,7 +200,8 @@ class NotifyBase virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; } virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; } virtual void notifyChat() { return; } - virtual void notifyChatStatus(const std::string& peer_id,const std::string& status_string) {} + 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 notifyTurtleSearchResult(uint32_t search_id,const std::list& files) { (void)files; } }; diff --git a/libretroshare/src/rsiface/rsmsgs.h b/libretroshare/src/rsiface/rsmsgs.h index f83a7b647..1f0045c15 100644 --- a/libretroshare/src/rsiface/rsmsgs.h +++ b/libretroshare/src/rsiface/rsmsgs.h @@ -132,6 +132,10 @@ virtual bool chatAvailable() = 0; virtual bool ChatSend(ChatInfo &ci) = 0; virtual bool getNewChat(std::list &chats) = 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 virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index a3bead43b..e25f9082d 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -109,6 +109,10 @@ bool p3Msgs::ChatSend(ChatInfo &ci) 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) { 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) ; } +std::string p3Msgs::getCustomStateString() +{ + return mChatSrv->getCustomStateString() ; +} +void p3Msgs::setCustomStateString(const std::string& state_string) +{ + mChatSrv->setCustomStateString(state_string) ; +} diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index b1a5bfefa..2209bd3b7 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -57,12 +57,18 @@ class p3Msgs: public RsMsgs virtual void setOwnAvatarData(const 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 */ virtual bool chatAvailable(); virtual bool ChatSend(ChatInfo &ci); virtual bool getNewChat(std::list &chats); virtual void sendStatusString(const std::string& peer_id,const std::string& status_string) ; + virtual void sendGroupChatStatusString(const std::string& status_string) ; /****************************************/ diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index ac54f1e27..d85e9f7dc 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -62,11 +62,22 @@ std::ostream& RsChatStatusItem::print(std::ostream &out, uint16_t indent) uint16_t int_Indent = indent + 2; printIndent(out, int_Indent); out << "Status string: " << status_string << std::endl; + out << "Flags : " << (void*)flags << std::endl; printRsItemEnd(out, "RsChatStatusItem", indent); 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) { 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_CHAT_STATUS: return new RsChatStatusItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem(data,*pktsize) ; default: std::cerr << "Unknown packet type in chat!" << std::endl ; return NULL ; @@ -120,11 +132,27 @@ uint32_t RsChatMsgItem::serial_size() uint32_t RsChatStatusItem::serial_size() { uint32_t s = 8; /* header */ + s += 4 ; // flags s += GetTlvStringSize(status_string); /* status */ 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 */ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) { @@ -191,6 +219,7 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) offset += 8; /* add mandatory parts first */ + ok &= setRawUInt32(data, tlvsize, &offset, flags); ok &= SetTlvString(data, tlvsize, &offset,TLV_TYPE_STR_MSG, status_string); if (offset != tlvsize) @@ -207,6 +236,48 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize) 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) : 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 ; #endif /* get mandatory parts first */ + ok &= getRawUInt32(data, rssize, &offset, &flags); ok &= GetTlvString(data, rssize, &offset,TLV_TYPE_STR_MSG, status_string); if (offset != rssize) @@ -247,6 +319,30 @@ RsChatStatusItem::RsChatStatusItem(void *data,uint32_t size) 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 ; +} + + /*************************************************************************/ diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index ac51f77f3..5a388fcc2 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -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_CONTAINS_AVATAR = 0x0004; 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 { @@ -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 uint32_t serial_size() ; // deserialise is handled using a constructor + uint32_t flags ; 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 { public: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index ceeb07f2a..e86f41af5 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -42,11 +42,12 @@ */ 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()); _own_avatar = NULL ; + _custom_status_string = "" ; } int p3ChatService::tick() @@ -116,12 +117,34 @@ class p3ChatService::AvatarInfo public: AvatarInfo() { + _image_size = 0 ; + _image_data = NULL ; _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. } + ~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) { + 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 ; @@ -139,13 +162,42 @@ class p3ChatService::AvatarInfo } _jpeg_wstring[i] = h ; } +#endif } - AvatarInfo(const std::wstring& s) : _jpeg_wstring(s) {} - - const std::wstring& toStdWString() const { return _jpeg_wstring; } - - void toUnsignedChar(unsigned char *& data,int& size) const +#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> 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 ; @@ -163,19 +215,47 @@ class p3ChatService::AvatarInfo 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. + 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 ids; + mConnMgr->getOnlineList(ids); -void p3ChatService::sendStatusString( const std::string& id , const std::string& status_string) +#ifdef CHAT_DEBUG + std::cerr << "p3ChatService::sendChat()"; + std::cerr << std::endl; +#endif + + for(std::list::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) { RsChatStatusItem *cs = new RsChatStatusItem ; cs->status_string = status_string ; + cs->flags = RS_CHAT_FLAG_PRIVATE ; cs->PeerId(id); #ifdef CHAT_DEBUG @@ -244,7 +324,7 @@ std::list p3ChatService::getChatQueue() #endif RsChatMsgItem *ci = dynamic_cast(item) ; - if(ci != NULL) + if(ci != NULL) // real chat message { #ifdef CHAT_DEBUG std::cerr << "p3ChatService::getChatQueue() Item:"; @@ -255,9 +335,17 @@ std::list p3ChatService::getChatQueue() #endif 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. + { sendAvatarJpegData(ci->PeerId()) ; + delete item ; + } else // normal msg. Return it normally. { // Check if new avatar is available at peer's. If so, send a request to get the avatar. @@ -280,9 +368,11 @@ std::list p3ChatService::getChatQueue() } ci->recvTime = now; - ilist.push_back(ci); + ilist.push_back(ci); // don't delete the item !! } + continue ; } + RsChatStatusItem *cs = dynamic_cast(item) ; if(cs != NULL) @@ -291,15 +381,42 @@ std::list p3ChatService::getChatQueue() #ifdef CHAT_DEBUG std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ; #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 ; + continue ; + } + + RsChatAvatarItem *ca = dynamic_cast(item) ; + + if(ca != NULL) + { + receiveAvatarJpegData(ca) ; + delete item ; + continue ; } } 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) { { @@ -319,6 +436,8 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size) 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 ******/ @@ -330,17 +449,34 @@ void p3ChatService::receiveAvatarJpegData(RsChatMsgItem *ci) _avatars[ci->PeerId()]->_peer_is_new = true ; _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) { // should be a Mutex here. RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + uint32_t s = 0 ; std::cerr << "p3chatservice:: own avatar requested from above. " << std::endl ; // has avatar. Return it strait away. // if(_own_avatar != NULL) - _own_avatar->toUnsignedChar(data,size) ; + { + _own_avatar->toUnsignedChar(data,s) ; + size = s ; + } else { data=NULL ; @@ -359,7 +495,9 @@ void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char * // 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 ; std::cerr << "Already has avatar. Returning it" << std::endl ; return ; @@ -387,14 +525,21 @@ void p3ChatService::sendAvatarRequest(const std::string& peer_id) sendItem(ci); } -RsChatMsgItem *p3ChatService::makeOwnAvatarItem() +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 ; } @@ -406,12 +551,12 @@ void p3ChatService::sendAvatarJpegData(const std::string& peer_id) if(_own_avatar != NULL) { - RsChatMsgItem *ci = makeOwnAvatarItem(); + RsChatAvatarItem *ci = makeOwnAvatarItem(); ci->PeerId(peer_id); // 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; sendItem(ci) ; @@ -420,89 +565,64 @@ void p3ChatService::sendAvatarJpegData(const std::string& peer_id) std::cerr << "Doing nothing" << std::endl ; } -bool p3ChatService::loadConfiguration(std::string &loadHash) +bool p3ChatService::loadList(std::list load) { - std::list::iterator 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())) + for(std::list::const_iterator it(load.begin());it!=load.end();++it) { - if(NULL != (mitem = dynamic_cast(item))) + RsChatAvatarItem *ai = NULL ; + + if(NULL != (ai = dynamic_cast(*it))) { 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 ; + + if(NULL != (mitem = dynamic_cast(*it))) + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + _custom_status_string = mitem->status_string ; + } + + + delete *it; } - - std::string hashin = in->gethash(); - delete pa_in; - - if (hashin != loadHash) - { - /* big error message! */ - std::cerr << "p3ChatService::loadConfiguration() FAILED! avatar Tampered" << std::endl; - std::string msgfileold = msgfile + ".failed"; - - rename(msgfile.c_str(), msgfileold.c_str()); - - std::cerr << "Moving Old file to: " << msgfileold << std::endl; - std::cerr << "removing dodgey msgs" << std::endl; - - _own_avatar = NULL ; - - setHash(""); - return false; - } - - setHash(hashin); - return true; } -bool p3ChatService::saveConfiguration() +std::list p3ChatService::saveList(bool& cleanup) { + cleanup = true ; /* now we create a pqistore, and stream all the msgs into it */ - std::string msgfile = Filename(); - 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); + std::list list ; if(_own_avatar != NULL) { - std::cerr << "Saving avatar config to file " << msgfile << std::endl ; - RsChatMsgItem *ci = makeOwnAvatarItem() ; + RsChatAvatarItem *ci = makeOwnAvatarItem() ; ci->PeerId(mConnMgr->getOwnId()); - if(!pa_out -> SendItem(ci)) - return false ; + list.push_back(ci) ; } - setHash(out->gethash()); - delete pa_out; + RsChatStatusItem *di = new RsChatStatusItem ; + di->status_string = _custom_status_string ; + di->flags = RS_CHAT_FLAG_CUSTOM_STATE ; - if(!RsDirUtil::renameFile(msgfiletmp,msgfile)) - { - getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + msgfile) ; - return false ; - } + list.push_back(di) ; - return true; + return list; +} + +RsSerialiser *p3ChatService::setupSerialiser() +{ + RsSerialiser *rss = new RsSerialiser ; + rss->addSerialType(new RsChatSerialiser) ; + + return rss ; } diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 96ac9879f..b9938e28b 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -39,7 +39,9 @@ #include "services/p3service.h" #include "pqi/p3connmgr.h" -class p3ChatService: public p3Service, public pqiConfig +//#define AVATAR_KEEP_BACKWRD_COMP + +class p3ChatService: public p3Service, public p3Config { public: p3ChatService(p3ConnectMgr *cm); @@ -51,6 +53,9 @@ class p3ChatService: public p3Service, public pqiConfig int sendChat(std::wstring msg); 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 ; } /// 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 @@ -64,9 +69,10 @@ class p3ChatService: public p3Service, public pqiConfig std::list getChatQueue(); - /*** Overloaded from pqiConfig ****/ - virtual bool loadConfiguration(std::string &loadHash); - virtual bool saveConfiguration(); + /************* from p3Config *******************/ + virtual RsSerialiser *setupSerialiser() ; + virtual std::list saveList(bool& cleanup) ; + virtual bool loadList(std::list load) ; private: RsMutex mChatMtx; @@ -77,17 +83,21 @@ class p3ChatService: public p3Service, public pqiConfig void sendAvatarJpegData(const std::string& peer_id) ; /// 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 void sendAvatarRequest(const std::string& peer_id) ; - RsChatMsgItem *makeOwnAvatarItem() ; + RsChatAvatarItem *makeOwnAvatarItem() ; p3ConnectMgr *mConnMgr; AvatarInfo *_own_avatar ; std::map _avatars ; + std::string _custom_status_string ; }; #endif // SERVICE_CHAT_HEADER diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index 6ade7b5ab..cbf5669f5 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -683,13 +683,17 @@ void PeersDialog::configurefriend() 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) { - RshareSettings settings; -// uint chatflags = settings.getChatFlags(); - - PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0); - pcd->updateStatusString(status_string); + if(is_private_chat) + { + PopupChatDialog *pcd = getPrivateChat(peer_id.toStdString(),rsPeers->getPeerName(peer_id.toStdString()), 0); + 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() diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index 83f63a3d4..b922f023e 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -68,7 +68,7 @@ public slots: void on_actionClearChat_triggered(); 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: diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 66ce0ff59..4aaf2bed3 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ; 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(ConfCertDialog::instance(),SIGNAL(configChanged()),w->networkDialog,SLOT(insertConnect())) ; diff --git a/retroshare-gui/src/rsiface/notifyqt.cpp b/retroshare-gui/src/rsiface/notifyqt.cpp index 3f80b327f..140f665a6 100644 --- a/retroshare-gui/src/rsiface/notifyqt.cpp +++ b/retroshare-gui/src/rsiface/notifyqt.cpp @@ -39,10 +39,16 @@ void NotifyQt::notifyErrorMsg(int list, int type, std::string msg) 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 ; - emit chatStatusChanged(QString::fromStdString(peer_id),QString::fromStdString(status_string)) ; + std::cerr << "notifyQt: Received custom status string: " << custom_state_string << std::endl ; + 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& files) diff --git a/retroshare-gui/src/rsiface/notifyqt.h b/retroshare-gui/src/rsiface/notifyqt.h index cf9bb2d3b..90cae0056 100644 --- a/retroshare-gui/src/rsiface/notifyqt.h +++ b/retroshare-gui/src/rsiface/notifyqt.h @@ -24,29 +24,17 @@ class NotifyQt: public QObject, public NotifyBase public: NotifyQt() : cDialog(NULL) -//, pDialog(NULL), -// dDialog(NULL), tDialog(NULL), -// hDialog(NULL), mDialog(NULL), -// sDialog(NULL), mWindow(NULL) { return; } virtual ~NotifyQt() { return; } 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 notifyListChange(int list, int type); 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); + 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); virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list& found_files); @@ -63,7 +51,8 @@ class NotifyQt: public QObject, public NotifyBase void messagesChanged() const ; void configChanged() 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 ; public slots: diff --git a/retroshare-gui/src/rsiface/rsiface.h b/retroshare-gui/src/rsiface/rsiface.h index 2da891b2c..aa582e280 100644 --- a/retroshare-gui/src/rsiface/rsiface.h +++ b/retroshare-gui/src/rsiface/rsiface.h @@ -200,7 +200,8 @@ class NotifyBase virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; } virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; } virtual void notifyChat() { return; } - virtual void notifyChatStatus(const std::string& peer_id,const std::string& status_string) {} + 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 notifyTurtleSearchResult(uint32_t search_id,const std::list& files) { (void)files; } }; diff --git a/retroshare-gui/src/rsiface/rsmsgs.h b/retroshare-gui/src/rsiface/rsmsgs.h index f83a7b647..1f0045c15 100644 --- a/retroshare-gui/src/rsiface/rsmsgs.h +++ b/retroshare-gui/src/rsiface/rsmsgs.h @@ -132,6 +132,10 @@ virtual bool chatAvailable() = 0; virtual bool ChatSend(ChatInfo &ci) = 0; virtual bool getNewChat(std::list &chats) = 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 virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;