added interface methods for public lobby exchange and subscription to public lobbies. Need a GUI now

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4759 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-01-07 19:52:58 +00:00
parent 434ba06c82
commit 485c394e2b
9 changed files with 140 additions and 13 deletions

View File

@ -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 setOwnAvatarData(const unsigned char *data,int size) = 0 ;
virtual void getOwnAvatarData(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 isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) = 0;
virtual bool getVirtualPeerId(const ChatLobbyId& lobby_id,std::string& vpid) = 0; virtual bool getVirtualPeerId(const ChatLobbyId& lobby_id,std::string& vpid) = 0;
virtual void getChatLobbyList(std::list<ChatLobbyInfo>& cl_info) = 0; virtual void getChatLobbyList(std::list<ChatLobbyInfo>& cl_info) = 0;
virtual void getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies) = 0 ;
virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0;
virtual bool acceptLobbyInvite(const ChatLobbyId& id) = 0 ; virtual bool acceptLobbyInvite(const ChatLobbyId& id) = 0 ;
virtual void denyLobbyInvite(const ChatLobbyId& id) = 0 ; virtual void denyLobbyInvite(const ChatLobbyId& id) = 0 ;

View File

@ -299,6 +299,16 @@ bool p3Msgs::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& ni
return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ; return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ;
} }
bool p3Msgs::joinPublicChatLobby(const ChatLobbyId& lobby_id)
{
return mChatSrv->joinPublicChatLobby(lobby_id) ;
}
void p3Msgs::getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies)
{
mChatSrv->getListOfNearbyChatLobbies(public_lobbies) ;
}
ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type) ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type)
{ {
return mChatSrv->createChatLobby(lobby_name,invited_friends,privacy_type) ; return mChatSrv->createChatLobby(lobby_name,invited_friends,privacy_type) ;

View File

@ -168,19 +168,21 @@ class p3Msgs: public RsMsgs
/****************************************/ /****************************************/
virtual bool getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) ; virtual bool joinPublicChatLobby(const ChatLobbyId& id) ;
virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) ; virtual void getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies) ;
virtual void getChatLobbyList(std::list<ChatLobbyInfo, std::allocator<ChatLobbyInfo> >&) ; virtual bool getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) ;
virtual void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) ;
virtual bool acceptLobbyInvite(const ChatLobbyId& id) ; virtual void getChatLobbyList(std::list<ChatLobbyInfo, std::allocator<ChatLobbyInfo> >&) ;
virtual void denyLobbyInvite(const ChatLobbyId& id) ; virtual void invitePeerToLobby(const ChatLobbyId&, const std::string&) ;
virtual void getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites) ; virtual bool acceptLobbyInvite(const ChatLobbyId& id) ;
virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; virtual void denyLobbyInvite(const ChatLobbyId& id) ;
virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string&) ; virtual void getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites) ;
virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ; virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ;
virtual bool setDefaultNickNameForChatLobby(const std::string&) ; virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string&) ;
virtual bool getDefaultNickNameForChatLobby(std::string& nick) ; virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ;
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type) ; virtual bool setDefaultNickNameForChatLobby(const std::string&) ;
virtual bool getDefaultNickNameForChatLobby(std::string& nick) ;
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
private: private:

View File

@ -1955,6 +1955,62 @@ void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id)
_lobby_invites_queue.erase(it) ; _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<std::string> invited_friends ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
// create a unique id.
//
std::map<ChatLobbyId,PublicChatLobbyRecord>::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<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
invited_friends.push_back(*it2) ;
}
for(std::list<std::string>::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<std::string>& invited_friends,uint32_t privacy_level) ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_level)
{ {
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG

View File

@ -168,7 +168,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
bool getDefaultNickNameForChatLobby(std::string& nick) ; bool getDefaultNickNameForChatLobby(std::string& nick) ;
void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ; void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ;
ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type) ; ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
void getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies) ; void getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies) ;
bool joinPublicChatLobby(const ChatLobbyId& id) ;
protected: protected:
/************* from p3Config *******************/ /************* from p3Config *******************/

View File

@ -270,6 +270,7 @@ HEADERS += rshare.h \
gui/profile/StatusMessage.h \ gui/profile/StatusMessage.h \
gui/chat/PopupChatWindow.h \ gui/chat/PopupChatWindow.h \
gui/chat/PopupChatDialog.h \ gui/chat/PopupChatDialog.h \
gui/ChatLobbyWidget.h \
gui/chat/ChatLobbyDialog.h \ gui/chat/ChatLobbyDialog.h \
gui/chat/CreateLobbyDialog.h \ gui/chat/CreateLobbyDialog.h \
gui/chat/HandleRichText.h \ gui/chat/HandleRichText.h \
@ -535,6 +536,7 @@ SOURCES += main.cpp \
gui/channels/ShareKey.cpp \ gui/channels/ShareKey.cpp \
gui/chat/PopupChatWindow.cpp \ gui/chat/PopupChatWindow.cpp \
gui/chat/PopupChatDialog.cpp \ gui/chat/PopupChatDialog.cpp \
gui/ChatLobbyWidget.cpp \
gui/chat/ChatLobbyDialog.cpp \ gui/chat/ChatLobbyDialog.cpp \
gui/chat/CreateLobbyDialog.cpp \ gui/chat/CreateLobbyDialog.cpp \
gui/chat/HandleRichText.cpp \ gui/chat/HandleRichText.cpp \

View File

@ -0,0 +1,33 @@
#include <retroshare/rsmsgs.h>
#include "ChatLobbyWidget.h"
ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags)
: RsAutoUpdatePage(5000,parent)
{
}
ChatLobbyWidget::~ChatLobbyWidget()
{
}
void ChatLobbyWidget::updateDisplay()
{
std::vector<PublicChatLobbyRecord> 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)
}

View File

@ -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() ;
};

View File

@ -50,6 +50,7 @@
#include "im_history/ImHistoryBrowser.h" #include "im_history/ImHistoryBrowser.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "NewsFeed.h" #include "NewsFeed.h"
#include "ChatLobbyWidget.h"
#include "notifyqt.h" #include "notifyqt.h"
#include "profile/ProfileWidget.h" #include "profile/ProfileWidget.h"
#include "profile/StatusMessage.h" #include "profile/StatusMessage.h"
@ -85,6 +86,7 @@ FriendsDialog::FriendsDialog(QWidget *parent)
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatar->setOwnId(); ui.avatar->setOwnId();
ui.peertabWidget->addTab(new ChatLobbyWidget(), tr("Chat lobbies"));
ui.peertabWidget->setTabPosition(QTabWidget::North); ui.peertabWidget->setTabPosition(QTabWidget::North);
ui.peertabWidget->addTab(new ProfileWidget(), tr("Profile")); ui.peertabWidget->addTab(new ProfileWidget(), tr("Profile"));
NewsFeed *newsFeed = new NewsFeed(); NewsFeed *newsFeed = new NewsFeed();