added menu to select identity when entering lobby; removed debug info

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-LobbiesWithGXSIds@7985 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-03-06 20:43:21 +00:00
parent 48b16a068f
commit 2f6a6a14b1
3 changed files with 103 additions and 37 deletions

View File

@ -37,7 +37,7 @@
#include "gxs/gxssecurity.h"
#include "services/p3idservice.h"
#define DEBUG_CHAT_LOBBIES 1
//#define DEBUG_CHAT_LOBBIES 1
static const int CONNECTION_CHALLENGE_MAX_COUNT = 20 ; // sends a connection challenge every 20 messages
static const time_t CONNECTION_CHALLENGE_MAX_MSG_AGE = 30 ; // maximum age of a message to be used in a connection challenge
@ -122,7 +122,7 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
}
if(!checkSignature(cli,cli->PeerId())) // check the object's signature and possibly request missing keys
{
std::cerr << "Signature mismatched for this lobby event item: " << std::endl;
std::cerr << "Signature mismatched for this lobby event item. Item will be dropped: " << std::endl;
cli->print(std::cerr) ;
std::cerr << std::endl;
return false;
@ -152,13 +152,17 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
std::list<RsPeerId> peer_list ;
peer_list.push_back(peer_id) ;
bool key_available = mIdService->requestKey(obj->signature.keyId,peer_list);
// network pre-request key to allow message authentication.
mIdService->requestKey(obj->signature.keyId,peer_list);
uint32_t size = obj->signed_serial_size() ;
unsigned char *memory = (unsigned char *)malloc(size) ;
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << "Checking object signature: " << std::endl;
std::cerr << " signature id: " << obj->signature.keyId << std::endl;
#endif
if(!obj->serialise_signed_part(memory,size))
{
@ -178,20 +182,26 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
return true ;
}
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << " key available. " << key_available << std::endl;
std::cerr << " data hash: " << RsDirUtil::sha1sum(memory,obj->signed_serial_size()) << std::endl;
std::cerr << " signed data: " << RsUtil::BinToHex((char*)memory,obj->signed_serial_size()) << std::endl;
#endif
if(!GxsSecurity::validateSignature((const char *)memory,obj->signed_serial_size(),signature_public_key,obj->signature))
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << " Signature: FAILS." << std::endl;
#endif
free(memory) ;
return false ;
}
free(memory) ;
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << " signature: CHECKS" << std::endl;
#endif
return true ;
}
@ -769,8 +779,6 @@ bool DistributedChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,c
if(!locked_bouncingObjectCheck(item,peer_id,lobby.participating_friends.size()))
return false;
bool is_message = (NULL != dynamic_cast<RsChatLobbyMsgItem*>(item)) ;
// Forward to allparticipating friends, except this peer.
for(std::set<RsPeerId>::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it)

View File

