From d9244225b797ef0a33371960ac97526c976c8da9 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 22 Nov 2011 19:40:57 +0000 Subject: [PATCH 01/17] Created this branch to develop chat lobby functionality git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4682 b45a01b8-16f6-495d-af2f-9b41ad6348cc From 5cdc36d7309ab499356e66aa1ab5b2ea69fe954a Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 23 Nov 2011 22:10:37 +0000 Subject: [PATCH 02/17] Basic methods and a bit of interface for chat lobby. Next: - chat lobby algorithmics (cache+broadcast system) - invitation handling - specification of chat lobby window with list of known/unknown participants git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4685 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 22 +- libretroshare/src/rsserver/p3msgs.cc | 14 + libretroshare/src/rsserver/p3msgs.h | 3 + libretroshare/src/services/p3chatservice.cc | 30 + libretroshare/src/services/p3chatservice.h | 5 + retroshare-gui/src/RetroShare.pro | 3 + .../src/gui/chat/ChatLobbyDialog.ui | 907 ++++++++++++++++++ retroshare-gui/src/gui/common/FriendList.cpp | 267 +++--- retroshare-gui/src/gui/common/FriendList.h | 2 + 9 files changed, 1137 insertions(+), 116 deletions(-) create mode 100644 retroshare-gui/src/gui/chat/ChatLobbyDialog.ui diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index b8157c500..f9d939871 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -61,6 +61,8 @@ #define RS_MSGTAGTYPE_LATER 5 #define RS_MSGTAGTYPE_USER 100 +typedef uint64_t ChatLobbyId ; + class MessageInfo { public: @@ -135,10 +137,17 @@ class ChatInfo std::wstring msg; }; +class ChatLobbyInfo +{ + public: + ChatLobbyId lobby_id ; + std::string display_name ; + std::list participating_friends ; // list of direct friend who participate. Used to broadcast sent messages. + std::list additional_peers ; // list of non direct friend who participate. Used to display only. +}; + std::ostream &operator<<(std::ostream &out, const MessageInfo &info); std::ostream &operator<<(std::ostream &out, const ChatInfo &info); -//std::ostream &operator<<(std::ostream &out, const MsgTagInfo); -//std::ostream &operator<<(std::ostream &out, const MsgTagType); bool operator==(const ChatInfo&, const ChatInfo&); @@ -185,13 +194,15 @@ virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0; /****************************************/ /* Chat */ virtual bool sendPublicChat(const std::wstring& msg) = 0; +virtual bool sendLobbyChat(const std::wstring& msg,const ChatLobbyId& lid) = 0; virtual bool sendPrivateChat(const std::string& id, const std::wstring& msg) = 0; -virtual int getPublicChatQueueCount() = 0; +virtual int getPublicChatQueueCount() = 0; virtual bool getPublicChatQueue(std::list &chats) = 0; -virtual int getPrivateChatQueueCount(bool incoming) = 0; +virtual int getPrivateChatQueueCount(bool incoming) = 0; virtual bool getPrivateChatQueueIds(bool incoming, std::list &ids) = 0; virtual bool getPrivateChatQueue(bool incoming, const std::string& id, std::list &chats) = 0; virtual bool clearPrivateChatQueue(bool incoming, const std::string& id) = 0; + virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ; virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ; @@ -205,6 +216,9 @@ 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 void getChatLobbyList(std::list& cl_info) = 0; +virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; + /****************************************/ }; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 56fb174a7..31cc6ec1e 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -260,3 +260,17 @@ void p3Msgs::setCustomStateString(const std::string& state_string) mChatSrv->setOwnCustomStateString(state_string) ; } +bool p3Msgs::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& id) +{ + return mChatSrv->sendLobbyChat(msg,id) ; +} +void p3Msgs::getChatLobbyList(std::list& linfos) +{ + mChatSrv->getChatLobbyList(linfos) ; +} +void p3Msgs::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id) +{ + mChatSrv->invitePeerToLobby(lobby_id,peer_id) ; +} + + diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 39b39e903..57f68c780 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -167,6 +167,9 @@ class p3Msgs: public RsMsgs /****************************************/ + virtual bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; + virtual void getChatLobbyList(std::list >&) ; + virtual void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; private: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 8c7e02040..51e29ea95 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -1135,3 +1135,33 @@ void p3ChatService::statusChange(const std::list &plist) } } } + +//********************** Chat Lobby Stuff ***********************// + +bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lobby_id) +{ + std::cerr << "Sending chat lobby message to lobby " << lobby_id << std::endl; + std::cerr << "msg:" << std::endl; + std::cerr << msg.c_str() << std::endl; + return true ; +} +void p3ChatService::getChatLobbyList(std::list& linfos) +{ + // fill up a dummy list for now. + + linfos.clear() ; + + ChatLobbyInfo info ; + info.lobby_id = 0x38484fe ; + info.display_name = "lobby 1" ; + info.participating_friends.push_back("friend 1") ; + info.participating_friends.push_back("friend 2") ; + info.additional_peers.push_back("peer 1") ; + + linfos.push_back(info) ; +} +void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id) +{ + std::cerr << "Sending invitation to peer " << peer_id << " to lobby "<< lobby_id << std::endl; +} + diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 619e67578..a1d5f8eea 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -153,6 +153,11 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor */ bool clearPrivateChatQueue(bool incoming, const std::string &id); + bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; + void getChatLobbyList(std::list >&) ; + void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; + + protected: /************* from p3Config *******************/ virtual RsSerialiser *setupSerialiser() ; diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 212417c8e..f56cfe4e3 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/chat/ChatLobbyDialog.h \ gui/chat/HandleRichText.h \ gui/chat/ChatStyle.h \ gui/channels/CreateChannel.h \ @@ -405,6 +406,7 @@ FORMS += gui/StartDialog.ui \ gui/channels/ShareKey.ui \ gui/chat/PopupChatWindow.ui \ gui/chat/PopupChatDialog.ui \ + gui/chat/ChatLobbyDialog.ui \ gui/connect/ConfCertDialog.ui \ gui/msgs/MessageComposer.ui \ gui/msgs/MessageWindow.ui\ @@ -527,6 +529,7 @@ SOURCES += main.cpp \ gui/channels/ShareKey.cpp \ gui/chat/PopupChatWindow.cpp \ gui/chat/PopupChatDialog.cpp \ +# gui/chat/ChatLobbyDialog.cpp \ gui/chat/HandleRichText.cpp \ gui/chat/ChatStyle.cpp \ gui/connect/ConfCertDialog.cpp \ diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.ui b/retroshare-gui/src/gui/chat/ChatLobbyDialog.ui new file mode 100644 index 000000000..e4ef50813 --- /dev/null +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.ui @@ -0,0 +1,907 @@ + + + PopupChatDialog + + + Qt::NonModal + + + + 0 + 0 + 662 + 499 + + + + MainWindow + + + + + + + 0 + + + + + 0 + + + 1 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 14 + 16777215 + + + + QFrame#frame{border: transparent} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + + + + 14 + 31 + + + + + 14 + 31 + + + + + + + + 16 + 31 + + + + true + + + + + + + Qt::Vertical + + + + 12 + 335 + + + + + + + + + + + + 132 + 16777215 + + + + border: transparent; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 9 + + + 3 + + + 9 + + + + + Qt::Vertical + + + + 61 + 141 + + + + + + + + + 116 + 116 + + + + + 116 + 116 + + + + + + + + + + + + + + QFrame#frame_2{border: transparent} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 2 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + + Arial + 13 + 75 + true + true + + + + TextLabel + + + + + + + + Arial + 9 + + + + TextLabel + + + + + + + + + + QFrame#infoframe{border: 1px solid #DCDC41; +border-radius: 6px; +background: #FFFFD7; +background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, +stop:0 #FFFFD7, stop:1 #FFFFB2);} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 6 + + + + + + 16 + 16 + + + + + + + :/images/info16.png + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + TextLabel + + + + + + + + 16 + 16 + + + + Qt::NoFocus + + + Close + + + QToolButton +{ + border-image: url(:/images/closenormal.png) +} + +QToolButton:hover +{ +border-image: url(:/images/closehover.png) +} + +QToolButton:pressed { +border-image: url(:/images/closepressed.png) +} + + + + + + true + + + + + + + + + + + 347 + 30 + + + + + 16777215 + 30 + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 1 + + + 6 + + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + QPushButton::menu-indicator { +subcontrol-origin: padding; +subcontrol-position: bottom right; +} + +QPushButton::menu-indicator:pressed, QPushButton::menu-indicator:open { +position: relative; +top: 1px; left: 1px; /* shift the arrow by 2 px */ +} + +QPushButton:hover { +border: 1px solid #CCCCCC; +} + + + + + + + :/images/configure.png:/images/configure.png + + + + 22 + 22 + + + + true + + + + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + Attach a Picture + + + + + + + :/images/add_image24.png:/images/add_image24.png + + + + 24 + 24 + + + + true + + + + + + + + 28 + 28 + + + + Qt::NoFocus + + + Add a File for your Friend + + + + + + + :/images/add-share24.png:/images/add-share24.png + + + + 24 + 24 + + + + true + + + + + + + Qt::Horizontal + + + + 190 + 25 + + + + + + + + Send + + + + + + + + 0 + 0 + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + + + + + 24 + 24 + + + + true + + + + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + Bold + + + + + + + ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup + + + false + + + true + + + + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + Underline + + + + + + + ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup + + + false + + + true + + + + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + Italic + + + + + + + ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup + + + false + + + true + + + + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + Font + + + + + + + ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup + + + false + + + true + + + + + + + + 28 + 28 + + + + + 28 + 28 + + + + Qt::NoFocus + + + Text Color + + + + + + true + + + + + + + + + + + + + 1 + + + Qt::Vertical + + + 2 + + + + + + + + 0 + 0 + + + + + 0 + 100 + + + + QTextBrowser{border: 1px solid #B8B6B1; +border-radius: 6px; +background: white;} + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;"></p></body></html> + + + true + + + true + + + + + + + + + 0 + + + + + + + + 0 + + + 3 + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + Qt::CustomContextMenu + + + QTextEdit{border: 1px solid #B8B6B1; +border-radius: 6px; +background: white;} + + + + + + + + 18 + 18 + + + + + 18 + 18 + + + + T + + + Qt::AlignCenter + + + + + + + + + + + + + Bold + + + + + Italic + + + + + Underline + + + + + Strike + + + + + + :/images/edit-clear-history.png:/images/edit-clear-history.png + + + Clear Chat History + + + + + true + + + Disable Emoticons + + + + + Save Chat History + + + Save Chat History + + + + + Clear offline messages + + + + + Browse Message History + + + Browse History + + + + + + :/images/edit-clear-history.png:/images/edit-clear-history.png + + + Delete Chat History + + + Deletes all stored and displayed chat history + + + + + + AvatarWidget + QWidget +
gui/common/AvatarWidget.h
+ 1 +
+
+ + + + +
diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 81c0b380d..3e8488e60 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -292,143 +292,162 @@ void FriendList::peerTreeWidgetCostumPopupMenu() contextMnu.addAction(widgetAction); // create menu entries - if (c) { // if a peer is selected - int type = c->type(); + if (c) + { // if a peer is selected + int type = c->type(); - // define header - switch (type) { - case TYPE_GROUP: - //this is a GPG key - textLabel->setText("" + tr("Group") + ""); - break; - case TYPE_GPG: - //this is a GPG key - textLabel->setText("" + tr("Friend") + ""); - break; - case TYPE_SSL: - //this is a SSL key - textLabel->setText("" + tr("Location") + ""); - break; - } + // define header + switch (type) { + case TYPE_GROUP: + //this is a GPG key + textLabel->setText("" + tr("Group") + ""); + break; + case TYPE_GPG: + //this is a GPG key + textLabel->setText("" + tr("Friend") + ""); + break; + case TYPE_SSL: + //this is a SSL key + textLabel->setText("" + tr("Location") + ""); + break; + } - switch (type) { - case TYPE_GROUP: - { - bool standard = c->data(COLUMN_DATA, ROLE_STANDARD).toBool(); + switch (type) { + case TYPE_GROUP: + { + bool standard = c->data(COLUMN_DATA, ROLE_STANDARD).toBool(); - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Group"), this, SLOT(msgfriend())); - contextMnu.addAction(QIcon(IMAGE_ADDFRIEND), tr("Add Friend"), this, SLOT(addFriend())); + contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Group"), this, SLOT(msgfriend())); + contextMnu.addAction(QIcon(IMAGE_ADDFRIEND), tr("Add Friend"), this, SLOT(addFriend())); - contextMnu.addSeparator(); + contextMnu.addSeparator(); - QAction *action = contextMnu.addAction(QIcon(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup())); - action->setDisabled(standard); + QAction *action = contextMnu.addAction(QIcon(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup())); + action->setDisabled(standard); - action = contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup())); - action->setDisabled(standard); - } - break; - case TYPE_GPG: - case TYPE_SSL: - { - contextMnu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy())); - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Friend"), this, SLOT(msgfriend())); + action = contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup())); + action->setDisabled(standard); - contextMnu.addSeparator(); + contextMnu.addAction(QIcon(IMAGE_CHAT), tr("Create chat lobby"), this, SLOT(createchatlobby())); + } + break; + case TYPE_GPG: + case TYPE_SSL: + { + contextMnu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy())); + QMenu *mnu = contextMnu.addMenu(QIcon(IMAGE_CHAT), tr("Invite to chat lobby")) ; - contextMnu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Friend Details"), this, SLOT(configurefriend())); -// contextMnu.addAction(QIcon(IMAGE_PEERINFO), tr("Profile View"), this, SLOT(viewprofile())); -// action = contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Export Friend"), this, SLOT(exportfriend())); + std::list cl_infos ; - if (type == TYPE_GPG) { - contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Recommend this Friend to..."), this, SLOT(recommendfriend())); - } + rsMsgs->getChatLobbyList(cl_infos) ; - contextMnu.addAction(QIcon(IMAGE_CONNECT), tr("Connect To Friend"), this, SLOT(connectfriend())); + for(std::list::const_iterator it(cl_infos.begin());it!=cl_infos.end();++it) + { + QAction* inviteToLobbyAction = new QAction(QString::fromUtf8((*it).display_name.c_str()), mnu); + inviteToLobbyAction->setData(QString::fromStdString((*it).lobby_id.c_str())); + connect(inviteToLobbyAction, SIGNAL(triggered()), this, SLOT(inviteToLobby())); + mnu->addAction(inviteToLobbyAction); + } - if (type == TYPE_GPG) { - contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink())); - } + mnu->addAction(QIcon(IMAGE_CHAT),tr("create new")) ; - QAction *action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste Friend Link"), this, SLOT(pastePerson())); - if (RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) { - action->setDisabled(true); - } + contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Friend"), this, SLOT(msgfriend())); - if (type == TYPE_GPG) { - contextMnu.addAction(QIcon(IMAGE_DENYFRIEND), tr("Deny Friend"), this, SLOT(removefriend())); - } else { - //this is a SSL key - contextMnu.addAction(QIcon(IMAGE_REMOVEFRIEND), tr("Remove Friend Location"), this, SLOT(removefriend())); - } + contextMnu.addSeparator(); - if (mShowGroups && type == TYPE_GPG) { - QMenu* addToGroupMenu = NULL; - QMenu* moveToGroupMenu = NULL; + contextMnu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Friend Details"), this, SLOT(configurefriend())); + // contextMnu.addAction(QIcon(IMAGE_PEERINFO), tr("Profile View"), this, SLOT(viewprofile())); + // action = contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Export Friend"), this, SLOT(exportfriend())); - std::list groupInfoList; - rsPeers->getGroupInfoList(groupInfoList); + if (type == TYPE_GPG) { + contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Recommend this Friend to..."), this, SLOT(recommendfriend())); + } - GroupDefs::sortByName(groupInfoList); + contextMnu.addAction(QIcon(IMAGE_CONNECT), tr("Connect To Friend"), this, SLOT(connectfriend())); - std::string gpgId = getRsId(c); + if (type == TYPE_GPG) { + contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink())); + } - QTreeWidgetItem *parent = c->parent(); + QAction *action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste Friend Link"), this, SLOT(pastePerson())); + if (RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) { + action->setDisabled(true); + } - bool foundGroup = false; - // add action for all groups, except the own group - for (std::list::iterator groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) { - if (std::find(groupIt->peerIds.begin(), groupIt->peerIds.end(), gpgId) == groupIt->peerIds.end()) { - if (parent) { - if (addToGroupMenu == NULL) { - addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu); - } - QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu); - addToGroupAction->setData(QString::fromStdString(groupIt->id)); - connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup())); - addToGroupMenu->addAction(addToGroupAction); - } + if (type == TYPE_GPG) { + contextMnu.addAction(QIcon(IMAGE_DENYFRIEND), tr("Deny Friend"), this, SLOT(removefriend())); + } else { + //this is a SSL key + contextMnu.addAction(QIcon(IMAGE_REMOVEFRIEND), tr("Remove Friend Location"), this, SLOT(removefriend())); + } - if (moveToGroupMenu == NULL) { - moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu); - } - QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu); - moveToGroupAction->setData(QString::fromStdString(groupIt->id)); - connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup())); - moveToGroupMenu->addAction(moveToGroupAction); - } else { - foundGroup = true; - } - } + if (mShowGroups && type == TYPE_GPG) { + QMenu* addToGroupMenu = NULL; + QMenu* moveToGroupMenu = NULL; - if (addToGroupMenu || moveToGroupMenu || foundGroup) { - QMenu *groupsMenu = contextMnu.addMenu(QIcon(IMAGE_GROUP16), tr("Groups")); + std::list groupInfoList; + rsPeers->getGroupInfoList(groupInfoList); - if (addToGroupMenu) { - groupsMenu->addMenu(addToGroupMenu); - } + GroupDefs::sortByName(groupInfoList); - if (moveToGroupMenu) { - groupsMenu->addMenu(moveToGroupMenu); - } + std::string gpgId = getRsId(c); - if (foundGroup) { - // add remove from group - if (parent && parent->type() == TYPE_GROUP) { - QAction *removeFromGroup = groupsMenu->addAction(tr("Remove from group")); - removeFromGroup->setData(parent->data(COLUMN_DATA, ROLE_ID)); - connect(removeFromGroup, SIGNAL(triggered()), this, SLOT(removeFromGroup())); - } + QTreeWidgetItem *parent = c->parent(); - QAction *removeFromAllGroups = groupsMenu->addAction(tr("Remove from all groups")); - removeFromAllGroups->setData(""); - connect(removeFromAllGroups, SIGNAL(triggered()), this, SLOT(removeFromGroup())); - } - } - } - } - } - } else { + bool foundGroup = false; + // add action for all groups, except the own group + for (std::list::iterator groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) { + if (std::find(groupIt->peerIds.begin(), groupIt->peerIds.end(), gpgId) == groupIt->peerIds.end()) { + if (parent) { + if (addToGroupMenu == NULL) { + addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu); + } + QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu); + addToGroupAction->setData(QString::fromStdString(groupIt->id)); + connect(addToGroupAction, SIGNAL(triggered()), this, SLOT(addToGroup())); + addToGroupMenu->addAction(addToGroupAction); + } + + if (moveToGroupMenu == NULL) { + moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu); + } + QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu); + moveToGroupAction->setData(QString::fromStdString(groupIt->id)); + connect(moveToGroupAction, SIGNAL(triggered()), this, SLOT(moveToGroup())); + moveToGroupMenu->addAction(moveToGroupAction); + } else { + foundGroup = true; + } + } + + if (addToGroupMenu || moveToGroupMenu || foundGroup) { + QMenu *groupsMenu = contextMnu.addMenu(QIcon(IMAGE_GROUP16), tr("Groups")); + + if (addToGroupMenu) { + groupsMenu->addMenu(addToGroupMenu); + } + + if (moveToGroupMenu) { + groupsMenu->addMenu(moveToGroupMenu); + } + + if (foundGroup) { + // add remove from group + if (parent && parent->type() == TYPE_GROUP) { + QAction *removeFromGroup = groupsMenu->addAction(tr("Remove from group")); + removeFromGroup->setData(parent->data(COLUMN_DATA, ROLE_ID)); + connect(removeFromGroup, SIGNAL(triggered()), this, SLOT(removeFromGroup())); + } + + QAction *removeFromAllGroups = groupsMenu->addAction(tr("Remove from all groups")); + removeFromAllGroups->setData(""); + connect(removeFromAllGroups, SIGNAL(triggered()), this, SLOT(removeFromGroup())); + } + } + } + } + } + } else { QAction *action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste Friend Link"), this, SLOT(pastePerson())); if (RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) { action->setDisabled(true); @@ -1371,6 +1390,30 @@ void FriendList::configurefriend() ConfCertDialog::showIt(getRsId(getCurrentPeer()), ConfCertDialog::PageDetails); } +void FriendList::inviteToLobby() +{ + QTreeWidgetItem *c = getCurrentPeer(); + + if (c == NULL) { + return; + } + + if (c->type() != TYPE_SSL) { + // wrong type + return; + } + + std::string lobby_id = qobject_cast(sender())->data().toString().toStdString(); + + if(lobby_id.empty()) + return; + + std::string peer_id = getRsId(c) ; + + // add to group + rsMsgs->invitePeerToLobby(ChatLobbyId(lobby_id), peer_id); +} + void FriendList::addToGroup() { QTreeWidgetItem *c = getCurrentPeer(); diff --git a/retroshare-gui/src/gui/common/FriendList.h b/retroshare-gui/src/gui/common/FriendList.h index db633cf3c..51396b139 100644 --- a/retroshare-gui/src/gui/common/FriendList.h +++ b/retroshare-gui/src/gui/common/FriendList.h @@ -122,6 +122,8 @@ private slots: void editGroup(); void removeGroup(); + + void inviteToLobby(); }; #endif // FRIENDLIST_H From cd30487898ee5a0f65a51c875f253cbb0860124c Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 25 Nov 2011 21:31:52 +0000 Subject: [PATCH 03/17] Added send and forward methods. Improved data structures. Next: serialization of ChatLobbyItems git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4690 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 14 ++- libretroshare/src/serialiser/rsmsgitems.h | 35 +++++-- libretroshare/src/services/p3chatservice.cc | 103 +++++++++++++++++-- libretroshare/src/services/p3chatservice.h | 16 +++ retroshare-gui/src/gui/common/FriendList.cpp | 6 +- 5 files changed, 152 insertions(+), 22 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index f9d939871..1486897fb 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -30,6 +30,7 @@ #include #include #include +#include #include "rstypes.h" @@ -61,7 +62,9 @@ #define RS_MSGTAGTYPE_LATER 5 #define RS_MSGTAGTYPE_USER 100 -typedef uint64_t ChatLobbyId ; +typedef uint64_t ChatLobbyId ; +typedef uint64_t ChatLobbyMsgId ; +typedef std::string ChatLobbyNickName ; class MessageInfo { @@ -140,10 +143,11 @@ class ChatInfo class ChatLobbyInfo { public: - ChatLobbyId lobby_id ; - std::string display_name ; - std::list participating_friends ; // list of direct friend who participate. Used to broadcast sent messages. - std::list additional_peers ; // list of non direct friend who participate. Used to display only. + ChatLobbyId lobby_id ; // unique id of the lobby + std::string nick_name ; // nickname to use for this lobby + + std::set participating_friends ; // list of direct friend who participate. Used to broadcast sent messages. + std::set nick_names ; // list of non direct friend who participate. Used to display only. }; std::ostream &operator<<(std::ostream &out, const MessageInfo &info); diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 249d2526a..08b82bdbf 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -44,12 +44,14 @@ const uint32_t RS_CHAT_FLAG_PUBLIC = 0x0020; const uint32_t RS_CHAT_FLAG_REQUEST_CUSTOM_STATE = 0x0040; const uint32_t RS_CHAT_FLAG_CUSTOM_STATE_AVAILABLE = 0x0080; const uint32_t RS_CHAT_FLAG_PARTIAL_MESSAGE = 0x0100; +const uint32_t RS_CHAT_FLAG_LOBBY = 0x0200; const uint32_t RS_CHATMSG_CONFIGFLAG_INCOMING = 0x0001; -const uint8_t RS_PKT_SUBTYPE_CHAT_AVATAR = 0x03 ; // default is 0x01 -const uint8_t RS_PKT_SUBTYPE_CHAT_STATUS = 0x04 ; // default is 0x01 -const uint8_t RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG = 0x05 ; // default is 0x01 +const uint8_t RS_PKT_SUBTYPE_CHAT_AVATAR = 0x03 ; +const uint8_t RS_PKT_SUBTYPE_CHAT_STATUS = 0x04 ; +const uint8_t RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG = 0x05 ; +const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_MSG = 0x06 ; // for defining tags themselves and msg tags const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03; @@ -57,6 +59,9 @@ const uint8_t RS_PKT_SUBTYPE_MSG_TAGS = 0x04; const uint8_t RS_PKT_SUBTYPE_MSG_SRC_TAG = 0x05; const uint8_t RS_PKT_SUBTYPE_MSG_PARENT_TAG = 0x06; +typedef uint64_t ChatLobbyId ; +typedef uint64_t ChatLobbyMsgId ; +typedef std::string ChatLobbyNickName ; class RsChatItem: public RsItem { @@ -81,9 +86,9 @@ class RsChatItem: public RsItem class RsChatMsgItem: public RsChatItem { public: - RsChatMsgItem() :RsChatItem(RS_PKT_SUBTYPE_DEFAULT) - { - } + RsChatMsgItem() :RsChatItem(RS_PKT_SUBTYPE_DEFAULT) {} + RsChatMsgItem(uint8_t subtype) :RsChatItem(subtype) {} + RsChatMsgItem(void *data,uint32_t size) ; // deserialization virtual ~RsChatMsgItem() {} @@ -100,6 +105,24 @@ class RsChatMsgItem: public RsChatItem uint32_t recvTime; }; +class RsChatLobbyMsgItem: public RsChatMsgItem +{ + public: + RsChatLobbyMsgItem() :RsChatMsgItem(RS_PKT_SUBTYPE_CHAT_LOBBY_MSG) {} + + RsChatLobbyMsgItem(void *data,uint32_t size) {} // deserialization /// TODO!!! + + virtual ~RsChatLobbyMsgItem() {} + + ChatLobbyId lobby_id ; + ChatLobbyMsgId msg_id ; + ChatLobbyNickName nick ; + + /// TODO !!! + virtual bool serialise(void *data,uint32_t& size) { return true ; } // Isn't it better that items can serialize themselves ? + virtual uint32_t serial_size() { return 0;} // deserialise is handled using a constructor +}; + /*! * For saving incoming and outgoing chat msgs * @see p3ChatService diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 51e29ea95..afa353e1f 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -24,6 +24,7 @@ */ #include "util/rsdir.h" +#include "util/rsrandom.h" #include "retroshare/rsiface.h" #include "pqi/pqibin.h" #include "pqi/pqinotify.h" @@ -1138,27 +1139,113 @@ void p3ChatService::statusChange(const std::list &plist) //********************** Chat Lobby Stuff ***********************// +bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "Handling ChatLobbyMsg " << std::hex << item->msg_id << ", lobby id " << item->lobby_id << ", from peer id " << item->PeerId() << std::endl; + + // send upward for display + + std::map::iterator it(_chat_lobbys.find(item->lobby_id)) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << "Chatlobby for id " << std::hex << item->lobby_id << " has no record. Dropping the msg." << std::dec << std::endl; + return false ; + } + ChatLobbyEntry& lobby(it->second) ; + + // Adds the peer id to the list of friend participants, even if it's not original msg source + + lobby.participating_friends.insert(item->PeerId()) ; + lobby.nick_names.insert(item->nick) ; + + // Checks wether the msg is already recorded or not + + std::map::const_iterator it2(lobby.msg_cache.find(item->msg_id)) ; + + if(it2 != lobby.msg_cache.end()) // found! + { + std::cerr << " Msg already received at time " << it2->second << ". Dropping!" << std::endl ; + return false ; + } + std::cerr << " Msg already not received already. Adding in cache, and forwarding!" << std::endl ; + + lobby.msg_cache[item->msg_id] = time(NULL) ; + + // Forward to allparticipating friends, except this peer. + + for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) + if((*it)!=item->PeerId() && mLinkMgr->isOnline(*it)) + { + RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem(*item) ; // copy almost everything + + item->PeerId(*it) ; + + sendItem(item); + } + return true ; +} + bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lobby_id) { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + std::cerr << "Sending chat lobby message to lobby " << lobby_id << std::endl; std::cerr << "msg:" << std::endl; std::cerr << msg.c_str() << std::endl; + + // get a pointer to the info for that chat lobby. + // + std::map::const_iterator it(_chat_lobbys.find(lobby_id)) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << "Chatlobby for id " << std::hex << lobby_id << " has no record. This is a serious error!!" << std::dec << std::endl; + return false ; + } + const ChatLobbyEntry& lobby(it->second) ; + + RsChatLobbyMsgItem item ; + + // chat lobby stuff + // + do { item.msg_id = RSRandom::random_u64(); } while( lobby.msg_cache.find(item.msg_id) != lobby.msg_cache.end() ) ; + + item.lobby_id = lobby_id ; + item.nick = lobby.nick_name ; + + // chat msg stuff + // + item.chatFlags = RS_CHAT_FLAG_LOBBY; + item.sendTime = time(NULL); + item.recvTime = item.sendTime; + item.message = msg; + + for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) + if(mLinkMgr->isOnline(*it)) + { + RsChatLobbyMsgItem *sitem = new RsChatLobbyMsgItem(item) ; // copies almost everything + + sitem->PeerId(*it) ; + + sendItem(sitem); + } + return true ; } + void p3ChatService::getChatLobbyList(std::list& linfos) { // fill up a dummy list for now. + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + linfos.clear() ; - ChatLobbyInfo info ; - info.lobby_id = 0x38484fe ; - info.display_name = "lobby 1" ; - info.participating_friends.push_back("friend 1") ; - info.participating_friends.push_back("friend 2") ; - info.additional_peers.push_back("peer 1") ; - - linfos.push_back(info) ; + for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it) + linfos.push_back(it->second) ; } void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id) { diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index a1d5f8eea..8e570776c 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -156,6 +156,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; void getChatLobbyList(std::list >&) ; void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; + void setLobbyNickName(const ChatLobbyNickName&) ; + const ChatLobbyNickName& lobbyNickName() const ; protected: @@ -203,6 +205,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor /// Called when a RsChatMsgItem is received. The item may be collapsed with any waiting partial chat item from the same peer. bool checkAndRebuildPartialMessage(RsChatMsgItem*) ; + /// receive and handle chat lobby item + bool recvLobbyChat(RsChatLobbyMsgItem*) ; + RsChatAvatarItem *makeOwnAvatarItem() ; RsChatStatusItem *makeOwnCustomStateStringItem() ; @@ -219,6 +224,17 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor std::string _custom_status_string ; std::map _state_strings ; + + class ChatLobbyEntry: public ChatLobbyInfo + { + public: + std::map msg_cache ; + + static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max. + void cleanCache() ; + }; + + std::map _chat_lobbys ; }; class p3ChatService::StateStringInfo diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 3e8488e60..b441326e2 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -343,8 +343,8 @@ void FriendList::peerTreeWidgetCostumPopupMenu() for(std::list::const_iterator it(cl_infos.begin());it!=cl_infos.end();++it) { - QAction* inviteToLobbyAction = new QAction(QString::fromUtf8((*it).display_name.c_str()), mnu); - inviteToLobbyAction->setData(QString::fromStdString((*it).lobby_id.c_str())); + QAction* inviteToLobbyAction = new QAction(QString::fromUtf8((*it).nick_name.c_str()), mnu); + inviteToLobbyAction->setData(QString::number((*it).lobby_id,16)); connect(inviteToLobbyAction, SIGNAL(triggered()), this, SLOT(inviteToLobby())); mnu->addAction(inviteToLobbyAction); } @@ -1411,7 +1411,7 @@ void FriendList::inviteToLobby() std::string peer_id = getRsId(c) ; // add to group - rsMsgs->invitePeerToLobby(ChatLobbyId(lobby_id), peer_id); + rsMsgs->invitePeerToLobby(ChatLobbyId(QString::fromStdString(lobby_id).toULongLong()), peer_id); } void FriendList::addToGroup() From 723a8ca7f078e187ff6cc50c37e62777a004efb6 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 26 Nov 2011 15:58:52 +0000 Subject: [PATCH 04/17] added serialisation code for lobby msgs, and test code for the new RsItems git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4692 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/serialiser/rsmsgitems.cc | 183 ++++++++++++++++-- libretroshare/src/serialiser/rsmsgitems.h | 37 +++- .../src/tests/serialiser/rsmsgitem_test.cc | 39 +++- 3 files changed, 237 insertions(+), 22 deletions(-) diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 4586146dd..712ac2ba8 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -57,7 +57,38 @@ std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) printRsItemEnd(out, "RsChatMsgItem", indent); return out; } +std::ostream& RsChatLobbyMsgItem::print(std::ostream &out, uint16_t indent) +{ + RsChatMsgItem::print(out,indent) ; + printIndent(out, indent); + out << "Lobby ID: " << std::hex << lobby_id << std::endl; + printIndent(out, indent); + out << "Msg ID: " << std::hex << msg_id << std::dec << std::endl; + printIndent(out, indent); + out << "Nick: " << nick << std::dec << std::endl; + + printRsItemEnd(out, "RsChatLobbyMsgItem", indent); + return out; +} + +std::ostream& RsChatLobbyInviteItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsChatLobbyInviteItem", indent); + uint16_t int_Indent = indent + 2; + + printIndent(out, int_Indent); + out << "peerId: " << PeerId() << std::endl; + + printIndent(out, int_Indent); + out << "lobby id: " << std::hex << lobby_id << std::dec << std::endl; + + printIndent(out, int_Indent); + out << "lobby name: " << lobby_name << std::endl; + + printRsItemEnd(out, "RsChatLobbyInviteItem", indent); + return out; +} std::ostream& RsPrivateChatMsgConfigItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsPrivateChatMsgConfigItem", indent); @@ -137,10 +168,12 @@ RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize) switch(getRsItemSubType(rstype)) { - case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem(data,*pktsize) ; case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_MSG: return new RsChatLobbyMsgItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem(data,*pktsize) ; default: std::cerr << "Unknown packet type in chat!" << std::endl ; return NULL ; @@ -157,6 +190,23 @@ uint32_t RsChatMsgItem::serial_size() return s; } +uint32_t RsChatLobbyMsgItem::serial_size() +{ + uint32_t s = RsChatMsgItem::serial_size() ; // parent + s += 8; // lobby_id + s += 8; // msg_id + s += GetTlvStringSize(nick) ; // nick + + return s; +} +uint32_t RsChatLobbyInviteItem::serial_size() +{ + uint32_t s = 8; /* header */ + s += 8; // lobby_id + s += GetTlvStringSize(lobby_name) ; // lobby name + + return s; +} uint32_t RsPrivateChatMsgConfigItem::serial_size() { uint32_t s = 8; /* header */ @@ -201,7 +251,7 @@ RsChatAvatarItem::~RsChatAvatarItem() /* serialise the data to the buffer */ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) { - uint32_t tlvsize = serial_size() ; + uint32_t tlvsize = RsChatMsgItem::serial_size() ; uint32_t offset = 0; if (pktsize < tlvsize) @@ -228,7 +278,7 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize) #ifdef CHAT_DEBUG std::cerr << "Serialized the following message:" << std::endl; std::cerr << "========== BEGIN MESSAGE =========" << std::endl; - for(int i=0;i +#include "util/rsrandom.h" #include "serialiser/rsmsgitems.h" #include "serialiser/rstlvutil.h" #include "util/utest.h" @@ -41,6 +42,24 @@ RsSerialType* init_item(RsChatMsgItem& cmi) return new RsChatSerialiser(); } +RsSerialType* init_item(RsChatLobbyMsgItem& cmi) +{ + RsSerialType *serial = init_item( *dynamic_cast(&cmi)) ; + + cmi.msg_id = RSRandom::random_u64() ; + cmi.lobby_id = RSRandom::random_u64() ; + cmi.nick = "My nickname" ; + + return serial ; +} + +RsSerialType* init_item(RsChatLobbyInviteItem& cmi) +{ + cmi.lobby_id = RSRandom::random_u64() ; + cmi.lobby_name = "Name of the lobby" ; + + return new RsChatSerialiser(); +} RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi) { @@ -162,8 +181,25 @@ bool operator ==(const RsChatStatusItem& csiLeft, const RsChatStatusItem& csiRig return true; } +bool operator ==(const RsChatLobbyMsgItem& csiLeft, const RsChatLobbyMsgItem& csiRight) +{ + if(! ( (RsChatMsgItem&)csiLeft == (RsChatMsgItem&)csiRight)) + return false ; + if(csiLeft.lobby_id != csiRight.lobby_id) return false ; + if(csiLeft.msg_id != csiRight.msg_id) return false ; + if(csiLeft.nick != csiRight.nick) return false ; + return true; +} + +bool operator ==(const RsChatLobbyInviteItem& csiLeft, const RsChatLobbyInviteItem& csiRight) +{ + if(csiLeft.lobby_id != csiRight.lobby_id) return false ; + if(csiLeft.lobby_name != csiRight.lobby_name) return false ; + + return true; +} bool operator ==(const RsChatAvatarItem& caiLeft, const RsChatAvatarItem& caiRight) { @@ -241,7 +277,8 @@ bool operator ==(const RsMsgParentId& msLeft, const RsMsgParentId& msRight) int main() { test_RsItem(); REPORT("Serialise/Deserialise RsChatMsgItem"); - test_RsItem(); REPORT("Serialise/Deserialise RsPrivateChatMsgConfigItem"); + test_RsItem(); REPORT("Serialise/Deserialise RsChatLobbyMsgItem"); + test_RsItem(); REPORT("Serialise/Deserialise RsChatLobbyInviteItem"); test_RsItem(); REPORT("Serialise/Deserialise RsChatStatusItem"); test_RsItem(); REPORT("Serialise/Deserialise RsChatAvatarItem"); test_RsItem(); REPORT("Serialise/Deserialise RsMsgItem"); From f4e41b32479f774cd6e67d8a5bc078644a74369e Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 26 Nov 2011 21:23:31 +0000 Subject: [PATCH 05/17] added algorithms to handle lobby invites git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4693 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsiface.h | 1 + libretroshare/src/retroshare/rsmsgs.h | 8 ++ libretroshare/src/services/p3chatservice.cc | 126 ++++++++++++++++++++ libretroshare/src/services/p3chatservice.h | 6 + 4 files changed, 141 insertions(+) diff --git a/libretroshare/src/retroshare/rsiface.h b/libretroshare/src/retroshare/rsiface.h index 863b69ccd..475f90ba0 100644 --- a/libretroshare/src/retroshare/rsiface.h +++ b/libretroshare/src/retroshare/rsiface.h @@ -222,6 +222,7 @@ const int NOTIFY_LIST_PRIVATE_INCOMING_CHAT = 14; const int NOTIFY_LIST_PRIVATE_OUTGOING_CHAT = 15; const int NOTIFY_LIST_GROUPLIST = 16; const int NOTIFY_LIST_CHANNELLIST_LOCKED = 17; // use connect with Qt::QueuedConnection +const int NOTIFY_LIST_CHAT_LOBBY_INVITATION = 18; const int NOTIFY_TYPE_SAME = 0x01; const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */ diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 1486897fb..7d5b3c449 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -140,11 +140,19 @@ class ChatInfo std::wstring msg; }; +class ChatLobbyInvite +{ + public: + ChatLobbyId lobby_id ; + std::string peer_id ; + std::string lobby_name ; +}; class ChatLobbyInfo { public: ChatLobbyId lobby_id ; // unique id of the lobby std::string nick_name ; // nickname to use for this lobby + std::string lobby_name ; // name to use for this lobby std::set participating_friends ; // list of direct friend who participate. Used to broadcast sent messages. std::set nick_names ; // list of non direct friend who participate. Used to display only. diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index afa353e1f..94359c2f0 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -1250,5 +1250,131 @@ void p3ChatService::getChatLobbyList(std::list& linfos) void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id) { std::cerr << "Sending invitation to peer " << peer_id << " to lobby "<< lobby_id << std::endl; + + RsChatLobbyInviteItem *item = new RsChatLobbyInviteItem ; + + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it = _chat_lobbys.find(lobby_id) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << " invitation send: canceled. Lobby " << lobby_id << " not found!" << std::endl; + return ; + } + item->lobby_id = lobby_id ; + item->lobby_name = it->second.lobby_name ; + item->PeerId(peer_id) ; + + sendItem(item) ; + + // Adds the invitation into the invitation cache. + // + it->second.invitations_sent[peer_id] = time(NULL) ; +} +void p3ChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item) +{ + std::cerr << "Received invite to lobby from " << item->PeerId() << " to lobby " << item->lobby_id << ", named " << item->lobby_name << std::endl; + + // 1 - store invite in a cache + // + // 1.1 - if the lobby is already setup, add the peer to the communicating peers. + // + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + std::map::const_iterator it = _chat_lobbys.find(item->lobby_id) ; + + if(it != _chat_lobbys.end()) + { + std::cerr << " Lobby already exists. Addign new friend " << item->PeerId() << " to it" << std::endl; + return ; + } + // no, then create a new invitation entry in the cache. + + ChatLobbyInvite invite ; + invite.lobby_id = item->lobby_id ; + invite.peer_id = item->PeerId() ; + invite.lobby_name = item->lobby_name ; + + _lobby_invites_queue[item->lobby_id] = invite ; + } + // 2 - notify the gui to ask the user. + rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT_LOBBY_INVITATION, NOTIFY_TYPE_ADD); +} + + +bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "Accepting chat lobby "<< lobby_id << std::endl; + + std::map::iterator it = _lobby_invites_queue.find(lobby_id) ; + + if(it == _lobby_invites_queue.end()) + { + std::cerr << " (EE) lobby invite not in cache!!" << std::endl; + return false; + } + + if(_chat_lobbys.find(lobby_id) != _chat_lobbys.end()) + { + std::cerr << " (II) Lobby already exists. Weird." << std::endl; + return true ; + } + + std::cerr << " Creating new Lobby entry." << std::endl; + + ChatLobbyEntry entry ; + entry.participating_friends.insert(it->second.peer_id) ; + entry.nick_name = mLinkMgr->getOwnId() ; // to be changed. For debug only!! + entry.lobby_id = lobby_id ; + entry.lobby_name = it->second.lobby_name ; + + _chat_lobbys[lobby_id] = entry ; + + _lobby_invites_queue.erase(it) ; // remove the invite from cache. + return true ; +} +void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "Denying chat lobby invite to "<< lobby_id << std::endl; + std::map::iterator it = _lobby_invites_queue.find(lobby_id) ; + + if(it == _lobby_invites_queue.end()) + { + std::cerr << " (EE) lobby invite not in cache!!" << std::endl; + return ; + } + + _lobby_invites_queue.erase(it) ; +} + +void p3ChatService::createChatLobby(const std::string& lobby_name,const std::list& invited_friends) +{ + std::cerr << "Creating a new Chat lobby !!" << std::endl; + ChatLobbyId lobby_id ; + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + // create a unique id. + // + do { lobby_id = RSRandom::random_u64() ; } while(_chat_lobbys.find(lobby_id) != _chat_lobbys.end()) ; + + std::cerr << " New (unique) ID: " << std::hex << lobby_id << std::dec << std::endl; + + ChatLobbyEntry entry ; + entry.participating_friends.clear() ; + entry.nick_name = mLinkMgr->getOwnId() ; // to be changed. For debug only!! + entry.lobby_id = lobby_id ; + entry.lobby_name = lobby_name ; + + _chat_lobbys[lobby_id] = entry ; + } + + for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) + invitePeerToLobby(lobby_id,*it) ; } diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 8e570776c..cdff133fa 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -207,6 +207,10 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor /// receive and handle chat lobby item bool recvLobbyChat(RsChatLobbyMsgItem*) ; + void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ; + bool acceptLobbyInvite(const ChatLobbyId&) ; + void denyLobbyInvite(const ChatLobbyId&) ; + void createChatLobby(const std::string& lobby_name,const std::list& invited_friends) ; RsChatAvatarItem *makeOwnAvatarItem() ; RsChatStatusItem *makeOwnCustomStateStringItem() ; @@ -229,12 +233,14 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor { public: std::map msg_cache ; + std::map invitations_sent ; static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max. void cleanCache() ; }; std::map _chat_lobbys ; + std::map _lobby_invites_queue ; }; class p3ChatService::StateStringInfo From 6c93253050574a322e9c50ef6b88305282e0d1fc Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 27 Nov 2011 21:04:10 +0000 Subject: [PATCH 06/17] - derived new class of PopupChatDialog to handle chat lobbies git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4694 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 4 + libretroshare/src/rsserver/p3msgs.cc | 12 + libretroshare/src/rsserver/p3msgs.h | 4 + libretroshare/src/services/p3chatservice.cc | 40 + libretroshare/src/services/p3chatservice.h | 6 +- retroshare-gui/src/RetroShare.pro | 3 +- .../src/gui/chat/ChatLobbyDialog.cpp | 73 ++ retroshare-gui/src/gui/chat/ChatLobbyDialog.h | 62 ++ .../src/gui/chat/ChatLobbyDialog.ui | 907 ------------------ .../src/gui/chat/PopupChatDialog.cpp | 8 +- retroshare-gui/src/gui/chat/PopupChatDialog.h | 3 + 11 files changed, 209 insertions(+), 913 deletions(-) create mode 100644 retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp create mode 100644 retroshare-gui/src/gui/chat/ChatLobbyDialog.h delete mode 100644 retroshare-gui/src/gui/chat/ChatLobbyDialog.ui diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 7d5b3c449..4c226c3fd 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -230,6 +230,9 @@ virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ; virtual void getChatLobbyList(std::list& cl_info) = 0; virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; +virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) = 0; +virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) = 0; +virtual bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) = 0 ; /****************************************/ @@ -237,3 +240,4 @@ virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& pe #endif + diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 31cc6ec1e..9db4d4519 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -272,5 +272,17 @@ void p3Msgs::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& p { mChatSrv->invitePeerToLobby(lobby_id,peer_id) ; } +void p3Msgs::unsubscribeChatLobby(const ChatLobbyId& lobby_id) +{ + mChatSrv->unsubscribeChatLobby(lobby_id) ; +} +bool p3Msgs::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) +{ + return mChatSrv->setNickNameForChatLobby(lobby_id,nick) ; +} +bool p3Msgs::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick_name) +{ + return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ; +} diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 57f68c780..3fbc4b27c 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -170,6 +170,10 @@ class p3Msgs: public RsMsgs virtual bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; virtual void getChatLobbyList(std::list >&) ; virtual void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; + 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) ; + private: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 94359c2f0..53d4735b3 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -1378,3 +1378,43 @@ void p3ChatService::createChatLobby(const std::string& lobby_name,const std::lis invitePeerToLobby(lobby_id,*it) ; } +void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + // send a lobby leaving packet. To be implemented. +} +bool p3ChatService::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "getting nickname for chat lobby "<< std::hex << lobby_id << std::dec << std::endl; + std::map::iterator it = _chat_lobbys.find(lobby_id) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << " (EE) lobby does not exist!!" << std::endl; + return false ; + } + + nick = it->second.nick_name ; + return true ; +} + +bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "Changing nickname for chat lobby " << std::hex << lobby_id << std::dec << " to " << nick << std::endl; + std::map::iterator it = _chat_lobbys.find(lobby_id) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << " (EE) lobby does not exist!!" << std::endl; + return false; + } + + it->second.nick_name = nick ; + return true ; +} + diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index cdff133fa..a165abb9d 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -156,9 +156,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; void getChatLobbyList(std::list >&) ; void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; - void setLobbyNickName(const ChatLobbyNickName&) ; - const ChatLobbyNickName& lobbyNickName() const ; - + bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ; + void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; + bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ; protected: /************* from p3Config *******************/ diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index f56cfe4e3..73e38f636 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -406,7 +406,6 @@ FORMS += gui/StartDialog.ui \ gui/channels/ShareKey.ui \ gui/chat/PopupChatWindow.ui \ gui/chat/PopupChatDialog.ui \ - gui/chat/ChatLobbyDialog.ui \ gui/connect/ConfCertDialog.ui \ gui/msgs/MessageComposer.ui \ gui/msgs/MessageWindow.ui\ @@ -529,7 +528,7 @@ SOURCES += main.cpp \ gui/channels/ShareKey.cpp \ gui/chat/PopupChatWindow.cpp \ gui/chat/PopupChatDialog.cpp \ -# gui/chat/ChatLobbyDialog.cpp \ + gui/chat/ChatLobbyDialog.cpp \ gui/chat/HandleRichText.cpp \ gui/chat/ChatStyle.cpp \ gui/connect/ConfCertDialog.cpp \ diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp new file mode 100644 index 000000000..789c9b2f4 --- /dev/null +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -0,0 +1,73 @@ +/**************************************************************** + * + * RetroShare is distributed under the following license: + * + * Copyright (C) 2011, csoler + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util/misc.h" +#include "rshare.h" + +#include +#include + +#include +#include + +#include "ChatLobbyDialog.h" + +/** Default constructor */ +ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, const QString &name, QWidget *parent, Qt::WFlags flags) + : PopupChatDialog(("Chat lobby 0x"+QString::number(lobby_id,16)).toStdString(),name,parent,flags),lobby_id(lid) +{ + // remove the avatar widget. Replace it with a friends list. + + ui.avatarWidget->hide() ; +} + +/** Destructor. */ +ChatLobbyDialog::~ChatLobbyDialog() +{ + // announce leaving of lobby + + rsMsgs->unsubscribeChatLobby(lobby_id) ; +} + +void ChatLobbyDialog::setNickName(const QString& nick) +{ + rsMsgs->setNickNameForChatLobby(lobby_id,nick.toStdString()) ; +} + +bool ChatLobbyDialog::sendPrivateChat(const std::wstring& msg) +{ + return rsMsgs->sendLobbyChat(msg,lobby_id) ; +} + diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h new file mode 100644 index 000000000..054ff2d11 --- /dev/null +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h @@ -0,0 +1,62 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2006, crypton + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + + +#ifndef _CHATLOBBYDIALOG_H +#define _CHATLOBBYDIALOG_H + +#include "ui_PopupChatDialog.h" + +class QAction; +class QTextEdit; +class QTextCharFormat; +class AttachFileItem; +class ChatInfo; + +#include +#include "ChatStyle.h" +#include "gui/style/RSStyle.h" +#include "PopupChatDialog.h" + +class ChatLobbyDialog: public PopupChatDialog +{ + Q_OBJECT + + protected: + /** Default constructor */ + ChatLobbyDialog(const ChatLobbyId& lobbyid, const QString &name, QWidget *parent = 0, Qt::WFlags flags = 0); + + /** Default destructor */ + virtual ~ChatLobbyDialog(); + +// virtual void addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType); +// virtual void sendChat(); + + virtual bool sendPrivateChat(const std::wstring& msg) ; // derived to send chat to the chat lobby + + protected slots: + void setNickName(const QString&) ; + + private: + ChatLobbyId lobby_id ; +}; + +#endif diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.ui b/retroshare-gui/src/gui/chat/ChatLobbyDialog.ui deleted file mode 100644 index e4ef50813..000000000 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.ui +++ /dev/null @@ -1,907 +0,0 @@ - - - PopupChatDialog - - - Qt::NonModal - - - - 0 - 0 - 662 - 499 - - - - MainWindow - - - - - - - 0 - - - - - 0 - - - 1 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 14 - 16777215 - - - - QFrame#frame{border: transparent} - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - - - - 14 - 31 - - - - - 14 - 31 - - - - - - - - 16 - 31 - - - - true - - - - - - - Qt::Vertical - - - - 12 - 335 - - - - - - - - - - - - 132 - 16777215 - - - - border: transparent; - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 3 - - - 9 - - - 3 - - - 9 - - - - - Qt::Vertical - - - - 61 - 141 - - - - - - - - - 116 - 116 - - - - - 116 - 116 - - - - - - - - - - - - - - QFrame#frame_2{border: transparent} - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 2 - - - 3 - - - 3 - - - 3 - - - - - - 0 - 0 - - - - - Arial - 13 - 75 - true - true - - - - TextLabel - - - - - - - - Arial - 9 - - - - TextLabel - - - - - - - - - - QFrame#infoframe{border: 1px solid #DCDC41; -border-radius: 6px; -background: #FFFFD7; -background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, -stop:0 #FFFFD7, stop:1 #FFFFB2);} - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 6 - - - - - - 16 - 16 - - - - - - - :/images/info16.png - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - TextLabel - - - - - - - - 16 - 16 - - - - Qt::NoFocus - - - Close - - - QToolButton -{ - border-image: url(:/images/closenormal.png) -} - -QToolButton:hover -{ -border-image: url(:/images/closehover.png) -} - -QToolButton:pressed { -border-image: url(:/images/closepressed.png) -} - - - - - - true - - - - - - - - - - - 347 - 30 - - - - - 16777215 - 30 - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 1 - - - 6 - - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - QPushButton::menu-indicator { -subcontrol-origin: padding; -subcontrol-position: bottom right; -} - -QPushButton::menu-indicator:pressed, QPushButton::menu-indicator:open { -position: relative; -top: 1px; left: 1px; /* shift the arrow by 2 px */ -} - -QPushButton:hover { -border: 1px solid #CCCCCC; -} - - - - - - - :/images/configure.png:/images/configure.png - - - - 22 - 22 - - - - true - - - - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - Attach a Picture - - - - - - - :/images/add_image24.png:/images/add_image24.png - - - - 24 - 24 - - - - true - - - - - - - - 28 - 28 - - - - Qt::NoFocus - - - Add a File for your Friend - - - - - - - :/images/add-share24.png:/images/add-share24.png - - - - 24 - 24 - - - - true - - - - - - - Qt::Horizontal - - - - 190 - 25 - - - - - - - - Send - - - - - - - - 0 - 0 - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - - - - - 24 - 24 - - - - true - - - - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - Bold - - - - - - - ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup - - - false - - - true - - - - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - Underline - - - - - - - ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup - - - false - - - true - - - - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - Italic - - - - - - - ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup - - - false - - - true - - - - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - Font - - - - - - - ../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup../../../../../../../Dokumente und Einstellungen/Linux/.designer/backup - - - false - - - true - - - - - - - - 28 - 28 - - - - - 28 - 28 - - - - Qt::NoFocus - - - Text Color - - - - - - true - - - - - - - - - - - - - 1 - - - Qt::Vertical - - - 2 - - - - - - - - 0 - 0 - - - - - 0 - 100 - - - - QTextBrowser{border: 1px solid #B8B6B1; -border-radius: 6px; -background: white;} - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;"></p></body></html> - - - true - - - true - - - - - - - - - 0 - - - - - - - - 0 - - - 3 - - - - - - - - 0 - 0 - - - - - 0 - 30 - - - - Qt::CustomContextMenu - - - QTextEdit{border: 1px solid #B8B6B1; -border-radius: 6px; -background: white;} - - - - - - - - 18 - 18 - - - - - 18 - 18 - - - - T - - - Qt::AlignCenter - - - - - - - - - - - - - Bold - - - - - Italic - - - - - Underline - - - - - Strike - - - - - - :/images/edit-clear-history.png:/images/edit-clear-history.png - - - Clear Chat History - - - - - true - - - Disable Emoticons - - - - - Save Chat History - - - Save Chat History - - - - - Clear offline messages - - - - - Browse Message History - - - Browse History - - - - - - :/images/edit-clear-history.png:/images/edit-clear-history.png - - - Delete Chat History - - - Deletes all stored and displayed chat history - - - - - - AvatarWidget - QWidget -
gui/common/AvatarWidget.h
- 1 -
-
- - - - -
diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 73a3f18af..87c95b951 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -684,7 +684,8 @@ void PopupChatDialog::sendChat() std::cout << "PopupChatDialog:sendChat " << std::endl; #endif - if (rsMsgs->sendPrivateChat(dialogId, msg)) { + if (sendPrivateChat(msg)) + { QDateTime currentTime = QDateTime::currentDateTime(); addChatMsg(false, QString::fromUtf8(rsPeers->getPeerName(ownId).c_str()), currentTime, currentTime, QString::fromStdWString(msg), TYPE_NORMAL); } @@ -697,6 +698,11 @@ void PopupChatDialog::sendChat() setFont(); } +bool PopupChatDialog::sendPrivateChat(const std::wstring& msg) +{ + return rsMsgs->sendPrivateChat(dialogId, msg) ; +} + /** Toggles the ToolBox on and off, changes toggle button text */ diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index 16715fb12..be7c36ac5 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -146,6 +146,9 @@ private: RSStyle style; +protected: + virtual bool sendPrivateChat(const std::wstring& msg) ; // can be derived to send chat to e.g. a chat lobby + /** Qt Designer generated object */ Ui::PopupChatDialog ui; }; From b01470c639f36e5ad566ac7857beaa5a426a05e2 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 27 Nov 2011 21:46:49 +0000 Subject: [PATCH 07/17] small corrections. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4695 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 1 + libretroshare/src/rsserver/p3msgs.cc | 5 +++++ libretroshare/src/rsserver/p3msgs.h | 2 +- libretroshare/src/services/p3chatservice.cc | 4 +++- libretroshare/src/services/p3chatservice.h | 2 +- retroshare-gui/src/gui/common/FriendList.cpp | 22 +++++++++++++++++++- retroshare-gui/src/gui/common/FriendList.h | 1 + 7 files changed, 33 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 4c226c3fd..d3cec07ad 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -233,6 +233,7 @@ virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& pe virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) = 0; virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) = 0; virtual bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) = 0 ; +virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends) = 0 ; /****************************************/ diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 9db4d4519..663cbf6aa 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -285,4 +285,9 @@ bool p3Msgs::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& ni return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ; } +ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::list& invited_friends) +{ + return mChatSrv->createChatLobby(lobby_name,invited_friends) ; +} + diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 3fbc4b27c..7f9a33569 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -173,7 +173,7 @@ class p3Msgs: public RsMsgs 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 ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends) ; private: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 53d4735b3..d6429c2f4 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -1352,7 +1352,7 @@ void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id) _lobby_invites_queue.erase(it) ; } -void p3ChatService::createChatLobby(const std::string& lobby_name,const std::list& invited_friends) +ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::list& invited_friends) { std::cerr << "Creating a new Chat lobby !!" << std::endl; ChatLobbyId lobby_id ; @@ -1376,6 +1376,8 @@ void p3ChatService::createChatLobby(const std::string& lobby_name,const std::lis for(std::list::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it) invitePeerToLobby(lobby_id,*it) ; + + return lobby_id ; } void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id) diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index a165abb9d..7df4fd905 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -159,6 +159,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ; void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ; + ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends) ; protected: /************* from p3Config *******************/ @@ -210,7 +211,6 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ; bool acceptLobbyInvite(const ChatLobbyId&) ; void denyLobbyInvite(const ChatLobbyId&) ; - void createChatLobby(const std::string& lobby_name,const std::list& invited_friends) ; RsChatAvatarItem *makeOwnAvatarItem() ; RsChatStatusItem *makeOwnCustomStateStringItem() ; diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index b441326e2..5ecd786f0 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -349,7 +349,7 @@ void FriendList::peerTreeWidgetCostumPopupMenu() mnu->addAction(inviteToLobbyAction); } - mnu->addAction(QIcon(IMAGE_CHAT),tr("create new")) ; + mnu->addAction(QIcon(IMAGE_CHAT),tr("create new"),this,SLOT(createchatlobby())) ; contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Friend"), this, SLOT(msgfriend())); @@ -1414,6 +1414,26 @@ void FriendList::inviteToLobby() rsMsgs->invitePeerToLobby(ChatLobbyId(QString::fromStdString(lobby_id).toULongLong()), peer_id); } +void FriendList::createchatlobby() +{ + QTreeWidgetItem *c = getCurrentPeer(); + + if (c == NULL) + return; + + std::list friend_list ; + + std::string peer_id = getRsId(c) ; + friend_list.push_back(peer_id) ; + + std::string lobby_name = "New lobby (Plz add the code to select this name at creation time)" ; + + // add to group + ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, friend_list); + + std::cerr << "gui: Created chat lobby " << std::hex << id << std::endl ; +} + void FriendList::addToGroup() { QTreeWidgetItem *c = getCurrentPeer(); diff --git a/retroshare-gui/src/gui/common/FriendList.h b/retroshare-gui/src/gui/common/FriendList.h index 51396b139..14e72046b 100644 --- a/retroshare-gui/src/gui/common/FriendList.h +++ b/retroshare-gui/src/gui/common/FriendList.h @@ -124,6 +124,7 @@ private slots: void removeGroup(); void inviteToLobby(); + void createchatlobby(); }; #endif // FRIENDLIST_H From 46f1e2b5625cc03603594cb7d0571a7508234f75 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 28 Nov 2011 22:36:13 +0000 Subject: [PATCH 08/17] added invitation system git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4696 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 3 +++ libretroshare/src/rsserver/p3msgs.cc | 13 ++++++++++ libretroshare/src/rsserver/p3msgs.h | 3 +++ libretroshare/src/services/p3chatservice.cc | 27 +++++++++++++++++++- libretroshare/src/services/p3chatservice.h | 5 ++-- retroshare-gui/src/gui/FriendsDialog.cpp | 16 ++++++++++++ retroshare-gui/src/gui/FriendsDialog.h | 1 + retroshare-gui/src/gui/common/FriendList.cpp | 11 +++++--- retroshare-gui/src/gui/notifyqt.cpp | 6 +++++ retroshare-gui/src/gui/notifyqt.h | 1 + retroshare-gui/src/main.cpp | 1 + 11 files changed, 81 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index d3cec07ad..5e4fcd678 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -230,6 +230,9 @@ virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ; virtual void getChatLobbyList(std::list& cl_info) = 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 ; +virtual void getPendingChatLobbyInvites(std::list& invites) = 0; virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) = 0; virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) = 0; virtual bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 663cbf6aa..aafe22dc9 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -290,4 +290,17 @@ ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::lis return mChatSrv->createChatLobby(lobby_name,invited_friends) ; } +bool p3Msgs::acceptLobbyInvite(const ChatLobbyId& id) +{ + return mChatSrv->acceptLobbyInvite(id) ; +} +void p3Msgs::denyLobbyInvite(const ChatLobbyId& id) +{ + mChatSrv->denyLobbyInvite(id) ; +} +void p3Msgs::getPendingChatLobbyInvites(std::list& invites) +{ + mChatSrv->getPendingChatLobbyInvites(invites) ; +} + diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 7f9a33569..f1dc1338e 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -170,6 +170,9 @@ class p3Msgs: public RsMsgs virtual bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; 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) ; diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index d6429c2f4..2bc1c5bd8 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -496,6 +496,19 @@ void p3ChatService::receiveChatQueue() delete item ; continue ; } + + RsChatLobbyInviteItem *cl = dynamic_cast(item) ; + + if(cl != NULL) + { + handleRecvLobbyInvite(cl) ; + delete item ; + continue ; + } + + std::cerr << "Received ChatItem of unhandled type: " << std::endl; + item->print(std::cerr,0) ; + delete item ; } if (publicChanged) { @@ -1249,7 +1262,7 @@ void p3ChatService::getChatLobbyList(std::list& linfos) } void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id) { - std::cerr << "Sending invitation to peer " << peer_id << " to lobby "<< lobby_id << std::endl; + std::cerr << "Sending invitation to peer " << peer_id << " to lobby "<< std::hex << lobby_id << std::dec << std::endl; RsChatLobbyInviteItem *item = new RsChatLobbyInviteItem ; @@ -1302,6 +1315,15 @@ void p3ChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item) rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT_LOBBY_INVITATION, NOTIFY_TYPE_ADD); } +void p3ChatService::getPendingChatLobbyInvites(std::list& invites) +{ + invites.clear() ; + + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + for(std::map::const_iterator it(_lobby_invites_queue.begin());it!=_lobby_invites_queue.end();++it) + invites.push_back(it->second) ; +} bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) { @@ -1334,6 +1356,9 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) _chat_lobbys[lobby_id] = entry ; _lobby_invites_queue.erase(it) ; // remove the invite from cache. + + // we should also send a message to the lobby to tell we're here. + return true ; } void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id) diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 7df4fd905..893d34526 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -155,6 +155,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; void getChatLobbyList(std::list >&) ; + bool acceptLobbyInvite(const ChatLobbyId& id) ; + void denyLobbyInvite(const ChatLobbyId& id) ; + void getPendingChatLobbyInvites(std::list& invites) ; void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ; void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; @@ -209,8 +212,6 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor /// receive and handle chat lobby item bool recvLobbyChat(RsChatLobbyMsgItem*) ; void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ; - bool acceptLobbyInvite(const ChatLobbyId&) ; - void denyLobbyInvite(const ChatLobbyId&) ; RsChatAvatarItem *makeOwnAvatarItem() ; RsChatStatusItem *makeOwnCustomStateStringItem() ; diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index bf6091adb..88da9c5ab 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -308,6 +308,22 @@ void FriendsDialog::updateStatusString(const QString& peer_id, const QString& st QTimer::singleShot(5000,this,SLOT(resetStatusBar())) ; } +void FriendsDialog::readChatLobbyInvites() +{ + std::list invites ; + rsMsgs->getPendingChatLobbyInvites(invites) ; + + for(std::list::const_iterator it(invites.begin());it!=invites.end();++it) + if(QMessageBox::Ok == QMessageBox::question(NULL,tr("Invitation to chat lobby"),QString::fromStdString((*it).peer_id)+QString(" invites you to chat lobby named ")+QString::fromUtf8((*it).lobby_name.c_str()),QMessageBox::Ok,QMessageBox::Ignore)) + { + std::cerr << "Accepting invite to lobby " << (*it).lobby_name << std::endl; + + rsMsgs->acceptLobbyInvite( (*it).lobby_id ) ; + } + else + rsMsgs->denyLobbyInvite( (*it).lobby_id ) ; +} + void FriendsDialog::updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat) { if(is_private_chat) diff --git a/retroshare-gui/src/gui/FriendsDialog.h b/retroshare-gui/src/gui/FriendsDialog.h index e63ef5db9..4d8750d8b 100644 --- a/retroshare-gui/src/gui/FriendsDialog.h +++ b/retroshare-gui/src/gui/FriendsDialog.h @@ -58,6 +58,7 @@ public slots: void insertChat(); void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText)); void resetStatusBar() ; + void readChatLobbyInvites() ; void fileHashingFinished(AttachFileItem* file); diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 5ecd786f0..23863cd0b 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -343,8 +343,10 @@ void FriendList::peerTreeWidgetCostumPopupMenu() for(std::list::const_iterator it(cl_infos.begin());it!=cl_infos.end();++it) { - QAction* inviteToLobbyAction = new QAction(QString::fromUtf8((*it).nick_name.c_str()), mnu); - inviteToLobbyAction->setData(QString::number((*it).lobby_id,16)); + std::cerr << "Adding meny entry with lobby id " << std::hex << (*it).lobby_id << std::dec << std::endl; + + QAction* inviteToLobbyAction = new QAction(QString::fromUtf8((*it).lobby_name.c_str()), mnu); + inviteToLobbyAction->setData(QString::number((*it).lobby_id)); connect(inviteToLobbyAction, SIGNAL(triggered()), this, SLOT(inviteToLobby())); mnu->addAction(inviteToLobbyAction); } @@ -1426,7 +1428,10 @@ void FriendList::createchatlobby() std::string peer_id = getRsId(c) ; friend_list.push_back(peer_id) ; - std::string lobby_name = "New lobby (Plz add the code to select this name at creation time)" ; + static int number=0 ; + + ++number ; + std::string lobby_name = "my cool lobby #"+QString::number(number).toStdString()+" (Plz add proper code to dynamically set this name in FriendList::createChatLobby())" ; // add to group ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, friend_list); diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 35bd51ff8..4b46f0ae7 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -307,6 +307,12 @@ void NotifyQt::notifyListChange(int list, int type) #endif emit filesPostModChanged(true) ; /* Local */ break; + case NOTIFY_LIST_CHAT_LOBBY_INVITATION: +#ifdef NOTIFY_DEBUG + std::cerr << "received files changed" << std::endl ; +#endif + emit chatLobbyInviteReceived() ; /* Local */ + break; case NOTIFY_LIST_DIRLIST_FRIENDS: #ifdef NOTIFY_DEBUG std::cerr << "received files changed" << std::endl ; diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 10d35f548..fe094b53f 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -92,6 +92,7 @@ class NotifyQt: public QObject, public NotifyBase void downloadCompleteCountChanged(int /* count */); void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status); void historyChanged(uint msgId, int type); + void chatLobbyInviteReceived() ; /* Notify from GUI */ void chatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType); diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 2f1073667..5a8ec44e3 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -281,6 +281,7 @@ int main(int argc, char *argv[]) QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ; QObject::connect(notify,SIGNAL(messagesTagsChanged()) ,w->messagesDialog ,SLOT(messagesTagsChanged() )) ; QObject::connect(notify,SIGNAL(messagesChanged()) ,w ,SLOT(updateMessages() )) ; + QObject::connect(notify,SIGNAL(chatLobbyInviteReceived()) ,w->friendsDialog ,SLOT(readChatLobbyInvites() )) ; QObject::connect(notify,SIGNAL(forumsChanged()) ,w ,SLOT(updateForums() ), Qt::QueuedConnection); QObject::connect(notify,SIGNAL(channelsChanged(int)) ,w ,SLOT(updateChannels(int) ), Qt::QueuedConnection); QObject::connect(notify,SIGNAL(downloadCompleteCountChanged(int)) ,w ,SLOT(updateTransfers(int) )); From a0e3522273d4d68cdcb323db6a8a239ffbb3a3b8 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 4 Dec 2011 14:31:48 +0000 Subject: [PATCH 09/17] debugged basic chat lobby communication git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4708 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 3 +- libretroshare/src/rsserver/p3msgs.cc | 5 +- libretroshare/src/rsserver/p3msgs.h | 3 +- libretroshare/src/serialiser/rsmsgitems.h | 3 + libretroshare/src/services/p3chatservice.cc | 203 ++++++++++++++---- libretroshare/src/services/p3chatservice.h | 8 +- .../src/gui/chat/ChatLobbyDialog.cpp | 11 +- retroshare-gui/src/gui/chat/ChatLobbyDialog.h | 8 +- .../src/gui/chat/PopupChatDialog.cpp | 22 +- retroshare-gui/src/gui/chat/PopupChatDialog.h | 3 +- 10 files changed, 217 insertions(+), 52 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 5e4fcd678..75b8764d9 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -134,6 +134,7 @@ class ChatInfo { public: std::string rsid; + std::string peer_nickname; unsigned int chatflags; uint32_t sendTime; uint32_t recvTime; @@ -206,7 +207,6 @@ virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0; /****************************************/ /* Chat */ virtual bool sendPublicChat(const std::wstring& msg) = 0; -virtual bool sendLobbyChat(const std::wstring& msg,const ChatLobbyId& lid) = 0; virtual bool sendPrivateChat(const std::string& id, const std::wstring& msg) = 0; virtual int getPublicChatQueueCount() = 0; virtual bool getPublicChatQueue(std::list &chats) = 0; @@ -228,6 +228,7 @@ 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 isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) = 0; virtual void getChatLobbyList(std::list& cl_info) = 0; virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; virtual bool acceptLobbyInvite(const ChatLobbyId& id) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index aafe22dc9..66a28408a 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -260,10 +260,11 @@ void p3Msgs::setCustomStateString(const std::string& state_string) mChatSrv->setOwnCustomStateString(state_string) ; } -bool p3Msgs::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& id) +bool p3Msgs::isLobbyId(const std::string& peer_id,ChatLobbyId& id) { - return mChatSrv->sendLobbyChat(msg,id) ; + return mChatSrv->isLobbyId(peer_id,id) ; } + void p3Msgs::getChatLobbyList(std::list& linfos) { mChatSrv->getChatLobbyList(linfos) ; diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index f1dc1338e..13601f600 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -167,7 +167,8 @@ class p3Msgs: public RsMsgs /****************************************/ - virtual bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; + + 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) ; diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 8c8447eb3..a9c9413a4 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -97,6 +97,8 @@ class RsChatMsgItem: public RsChatItem virtual void clear() {} virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual RsChatMsgItem *duplicate() const { return new RsChatMsgItem(*this) ; } + 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 @@ -116,6 +118,7 @@ class RsChatLobbyMsgItem: public RsChatMsgItem virtual ~RsChatLobbyMsgItem() {} virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + virtual RsChatMsgItem *duplicate() const { return new RsChatLobbyMsgItem(*this) ; } 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 diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 2bc1c5bd8..1b4716e17 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -208,7 +208,7 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg) { // chop off the first 15000 wchars - RsChatMsgItem *item = new RsChatMsgItem(*msg) ; + RsChatMsgItem *item = msg->duplicate() ; item->message = item->message.substr(0,MAX_STRING_SIZE) ; msg->message = msg->message.substr(MAX_STRING_SIZE,msg->message.size()-MAX_STRING_SIZE) ; @@ -216,7 +216,7 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg) // Clear out any one time flags that should not be copied into multiple objects. This is // a precaution, in case the receivign peer does not yet handle split messages transparently. // - item->chatFlags &= (RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_PUBLIC) ; + item->chatFlags &= (RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_PUBLIC | RS_CHAT_FLAG_LOBBY) ; // Indicate that the message is to be continued. // @@ -226,8 +226,63 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg) sendItem(msg) ; } +void p3ChatService::locked_printDebugInfo() const +{ + std::cerr << "Recorded lobbies: " << std::endl; + + for( std::map::const_iterator it(_chat_lobbys.begin()) ;it!=_chat_lobbys.end();++it) + { + std::cerr << " Lobby id\t: " << it->first << std::endl; + std::cerr << " Lobby name\t: " << it->second.lobby_name << std::endl; + std::cerr << " nick name\t: " << it->second.nick_name << std::endl; + std::cerr << " Lobby peer id\t: " << it->second.virtual_peer_id << std::endl; + std::cerr << " Participating friends: " << std::endl; + + for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + std::cerr << " " << *it2 << std::endl; + + std::cerr << " Participating nick names: " << std::endl; + + for(std::set::const_iterator it2(it->second.nick_names.begin());it2!=it->second.nick_names.end();++it2) + std::cerr << " " << *it2 << std::endl; + + } + + std::cerr << "Recorded lobby names: " << std::endl; + + for( std::map::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it) + std::cerr << " \"" << it->first << "\" id = " << it->second << std::endl; +} + +bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + locked_printDebugInfo() ; // debug + + for( std::map::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it) + std::cerr << "Testing \"" << id << "\" against \"" << it->first << "\" result=" << (it->first == id) << std::endl; + + std::map::const_iterator it(_lobby_ids.find(id)) ; + + if(it != _lobby_ids.end()) + { + lobby_id = it->second ; + return true ; + } + else + return false ; +} + bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstring &msg) { + // look into ID. Is it a peer, or a chat lobby? + + ChatLobbyId lobby_id ; + + if(isLobbyId(id,lobby_id)) + return sendLobbyChat(msg,lobby_id) ; + // make chat item.... #ifdef CHAT_DEBUG std::cerr << "p3ChatService::sendPrivateChat()"; @@ -364,6 +419,42 @@ bool p3ChatService::checkAndRebuildPartialMessage(RsChatMsgItem *ci) } } +void p3ChatService::checkAndRedirectMsgToLobby(RsChatMsgItem *ci) +{ + std::cerr << "Checking msg..." << std::endl; + + if(!(ci->chatFlags & RS_CHAT_FLAG_LOBBY)) + { + std::cerr << " normal chat!" << std::endl; + return ; + } + else + std::cerr << " lobby chat!" << std::endl; + + RsChatLobbyMsgItem *lobbyItem = dynamic_cast(ci) ; + + if(ci == NULL) + std::cerr << "Warning: chat message has lobby flag, but is not a chat lobby item!!" << std::endl; + + std::string vpeer_id ; + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::map::const_iterator it = _chat_lobbys.find(lobbyItem->lobby_id) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << "(EE) p3ChatService::checkAndRedirectMsgToLobby(): RsItem is a lobby item, but the id is not known!!" << std::endl; + return ; + } + vpeer_id = it->second.virtual_peer_id ; + } + + recvLobbyChat(lobbyItem) ; // needs the proper peerId + ci->PeerId(vpeer_id) ; // thenthe peer Id is changed to the lobby id (virtual peer id). +} + + void p3ChatService::receiveChatQueue() { @@ -382,6 +473,10 @@ void p3ChatService::receiveChatQueue() if(ci != NULL) // real chat message { + // check if it's a lobby msg, in which case we replace the peer id by the lobby's virtual peer id. + // + checkAndRedirectMsgToLobby(ci) ; + #ifdef CHAT_DEBUG std::cerr << "p3ChatService::receiveChatQueue() Item:"; std::cerr << std::endl; @@ -434,9 +529,11 @@ void p3ChatService::receiveChatQueue() ci->recvTime = now; if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) { + std::cerr << "Adding msg 0x" << std::hex << (void*)ci << std::dec << " to private chat incoming list." << std::endl; privateChanged = true; privateIncomingList.push_back(ci); // don't delete the item !! } else { + std::cerr << "Adding msg 0x" << std::hex << (void*)ci << std::dec << " to public chat incoming list." << std::endl; publicChanged = true; publicList.push_back(ci); // don't delete the item !! @@ -447,6 +544,7 @@ void p3ChatService::receiveChatQueue() } } /* UNLOCK */ } + continue ; } RsChatStatusItem *cs = dynamic_cast(item) ; @@ -508,7 +606,6 @@ void p3ChatService::receiveChatQueue() std::cerr << "Received ChatItem of unhandled type: " << std::endl; item->print(std::cerr,0) ; - delete item ; } if (publicChanged) { @@ -695,16 +792,15 @@ void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i) i.recvTime = c->recvTime; i.msg = c->message; + RsChatLobbyMsgItem *lobbyItem = dynamic_cast(c) ; + + if(lobbyItem != NULL) + i.peer_nickname = lobbyItem->nick; + if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) - { i.chatflags |= RS_CHAT_PRIVATE; - //std::cerr << "RsServer::initRsChatInfo() Chat Private!!!"; - } else - { i.chatflags |= RS_CHAT_PUBLIC; - //std::cerr << "RsServer::initRsChatInfo() Chat Public!!!"; - } } void p3ChatService::setOwnCustomStateString(const std::string& s) @@ -1231,7 +1327,7 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo // chat msg stuff // - item.chatFlags = RS_CHAT_FLAG_LOBBY; + item.chatFlags = RS_CHAT_FLAG_LOBBY | RS_CHAT_FLAG_PRIVATE; item.sendTime = time(NULL); item.recvTime = item.sendTime; item.message = msg; @@ -1327,40 +1423,69 @@ void p3ChatService::getPendingChatLobbyInvites(std::list& invit bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) { - RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - - std::cerr << "Accepting chat lobby "<< lobby_id << std::endl; - - std::map::iterator it = _lobby_invites_queue.find(lobby_id) ; - - if(it == _lobby_invites_queue.end()) { - std::cerr << " (EE) lobby invite not in cache!!" << std::endl; - return false; + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "Accepting chat lobby "<< lobby_id << std::endl; + + std::map::iterator it = _lobby_invites_queue.find(lobby_id) ; + + if(it == _lobby_invites_queue.end()) + { + std::cerr << " (EE) lobby invite not in cache!!" << std::endl; + return false; + } + + if(_chat_lobbys.find(lobby_id) != _chat_lobbys.end()) + { + std::cerr << " (II) Lobby already exists. Weird." << std::endl; + return true ; + } + + std::cerr << " Creating new Lobby entry." << std::endl; + + ChatLobbyEntry entry ; + entry.participating_friends.insert(it->second.peer_id) ; + entry.nick_name = mLinkMgr->getOwnId() ; // to be changed. For debug only!! + entry.lobby_id = lobby_id ; + entry.lobby_name = it->second.lobby_name ; + entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ; + + _lobby_ids[entry.virtual_peer_id] = lobby_id ; + _chat_lobbys[lobby_id] = entry ; + + _lobby_invites_queue.erase(it) ; // remove the invite from cache. + + // we should also send a message to the lobby to tell we're here. + + std::cerr << " Pushing new msg item to incoming msgs." << std::endl; + + RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem; + item->lobby_id = entry.lobby_id ; + item->msg_id = 0 ; + item->nick = "" ; + item->message = std::wstring(L"Welcome to chat lobby") ; + item->PeerId(entry.virtual_peer_id) ; + item->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_LOBBY ; + + privateIncomingList.push_back(item) ; } + std::cerr << " Notifying of new recvd msg." << std::endl ; - if(_chat_lobbys.find(lobby_id) != _chat_lobbys.end()) - { - std::cerr << " (II) Lobby already exists. Weird." << std::endl; - return true ; - } + rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD); - std::cerr << " Creating new Lobby entry." << std::endl; - - ChatLobbyEntry entry ; - entry.participating_friends.insert(it->second.peer_id) ; - entry.nick_name = mLinkMgr->getOwnId() ; // to be changed. For debug only!! - entry.lobby_id = lobby_id ; - entry.lobby_name = it->second.lobby_name ; - - _chat_lobbys[lobby_id] = entry ; - - _lobby_invites_queue.erase(it) ; // remove the invite from cache. - - // we should also send a message to the lobby to tell we're here. - return true ; } + +std::string p3ChatService::makeVirtualPeerId(ChatLobbyId lobby_id) +{ + std::ostringstream os ; + os << "Chat Lobby 0x" << std::hex << lobby_id << std::dec ; + + return os.str() ; +} + + void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1395,7 +1520,9 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s entry.nick_name = mLinkMgr->getOwnId() ; // to be changed. For debug only!! entry.lobby_id = lobby_id ; entry.lobby_name = lobby_name ; + entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ; + _lobby_ids[entry.virtual_peer_id] = lobby_id ; _chat_lobbys[lobby_id] = entry ; } diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 893d34526..ab65c5a8a 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -153,7 +153,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor */ bool clearPrivateChatQueue(bool incoming, const std::string &id); - bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; + bool isLobbyId(const std::string&, ChatLobbyId&) ; void getChatLobbyList(std::list >&) ; bool acceptLobbyInvite(const ChatLobbyId& id) ; void denyLobbyInvite(const ChatLobbyId& id) ; @@ -211,7 +211,11 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor /// receive and handle chat lobby item bool recvLobbyChat(RsChatLobbyMsgItem*) ; + bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ; + void checkAndRedirectMsgToLobby(RsChatMsgItem*) ; + static std::string makeVirtualPeerId(ChatLobbyId) ; + void locked_printDebugInfo() const ; RsChatAvatarItem *makeOwnAvatarItem() ; RsChatStatusItem *makeOwnCustomStateStringItem() ; @@ -235,6 +239,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor public: std::map msg_cache ; std::map invitations_sent ; + std::string virtual_peer_id ; static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max. void cleanCache() ; @@ -242,6 +247,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor std::map _chat_lobbys ; std::map _lobby_invites_queue ; + std::map _lobby_ids ; }; class p3ChatService::StateStringInfo diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 789c9b2f4..a73fe71e9 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -38,6 +38,7 @@ #include #include +#include #include #include @@ -45,12 +46,13 @@ #include "ChatLobbyDialog.h" /** Default constructor */ -ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, const QString &name, QWidget *parent, Qt::WFlags flags) - : PopupChatDialog(("Chat lobby 0x"+QString::number(lobby_id,16)).toStdString(),name,parent,flags),lobby_id(lid) +ChatLobbyDialog::ChatLobbyDialog(const std::string& dialog_id,const ChatLobbyId& lid, const QString &name, QWidget *parent, Qt::WFlags flags) + : PopupChatDialog(dialog_id,name,parent,flags),lobby_id(lid) { // remove the avatar widget. Replace it with a friends list. ui.avatarWidget->hide() ; + PopupChatDialog::updateStatus(QString::fromStdString(getPeerId()),RS_STATUS_ONLINE) ; } /** Destructor. */ @@ -66,8 +68,9 @@ void ChatLobbyDialog::setNickName(const QString& nick) rsMsgs->setNickNameForChatLobby(lobby_id,nick.toStdString()) ; } -bool ChatLobbyDialog::sendPrivateChat(const std::wstring& msg) +void ChatLobbyDialog::updateStatus(const QString &peer_id, int status) { - return rsMsgs->sendLobbyChat(msg,lobby_id) ; + // For now. We need something more efficient to tell when the lobby is disconnected. + // } diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h index 054ff2d11..65c220360 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h @@ -42,7 +42,7 @@ class ChatLobbyDialog: public PopupChatDialog protected: /** Default constructor */ - ChatLobbyDialog(const ChatLobbyId& lobbyid, const QString &name, QWidget *parent = 0, Qt::WFlags flags = 0); + ChatLobbyDialog(const std::string& id,const ChatLobbyId& lid, const QString &name, QWidget *parent = 0, Qt::WFlags flags = 0); /** Default destructor */ virtual ~ChatLobbyDialog(); @@ -50,7 +50,11 @@ class ChatLobbyDialog: public PopupChatDialog // virtual void addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType); // virtual void sendChat(); - virtual bool sendPrivateChat(const std::wstring& msg) ; // derived to send chat to the chat lobby + friend class PopupChatDialog ; + + // The following methods are differentfrom those of the parent: + // + virtual void updateStatus(const QString &peer_id, int status) ; // needs grouped status. Not yet implemented. protected slots: void setNickName(const QString&) ; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 87c95b951..4f859a2ea 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -34,6 +34,7 @@ #include #include "PopupChatDialog.h" +#include "ChatLobbyDialog.h" #include "PopupChatWindow.h" #include "gui/RetroShareLink.h" #include "util/misc.h" @@ -129,7 +130,7 @@ PopupChatDialog::PopupChatDialog(const std::string &id, const QString &name, QWi connect(ui.actionSave_Chat_History, SIGNAL(triggered()), this, SLOT(fileSaveAs())); connect(ui.actionClearOfflineMessages, SIGNAL(triggered()), this, SLOT(clearOfflineMessages())); - connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int))); + connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus_slot(const QString&, int))); connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&))); connect(ui.chattextEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint))); @@ -263,13 +264,25 @@ void PopupChatDialog::processSettings(bool bLoad) { /* see if it exists already */ PopupChatDialog *popupchatdialog = getExistingInstance(id); + if (popupchatdialog == NULL) { if (chatflags & RS_CHAT_OPEN) { RsPeerDetails sslDetails; - if (rsPeers->getPeerDetails(id, sslDetails)) { + ChatLobbyId lobby_id ; + + if (rsPeers->getPeerDetails(id, sslDetails)) + { popupchatdialog = new PopupChatDialog(id, PeerDefs::nameWithLocation(sslDetails)); chatDialogs[id] = popupchatdialog; + PopupChatWindow *window = PopupChatWindow::getWindow(false); + window->addDialog(popupchatdialog); + } + else if (rsMsgs->isLobbyId(id, lobby_id)) + { + popupchatdialog = new ChatLobbyDialog(id,lobby_id,QString::fromStdString(id)); + chatDialogs[id] = popupchatdialog; + PopupChatWindow *window = PopupChatWindow::getWindow(false); window->addDialog(popupchatdialog); } @@ -1055,6 +1068,11 @@ void PopupChatDialog::clearOfflineMessages() manualDelete = false; } +void PopupChatDialog::updateStatus_slot(const QString &peer_id, int status) +{ + updateStatus(peer_id,status) ; +} + void PopupChatDialog::updateStatus(const QString &peer_id, int status) { std::string stdPeerId = peer_id.toStdString(); diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index be7c36ac5..c383d6b75 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -59,9 +59,10 @@ public: void activate(); bool setStyle(); const RSStyle &getStyle(); + virtual void updateStatus(const QString &peer_id, int status); public slots: - void updateStatus(const QString &peer_id, int status); + void updateStatus_slot(const QString &peer_id, int status); protected: /** Default constructor */ From 71a079b55f71692a1bf5366795c3f904aaee6cc7 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 4 Dec 2011 22:03:54 +0000 Subject: [PATCH 10/17] added chat lobby creation window git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4709 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 1 + libretroshare/src/rsserver/p3msgs.cc | 4 + libretroshare/src/rsserver/p3msgs.h | 1 + libretroshare/src/services/p3chatservice.cc | 16 +- libretroshare/src/services/p3chatservice.h | 1 + retroshare-gui/src/RetroShare.pro | 3 + .../src/gui/chat/CreateLobbyDialog.cpp | 193 ++++++++++++ .../src/gui/chat/CreateLobbyDialog.h | 41 +++ .../src/gui/chat/CreateLobbyDialog.ui | 289 ++++++++++++++++++ retroshare-gui/src/gui/common/FriendList.cpp | 15 +- 10 files changed, 552 insertions(+), 12 deletions(-) create mode 100644 retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp create mode 100644 retroshare-gui/src/gui/chat/CreateLobbyDialog.h create mode 100644 retroshare-gui/src/gui/chat/CreateLobbyDialog.ui diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 75b8764d9..cff132073 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -229,6 +229,7 @@ virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ; virtual void getOwnAvatarData(unsigned char *& data,int& size) = 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 invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; virtual bool acceptLobbyInvite(const ChatLobbyId& id) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 66a28408a..7a66a7b6a 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -260,6 +260,10 @@ void p3Msgs::setCustomStateString(const std::string& state_string) mChatSrv->setOwnCustomStateString(state_string) ; } +bool p3Msgs::getVirtualPeerId(const ChatLobbyId& id,std::string& peer_id) +{ + return mChatSrv->getVirtualPeerId(id,peer_id) ; +} bool p3Msgs::isLobbyId(const std::string& peer_id,ChatLobbyId& id) { return mChatSrv->isLobbyId(peer_id,id) ; diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 13601f600..25fd968a0 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -168,6 +168,7 @@ 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&) ; diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 1b4716e17..1570e4be4 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -226,6 +226,19 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg) sendItem(msg) ; } +bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::map::const_iterator it(_chat_lobbys.find(id)) ; + + if(it == _chat_lobbys.end()) + return false ; + + vpid = it->second.virtual_peer_id ; + return true ; +} + void p3ChatService::locked_printDebugInfo() const { std::cerr << "Recorded lobbies: " << std::endl; @@ -260,9 +273,6 @@ bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id) locked_printDebugInfo() ; // debug - for( std::map::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it) - std::cerr << "Testing \"" << id << "\" against \"" << it->first << "\" result=" << (it->first == id) << std::endl; - std::map::const_iterator it(_lobby_ids.find(id)) ; if(it != _lobby_ids.end()) diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index ab65c5a8a..1007fc114 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -153,6 +153,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor */ bool clearPrivateChatQueue(bool incoming, const std::string &id); + bool getVirtualPeerId(const ChatLobbyId&, std::string& virtual_peer_id) ; bool isLobbyId(const std::string&, ChatLobbyId&) ; void getChatLobbyList(std::list >&) ; bool acceptLobbyInvite(const ChatLobbyId& id) ; diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 73e38f636..92408cc08 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -271,6 +271,7 @@ HEADERS += rshare.h \ gui/chat/PopupChatWindow.h \ gui/chat/PopupChatDialog.h \ gui/chat/ChatLobbyDialog.h \ + gui/chat/CreateLobbyDialog.h \ gui/chat/HandleRichText.h \ gui/chat/ChatStyle.h \ gui/channels/CreateChannel.h \ @@ -406,6 +407,7 @@ FORMS += gui/StartDialog.ui \ gui/channels/ShareKey.ui \ gui/chat/PopupChatWindow.ui \ gui/chat/PopupChatDialog.ui \ + gui/chat/CreateLobbyDialog.ui \ gui/connect/ConfCertDialog.ui \ gui/msgs/MessageComposer.ui \ gui/msgs/MessageWindow.ui\ @@ -529,6 +531,7 @@ SOURCES += main.cpp \ gui/chat/PopupChatWindow.cpp \ gui/chat/PopupChatDialog.cpp \ gui/chat/ChatLobbyDialog.cpp \ + gui/chat/CreateLobbyDialog.cpp \ gui/chat/HandleRichText.cpp \ gui/chat/ChatStyle.cpp \ gui/connect/ConfCertDialog.cpp \ diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp new file mode 100644 index 000000000..f0f750020 --- /dev/null +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp @@ -0,0 +1,193 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2010 Christopher Evi-Parker + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include "CreateLobbyDialog.h" + +#include +#include + +#include +#include + +#include "gui/common/PeerDefs.h" +#include "gui/chat/PopupChatDialog.h" + +CreateLobbyDialog::CreateLobbyDialog(const std::list& peer_list,QWidget *parent, Qt::WFlags flags, std::string grpId, int grpType) : + QDialog(parent, flags), mGrpId(grpId), mGrpType(grpType) +{ + ui = new Ui::CreateLobbyDialog() ; + ui->setupUi(this); + + ui->lobbyName_LE->setPlaceholderText(tr("Put a sensible lobby name here")) ; + ui->nickName_LE->setPlaceholderText(tr("Your nickname")) ; + + connect( ui->shareButton, SIGNAL( clicked ( bool ) ), this, SLOT( shareKey( ) ) ); + connect( ui->cancelButton, SIGNAL( clicked ( bool ) ), this, SLOT( cancel( ) ) ); + connect( ui->lobbyName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) ); + connect( ui->nickName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) ); + + connect(ui->keyShareList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ), + this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) )); + + setShareList(peer_list); +} + + +CreateLobbyDialog::~CreateLobbyDialog() +{ + delete ui; +} + +void CreateLobbyDialog::closeEvent (QCloseEvent * event) +{ + QWidget::closeEvent(event); +} + +void CreateLobbyDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void CreateLobbyDialog::checkTextFields() +{ + if(ui->lobbyName_LE->text() == "" || ui->nickName_LE->text() == "") + ui->shareButton->setEnabled(false) ; + else + ui->shareButton->setEnabled(true) ; +} +void CreateLobbyDialog::createLobby() +{ + if(mShareList.empty()) + { + QMessageBox::warning(this, tr("RetroShare"),tr("Please select at least one peer"), + QMessageBox::Ok, QMessageBox::Ok); + + return; + } + + // create chat lobby !! + std::string lobby_name = ui->lobbyName_LE->text().toStdString() ; + + // add to group + ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, mShareList); + + std::cerr << "gui: Created chat lobby " << std::hex << id << std::endl ; + + // open chat window !! + std::string vpid ; + + if(rsMsgs->getVirtualPeerId(id,vpid)) + PopupChatDialog::chatFriend(vpid) ; + + close(); +} + +void CreateLobbyDialog::cancel() +{ + close(); +} + +void CreateLobbyDialog::setShareList(const std::list& friend_list) +{ + if (!rsPeers) + { + /* not ready yet! */ + return; + } + + std::list peers; + std::list::iterator it; + + rsPeers->getFriendList(peers); + + /* get a link to the table */ + QTreeWidget *shareWidget = ui->keyShareList; + + QList items; + + for(it = peers.begin(); it != peers.end(); it++) + { + RsPeerDetails detail; + if (!rsPeers->getPeerDetails(*it, detail)) + { + continue; /* BAD */ + } + + /* make a widget per friend */ + QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0); + + item -> setText(0, PeerDefs::nameWithLocation(detail)); + if (detail.state & RS_PEER_STATE_CONNECTED) { + item -> setTextColor(0,(Qt::darkBlue)); + } + item -> setSizeHint(0, QSize( 17,17 ) ); + item -> setText(1, QString::fromStdString(detail.id)); + item -> setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); + + item -> setCheckState(0, Qt::Unchecked); + + for(std::list::const_iterator it2(friend_list.begin());it2!=friend_list.end();++it2) + if(*it == *it2) + { + item -> setCheckState(0, Qt::Checked); + break ; + } + + /* add to the list */ + items.append(item); + } + + /* remove old items */ + shareWidget->clear(); + shareWidget->setColumnCount(1); + + /* add the items in! */ + shareWidget->insertTopLevelItems(0, items); + + shareWidget->update(); /* update display */ +} + +void CreateLobbyDialog::togglePersonItem( QTreeWidgetItem *item, int /*col*/ ) +{ + /* extract id */ + std::string id = (item -> text(1)).toStdString(); + + /* get state */ + bool checked = (Qt::Checked == item -> checkState(0)); /* alway column 0 */ + + /* call control fns */ + std::list::iterator lit = std::find(mShareList.begin(), mShareList.end(), id); + + if(checked && (lit == mShareList.end())) + mShareList.push_back(id); // make sure ids not added already + else if(lit != mShareList.end()) + mShareList.erase(lit); + + return; +} + diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.h b/retroshare-gui/src/gui/chat/CreateLobbyDialog.h new file mode 100644 index 000000000..f2ffaf948 --- /dev/null +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.h @@ -0,0 +1,41 @@ +#ifndef SHAREKEY_H +#define SHAREKEY_H + +#include + +#include "ui_CreateLobbyDialog.h" + +class CreateLobbyDialog : public QDialog { + Q_OBJECT +public: + /* + *@param chanId The channel id to send request for + */ + CreateLobbyDialog(const std::list& friends_list,QWidget *parent = 0, Qt::WFlags flags = 0, std::string grpId = "", int grpType = 0); + ~CreateLobbyDialog(); + +protected: + void changeEvent(QEvent *e); + void closeEvent (QCloseEvent * event); + +private: + + void setShareList(const std::list&); + + Ui::CreateLobbyDialog *ui; + + std::string mGrpId; + std::list mShareList; + int mGrpType; + +private slots: + + void createLobby(); + void checkTextFields(); + void cancel(); + void togglePersonItem(QTreeWidgetItem* item, int col); + + +}; + +#endif // SHAREKEY_H diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.ui b/retroshare-gui/src/gui/chat/CreateLobbyDialog.ui new file mode 100644 index 000000000..911766fff --- /dev/null +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.ui @@ -0,0 +1,289 @@ + + + CreateLobbyDialog + + + + 0 + 0 + 586 + 532 + + + + Create Chat Lobby + + + + 0 + + + 0 + + + + + + + + 239 + 49 + + + + QFrame#frame{background-image: url(:/images/connect/connectFriendBanner.png); +} + + + QFrame::NoFrame + + + QFrame::Raised + + + + 6 + + + + + + 64 + 64 + + + + + + + :/images/user/agt_forum64.png + + + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:18pt; font-weight:600; color:#ffffff;">Create Chat Lobby</span></p></body></html> + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + Lobby name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Your nick name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;">Select the Friends with which you want to group chat.</span></p></body></html> + + + + + + + true + + + + 0 + 0 + + + + + 52487 + 524287 + + + + + 220 + 0 + + + + + 0 + 0 + + + + check peers you would like to share private publish key with + + + false + + + QDockWidget::NoDockWidgetFeatures + + + Invited friends + + + + + 0 + + + 0 + + + + + + 0 + 4 + + + + + 20 + 0 + + + + + 1677215 + 16777215 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16 + 16 + + + + true + + + + Contacts: + + + + + + + + + + + + QLayout::SetDefaultConstraint + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Create + + + + + + + Cancel + + + + + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index 23863cd0b..d2b866846 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -31,6 +31,7 @@ #include "GroupDefs.h" #include "gui/chat/PopupChatDialog.h" +#include "gui/chat/CreateLobbyDialog.h" #include "gui/common/AvatarDefs.h" #include "gui/connect/ConfCertDialog.h" #include "gui/connect/ConnectFriendWizard.h" @@ -1414,6 +1415,10 @@ void FriendList::inviteToLobby() // add to group rsMsgs->invitePeerToLobby(ChatLobbyId(QString::fromStdString(lobby_id).toULongLong()), peer_id); + + std::string vpeer_id ; + if(rsMsgs->getVirtualPeerId( ChatLobbyId(QString::fromStdString(lobby_id).toULongLong() ),vpeer_id) ) + PopupChatDialog::chatFriend(vpeer_id) ; } void FriendList::createchatlobby() @@ -1428,15 +1433,7 @@ void FriendList::createchatlobby() std::string peer_id = getRsId(c) ; friend_list.push_back(peer_id) ; - static int number=0 ; - - ++number ; - std::string lobby_name = "my cool lobby #"+QString::number(number).toStdString()+" (Plz add proper code to dynamically set this name in FriendList::createChatLobby())" ; - - // add to group - ChatLobbyId id = rsMsgs->createChatLobby(lobby_name, friend_list); - - std::cerr << "gui: Created chat lobby " << std::hex << id << std::endl ; + CreateLobbyDialog(friend_list).exec() ; } void FriendList::addToGroup() From 0086e182ecfc9f4bcdf30d39e8fac20fb9bc7d16 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 4 Dec 2011 22:22:15 +0000 Subject: [PATCH 11/17] bug fixes git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4710 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3chatservice.cc | 5 +++++ retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 1570e4be4..af6d23f2f 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -230,12 +230,17 @@ bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + std::cerr << "Was asked for virtual peer name of " << std::hex << id << std::dec<< std::endl; std::map::const_iterator it(_chat_lobbys.find(id)) ; if(it == _chat_lobbys.end()) + { + std::cerr << " not found!! " << std::endl; return false ; + } vpid = it->second.virtual_peer_id ; + std::cerr << " returning " << vpid << std::endl; return true ; } diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp index f0f750020..e9bba705c 100644 --- a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp @@ -39,7 +39,7 @@ CreateLobbyDialog::CreateLobbyDialog(const std::list& peer_list,QWi ui->lobbyName_LE->setPlaceholderText(tr("Put a sensible lobby name here")) ; ui->nickName_LE->setPlaceholderText(tr("Your nickname")) ; - connect( ui->shareButton, SIGNAL( clicked ( bool ) ), this, SLOT( shareKey( ) ) ); + connect( ui->shareButton, SIGNAL( clicked ( bool ) ), this, SLOT( createLobby( ) ) ); connect( ui->cancelButton, SIGNAL( clicked ( bool ) ), this, SLOT( cancel( ) ) ); connect( ui->lobbyName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) ); connect( ui->nickName_LE, SIGNAL( textChanged ( QString ) ), this, SLOT( checkTextFields( ) ) ); @@ -48,6 +48,7 @@ CreateLobbyDialog::CreateLobbyDialog(const std::list& peer_list,QWi this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) )); setShareList(peer_list); + checkTextFields() ; } @@ -123,6 +124,7 @@ void CreateLobbyDialog::setShareList(const std::list& friend_list) std::list peers; std::list::iterator it; + mShareList.clear() ; rsPeers->getFriendList(peers); /* get a link to the table */ @@ -155,6 +157,7 @@ void CreateLobbyDialog::setShareList(const std::list& friend_list) if(*it == *it2) { item -> setCheckState(0, Qt::Checked); + mShareList.push_back(*it) ; break ; } From 816a47780648bbeb52896a5d4f79ab996ad5accf Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 7 Dec 2011 00:12:17 +0000 Subject: [PATCH 12/17] bug corrections git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4712 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3chatservice.cc | 11 +++++++---- retroshare-gui/src/gui/FriendsDialog.cpp | 6 ++++++ retroshare-gui/src/gui/chat/PopupChatDialog.cpp | 10 ++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index af6d23f2f..ffc113fb4 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -1303,11 +1303,11 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item) for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) if((*it)!=item->PeerId() && mLinkMgr->isOnline(*it)) { - RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem(*item) ; // copy almost everything + RsChatLobbyMsgItem *item2 = new RsChatLobbyMsgItem(*item) ; // copy almost everything - item->PeerId(*it) ; + item2->PeerId(*it) ; - sendItem(item); + sendItem(item2); } return true ; } @@ -1318,7 +1318,7 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo std::cerr << "Sending chat lobby message to lobby " << lobby_id << std::endl; std::cerr << "msg:" << std::endl; - std::cerr << msg.c_str() << std::endl; + std::wcerr << msg << std::endl; // get a pointer to the info for that chat lobby. // @@ -1489,6 +1489,9 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD); + // send AKN item + + sendLobbyChat(L"[...] joined the lobby",lobby_id) ; return true ; } diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 88da9c5ab..a02962227 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -319,6 +319,12 @@ void FriendsDialog::readChatLobbyInvites() std::cerr << "Accepting invite to lobby " << (*it).lobby_name << std::endl; rsMsgs->acceptLobbyInvite( (*it).lobby_id ) ; + + std::string vpid ; + if(rsMsgs->getVirtualPeerId( (*it).lobby_id,vpid ) ) + PopupChatDialog::chatFriend(vpid) ; + else + std::cerr << "No lobby known with id 0x" << std::hex << (*it).lobby_id << std::dec << std::endl; } else rsMsgs->denyLobbyInvite( (*it).lobby_id ) ; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 4f859a2ea..e07359671 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -359,10 +359,16 @@ void PopupChatDialog::chatFriend(const std::string &id) } std::cerr<<" popup dialog chat friend 1"<isLobbyId(id,lid)) + { + getPrivateChat(id, RS_CHAT_OPEN | RS_CHAT_FOCUS); + return ; + } + RsPeerDetails detail; - if (!rsPeers->getPeerDetails(id, detail)) { + if (!rsPeers->getPeerDetails(id, detail)) return; - } std::string firstId; From d4abb4278814c66ab35919c2eaa4b831880930c5 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 26 Dec 2011 14:45:45 +0000 Subject: [PATCH 13/17] added challenge protocol to securely improve lobby connectivity git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4735 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/serialiser/rsmsgitems.cc | 60 ++++++ libretroshare/src/serialiser/rsmsgitems.h | 17 +- libretroshare/src/services/p3chatservice.cc | 216 ++++++++++++++++---- libretroshare/src/services/p3chatservice.h | 11 +- 4 files changed, 259 insertions(+), 45 deletions(-) diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 712ac2ba8..11dc36692 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -57,6 +57,15 @@ std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) printRsItemEnd(out, "RsChatMsgItem", indent); return out; } + +std::ostream& RsChatLobbyConnectChallengeItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsChatLobbyConnectChallengeItem", indent); + printIndent(out, indent); + out << "Challenge Code: " << std::hex << challenge_code << std::endl; + printRsItemEnd(out, "RsChatLobbyConnectChallengeItem", indent); + return out; +} std::ostream& RsChatLobbyMsgItem::print(std::ostream &out, uint16_t indent) { RsChatMsgItem::print(out,indent) ; @@ -190,6 +199,13 @@ uint32_t RsChatMsgItem::serial_size() return s; } +uint32_t RsChatLobbyConnectChallengeItem::serial_size() +{ + uint32_t s = 8; /* header */ + s += 8; // challenge code + return s ; +} + uint32_t RsChatLobbyMsgItem::serial_size() { uint32_t s = RsChatMsgItem::serial_size() ; // parent @@ -339,6 +355,33 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize) return ok ; } +bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize) +{ + uint32_t tlvsize = serial_size() ; + + if (pktsize < tlvsize) + return false; /* not enough space */ + + bool ok = true ; + ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! + uint32_t offset = 8 ; + + ok &= setRawUInt64(data, tlvsize, &offset, challenge_code); + + 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 + pktsize = tlvsize ; + return ok ; +} + bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -540,6 +583,23 @@ RsChatLobbyMsgItem::RsChatLobbyMsgItem(void *data,uint32_t /*size*/) std::cerr << "Unknown error while deserializing." << std::endl ; } +RsChatLobbyConnectChallengeItem::RsChatLobbyConnectChallengeItem(void *data,uint32_t /*size*/) + : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE) +{ + uint32_t rssize = getRsItemSize(data); + bool ok = true ; + + std::cerr << "RsChatLobbyConnectChallengeItem: rsitem size is " << rssize << std::endl; + uint32_t offset = 8 ; + + /* get mandatory parts first */ + ok &= getRawUInt64(data, rssize, &offset, &challenge_code); + + if (offset != rssize) + std::cerr << "Size error while deserializing." << std::endl ; + if (!ok) + std::cerr << "Unknown error while deserializing." << std::endl ; +} RsChatLobbyInviteItem::RsChatLobbyInviteItem(void *data,uint32_t /*size*/) : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) { diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index a9c9413a4..b8c09d583 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -54,6 +54,7 @@ const uint8_t RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG = 0x05 ; const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_MSG = 0x06 ; const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x07 ; const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_ACCEPT = 0x08 ; +const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE = 0x09 ; // for defining tags themselves and msg tags const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03; @@ -128,6 +129,21 @@ class RsChatLobbyMsgItem: public RsChatMsgItem ChatLobbyNickName nick ; }; +class RsChatLobbyConnectChallengeItem: public RsChatItem +{ + public: + RsChatLobbyConnectChallengeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE) {} + RsChatLobbyConnectChallengeItem(void *data,uint32_t size) ; // deserialization + + virtual ~RsChatLobbyConnectChallengeItem() {} + virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + + uint64_t challenge_code ; + + 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 +}; + class RsChatLobbyInviteItem: public RsChatItem { public: @@ -140,7 +156,6 @@ class RsChatLobbyInviteItem: public RsChatItem ChatLobbyId lobby_id ; std::string lobby_name ; - /// TODO !!! 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 }; diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index ffc113fb4..9cf115ced 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -26,6 +26,7 @@ #include "util/rsdir.h" #include "util/rsrandom.h" #include "retroshare/rsiface.h" +#include "retroshare/rspeers.h" #include "pqi/pqibin.h" #include "pqi/pqinotify.h" #include "pqi/pqistore.h" @@ -44,6 +45,8 @@ * */ +static const int CONNECTION_CHALLENGE_MAX_COUNT = 10 ; // sends a connexion challenge every 10 messages + p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr) :p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr) { @@ -51,6 +54,7 @@ p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr) _own_avatar = NULL ; _custom_status_string = "" ; + _default_nick_name = rsPeers->getPeerName(rsPeers->getOwnId()); } int p3ChatService::tick() @@ -619,6 +623,16 @@ void p3ChatService::receiveChatQueue() continue ; } + RsChatLobbyConnectChallengeItem *cn = dynamic_cast(item) ; + + if(cn != NULL) + { + handleConnectionChallenge(cn) ; + delete item ; + continue ; + } + + std::cerr << "Received ChatItem of unhandled type: " << std::endl; item->print(std::cerr,0) ; } @@ -1265,50 +1279,66 @@ void p3ChatService::statusChange(const std::list &plist) bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item) { - RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + bool send_challenge = false ; + ChatLobbyId send_challenge_lobby ; - std::cerr << "Handling ChatLobbyMsg " << std::hex << item->msg_id << ", lobby id " << item->lobby_id << ", from peer id " << item->PeerId() << std::endl; - - // send upward for display - - std::map::iterator it(_chat_lobbys.find(item->lobby_id)) ; - - if(it == _chat_lobbys.end()) { - std::cerr << "Chatlobby for id " << std::hex << item->lobby_id << " has no record. Dropping the msg." << std::dec << std::endl; - return false ; - } - ChatLobbyEntry& lobby(it->second) ; + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - // Adds the peer id to the list of friend participants, even if it's not original msg source - - lobby.participating_friends.insert(item->PeerId()) ; - lobby.nick_names.insert(item->nick) ; + std::cerr << "Handling ChatLobbyMsg " << std::hex << item->msg_id << ", lobby id " << item->lobby_id << ", from peer id " << item->PeerId() << std::endl; - // Checks wether the msg is already recorded or not - - std::map::const_iterator it2(lobby.msg_cache.find(item->msg_id)) ; + // send upward for display - if(it2 != lobby.msg_cache.end()) // found! - { - std::cerr << " Msg already received at time " << it2->second << ". Dropping!" << std::endl ; - return false ; - } - std::cerr << " Msg already not received already. Adding in cache, and forwarding!" << std::endl ; + std::map::iterator it(_chat_lobbys.find(item->lobby_id)) ; - lobby.msg_cache[item->msg_id] = time(NULL) ; - - // Forward to allparticipating friends, except this peer. - - for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) - if((*it)!=item->PeerId() && mLinkMgr->isOnline(*it)) + if(it == _chat_lobbys.end()) { - RsChatLobbyMsgItem *item2 = new RsChatLobbyMsgItem(*item) ; // copy almost everything - - item2->PeerId(*it) ; - - sendItem(item2); + std::cerr << "Chatlobby for id " << std::hex << item->lobby_id << " has no record. Dropping the msg." << std::dec << std::endl; + return false ; } + ChatLobbyEntry& lobby(it->second) ; + + // Adds the peer id to the list of friend participants, even if it's not original msg source + + lobby.participating_friends.insert(item->PeerId()) ; + lobby.nick_names.insert(item->nick) ; + + // Checks wether the msg is already recorded or not + + std::map::const_iterator it2(lobby.msg_cache.find(item->msg_id)) ; + + if(it2 != lobby.msg_cache.end()) // found! + { + std::cerr << " Msg already received at time " << it2->second << ". Dropping!" << std::endl ; + return false ; + } + std::cerr << " Msg already not received already. Adding in cache, and forwarding!" << std::endl ; + + lobby.msg_cache[item->msg_id] = time(NULL) ; + + // Forward to allparticipating friends, except this peer. + + for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) + if((*it)!=item->PeerId() && mLinkMgr->isOnline(*it)) + { + RsChatLobbyMsgItem *item2 = new RsChatLobbyMsgItem(*item) ; // copy almost everything + + item2->PeerId(*it) ; + + sendItem(item2); + } + + if(++lobby.connexion_challenge_count > CONNECTION_CHALLENGE_MAX_COUNT) + { + lobby.connexion_challenge_count = 0 ; + send_challenge_lobby = item->lobby_id ; + send_challenge = true ; + } + } + + if(send_challenge) + sendConnectionChallenge(send_challenge_lobby) ; + return true ; } @@ -1360,6 +1390,101 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo return true ; } +void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) +{ + // Look into message cache of all lobbys to handle the challenge. + // + std::cerr << "p3ChatService::handleConnectionChallenge(): received connexion challenge:" << std::endl; + std::cerr << " Challenge code = 0x" << std::hex << item->challenge_code << std::dec << std::endl; + std::cerr << " Peer Id = " << item->PeerId() << std::endl; + + ChatLobbyId lobby_id ; + bool found = false ; + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it) + for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();++it2) + if(makeConnexionChallengeCode(it->first,it2->first) == item->challenge_code) + { + std::cerr << " Challenge accepted for lobby " << std::hex << it->first << ", for chat msg " << it2->first << std::dec << std::endl ; + std::cerr << " Sending connection request to peer " << item->PeerId() << std::endl; + + lobby_id = it->first ; + found = true ; + } + } + + if(found) + invitePeerToLobby(lobby_id, item->PeerId()) ; + else + std::cerr << " Challenge denied: no existing cached msg has matching Id." << std::endl; +} + +void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::cerr << "Sending connection challenge to friends for lobby 0x" << std::hex << lobby_id << std::dec << std::endl ; + + // look for a msg in cache. Any recent msg is fine. + + std::map::const_iterator it = _chat_lobbys.find(lobby_id) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << "ERROR: sendConnectionChallenge(): could not find lobby 0x" << std::hex << lobby_id << std::dec << std::endl; + return ; + } + + time_t now = time(NULL) ; + uint64_t code = 0 ; + + for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();++it2) + if(it2->second + 20 < now) // any msg not older than 20 seconds is fine. + { + std::cerr << " Using msg id 0x" << std::hex << it2->first << ", challenge code = " << code << std::dec << std::endl; + code = makeConnexionChallengeCode(lobby_id,it2->first) ; + } + + if(code == 0) + { + std::cerr << " No suitable message found in cache. Weird !!" << std::endl; + return ; + } + + // Broadcast to all direct friends + + std::list ids ; + mLinkMgr->getOnlineList(ids); + + for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) + { + RsChatLobbyConnectChallengeItem *item = new RsChatLobbyConnectChallengeItem ; + + item->PeerId(*it) ; + item->challenge_code = code ; + + sendItem(item); + } +} + +uint64_t p3ChatService::makeConnexionChallengeCode(ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) +{ + uint64_t a = lobby_id ; + uint64_t b = msg_id ; + + for(int i=0;i<10;++i) + { + a = ((a+0x3eb57bac44980ab2) ^ (b+0x11278ea3b205aa4e)) + 0x928eeba8 ; + b = ((~b) << 4) + (a & 0xffff) ; + } + + std::cerr << "Making connection challenge id: lobby_id=0x" << std::hex << lobby_id << ", msg=0x" << msg_id << ", code = " << a << std::dec << std::endl ; + + return a ; +} + void p3ChatService::getChatLobbyList(std::list& linfos) { // fill up a dummy list for now. @@ -1406,11 +1531,13 @@ void p3ChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item) // { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::map::const_iterator it = _chat_lobbys.find(item->lobby_id) ; + std::map::iterator it = _chat_lobbys.find(item->lobby_id) ; if(it != _chat_lobbys.end()) { std::cerr << " Lobby already exists. Addign new friend " << item->PeerId() << " to it" << std::endl; + + it->second.participating_friends.insert(item->PeerId()) ; return ; } // no, then create a new invitation entry in the cache. @@ -1461,10 +1588,11 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) ChatLobbyEntry entry ; entry.participating_friends.insert(it->second.peer_id) ; - entry.nick_name = mLinkMgr->getOwnId() ; // to be changed. For debug only!! + entry.nick_name = _default_nick_name ; // to be changed. For debug only!! entry.lobby_id = lobby_id ; entry.lobby_name = it->second.lobby_name ; entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ; + entry.connexion_challenge_count = 0 ; _lobby_ids[entry.virtual_peer_id] = lobby_id ; _chat_lobbys[lobby_id] = entry ; @@ -1478,7 +1606,7 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem; item->lobby_id = entry.lobby_id ; item->msg_id = 0 ; - item->nick = "" ; + item->nick = "Lobby management" ; item->message = std::wstring(L"Welcome to chat lobby") ; item->PeerId(entry.virtual_peer_id) ; item->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_LOBBY ; @@ -1490,8 +1618,11 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD); // send AKN item - - sendLobbyChat(L"[...] joined the lobby",lobby_id) ; + std::wstring wmsg(_default_nick_name.length(), L' '); // Make room for characters + // Copy string to wstring. + std::copy(_default_nick_name.begin(), _default_nick_name.end(), wmsg.begin()); + + sendLobbyChat(wmsg + L" joined the lobby",lobby_id) ; return true ; } @@ -1535,10 +1666,11 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s ChatLobbyEntry entry ; entry.participating_friends.clear() ; - entry.nick_name = mLinkMgr->getOwnId() ; // to be changed. For debug only!! + entry.nick_name = _default_nick_name ; // to be changed. For debug only!! entry.lobby_id = lobby_id ; entry.lobby_name = lobby_name ; entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ; + entry.connexion_challenge_count = 0 ; _lobby_ids[entry.virtual_peer_id] = lobby_id ; _chat_lobbys[lobby_id] = entry ; diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 1007fc114..c2563df90 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -215,9 +215,13 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ; void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ; void checkAndRedirectMsgToLobby(RsChatMsgItem*) ; - static std::string makeVirtualPeerId(ChatLobbyId) ; - void locked_printDebugInfo() const ; + void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ; + void sendConnectionChallenge(ChatLobbyId id) ; + static std::string makeVirtualPeerId(ChatLobbyId) ; + static uint64_t makeConnexionChallengeCode(ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ; + + void locked_printDebugInfo() const ; RsChatAvatarItem *makeOwnAvatarItem() ; RsChatStatusItem *makeOwnCustomStateStringItem() ; @@ -244,11 +248,14 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max. void cleanCache() ; + int connexion_challenge_count ; }; std::map _chat_lobbys ; std::map _lobby_invites_queue ; std::map _lobby_ids ; + std::string _default_nick_name ; + time_t last_lobby_challenge_time ; // prevents bruteforce attack }; class p3ChatService::StateStringInfo From 9b79d70fa88fce7ec5ade004377406a15b10067a Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 26 Dec 2011 17:39:38 +0000 Subject: [PATCH 14/17] debugging of connectivity challenge git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4736 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/serialiser/rsmsgitems.cc | 10 +--- libretroshare/src/services/p3chatservice.cc | 56 +++++++++++---------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 11dc36692..76839bca1 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -183,6 +183,7 @@ RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize) case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem(data,*pktsize) ; case RS_PKT_SUBTYPE_CHAT_LOBBY_MSG: return new RsChatLobbyMsgItem(data,*pktsize) ; case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem(data,*pktsize) ; default: std::cerr << "Unknown packet type in chat!" << std::endl ; return NULL ; @@ -333,15 +334,6 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize) ok &= setRawUInt64(data, tlvsize, &offset, msg_id); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, nick); -#ifdef CHAT_DEBUG - std::cerr << "Serialized the following message:" << std::endl; - std::cerr << "========== BEGIN MESSAGE =========" << std::endl; - for(uint32_t i=0;i::const_iterator it(_chat_lobbys.begin()) ;it!=_chat_lobbys.end();++it) { - std::cerr << " Lobby id\t: " << it->first << std::endl; - std::cerr << " Lobby name\t: " << it->second.lobby_name << std::endl; - std::cerr << " nick name\t: " << it->second.nick_name << std::endl; + std::cerr << " Lobby id\t\t: " << std::hex << it->first << std::dec << std::endl; + std::cerr << " Lobby name\t\t: " << it->second.lobby_name << std::endl; + std::cerr << " nick name\t\t: " << it->second.nick_name << std::endl; std::cerr << " Lobby peer id\t: " << it->second.virtual_peer_id << std::endl; + std::cerr << " Challenge count\t: " << it->second.connexion_challenge_count << std::endl; + std::cerr << " Cached messages\t: " << it->second.msg_cache.size() << std::endl; + + for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();++it2) + std::cerr << " " << std::hex << it2->first << std::dec << " time=" << it2->second << std::endl; + std::cerr << " Participating friends: " << std::endl; for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) @@ -273,15 +279,13 @@ void p3ChatService::locked_printDebugInfo() const std::cerr << "Recorded lobby names: " << std::endl; for( std::map::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it) - std::cerr << " \"" << it->first << "\" id = " << it->second << std::endl; + std::cerr << " \"" << it->first << "\" id = " << std::hex << it->second << std::dec << std::endl; } bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - locked_printDebugInfo() ; // debug - std::map::const_iterator it(_lobby_ids.find(id)) ; if(it != _lobby_ids.end()) @@ -464,6 +468,7 @@ void p3ChatService::checkAndRedirectMsgToLobby(RsChatMsgItem *ci) if(it == _chat_lobbys.end()) { std::cerr << "(EE) p3ChatService::checkAndRedirectMsgToLobby(): RsItem is a lobby item, but the id is not known!!" << std::endl; + ci->PeerId(std::string()) ; return ; } vpeer_id = it->second.virtual_peer_id ; @@ -1285,6 +1290,7 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + locked_printDebugInfo() ; // debug std::cerr << "Handling ChatLobbyMsg " << std::hex << item->msg_id << ", lobby id " << item->lobby_id << ", from peer id " << item->PeerId() << std::endl; // send upward for display @@ -1346,20 +1352,20 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - std::cerr << "Sending chat lobby message to lobby " << lobby_id << std::endl; + std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl; std::cerr << "msg:" << std::endl; std::wcerr << msg << std::endl; // get a pointer to the info for that chat lobby. // - std::map::const_iterator it(_chat_lobbys.find(lobby_id)) ; + std::map::iterator it(_chat_lobbys.find(lobby_id)) ; if(it == _chat_lobbys.end()) { std::cerr << "Chatlobby for id " << std::hex << lobby_id << " has no record. This is a serious error!!" << std::dec << std::endl; return false ; } - const ChatLobbyEntry& lobby(it->second) ; + ChatLobbyEntry& lobby(it->second) ; RsChatLobbyMsgItem item ; @@ -1367,6 +1373,8 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo // do { item.msg_id = RSRandom::random_u64(); } while( lobby.msg_cache.find(item.msg_id) != lobby.msg_cache.end() ) ; + lobby.msg_cache[item.msg_id] = time(NULL) ; // put the msg in cache! + item.lobby_id = lobby_id ; item.nick = lobby.nick_name ; @@ -1387,6 +1395,7 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo sendItem(sitem); } + locked_printDebugInfo() ; // debug return true ; } @@ -1403,9 +1412,13 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it) - for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();++it2) - if(makeConnexionChallengeCode(it->first,it2->first) == item->challenge_code) + for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end() && !found;++it) + for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end() && !found;++it2) + { + uint64_t code = makeConnexionChallengeCode(it->first,it2->first) ; + std::cerr << " Lobby_id = 0x" << std::hex << it->first << ", msg_id = 0x" << it2->first << ": code = 0x" << code << std::dec << std::endl ; + + if(code == item->challenge_code) { std::cerr << " Challenge accepted for lobby " << std::hex << it->first << ", for chat msg " << it2->first << std::dec << std::endl ; std::cerr << " Sending connection request to peer " << item->PeerId() << std::endl; @@ -1413,6 +1426,7 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i lobby_id = it->first ; found = true ; } + } } if(found) @@ -1441,10 +1455,11 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id) uint64_t code = 0 ; for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();++it2) - if(it2->second + 20 < now) // any msg not older than 20 seconds is fine. + if(it2->second + 20 > now) // any msg not older than 20 seconds is fine. { - std::cerr << " Using msg id 0x" << std::hex << it2->first << ", challenge code = " << code << std::dec << std::endl; code = makeConnexionChallengeCode(lobby_id,it2->first) ; + std::cerr << " Using msg id 0x" << std::hex << it2->first << ", challenge code = " << code << std::dec << std::endl; + break ; } if(code == 0) @@ -1471,18 +1486,7 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id) uint64_t p3ChatService::makeConnexionChallengeCode(ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) { - uint64_t a = lobby_id ; - uint64_t b = msg_id ; - - for(int i=0;i<10;++i) - { - a = ((a+0x3eb57bac44980ab2) ^ (b+0x11278ea3b205aa4e)) + 0x928eeba8 ; - b = ((~b) << 4) + (a & 0xffff) ; - } - - std::cerr << "Making connection challenge id: lobby_id=0x" << std::hex << lobby_id << ", msg=0x" << msg_id << ", code = " << a << std::dec << std::endl ; - - return a ; + return ((uint64_t)lobby_id) ^ (uint64_t)msg_id ; } void p3ChatService::getChatLobbyList(std::list& linfos) From cc57ab24629185e0c45022b602ffcdd458a90136 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 26 Dec 2011 22:43:54 +0000 Subject: [PATCH 15/17] added load/save of default nickname, plus some debugging git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4737 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 2 + libretroshare/src/rsserver/p3msgs.cc | 9 ++ libretroshare/src/rsserver/p3msgs.h | 2 + libretroshare/src/services/p3chatservice.cc | 84 +++++++++++-- libretroshare/src/services/p3chatservice.h | 9 +- .../src/gui/chat/ChatLobbyDialog.cpp | 11 ++ retroshare-gui/src/gui/chat/ChatLobbyDialog.h | 1 + .../src/gui/chat/CreateLobbyDialog.cpp | 10 +- .../src/gui/chat/PopupChatDialog.cpp | 17 ++- retroshare-gui/src/gui/settings/ChatPage.cpp | 7 ++ retroshare-gui/src/gui/settings/ChatPage.ui | 110 +++++++++++++----- 11 files changed, 211 insertions(+), 51 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index cff132073..1d88a4202 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -238,6 +238,8 @@ virtual void getPendingChatLobbyInvites(std::list& invites) = 0 virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) = 0; virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) = 0; virtual bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) = 0 ; +virtual bool setDefaultNickNameForChatLobby(const std::string& nick) = 0; +virtual bool getDefaultNickNameForChatLobby(std::string& nick) = 0 ; virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends) = 0 ; /****************************************/ diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 7a66a7b6a..ac902415f 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -281,6 +281,15 @@ void p3Msgs::unsubscribeChatLobby(const ChatLobbyId& lobby_id) { mChatSrv->unsubscribeChatLobby(lobby_id) ; } +bool p3Msgs::setDefaultNickNameForChatLobby(const std::string& nick) +{ + return mChatSrv->setDefaultNickNameForChatLobby(nick) ; +} +bool p3Msgs::getDefaultNickNameForChatLobby(std::string& nick_name) +{ + return mChatSrv->getDefaultNickNameForChatLobby(nick_name) ; +} + bool p3Msgs::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) { return mChatSrv->setNickNameForChatLobby(lobby_id,nick) ; diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 25fd968a0..1e104def0 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -178,6 +178,8 @@ class p3Msgs: public RsMsgs 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) ; private: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 4c4a2256f..33f73f506 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -34,18 +34,16 @@ #include "pqi/p3historymgr.h" #include "services/p3chatservice.h" +#include "serialiser/rsconfigitems.h" /**** * #define CHAT_DEBUG 1 ****/ -/************ NOTE ********************************* - * This Service is so simple that there is no - * mutex protection required! - * - */ +static const int CONNECTION_CHALLENGE_MAX_COUNT = 15 ; // sends a connexion challenge every 15 messages +static const int LOBBY_CACHE_CLEANING_PERIOD = 10 ; // sends a connexion challenge every 15 messages +static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max. -static const int CONNECTION_CHALLENGE_MAX_COUNT = 10 ; // sends a connexion challenge every 10 messages p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr) :p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr) @@ -63,6 +61,15 @@ int p3ChatService::tick() receiveChatQueue(); } + static time_t last_clean_time = 0 ; + time_t now = time(NULL) ; + + if(last_clean_time + LOBBY_CACHE_CLEANING_PERIOD < now) + { + cleanLobbyCaches() ; + last_clean_time = now ; + } + return 0; } @@ -1168,6 +1175,16 @@ bool p3ChatService::loadList(std::list& load) continue; } + RsConfigKeyValueSet *vitem = NULL ; + + if(NULL != (vitem = dynamic_cast(*it))) + for(std::list::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) + if(kit->key == "DEFAULT_NICK_NAME") + { + std::cerr << "Loaded config default nick name for chat: " << kit->value << std::endl ; + _default_nick_name = kit->value ; + } + // delete unknown items delete *it; } @@ -1217,6 +1234,14 @@ bool p3ChatService::saveList(bool& cleanup, std::list& list) list.push_back(ci); } + RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; + RsTlvKeyValue kv; + kv.key = "DEFAULT_NICK_NAME" ; + kv.value = _default_nick_name ; + vitem->tlvkvs.pairs.push_back(kv) ; + + list.push_back(vitem) ; + return true; } @@ -1230,6 +1255,7 @@ RsSerialiser *p3ChatService::setupSerialiser() { RsSerialiser *rss = new RsSerialiser ; rss->addSerialType(new RsChatSerialiser) ; + rss->addSerialType(new RsGeneralConfigSerialiser()); return rss ; } @@ -1412,7 +1438,7 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end() && !found;++it) + for(std::map::iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end() && !found;++it) for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end() && !found;++it2) { uint64_t code = makeConnexionChallengeCode(it->first,it2->first) ; @@ -1425,11 +1451,14 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i lobby_id = it->first ; found = true ; + + // also add the peer to the list of participating friends + it->second.participating_friends.insert(item->PeerId()) ; } } } - if(found) + if(found) // send invitation. As the peer already has the lobby, the invitation will most likely be accepted. invitePeerToLobby(lobby_id, item->PeerId()) ; else std::cerr << " Challenge denied: no existing cached msg has matching Id." << std::endl; @@ -1520,10 +1549,6 @@ void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::st item->PeerId(peer_id) ; sendItem(item) ; - - // Adds the invitation into the invitation cache. - // - it->second.invitations_sent[peer_id] = time(NULL) ; } void p3ChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item) { @@ -1692,6 +1717,17 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id) // send a lobby leaving packet. To be implemented. } +bool p3ChatService::setDefaultNickNameForChatLobby(const std::string& nick) +{ + _default_nick_name = nick; + IndicateConfigChanged() ; + return true ; +} +bool p3ChatService::getDefaultNickNameForChatLobby(std::string& nick) +{ + nick = _default_nick_name ; + return true ; +} bool p3ChatService::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1726,3 +1762,27 @@ bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const st return true ; } +void p3ChatService::cleanLobbyCaches() +{ + std::cerr << "Cleaning chat lobby caches." << std::endl; + + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + time_t now = time(NULL) ; + + for(std::map::iterator it = _chat_lobbys.begin();it!=_chat_lobbys.end();++it) + for(std::map::iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();) + if(it2->second + MAX_KEEP_MSG_RECORD < now) + { + std::cerr << " removing old msg 0x" << std::hex << it2->first << ", time=" << std::dec << it2->second << std::endl; + + std::map::iterator tmp(it2) ; + ++tmp ; + it->second.msg_cache.erase(it2) ; + it2 = tmp ; + } + else + ++it2 ; +} + + diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index c2563df90..c46dac05a 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -160,9 +160,11 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor void denyLobbyInvite(const ChatLobbyId& id) ; void getPendingChatLobbyInvites(std::list& invites) ; void invitePeerToLobby(const ChatLobbyId&, const std::string&) ; - bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ; void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ; + bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ; bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ; + bool setDefaultNickNameForChatLobby(const std::string& nick) ; + bool getDefaultNickNameForChatLobby(std::string& nick) ; ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list& invited_friends) ; protected: @@ -217,6 +219,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor void checkAndRedirectMsgToLobby(RsChatMsgItem*) ; void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ; void sendConnectionChallenge(ChatLobbyId id) ; + void cleanLobbyCaches() ; static std::string makeVirtualPeerId(ChatLobbyId) ; static uint64_t makeConnexionChallengeCode(ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ; @@ -243,11 +246,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor { public: std::map msg_cache ; - std::map invitations_sent ; std::string virtual_peer_id ; - - static const time_t MAX_KEEP_MSG_RECORD = 240 ; // keep msg record for 240 secs max. - void cleanCache() ; int connexion_challenge_count ; }; diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index a73fe71e9..57839a3b9 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -53,6 +53,8 @@ ChatLobbyDialog::ChatLobbyDialog(const std::string& dialog_id,const ChatLobbyId& ui.avatarWidget->hide() ; PopupChatDialog::updateStatus(QString::fromStdString(getPeerId()),RS_STATUS_ONLINE) ; + + QObject::connect(this,SIGNAL(close()),this,SLOT(closeAndAsk())) ; } /** Destructor. */ @@ -63,6 +65,15 @@ ChatLobbyDialog::~ChatLobbyDialog() rsMsgs->unsubscribeChatLobby(lobby_id) ; } +void ChatLobbyDialog::closeEvent(QCloseEvent* e) +{ + std::cerr << "In close event!" << std::endl; + if(QMessageBox::Yes == QMessageBox::question(NULL,tr("Unsubsribe to lobby?"),tr("Do you want to unsubscribe to this chat lobby?"),QMessageBox::Yes, QMessageBox::No)) + rsMsgs->unsubscribeChatLobby(lobby_id) ; + + PopupChatDialog::closeEvent(e) ; +} + void ChatLobbyDialog::setNickName(const QString& nick) { rsMsgs->setNickNameForChatLobby(lobby_id,nick.toStdString()) ; diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h index 65c220360..44de79adf 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h @@ -55,6 +55,7 @@ class ChatLobbyDialog: public PopupChatDialog // The following methods are differentfrom those of the parent: // virtual void updateStatus(const QString &peer_id, int status) ; // needs grouped status. Not yet implemented. + virtual void closeEvent(QCloseEvent*) ; protected slots: void setNickName(const QString&) ; diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp index e9bba705c..c7313a3d8 100644 --- a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp @@ -36,8 +36,12 @@ CreateLobbyDialog::CreateLobbyDialog(const std::list& peer_list,QWi ui = new Ui::CreateLobbyDialog() ; ui->setupUi(this); + std::string default_nick ; + rsMsgs->getDefaultNickNameForChatLobby(default_nick) ; + ui->lobbyName_LE->setPlaceholderText(tr("Put a sensible lobby name here")) ; - ui->nickName_LE->setPlaceholderText(tr("Your nickname")) ; + ui->nickName_LE->setPlaceholderText(tr("Your nickname for this lobby")) ; + ui->nickName_LE->setText(QString::fromStdString(default_nick)) ; connect( ui->shareButton, SIGNAL( clicked ( bool ) ), this, SLOT( createLobby( ) ) ); connect( ui->cancelButton, SIGNAL( clicked ( bool ) ), this, SLOT( cancel( ) ) ); @@ -99,6 +103,10 @@ void CreateLobbyDialog::createLobby() std::cerr << "gui: Created chat lobby " << std::hex << id << std::endl ; + // set nick name ! + + rsMsgs->setNickNameForChatLobby(id,ui->nickName_LE->text().toStdString()) ; + // open chat window !! std::string vpid ; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index e07359671..fd6cd7140 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -280,12 +280,19 @@ void PopupChatDialog::processSettings(bool bLoad) } else if (rsMsgs->isLobbyId(id, lobby_id)) { - popupchatdialog = new ChatLobbyDialog(id,lobby_id,QString::fromStdString(id)); - chatDialogs[id] = popupchatdialog; + std::list linfos; + rsMsgs->getChatLobbyList(linfos) ; - PopupChatWindow *window = PopupChatWindow::getWindow(false); - window->addDialog(popupchatdialog); - } + for(std::list::const_iterator it(linfos.begin());it!=linfos.end();++it) + if( (*it).lobby_id == lobby_id) + { + popupchatdialog = new ChatLobbyDialog(id,lobby_id,QString::fromStdString((*it).lobby_name)); + chatDialogs[id] = popupchatdialog; + + PopupChatWindow *window = PopupChatWindow::getWindow(false); + window->addDialog(popupchatdialog); + } + } } } diff --git a/retroshare-gui/src/gui/settings/ChatPage.cpp b/retroshare-gui/src/gui/settings/ChatPage.cpp index 1365c5ef6..1f7b1be34 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.cpp +++ b/retroshare-gui/src/gui/settings/ChatPage.cpp @@ -28,6 +28,7 @@ #include "rsharesettings.h" #include +#include #define VARIANT_STANDARD "Standard" @@ -115,6 +116,8 @@ ChatPage::save(QString &/*errmsg*/) rsHistory->setSaveCount(true, ui.publicChatSaveCount->value()); rsHistory->setSaveCount(false, ui.privateChatSaveCount->value()); + rsMsgs->setDefaultNickNameForChatLobby(ui.chatLobbyNick_LE->text().toStdString()) ; + ChatStyleInfo info; QListWidgetItem *item = ui.publicList->currentItem(); if (item) { @@ -175,6 +178,10 @@ ChatPage::load() publicStylePath = loadStyleInfo(ChatStyle::TYPE_PUBLIC, ui.publicList, ui.publicComboBoxVariant, publicStyleVariant); privateStylePath = loadStyleInfo(ChatStyle::TYPE_PRIVATE, ui.privateList, ui.privateComboBoxVariant, privateStyleVariant); historyStylePath = loadStyleInfo(ChatStyle::TYPE_HISTORY, ui.historyList, ui.historyComboBoxVariant, historyStyleVariant); + + std::string nick ; + rsMsgs->getDefaultNickNameForChatLobby(nick) ; + ui.chatLobbyNick_LE->setText(QString::fromStdString(nick)) ; } void ChatPage::on_pushButtonChangeChatFont_clicked() diff --git a/retroshare-gui/src/gui/settings/ChatPage.ui b/retroshare-gui/src/gui/settings/ChatPage.ui index a74dc4262..a4f234863 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.ui +++ b/retroshare-gui/src/gui/settings/ChatPage.ui @@ -521,35 +521,89 @@ Chat Settings - - - - - Enable Emoticons Privat Chat - - - true - - + + + + + + + Enable Emoticons Privat Chat + + + true + + + + + + + Enable Emoticons Group Chat + + + true + + + + + + + Send message with Ctrl+Return + + + + + + + Default nickname for chat lobbies: + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Maximum + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - - - Enable Emoticons Group Chat - - - true - - - - - - - Send message with Ctrl+Return - - - - + From 3addb36e4c9699158a9be0753cfe5b34dc461919 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 27 Dec 2011 13:47:37 +0000 Subject: [PATCH 16/17] added unsubscribe protocol, updated GUI git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4738 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/serialiser/rsmsgitems.cc | 60 +++++++++++++++++- libretroshare/src/serialiser/rsmsgitems.h | 17 +++++ libretroshare/src/services/p3chatservice.cc | 63 ++++++++++++++++++- libretroshare/src/services/p3chatservice.h | 1 + .../src/gui/chat/ChatLobbyDialog.cpp | 10 +-- retroshare-gui/src/gui/chat/ChatLobbyDialog.h | 1 - .../src/gui/chat/CreateLobbyDialog.cpp | 2 +- .../src/gui/chat/CreateLobbyDialog.ui | 11 ++++ .../src/gui/chat/PopupChatDialog.cpp | 8 +++ retroshare-gui/src/gui/chat/PopupChatDialog.h | 1 + retroshare-gui/src/gui/common/FriendList.cpp | 56 +++++++++++++++-- retroshare-gui/src/gui/common/FriendList.h | 2 + 12 files changed, 213 insertions(+), 19 deletions(-) diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 76839bca1..c89141d24 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -57,7 +57,14 @@ std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) printRsItemEnd(out, "RsChatMsgItem", indent); return out; } - +std::ostream& RsChatLobbyUnsubscribeItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsChatLobbyUnsubscribeItem", indent); + printIndent(out, indent); + out << "Lobby id: " << std::hex << lobby_id << std::endl; + printRsItemEnd(out, "RsChatLobbyUnsubscribeItem", indent); + return out; +} std::ostream& RsChatLobbyConnectChallengeItem::print(std::ostream &out, uint16_t indent) { printRsItemBase(out, "RsChatLobbyConnectChallengeItem", indent); @@ -184,6 +191,7 @@ RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize) case RS_PKT_SUBTYPE_CHAT_LOBBY_MSG: return new RsChatLobbyMsgItem(data,*pktsize) ; case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem(data,*pktsize) ; case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem(data,*pktsize) ; + case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem(data,*pktsize) ; default: std::cerr << "Unknown packet type in chat!" << std::endl ; return NULL ; @@ -200,6 +208,14 @@ uint32_t RsChatMsgItem::serial_size() return s; } +uint32_t RsChatLobbyUnsubscribeItem::serial_size() +{ + uint32_t s = 8; /* header */ + s += 8; // challenge code + return s ; +} + + uint32_t RsChatLobbyConnectChallengeItem::serial_size() { uint32_t s = 8; /* header */ @@ -347,6 +363,32 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize) return ok ; } +bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize) +{ + uint32_t tlvsize = serial_size() ; + + if (pktsize < tlvsize) + return false; /* not enough space */ + + bool ok = true ; + ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! + uint32_t offset = 8 ; + + ok &= setRawUInt64(data, tlvsize, &offset, lobby_id); + + 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 + pktsize = tlvsize ; + return ok ; +} bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize) { uint32_t tlvsize = serial_size() ; @@ -574,7 +616,23 @@ RsChatLobbyMsgItem::RsChatLobbyMsgItem(void *data,uint32_t /*size*/) if (!ok) std::cerr << "Unknown error while deserializing." << std::endl ; } +RsChatLobbyUnsubscribeItem::RsChatLobbyUnsubscribeItem(void *data,uint32_t /*size*/) + : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) +{ + uint32_t rssize = getRsItemSize(data); + bool ok = true ; + std::cerr << "RsChatLobbyUnsubscribeItem: rsitem size is " << rssize << std::endl; + uint32_t offset = 8 ; + + /* get mandatory parts first */ + ok &= getRawUInt64(data, rssize, &offset, &lobby_id); + + if (offset != rssize) + std::cerr << "Size error while deserializing." << std::endl ; + if (!ok) + std::cerr << "Unknown error while deserializing." << std::endl ; +} RsChatLobbyConnectChallengeItem::RsChatLobbyConnectChallengeItem(void *data,uint32_t /*size*/) : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE) { diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index b8c09d583..523d90686 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -55,6 +55,7 @@ const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_MSG = 0x06 ; const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x07 ; const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_ACCEPT = 0x08 ; const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE = 0x09 ; +const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE= 0x0A ; // for defining tags themselves and msg tags const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03; @@ -129,6 +130,22 @@ class RsChatLobbyMsgItem: public RsChatMsgItem ChatLobbyNickName nick ; }; +class RsChatLobbyUnsubscribeItem: public RsChatItem +{ + public: + RsChatLobbyUnsubscribeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) {} + RsChatLobbyUnsubscribeItem(void *data,uint32_t size) ; // deserialization + + virtual ~RsChatLobbyUnsubscribeItem() {} + virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + + uint64_t lobby_id ; + + 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 +}; + + class RsChatLobbyConnectChallengeItem: public RsChatItem { public: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 33f73f506..6ef90464b 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -644,6 +644,15 @@ void p3ChatService::receiveChatQueue() continue ; } + RsChatLobbyUnsubscribeItem *cu = dynamic_cast(item) ; + + if(cu != NULL) + { + handleFriendUnsubscribeLobby(cu) ; + delete item ; + continue ; + } + std::cerr << "Received ChatItem of unhandled type: " << std::endl; item->print(std::cerr,0) ; @@ -1711,11 +1720,63 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s return lobby_id ; } +void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *item) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + std::map::iterator it = _chat_lobbys.find(item->lobby_id) ; + + std::cerr << "Received unsubscribed to lobby " << item->lobby_id << ", from friend " << item->PeerId() << std::endl; + + if(it == _chat_lobbys.end()) + { + std::cerr << "Chat lobby " << item->lobby_id << " does not exist ! Can't unsubscribe!" << std::endl; + return ; + } + + for(std::set::iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + if(*it2 == item->PeerId()) + { + std::cerr << " removing peer id " << item->PeerId() << " from participant list of lobby " << item->lobby_id << std::endl; + it->second.participating_friends.erase(it2) ; + break ; + } +} + void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - // send a lobby leaving packet. To be implemented. + std::map::iterator it = _chat_lobbys.find(id) ; + + if(it == _chat_lobbys.end()) + { + std::cerr << "Chat lobby " << id << " does not exist ! Can't unsubscribe!" << std::endl; + return ; + } + // send a lobby leaving packet to all friends + + for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) + { + RsChatLobbyUnsubscribeItem *item = new RsChatLobbyUnsubscribeItem ; + + item->lobby_id = id ; + item->PeerId(*it2) ; + + sendItem(item) ; + } + + // remove lobby information + + _chat_lobbys.erase(it) ; + + for(std::map::iterator it2(_lobby_ids.begin());it2!=_lobby_ids.end();++it2) + if(it2->second == id) + { + _lobby_ids.erase(it2) ; + break ; + } + + // done! } bool p3ChatService::setDefaultNickNameForChatLobby(const std::string& nick) { diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index c46dac05a..b99d9c1e9 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -219,6 +219,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor void checkAndRedirectMsgToLobby(RsChatMsgItem*) ; void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ; void sendConnectionChallenge(ChatLobbyId id) ; + void handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem*) ; void cleanLobbyCaches() ; static std::string makeVirtualPeerId(ChatLobbyId) ; diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 57839a3b9..8fda5a57b 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -62,16 +62,8 @@ ChatLobbyDialog::~ChatLobbyDialog() { // announce leaving of lobby - rsMsgs->unsubscribeChatLobby(lobby_id) ; -} - -void ChatLobbyDialog::closeEvent(QCloseEvent* e) -{ - std::cerr << "In close event!" << std::endl; - if(QMessageBox::Yes == QMessageBox::question(NULL,tr("Unsubsribe to lobby?"),tr("Do you want to unsubscribe to this chat lobby?"),QMessageBox::Yes, QMessageBox::No)) + if(QMessageBox::Yes == QMessageBox::question(NULL,tr("Unsubscribe to lobby?"),tr("Do you want to unsubscribe to this chat lobby?"),QMessageBox::Yes | QMessageBox::No)) rsMsgs->unsubscribeChatLobby(lobby_id) ; - - PopupChatDialog::closeEvent(e) ; } void ChatLobbyDialog::setNickName(const QString& nick) diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h index 44de79adf..65c220360 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h @@ -55,7 +55,6 @@ class ChatLobbyDialog: public PopupChatDialog // The following methods are differentfrom those of the parent: // virtual void updateStatus(const QString &peer_id, int status) ; // needs grouped status. Not yet implemented. - virtual void closeEvent(QCloseEvent*) ; protected slots: void setNickName(const QString&) ; diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp index c7313a3d8..546a96fae 100644 --- a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp @@ -40,7 +40,7 @@ CreateLobbyDialog::CreateLobbyDialog(const std::list& peer_list,QWi rsMsgs->getDefaultNickNameForChatLobby(default_nick) ; ui->lobbyName_LE->setPlaceholderText(tr("Put a sensible lobby name here")) ; - ui->nickName_LE->setPlaceholderText(tr("Your nickname for this lobby")) ; + ui->nickName_LE->setPlaceholderText(tr("Your nickname for this lobby (Change default name in options->chat)")) ; ui->nickName_LE->setText(QString::fromStdString(default_nick)) ; connect( ui->shareButton, SIGNAL( clicked ( bool ) ), this, SLOT( createLobby( ) ) ); diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.ui b/retroshare-gui/src/gui/chat/CreateLobbyDialog.ui index 911766fff..accb62a4a 100644 --- a/retroshare-gui/src/gui/chat/CreateLobbyDialog.ui +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.ui @@ -88,6 +88,17 @@ p, li { white-space: pre-wrap; } QFrame::Raised + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">A chat lobby is a decentralized and anonymous chat group. All participants receive all messages. Once the lobby is created you can invite other friends from the Friends tab.</p></body></html> + + + diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index fd6cd7140..2c6080fc1 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -359,6 +359,14 @@ void PopupChatDialog::processSettings(bool bLoad) } } +void PopupChatDialog::closeChat(const std::string& id) +{ + PopupChatDialog *popupchatdialog = getExistingInstance(id); + + if(popupchatdialog != NULL) + popupchatdialog->hide() ; +} + void PopupChatDialog::chatFriend(const std::string &id) { if (id.empty()){ diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index c383d6b75..00d72367d 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -47,6 +47,7 @@ public: static PopupChatDialog *getPrivateChat(const std::string &id, uint chatflags); static void cleanupChat(); static void chatFriend(const std::string &id); + static void closeChat(const std::string &id); static void privateChatChanged(int list, int type); void updateStatusString(const QString& peer_id, const QString& statusString); diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index d2b866846..028e24108 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -336,23 +336,36 @@ void FriendList::peerTreeWidgetCostumPopupMenu() case TYPE_SSL: { contextMnu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy())); - QMenu *mnu = contextMnu.addMenu(QIcon(IMAGE_CHAT), tr("Invite to chat lobby")) ; + QMenu *mnu = contextMnu.addMenu(QIcon(IMAGE_CHAT), tr("Chat lobbies")) ; + mnu->addAction(QIcon(IMAGE_ADDFRIEND),tr("create new"),this,SLOT(createchatlobby())) ; + + // Get existing lobbies + // std::list cl_infos ; - rsMsgs->getChatLobbyList(cl_infos) ; for(std::list::const_iterator it(cl_infos.begin());it!=cl_infos.end();++it) { std::cerr << "Adding meny entry with lobby id " << std::hex << (*it).lobby_id << std::dec << std::endl; - QAction* inviteToLobbyAction = new QAction(QString::fromUtf8((*it).lobby_name.c_str()), mnu); + QMenu *mnu2 = mnu->addMenu(QIcon(IMAGE_CHAT), QString::fromUtf8((*it).lobby_name.c_str())) ; + + QAction* inviteToLobbyAction = new QAction(tr("Invite this friend"), mnu2); inviteToLobbyAction->setData(QString::number((*it).lobby_id)); connect(inviteToLobbyAction, SIGNAL(triggered()), this, SLOT(inviteToLobby())); - mnu->addAction(inviteToLobbyAction); - } + mnu2->addAction(inviteToLobbyAction); - mnu->addAction(QIcon(IMAGE_CHAT),tr("create new"),this,SLOT(createchatlobby())) ; + QAction* showLobbyAction = new QAction(tr("Show"), mnu2); + showLobbyAction->setData(QString::number((*it).lobby_id)); + connect(showLobbyAction, SIGNAL(triggered()), this, SLOT(showLobby())); + mnu2->addAction(showLobbyAction); + + QAction* unsubscribeToLobbyAction = new QAction(tr("Unsubscribe"), mnu2); + unsubscribeToLobbyAction->setData(QString::number((*it).lobby_id)); + connect(unsubscribeToLobbyAction, SIGNAL(triggered()), this, SLOT(unsubscribeToLobby())); + mnu2->addAction(unsubscribeToLobbyAction); + } contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Friend"), this, SLOT(msgfriend())); @@ -1393,6 +1406,37 @@ void FriendList::configurefriend() ConfCertDialog::showIt(getRsId(getCurrentPeer()), ConfCertDialog::PageDetails); } +void FriendList::showLobby() +{ + std::string lobby_id = qobject_cast(sender())->data().toString().toStdString(); + + if(lobby_id.empty()) + return; + + std::string vpeer_id ; + + if(rsMsgs->getVirtualPeerId( ChatLobbyId(QString::fromStdString(lobby_id).toULongLong() ),vpeer_id)) + PopupChatDialog::chatFriend(vpeer_id) ; +} +void FriendList::unsubscribeToLobby() +{ + std::string lobby_id = qobject_cast(sender())->data().toString().toStdString(); + + if(lobby_id.empty()) + return; + + std::string vpeer_id ; + rsMsgs->getVirtualPeerId( ChatLobbyId(QString::fromStdString(lobby_id).toULongLong() ),vpeer_id) ; + + if(QMessageBox::Ok == QMessageBox::question(this,tr("Unsubscribe to lobby"),tr("You are about to unsubscribe a chat lobby
You can only re-enter if your friends invite you again."),QMessageBox::Ok | QMessageBox::Cancel)) + rsMsgs->unsubscribeChatLobby(ChatLobbyId(QString::fromStdString(lobby_id).toULongLong())) ; + + // we should also close existing windows. + + PopupChatDialog::closeChat(vpeer_id) ; +} + + void FriendList::inviteToLobby() { QTreeWidgetItem *c = getCurrentPeer(); diff --git a/retroshare-gui/src/gui/common/FriendList.h b/retroshare-gui/src/gui/common/FriendList.h index 14e72046b..459751214 100644 --- a/retroshare-gui/src/gui/common/FriendList.h +++ b/retroshare-gui/src/gui/common/FriendList.h @@ -125,6 +125,8 @@ private slots: void inviteToLobby(); void createchatlobby(); + void unsubscribeToLobby(); + void showLobby(); }; #endif // FRIENDLIST_H From bcd2973b3288a10fca188899345ab42417576269 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 27 Dec 2011 15:35:43 +0000 Subject: [PATCH 17/17] put debug info between ifdefs git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-ChatLobby@4739 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3chatservice.cc | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 6ef90464b..8ccdf3923 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -241,17 +241,23 @@ bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ +#ifdef CHAT_DEBUG std::cerr << "Was asked for virtual peer name of " << std::hex << id << std::dec<< std::endl; +#endif std::map::const_iterator it(_chat_lobbys.find(id)) ; if(it == _chat_lobbys.end()) { +#ifdef CHAT_DEBUG std::cerr << " not found!! " << std::endl; +#endif return false ; } vpid = it->second.virtual_peer_id ; +#ifdef CHAT_DEBUG std::cerr << " returning " << vpid << std::endl; +#endif return true ; } @@ -451,15 +457,21 @@ bool p3ChatService::checkAndRebuildPartialMessage(RsChatMsgItem *ci) void p3ChatService::checkAndRedirectMsgToLobby(RsChatMsgItem *ci) { +#ifdef CHAT_DEBUG std::cerr << "Checking msg..." << std::endl; +#endif if(!(ci->chatFlags & RS_CHAT_FLAG_LOBBY)) { +#ifdef CHAT_DEBUG std::cerr << " normal chat!" << std::endl; +#endif return ; } +#ifdef CHAT_DEBUG else std::cerr << " lobby chat!" << std::endl; +#endif RsChatLobbyMsgItem *lobbyItem = dynamic_cast(ci) ; @@ -1326,7 +1338,9 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item) RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ locked_printDebugInfo() ; // debug +#ifdef CHAT_DEBUG std::cerr << "Handling ChatLobbyMsg " << std::hex << item->msg_id << ", lobby id " << item->lobby_id << ", from peer id " << item->PeerId() << std::endl; +#endif // send upward for display @@ -1353,7 +1367,9 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item) std::cerr << " Msg already received at time " << it2->second << ". Dropping!" << std::endl ; return false ; } +#ifdef CHAT_DEBUG std::cerr << " Msg already not received already. Adding in cache, and forwarding!" << std::endl ; +#endif lobby.msg_cache[item->msg_id] = time(NULL) ; @@ -1387,9 +1403,11 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ +#ifdef CHAT_DEBUG std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl; std::cerr << "msg:" << std::endl; std::wcerr << msg << std::endl; +#endif // get a pointer to the info for that chat lobby. // @@ -1438,9 +1456,11 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i { // Look into message cache of all lobbys to handle the challenge. // +#ifdef CHAT_DEBUG std::cerr << "p3ChatService::handleConnectionChallenge(): received connexion challenge:" << std::endl; std::cerr << " Challenge code = 0x" << std::hex << item->challenge_code << std::dec << std::endl; std::cerr << " Peer Id = " << item->PeerId() << std::endl; +#endif ChatLobbyId lobby_id ; bool found = false ; @@ -1451,12 +1471,16 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i for(std::map::const_iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end() && !found;++it2) { uint64_t code = makeConnexionChallengeCode(it->first,it2->first) ; +#ifdef CHAT_DEBUG std::cerr << " Lobby_id = 0x" << std::hex << it->first << ", msg_id = 0x" << it2->first << ": code = 0x" << code << std::dec << std::endl ; +#endif if(code == item->challenge_code) { +#ifdef CHAT_DEBUG std::cerr << " Challenge accepted for lobby " << std::hex << it->first << ", for chat msg " << it2->first << std::dec << std::endl ; std::cerr << " Sending connection request to peer " << item->PeerId() << std::endl; +#endif lobby_id = it->first ; found = true ; @@ -1477,7 +1501,9 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ +#ifdef CHAT_DEBUG std::cerr << "Sending connection challenge to friends for lobby 0x" << std::hex << lobby_id << std::dec << std::endl ; +#endif // look for a msg in cache. Any recent msg is fine. @@ -1496,7 +1522,9 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id) if(it2->second + 20 > now) // any msg not older than 20 seconds is fine. { code = makeConnexionChallengeCode(lobby_id,it2->first) ; +#ifdef CHAT_DEBUG std::cerr << " Using msg id 0x" << std::hex << it2->first << ", challenge code = " << code << std::dec << std::endl; +#endif break ; } @@ -1540,7 +1568,9 @@ void p3ChatService::getChatLobbyList(std::list& linfos) } void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id) { +#ifdef CHAT_DEBUG std::cerr << "Sending invitation to peer " << peer_id << " to lobby "<< std::hex << lobby_id << std::dec << std::endl; +#endif RsChatLobbyInviteItem *item = new RsChatLobbyInviteItem ; @@ -1561,7 +1591,9 @@ void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::st } void p3ChatService::handleRecvLobbyInvite(RsChatLobbyInviteItem *item) { +#ifdef CHAT_DEBUG std::cerr << "Received invite to lobby from " << item->PeerId() << " to lobby " << item->lobby_id << ", named " << item->lobby_name << std::endl; +#endif // 1 - store invite in a cache // @@ -1606,7 +1638,9 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ +#ifdef CHAT_DEBUG std::cerr << "Accepting chat lobby "<< lobby_id << std::endl; +#endif std::map::iterator it = _lobby_invites_queue.find(lobby_id) ; @@ -1622,7 +1656,9 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) return true ; } +#ifdef CHAT_DEBUG std::cerr << " Creating new Lobby entry." << std::endl; +#endif ChatLobbyEntry entry ; entry.participating_friends.insert(it->second.peer_id) ; @@ -1639,7 +1675,9 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) // we should also send a message to the lobby to tell we're here. +#ifdef CHAT_DEBUG std::cerr << " Pushing new msg item to incoming msgs." << std::endl; +#endif RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem; item->lobby_id = entry.lobby_id ; @@ -1651,7 +1689,9 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id) privateIncomingList.push_back(item) ; } +#ifdef CHAT_DEBUG std::cerr << " Notifying of new recvd msg." << std::endl ; +#endif rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD); @@ -1677,7 +1717,9 @@ void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ +#ifdef CHAT_DEBUG std::cerr << "Denying chat lobby invite to "<< lobby_id << std::endl; +#endif std::map::iterator it = _lobby_invites_queue.find(lobby_id) ; if(it == _lobby_invites_queue.end()) @@ -1691,7 +1733,9 @@ void p3ChatService::denyLobbyInvite(const ChatLobbyId& lobby_id) ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::list& invited_friends) { +#ifdef CHAT_DEBUG std::cerr << "Creating a new Chat lobby !!" << std::endl; +#endif ChatLobbyId lobby_id ; { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1700,7 +1744,9 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s // do { lobby_id = RSRandom::random_u64() ; } while(_chat_lobbys.find(lobby_id) != _chat_lobbys.end()) ; +#ifdef CHAT_DEBUG std::cerr << " New (unique) ID: " << std::hex << lobby_id << std::dec << std::endl; +#endif ChatLobbyEntry entry ; entry.participating_friends.clear() ; @@ -1725,7 +1771,9 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ std::map::iterator it = _chat_lobbys.find(item->lobby_id) ; +#ifdef CHAT_DEBUG std::cerr << "Received unsubscribed to lobby " << item->lobby_id << ", from friend " << item->PeerId() << std::endl; +#endif if(it == _chat_lobbys.end()) { @@ -1736,7 +1784,9 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite for(std::set::iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) if(*it2 == item->PeerId()) { +#ifdef CHAT_DEBUG std::cerr << " removing peer id " << item->PeerId() << " from participant list of lobby " << item->lobby_id << std::endl; +#endif it->second.participating_friends.erase(it2) ; break ; } @@ -1793,7 +1843,9 @@ bool p3ChatService::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::str { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ +#ifdef CHAT_DEBUG std::cerr << "getting nickname for chat lobby "<< std::hex << lobby_id << std::dec << std::endl; +#endif std::map::iterator it = _chat_lobbys.find(lobby_id) ; if(it == _chat_lobbys.end()) @@ -1810,7 +1862,9 @@ bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const st { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ +#ifdef CHAT_DEBUG std::cerr << "Changing nickname for chat lobby " << std::hex << lobby_id << std::dec << " to " << nick << std::endl; +#endif std::map::iterator it = _chat_lobbys.find(lobby_id) ; if(it == _chat_lobbys.end()) @@ -1825,7 +1879,9 @@ bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const st void p3ChatService::cleanLobbyCaches() { +#ifdef CHAT_DEBUG std::cerr << "Cleaning chat lobby caches." << std::endl; +#endif RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -1835,7 +1891,9 @@ void p3ChatService::cleanLobbyCaches() for(std::map::iterator it2(it->second.msg_cache.begin());it2!=it->second.msg_cache.end();) if(it2->second + MAX_KEEP_MSG_RECORD < now) { +#ifdef CHAT_DEBUG std::cerr << " removing old msg 0x" << std::hex << it2->first << ", time=" << std::dec << it2->second << std::endl; +#endif std::map::iterator tmp(it2) ; ++tmp ;