From 89187bd453dbf0112dcee05cb0e71bd18875b6bd Mon Sep 17 00:00:00 2001 From: electron128 Date: Wed, 24 Jun 2015 11:13:53 +0000 Subject: [PATCH] webui: added check for empty avatars and implemented avatar notify callback git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8551 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libresapi/src/api/PeersHandler.cpp | 28 +++++++++++++++++++++++++--- libresapi/src/api/PeersHandler.h | 1 + libresapi/src/webfiles/gui.jsx | 2 +- libresapi/src/webui/gui.jsx | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libresapi/src/api/PeersHandler.cpp b/libresapi/src/api/PeersHandler.cpp index f0b9dd06b..1a296c0fb 100644 --- a/libresapi/src/api/PeersHandler.cpp +++ b/libresapi/src/api/PeersHandler.cpp @@ -24,13 +24,17 @@ void peerDetailsToStream(StreamBase& stream, RsPeerDetails& details) ; } -bool peerInfoToStream(StreamBase& stream, RsPeerDetails& details, RsPeers* peers, std::list& grpInfo) +bool peerInfoToStream(StreamBase& stream, RsPeerDetails& details, RsPeers* peers, std::list& grpInfo, bool have_avatar) { bool ok = true; peerDetailsToStream(stream, details); stream << makeKeyValue("is_online", peers->isOnline(details.id)); std::string avatar_address = "/"+details.id.toStdString()+"/avatar_image"; + + if(!have_avatar) + avatar_address = ""; + stream << makeKeyValue("avatar_address", avatar_address); StreamBase& grpStream = stream.getStreamToMember("groups"); @@ -77,6 +81,12 @@ void PeersHandler::notifyListChange(int list, int type) } } +void PeersHandler::notifyPeerHasNewAvatar(std::string /*peer_id*/) +{ + RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + mStateTokenServer->replaceToken(mStateToken); +} + void PeersHandler::tick() { std::list online; @@ -91,6 +101,18 @@ void PeersHandler::tick() } } +static bool have_avatar(RsMsgs* msgs, const RsPeerId& id) +{ + // check if avatar data is available + // requests missing avatar images as a side effect + unsigned char *data = NULL ; + int size = 0 ; + msgs->getAvatarData(id, data,size) ; + std::vector avatar(data, data+size); + delete[] data; + return size != 0; +} + void PeersHandler::handleWildcard(Request &req, Response &resp) { bool ok = false; @@ -132,7 +154,7 @@ void PeersHandler::handleWildcard(Request &req, Response &resp) mRsPeers->getGroupInfoList(grpInfo); RsPeerDetails details; ok &= mRsPeers->getPeerDetails(RsPeerId(str), details); - ok = peerInfoToStream(resp.mDataStream, details, mRsPeers, grpInfo); + ok = peerInfoToStream(resp.mDataStream, details, mRsPeers, grpInfo, have_avatar(mRsMsgs, RsPeerId(str))); } } } @@ -182,7 +204,7 @@ void PeersHandler::handleWildcard(Request &req, Response &resp) for(std::vector::iterator vit = detailsVec.begin(); vit != detailsVec.end(); ++vit) { if(vit->gpg_id == *lit) - peerInfoToStream(locationStream.getStreamToMember(),*vit, mRsPeers, grpInfo); + peerInfoToStream(locationStream.getStreamToMember(),*vit, mRsPeers, grpInfo, have_avatar(mRsMsgs, vit->id)); } } resp.mStateToken = getCurrentStateToken(); diff --git a/libresapi/src/api/PeersHandler.h b/libresapi/src/api/PeersHandler.h index df810acf1..e5b5fa6ea 100644 --- a/libresapi/src/api/PeersHandler.h +++ b/libresapi/src/api/PeersHandler.h @@ -20,6 +20,7 @@ public: // from NotifyClient // note: this may get called from foreign threads virtual void notifyListChange(int list, int type); // friends list change + virtual void notifyPeerHasNewAvatar(std::string /*peer_id*/); // from Tickable virtual void tick(); diff --git a/libresapi/src/webfiles/gui.jsx b/libresapi/src/webfiles/gui.jsx index 09681ef55..6a86a8dc2 100644 --- a/libresapi/src/webfiles/gui.jsx +++ b/libresapi/src/webfiles/gui.jsx @@ -314,7 +314,7 @@ var Peers3 = React.createClass({ return(
{/*
*/}{loc.location}
); }); var avatars = this.props.data.locations.map(function(loc){ - if(loc.is_online) + if(loc.is_online && (loc.avatar_address !== "")) { var avatar_url = api_url + component.getPath() + loc.avatar_address; return ; diff --git a/libresapi/src/webui/gui.jsx b/libresapi/src/webui/gui.jsx index 09681ef55..6a86a8dc2 100644 --- a/libresapi/src/webui/gui.jsx +++ b/libresapi/src/webui/gui.jsx @@ -314,7 +314,7 @@ var Peers3 = React.createClass({ return(
{/*
*/}{loc.location}
); }); var avatars = this.props.data.locations.map(function(loc){ - if(loc.is_online) + if(loc.is_online && (loc.avatar_address !== "")) { var avatar_url = api_url + component.getPath() + loc.avatar_address; return ;