@ -13,11 +13,13 @@
#include "chat/ChatLobbyUserNotify.h"
#include "util/HandleRichText.h"
#include "util/QtVersion.h"
#include <gui/settings/rsharesettings.h>
#include "gui/settings/rsharesettings.h"
#include "gui/gxs/GxsIdDetails.h"
#include "retroshare/rsmsgs.h"
#include "retroshare/rspeers.h"
#include "retroshare/rsnotify.h"
#include "retroshare/rsidentity.h"
#define COLUMN_NAME 0
#define COLUMN_USER_COUNT 1
@ -212,16 +214,51 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint)
action->setData(item->data(COLUMN_DATA, ROLE_PRIVACYLEVEL).toInt());
}
if (item && item->type() == TYPE_LOBBY) {
if (item->data(COLUMN_DATA, ROLE_SUBSCRIBED).toBool()) {
contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe"), this, SLOT(unsubscribeItem()));
} else {
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Subscribe"), this, SLOT(subscribeItem()));
if (item && item->type() == TYPE_LOBBY)
{
if (item->data(COLUMN_DATA, ROLE_SUBSCRIBED).toBool())
contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Leave this lobby"), this, SLOT(unsubscribeItem()));
else
{
std::list<RsGxsId> own_identities ;
rsIdentity->getOwnIds(own_identities) ;
QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem();
uint32_t item_flags = item->data(COLUMN_DATA,ROLE_ID).toUInt() ;
if(own_identities.size() <= 1)
{
QAction *action = contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Enter this lobby"), this, SLOT(subscribeChatLobbyAs()));
if(own_identities.empty())
action->setEnabled(false) ;
else
action->setData(QString::fromStdString((own_identities.front()).toStdString())) ;
}
if (item->data(COLUMN_DATA, ROLE_AUTOSUBSCRIBE).toBool()) {
else
{
QMenu *mnu = contextMnu.addMenu(QIcon(IMAGE_SUBSCRIBE),tr("Enter this lobby as...")) ;
for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it)
{
RsIdentityDetails idd ;
rsIdentity->getIdDetails(*it,idd) ;
QPixmap pixmap ;
if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG"))
pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ;
QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(subscribeChatLobbyAs()));
action->setData(QString::fromStdString((*it).toStdString())) ;
}
}
if (item->data(COLUMN_DATA, ROLE_AUTOSUBSCRIBE).toBool())
contextMnu.addAction(QIcon(IMAGE_AUTOSUBSCRIBE), tr("Remove Auto Subscribe"), this, SLOT(autoSubscribeItem()));
} else {
else
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Add Auto Subscribe"), this, SLOT(autoSubscribeItem()));
}
}
@ -579,8 +616,26 @@ void ChatLobbyWidget::showLobby(QTreeWidgetItem *item)
else
ui.stackedWidget->setCurrentWidget(_lobby_infos[id].dialog) ;
}
void ChatLobbyWidget::subscribeChatLobbyAs()
{
QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem();
static void subscribeLobby(QTreeWidgetItem *item)
if(!item)
return ;
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
QAction *action = qobject_cast<QAction *>(QObject::sender());
if (!action)
return ;
RsGxsId gxs_id(action->data().toString().toStdString());
uint32_t error_code ;
if(rsMsgs->joinVisibleChatLobby(id,gxs_id))
ChatDialog::chatFriend(ChatId(id),true) ;
}
void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
{
if (item == NULL || item->type() != TYPE_LOBBY) {
return;
@ -602,7 +657,7 @@ void ChatLobbyWidget::autoSubscribeLobby(QTreeWidgetItem *item)
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
if (!isAutoSubscribe) subscribeLobby(item);
if (!isAutoSubscribe) subscribeChatLobbyAtItem(item);
}
void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
@ -639,7 +694,7 @@ void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
void ChatLobbyWidget::subscribeItem()
{
subscribeLobby(ui.lobbyTreeWidget->currentItem());
subscribeChatLobbyAtItem(ui.lobbyTreeWidget->currentItem());
}
void ChatLobbyWidget::autoSubscribeItem()
@ -822,7 +877,7 @@ void ChatLobbyWidget::updateMessageChanged(ChatLobbyId id)
void ChatLobbyWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/)
{
subscribeLobby(item);
subscribeChatLobbyAtItem(item);
}
void ChatLobbyWidget::displayChatLobbyEvent(qulonglong lobby_id, int event_type, const QString& gxs_id, const QString& str)

View File

@ -63,6 +63,7 @@ protected slots:
void showLobby(QTreeWidgetItem *lobby_item) ;
void showBlankPage(ChatLobbyId id) ;
void unsubscribeChatLobby(ChatLobbyId id) ;
void subscribeChatLobbyAs() ;
void updateTypingStatus(ChatLobbyId id) ;
void resetLobbyTreeIcons() ;
void updateMessageChanged(ChatLobbyId);
@ -81,6 +82,8 @@ private slots:
private:
void autoSubscribeLobby(QTreeWidgetItem *item);
void subscribeChatLobby(ChatLobbyId id) ;
void subscribeChatLobbyAtItem(QTreeWidgetItem *item) ;
bool filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn);