Skip to content

[WIP] Getting rid of old notify system #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/chat/distantchat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,23 @@ void DistantChatService::notifyTunnelStatus( const RsGxsTunnelId& tunnel_id, uin
DISTANT_CHAT_DEBUG() << "DistantChatService::notifyTunnelStatus(): got notification " << std::hex << tunnel_status << std::dec << " for tunnel " << tunnel_id << std::endl;
#endif

#warning TODO: I had to comment out calls to notifyPeerStatusChanged, which anyway looked misplaced here. Probably a hack.
switch(tunnel_status)
{
default:
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_UNKNOWN: std::cerr << "(EE) don't know how to handle RS_GXS_TUNNEL_STATUS_UNKNOWN !" << std::endl;
break ;

case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_CAN_TALK: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is secured. You can talk!") ;
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_ONLINE) ;
//RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_ONLINE) ;
break ;

case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is down...") ;
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
//RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
break ;

case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is down...") ;
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
//RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
break ;
}
}
Expand Down
113 changes: 91 additions & 22 deletions src/chat/distributedchat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,13 @@ void DistributedChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
for(std::list<ChatLobbyId>::const_iterator it = invitationNeeded.begin();it!=invitationNeeded.end();++it)
invitePeerToLobby(*it,item->PeerId(),false) ;

RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
_should_reset_lobby_counts = false ;
//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;

auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

_should_reset_lobby_counts = false ;
}

void DistributedChatService::addTimeShiftStatistics(int D)
Expand Down Expand Up @@ -654,7 +659,14 @@ void DistributedChatService::addTimeShiftStatistics(int D)
#endif

if(expected > 9) // if more than 20 samples
RsServer::notify()->notifyChatLobbyTimeShift( (int)pow(2.0f,expected)) ;
{
//LIST_CHANGEDRsServer::notify()->notifyChatLobbyTimeShift( (int)pow(2.0f,expected)) ;

auto ev = std::make_shared<RsSystemErrorEvent>();
ev->mEventCode = RsSystemErrorEventCode::TIME_SHIFT_PROBLEM;
ev->mTimeShift = (int)pow(2.0f,expected);
rsEvents->postEvent(ev);
}

total = 0.0f ;
log_delay_histogram.clear() ;
Expand Down Expand Up @@ -754,7 +766,12 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
std::cerr << " doing specific job for this status item." << std::endl;
#endif

if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_LEFT) // if a peer left. Remove its nickname from the list.
auto ev = std::make_shared<RsChatStatusEvent>();
ev->mGxsId = item->signature.keyId;
ev->mLobbyId = item->lobby_id;
ev->str = item->string1;

if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_LEFT) // if a peer left. Remove its nickname from the list.
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << " removing nickname " << item->nick << " from lobby " << std::hex << item->lobby_id << std::dec << std::endl;
Expand All @@ -780,7 +797,8 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
std::cerr << " (EE) nickname " << item->nick << " not in participant nicknames list!" << std::endl;
#endif
}
}
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_LEFT;
}
else if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_JOINED) // if a joined left. Add its nickname to the list.
{
#ifdef DEBUG_CHAT_LOBBIES
Expand All @@ -800,7 +818,8 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
// trigger a keep alive packets so as to inform the new participant of our presence in the chatroom
it->second.last_keep_alive_packet_time = 0 ;
}
}
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_JOINED ;
}
else if(item->event_type == RS_CHAT_LOBBY_EVENT_KEEP_ALIVE) // keep alive packet.
{
#ifdef DEBUG_CHAT_LOBBIES
Expand All @@ -818,9 +837,16 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
std::cerr << " added nickname " << item->nick << " from lobby " << std::hex << item->lobby_id << std::dec << std::endl;
#endif
}
}
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_KEEP_ALIVE ;
}
else if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_STATUS)
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_STATUS ;
else if(item->event_type == RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME)
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME;

RsServer::notify()->notifyChatLobbyEvent(item->lobby_id,item->event_type,item->signature.keyId,item->string1);
rsEvents->postEvent(ev);

