diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 8b6129a21..7e19ab13b 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -249,9 +249,11 @@ virtual void getAvatarData(const std::string& pid,unsigned char *& data,int& siz virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ; virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ; +virtual bool joinPublicChatLobby(const ChatLobbyId& lobby_id) = 0 ; virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) = 0; virtual bool getVirtualPeerId(const ChatLobbyId& lobby_id,std::string& vpid) = 0; virtual void getChatLobbyList(std::list& cl_info) = 0; +virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) = 0 ; virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; virtual bool acceptLobbyInvite(const ChatLobbyId& id) = 0 ; virtual void denyLobbyInvite(const ChatLobbyId& id) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 917c3985f..eab72ce12 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -299,6 +299,16 @@ bool p3Msgs::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& ni return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ; } +bool p3Msgs::joinPublicChatLobby(const ChatLobbyId& lobby_id) +{ + return mChatSrv->joinPublicChatLobby(lobby_id) ; +} + +void p3Msgs::getListOfNearbyChatLobbies(std::vector& public_lobbies) +{ + mChatSrv->getListOfNearbyChatLobbies(public_lobbies) ; +} + ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::list& invited_friends,uint32_t privacy_type) { return mChatSrv->createChatLobby(lobby_name,invited_friends,privacy_type) ; diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index c2cbf4f39..fc6a88141 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -168,19 +168,21 @@ class p3Msgs: public RsMsgs /****************************************/ - virtual bool getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) ; - virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) ; - virtual void getChatLobbyList(std::list >&) ; - virtual void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; - virtual bool acceptLobbyInvite(const ChatLobbyId& id) ; - virtual void denyLobbyInvite(const ChatLobbyId& id) ; - virtual void getPendingChatLobbyInvites(std::list& invites) ; - virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; - virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string&) ; - virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ; - virtual bool setDefaultNickNameForChatLobby(const std::string&) ; - virtual bool getDefaultNickNameForChatLobby(std::string& nick) ; - virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends,uint32_t privacy_type) ; + virtual bool joinPublicChatLobby(const ChatLobbyId& id) ; + virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; + virtual bool getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) ; + virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) ; + virtual void getChatLobbyList(std::list >&) ; + virtual void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; + virtual bool acceptLobbyInvite(const ChatLobbyId& id) ; + virtual void denyLobbyInvite(const ChatLobbyId& id) ; + virtual void getPendingChatLobbyInvites(std::list& invites) ; + virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; + virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string&) ; + virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ; + virtual bool setDefaultNickNameForChatLobby(const std::string&) ; + virtual bool getDefaultNickNameForChatLobby(std::string& nick) ; + virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends,uint32_t privacy_type) ; private: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 6bd8a57b0..99bca4285 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -1955,6 +1955,62 @@ void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id) _lobby_invites_queue.erase(it) ; } +bool p3ChatService::joinPublicChatLobby(const ChatLobbyId& lobby_id) +{ +#ifdef CHAT_DEBUG + std::cerr << "Joining public chat lobby " << std::hex << lobby_id << std::dec << std::endl; +#endif + std::list invited_friends ; + + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + // create a unique id. + // + std::map::const_iterator it(_public_lobbies.find(lobby_id)) ; + + if(it == _public_lobbies.end()) + { + std::cerr << " lobby is not a known public chat lobby. Sorry!" << std::endl; + return false ; + } + +#ifdef CHAT_DEBUG + std::cerr << " lobby found. Initiating join sequence..." << std::endl; +#endif + + if(_chat_lobbys.find(lobby_id) != _chat_lobbys.end()) + { + std::cerr << " lobby already in participating list. Returning!" << std::endl; + return true ; + } + + std::cerr << " Creating new lobby entry." << std::endl; + + ChatLobbyEntry entry ; + entry.lobby_privacy_level = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ; + entry.participating_friends.clear() ; + entry.nick_name = _default_nick_name ; + entry.lobby_id = lobby_id ; + entry.lobby_name = it->second.lobby_name ; + entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ; + entry.connexion_challenge_count = 0 ; + entry.last_activity = time(NULL) ; + entry.last_connexion_challenge_time = time(NULL) ; + + _lobby_ids[entry.virtual_peer_id] = lobby_id ; + _chat_lobbys[lobby_id] = entry ; + + for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + invited_friends.push_back(*it2) ; + } + + for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) + invitePeerToLobby(lobby_id,*it) ; + + return true ; +} + ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::list& invited_friends,uint32_t privacy_level) { #ifdef CHAT_DEBUG diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 941b4ee98..e31ef5ec9 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -168,7 +168,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor bool getDefaultNickNameForChatLobby(std::string& nick) ; void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ; ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends,uint32_t privacy_type) ; + void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; + bool joinPublicChatLobby(const ChatLobbyId& id) ; protected: /************* from p3Config *******************/ diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 64bb60dfc..37988db2d 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -270,6 +270,7 @@ HEADERS += rshare.h \ gui/profile/StatusMessage.h \ gui/chat/PopupChatWindow.h \ gui/chat/PopupChatDialog.h \ + gui/ChatLobbyWidget.h \ gui/chat/ChatLobbyDialog.h \ gui/chat/CreateLobbyDialog.h \ gui/chat/HandleRichText.h \ @@ -535,6 +536,7 @@ SOURCES += main.cpp \ gui/channels/ShareKey.cpp \ gui/chat/PopupChatWindow.cpp \ gui/chat/PopupChatDialog.cpp \ + gui/ChatLobbyWidget.cpp \ gui/chat/ChatLobbyDialog.cpp \ gui/chat/CreateLobbyDialog.cpp \ gui/chat/HandleRichText.cpp \ diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp new file mode 100644 index 000000000..dbf67b6de --- /dev/null +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -0,0 +1,33 @@ +#include +#include "ChatLobbyWidget.h" + +ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags) + : RsAutoUpdatePage(5000,parent) +{ +} +ChatLobbyWidget::~ChatLobbyWidget() +{ +} + +void ChatLobbyWidget::updateDisplay() +{ + std::vector public_lobbies ; + rsMsgs->getListOfNearbyChatLobbies(public_lobbies) ; + + // now, do a nice display of public lobbies. + + // Each lobby can be joined directly, by calling + // rsMsgs->joinPublicLobby(chatLobbyId) ; + + // e.g. fill a list of public lobbies + + // also maintain a list of active chat lobbies. Each active (subscribed) lobby has a lobby tab in the gui. + // Each tab knows its lobby id and its virtual peer id (the one to send private chat messages to) + // + // One possibility is to convert ChatLobbyDialog to be used at a chat lobby tab. + + // then the lobby can be accessed using the virtual peer id through + // rsMsgs->getVirtualPeerId(ChatLobbyId,std::string& virtual_peer_id) +} + + diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.h b/retroshare-gui/src/gui/ChatLobbyWidget.h new file mode 100644 index 000000000..112998a8a --- /dev/null +++ b/retroshare-gui/src/gui/ChatLobbyWidget.h @@ -0,0 +1,18 @@ +#pragma once + +#include "RsAutoUpdatePage.h" + +class ChatLobbyWidget : public RsAutoUpdatePage +{ + Q_OBJECT + + public: + /** Default constructor */ + ChatLobbyWidget(QWidget *parent = 0, Qt::WFlags flags = 0); + + /** Default destructor */ + ~ChatLobbyWidget(); + + virtual void updateDisplay() ; +}; + diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 242ac4cbf..8dee73379 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -50,6 +50,7 @@ #include "im_history/ImHistoryBrowser.h" #include "MainWindow.h" #include "NewsFeed.h" +#include "ChatLobbyWidget.h" #include "notifyqt.h" #include "profile/ProfileWidget.h" #include "profile/StatusMessage.h" @@ -85,6 +86,7 @@ FriendsDialog::FriendsDialog(QWidget *parent) ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatar->setOwnId(); + ui.peertabWidget->addTab(new ChatLobbyWidget(), tr("Chat lobbies")); ui.peertabWidget->setTabPosition(QTabWidget::North); ui.peertabWidget->addTab(new ProfileWidget(), tr("Profile")); NewsFeed *newsFeed = new NewsFeed();