//RsServer::notify()->notifyChatLobbyEvent(item->lobby_id,item->event_type,item->signature.keyId,item->string1);
}

void DistributedChatService::getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecord>& visible_lobbies)
Expand Down Expand Up @@ -1392,7 +1418,12 @@ void DistributedChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item)
_lobby_invites_queue[item->lobby_id] = invite ;
}
// 2 - notify the gui to ask the user.
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_INVITATION, NOTIFY_TYPE_ADD);

auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_INVITE_RECEIVED;
rsEvents->postEvent(ev);

//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_INVITATION, NOTIFY_TYPE_ADD);
}

void DistributedChatService::getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites)
Expand Down Expand Up @@ -1494,10 +1525,15 @@ bool DistributedChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id,const
std::cerr << " Notifying of new recvd msg." << std::endl ;
#endif

RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD);
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD);
//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD);

// send AKN item
auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD);

// send AKN item
sendLobbyStatusNewPeer(lobby_id) ;

return true ;
Expand Down Expand Up @@ -1613,8 +1649,13 @@ bool DistributedChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id,co
for(std::list<RsPeerId>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
invitePeerToLobby(lobby_id,*it) ;

RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
sendLobbyStatusNewPeer(lobby_id) ;
//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;

auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

sendLobbyStatusNewPeer(lobby_id) ;

return true ;
}
Expand Down Expand Up @@ -1663,9 +1704,13 @@ ChatLobbyId DistributedChatService::createChatLobby(const std::string& lobby_nam
for(std::set<RsPeerId>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
invitePeerToLobby(lobby_id,*it) ;

RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;

triggerConfigSave();
auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

triggerConfigSave();

return lobby_id ;
}
Expand Down Expand Up @@ -1698,7 +1743,12 @@ void DistributedChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribe
}
}

RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_MOD) ;
//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_MOD) ;

auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

}

void DistributedChatService::unsubscribeChatLobby(const ChatLobbyId& id)
Expand Down Expand Up @@ -1744,7 +1794,12 @@ void DistributedChatService::unsubscribeChatLobby(const ChatLobbyId& id)
}

triggerConfigSave(); // so that we save the subscribed lobbies
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_DEL) ;

//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_DEL) ;

auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

// done!
}
Expand Down Expand Up @@ -1890,7 +1945,11 @@ void DistributedChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id,
_lobby_default_identity.erase(lobby_id);
}

RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
triggerConfigSave();
}

Expand Down Expand Up @@ -2024,7 +2083,13 @@ void DistributedChatService::cleanLobbyCaches()

// update the gui
for(std::list<ChatLobbyId>::const_iterator it(changed_lobbies.begin());it!=changed_lobbies.end();++it)
RsServer::notify()->notifyChatLobbyEvent(*it,RS_CHAT_LOBBY_EVENT_KEEP_ALIVE,RsGxsId(),"") ;
{
//RsServer::notify()->notifyChatLobbyEvent(*it,RS_CHAT_LOBBY_EVENT_KEEP_ALIVE,RsGxsId(),"") ;

auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_EVENT_KEEP_ALIVE;
rsEvents->postEvent(ev);
}

// send peer joined
for(std::list<ChatLobbyId>::const_iterator it(joined_lobby_ids.begin());it!=joined_lobby_ids.end();++it)
Expand Down Expand Up @@ -2197,9 +2262,13 @@ bool DistributedChatService::processLoadListItem(const RsItem *item)

// make the UI aware of the existing chat room

RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
//RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;

auto ev = std::make_shared<RsChatStatusEvent>();
ev->mEventCode = RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED;
rsEvents->postEvent(ev);

return true;
return true;
}

return false ;
Expand Down
31 changes: 27 additions & 4 deletions src/chat/p3chatservice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,15 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca)
#ifdef CHAT_DEBUG
std::cerr << "Received avatar data for peer " << ca->PeerId() << ". Notifying." << std::endl ;
#endif
RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ;
//RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ;

if(rsEvents)
{
auto e = std::make_shared<RsFriendListEvent>();
e->mSslId = ca->PeerId();
e->mEventCode = RsFriendListEventCode::NODE_AVATAR_CHANGED;
rsEvents->postEvent(e);
}
}

uint32_t p3ChatService::getMaxMessageSecuritySize(int type)
Expand Down Expand Up @@ -1003,7 +1011,14 @@ void p3ChatService::setOwnCustomStateString(const std::string& s)
mServiceCtrl->getPeersConnected(getServiceInfo().mServiceType, onlineList);
}

RsServer::notify()->notifyOwnStatusMessageChanged() ;
//RsServer::notify()->notifyOwnStatusMessageChanged() ;
if(rsEvents)
{
auto e = std::make_shared<RsFriendListEvent>();
e->mEventCode = RsFriendListEventCode::OWN_STATUS_CHANGED;
e->mSslId = mServiceCtrl->getOwnId();
rsEvents->postEvent(e);
}

// alert your online peers to your newly set status
std::set<RsPeerId>::iterator it(onlineList.begin());
Expand All @@ -1019,7 +1034,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s)
IndicateConfigChanged();
}

void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
void p3ChatService::setOwnNodeAvatarJpegData(const unsigned char *data,int size)
{
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
Expand All @@ -1043,7 +1058,15 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
}
IndicateConfigChanged();

RsServer::notify()->notifyOwnAvatarChanged() ;
//RsServer::notify()->notifyOwnAvatarChanged() ;

if(rsEvents)
{
auto e = std::make_shared<RsFriendListEvent>();
e->mEventCode = RsFriendListEventCode::OWN_AVATAR_CHANGED;
e->mSslId = mServiceCtrl->getOwnId();
rsEvents->postEvent(e);
}

#ifdef CHAT_DEBUG
std::cerr << "p3chatservice:setOwnAvatarJpegData() done." << std::endl ;
Expand Down
4 changes: 2 additions & 2 deletions src/chat/p3chatservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef RsPeerId ChatLobbyVirtualPeerId ;

struct RsChatMessageEvent : RsEvent
{
RsChatMessageEvent() : RsEvent(RsEventType::CHAT_MESSAGE) {}
RsChatMessageEvent() : RsEvent(RsEventType::CHAT_SERVICE) {}
~RsChatMessageEvent() override = default;

///* @see RsEvent @see RsSerializable
Expand Down Expand Up @@ -152,7 +152,7 @@ class p3ChatService :
* Sets the avatar data and size for client's account
* @param data is copied, so should be destroyed by the caller
*/
void setOwnAvatarJpegData(const unsigned char *data,int size) ;
void setOwnNodeAvatarJpegData(const unsigned char *data,int size) ;

/*!
* Gets the avatar data for clients account
Expand Down
20 changes: 16 additions & 4 deletions src/file_sharing/directory_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,15 @@ bool LocalDirectoryUpdater::sweepSharedDirectories(bool& some_files_not_ready)

mIsChecking = true;

RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
//RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);

/* recursive update algorithm works that way:
if(rsEvents)
{
auto ev = std::make_shared<RsSharedDirectoriesEvent>();
ev->mEventCode = RsSharedDirectoriesEventCode::OWN_DIR_LIST_PROCESSING;
rsEvents->postEvent(ev);
}
/* recursive update algorithm works that way:
* - the external loop starts on the shared directory list and goes through
* sub-directories
* - at the same time, it updates the local list of shared directories.
Expand Down Expand Up @@ -223,8 +229,14 @@ bool LocalDirectoryUpdater::sweepSharedDirectories(bool& some_files_not_ready)
* dir list, because the two are not necessarily in the same order. */
}

RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
mIsChecking = false;
//RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
if(rsEvents)
{
auto ev = std::make_shared<RsSharedDirectoriesEvent>();
ev->mEventCode = RsSharedDirectoriesEventCode::OWN_DIR_LIST_UPDATED;
rsEvents->postEvent(ev);
}
mIsChecking = false;

return true;
}
Expand Down
Loading