mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-04-19 14:55:54 -04:00
Imported chat lobby function from branch v0.5-ChatLobby (merged commits 4682-4739)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4740 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
60bb76e3df
@ -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 */
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
#include "rstypes.h"
|
||||
|
||||
@ -61,6 +62,10 @@
|
||||
#define RS_MSGTAGTYPE_LATER 5
|
||||
#define RS_MSGTAGTYPE_USER 100
|
||||
|
||||
typedef uint64_t ChatLobbyId ;
|
||||
typedef uint64_t ChatLobbyMsgId ;
|
||||
typedef std::string ChatLobbyNickName ;
|
||||
|
||||
class MessageInfo
|
||||
{
|
||||
public:
|
||||
@ -129,16 +134,33 @@ class ChatInfo
|
||||
{
|
||||
public:
|
||||
std::string rsid;
|
||||
std::string peer_nickname;
|
||||
unsigned int chatflags;
|
||||
uint32_t sendTime;
|
||||
uint32_t recvTime;
|
||||
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<std::string> participating_friends ; // list of direct friend who participate. Used to broadcast sent messages.
|
||||
std::set<std::string> nick_names ; // 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&);
|
||||
|
||||
@ -186,12 +208,13 @@ virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0;
|
||||
/* Chat */
|
||||
virtual bool sendPublicChat(const std::wstring& msg) = 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<ChatInfo> &chats) = 0;
|
||||
virtual int getPrivateChatQueueCount(bool incoming) = 0;
|
||||
virtual int getPrivateChatQueueCount(bool incoming) = 0;
|
||||
virtual bool getPrivateChatQueueIds(bool incoming, std::list<std::string> &ids) = 0;
|
||||
virtual bool getPrivateChatQueue(bool incoming, const std::string& id, std::list<ChatInfo> &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,9 +228,24 @@ 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 bool getVirtualPeerId(const ChatLobbyId& lobby_id,std::string& vpid) = 0;
|
||||
virtual void getChatLobbyList(std::list<ChatLobbyInfo>& 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<ChatLobbyInvite>& 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<std::string>& invited_friends) = 0 ;
|
||||
|
||||
/****************************************/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -260,3 +260,61 @@ 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) ;
|
||||
}
|
||||
|
||||
void p3Msgs::getChatLobbyList(std::list<ChatLobbyInfo>& linfos)
|
||||
{
|
||||
mChatSrv->getChatLobbyList(linfos) ;
|
||||
}
|
||||
void p3Msgs::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id)
|
||||
{
|
||||
mChatSrv->invitePeerToLobby(lobby_id,peer_id) ;
|
||||
}
|
||||
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) ;
|
||||
}
|
||||
bool p3Msgs::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick_name)
|
||||
{
|
||||
return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ;
|
||||
}
|
||||
|
||||
ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends)
|
||||
{
|
||||
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<ChatLobbyInvite>& invites)
|
||||
{
|
||||
mChatSrv->getPendingChatLobbyInvites(invites) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,6 +168,20 @@ 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<ChatLobbyInfo, std::allocator<ChatLobbyInfo> >&) ;
|
||||
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<ChatLobbyInvite>& invites) ;
|
||||
virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ;
|
||||
virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string&) ;
|
||||
virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ;
|
||||
virtual bool setDefaultNickNameForChatLobby(const std::string&) ;
|
||||
virtual bool getDefaultNickNameForChatLobby(std::string& nick) ;
|
||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends) ;
|
||||
|
||||
private:
|
||||
|
||||
p3MsgService *mMsgSrv;
|
||||
|
@ -57,7 +57,54 @@ 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);
|
||||
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) ;
|
||||
|
||||
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 +184,14 @@ 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) ;
|
||||
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 ;
|
||||
@ -157,6 +208,38 @@ 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 */
|
||||
s += 8; // challenge code
|
||||
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 +284,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 +311,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<message.length();++i)
|
||||
for(uint32_t i=0;i<message.length();++i)
|
||||
std::cerr << (char)message[i] ;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "=========== END MESSAGE ==========" << std::endl;
|
||||
@ -244,12 +327,121 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
|
||||
#endif
|
||||
return ok ;
|
||||
}
|
||||
|
||||
std::cerr << "Serialization result: " ;
|
||||
for(int i=0;i<20;++i)
|
||||
std::cerr << (int)((uint8_t*)data)[i] << " " ;
|
||||
std::cerr << std::endl ;
|
||||
return ok;
|
||||
/* serialise the data to the buffer */
|
||||
bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
|
||||
{
|
||||
uint32_t tlvsize = serial_size() ;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
bool ok = true;
|
||||
ok &= RsChatMsgItem::serialise(data,pktsize) ; // first, serialize parent
|
||||
uint32_t offset = pktsize;
|
||||
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header!
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, lobby_id);
|
||||
ok &= setRawUInt64(data, tlvsize, &offset, msg_id);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, nick);
|
||||
|
||||
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
|
||||
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() ;
|
||||
|
||||
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() ;
|
||||
|
||||
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);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, lobby_name);
|
||||
|
||||
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 RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize)
|
||||
@ -377,8 +569,8 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
|
||||
|
||||
return ok;
|
||||
}
|
||||
RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_DEFAULT)
|
||||
RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/,uint8_t subtype)
|
||||
: RsChatItem(subtype)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
@ -403,6 +595,83 @@ RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/)
|
||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
}
|
||||
|
||||
RsChatLobbyMsgItem::RsChatLobbyMsgItem(void *data,uint32_t /*size*/)
|
||||
: RsChatMsgItem(data,0,RS_PKT_SUBTYPE_CHAT_LOBBY_MSG)
|
||||
{
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
uint32_t offset = RsChatMsgItem::serial_size() ;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt64(data, rssize, &offset, &lobby_id);
|
||||
ok &= getRawUInt64(data, rssize, &offset, &msg_id);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, nick);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Building new chat msg item." << std::endl ;
|
||||
#endif
|
||||
if (offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
std::cerr << "RsChatLobbyInviteItem: rsitem size is " << rssize << std::endl;
|
||||
uint32_t offset = 8 ;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= getRawUInt64(data, rssize, &offset, &lobby_id);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, lobby_name);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Building new chat msg item." << std::endl ;
|
||||
#endif
|
||||
if (offset != rssize)
|
||||
std::cerr << "Size error while deserializing." << std::endl ;
|
||||
if (!ok)
|
||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||
}
|
||||
|
||||
RsPrivateChatMsgConfigItem::RsPrivateChatMsgConfigItem(void *data,uint32_t /*size*/)
|
||||
: RsChatItem(RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG)
|
||||
{
|
||||
|
@ -44,19 +44,28 @@ 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 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 ;
|
||||
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;
|
||||
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;
|
||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03;
|
||||
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,15 +90,17 @@ class RsChatItem: public RsItem
|
||||
class RsChatMsgItem: public RsChatItem
|
||||
{
|
||||
public:
|
||||
RsChatMsgItem() :RsChatItem(RS_PKT_SUBTYPE_DEFAULT)
|
||||
{
|
||||
}
|
||||
RsChatMsgItem(void *data,uint32_t size) ; // deserialization
|
||||
RsChatMsgItem() :RsChatItem(RS_PKT_SUBTYPE_DEFAULT) {}
|
||||
RsChatMsgItem(uint8_t subtype) :RsChatItem(subtype) {}
|
||||
|
||||
RsChatMsgItem(void *data,uint32_t size,uint8_t subtype = RS_PKT_SUBTYPE_DEFAULT) ; // deserialization
|
||||
|
||||
virtual ~RsChatMsgItem() {}
|
||||
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
|
||||
|
||||
@ -100,6 +111,72 @@ 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() {}
|
||||
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
|
||||
|
||||
ChatLobbyId lobby_id ;
|
||||
ChatLobbyMsgId msg_id ;
|
||||
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:
|
||||
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:
|
||||
RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {}
|
||||
RsChatLobbyInviteItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
virtual ~RsChatLobbyInviteItem() {}
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
ChatLobbyId lobby_id ;
|
||||
std::string lobby_name ;
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
/*!
|
||||
* For saving incoming and outgoing chat msgs
|
||||
* @see p3ChatService
|
||||
|
@ -24,7 +24,9 @@
|
||||
*/
|
||||
|
||||
#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"
|
||||
@ -32,16 +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.
|
||||
|
||||
|
||||
p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr)
|
||||
@ -50,6 +52,7 @@ p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
|
||||
|
||||
_own_avatar = NULL ;
|
||||
_custom_status_string = "" ;
|
||||
_default_nick_name = rsPeers->getPeerName(rsPeers->getOwnId());
|
||||
}
|
||||
|
||||
int p3ChatService::tick()
|
||||
@ -58,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;
|
||||
}
|
||||
|
||||
@ -207,7 +219,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) ;
|
||||
@ -215,7 +227,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.
|
||||
//
|
||||
@ -225,8 +237,88 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
||||
sendItem(msg) ;
|
||||
}
|
||||
|
||||
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<ChatLobbyId,ChatLobbyEntry>::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 ;
|
||||
}
|
||||
|
||||
void p3ChatService::locked_printDebugInfo() const
|
||||
{
|
||||
std::cerr << "Recorded lobbies: " << std::endl;
|
||||
|
||||
for( std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it(_chat_lobbys.begin()) ;it!=_chat_lobbys.end();++it)
|
||||
{
|
||||
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<ChatLobbyMsgId,time_t>::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<std::string>::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<std::string>::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<std::string,ChatLobbyId>::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it)
|
||||
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 ******/
|
||||
|
||||
std::map<std::string,ChatLobbyId>::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()";
|
||||
@ -363,6 +455,49 @@ 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<RsChatLobbyMsgItem*>(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<ChatLobbyId,ChatLobbyEntry>::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;
|
||||
ci->PeerId(std::string()) ;
|
||||
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()
|
||||
{
|
||||
@ -381,6 +516,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;
|
||||
@ -433,9 +572,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 !!
|
||||
|
||||
@ -446,6 +587,7 @@ void p3ChatService::receiveChatQueue()
|
||||
}
|
||||
} /* UNLOCK */
|
||||
}
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatStatusItem *cs = dynamic_cast<RsChatStatusItem*>(item) ;
|
||||
@ -495,6 +637,37 @@ void p3ChatService::receiveChatQueue()
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatLobbyInviteItem *cl = dynamic_cast<RsChatLobbyInviteItem*>(item) ;
|
||||
|
||||
if(cl != NULL)
|
||||
{
|
||||
handleRecvLobbyInvite(cl) ;
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatLobbyConnectChallengeItem *cn = dynamic_cast<RsChatLobbyConnectChallengeItem*>(item) ;
|
||||
|
||||
if(cn != NULL)
|
||||
{
|
||||
handleConnectionChallenge(cn) ;
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
RsChatLobbyUnsubscribeItem *cu = dynamic_cast<RsChatLobbyUnsubscribeItem*>(item) ;
|
||||
|
||||
if(cu != NULL)
|
||||
{
|
||||
handleFriendUnsubscribeLobby(cu) ;
|
||||
delete item ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
|
||||
std::cerr << "Received ChatItem of unhandled type: " << std::endl;
|
||||
item->print(std::cerr,0) ;
|
||||
}
|
||||
|
||||
if (publicChanged) {
|
||||
@ -681,16 +854,15 @@ void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
|
||||
i.recvTime = c->recvTime;
|
||||
i.msg = c->message;
|
||||
|
||||
RsChatLobbyMsgItem *lobbyItem = dynamic_cast<RsChatLobbyMsgItem*>(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)
|
||||
@ -1024,6 +1196,16 @@ bool p3ChatService::loadList(std::list<RsItem*>& load)
|
||||
continue;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = NULL ;
|
||||
|
||||
if(NULL != (vitem = dynamic_cast<RsConfigKeyValueSet*>(*it)))
|
||||
for(std::list<RsTlvKeyValue>::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;
|
||||
}
|
||||
@ -1073,6 +1255,14 @@ bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& 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;
|
||||
}
|
||||
|
||||
@ -1086,6 +1276,7 @@ RsSerialiser *p3ChatService::setupSerialiser()
|
||||
{
|
||||
RsSerialiser *rss = new RsSerialiser ;
|
||||
rss->addSerialType(new RsChatSerialiser) ;
|
||||
rss->addSerialType(new RsGeneralConfigSerialiser());
|
||||
|
||||
return rss ;
|
||||
}
|
||||
@ -1135,3 +1326,582 @@ void p3ChatService::statusChange(const std::list<pqipeer> &plist)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//********************** Chat Lobby Stuff ***********************//
|
||||
|
||||
bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item)
|
||||
{
|
||||
bool send_challenge = false ;
|
||||
ChatLobbyId send_challenge_lobby ;
|
||||
|
||||
{
|
||||
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
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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<ChatLobbyMsgId,time_t>::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 ;
|
||||
}
|
||||
#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) ;
|
||||
|
||||
// Forward to allparticipating friends, except this peer.
|
||||
|
||||
for(std::set<std::string>::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 ;
|
||||
}
|
||||
|
||||
bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lobby_id)
|
||||
{
|
||||
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.
|
||||
//
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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 ;
|
||||
}
|
||||
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() ) ;
|
||||
|
||||
lobby.msg_cache[item.msg_id] = time(NULL) ; // put the msg in cache!
|
||||
|
||||
item.lobby_id = lobby_id ;
|
||||
item.nick = lobby.nick_name ;
|
||||
|
||||
// chat msg stuff
|
||||
//
|
||||
item.chatFlags = RS_CHAT_FLAG_LOBBY | RS_CHAT_FLAG_PRIVATE;
|
||||
item.sendTime = time(NULL);
|
||||
item.recvTime = item.sendTime;
|
||||
item.message = msg;
|
||||
|
||||
for(std::set<std::string>::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);
|
||||
}
|
||||
|
||||
locked_printDebugInfo() ; // debug
|
||||
return true ;
|
||||
}
|
||||
|
||||
void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item)
|
||||
{
|
||||
// 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 ;
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end() && !found;++it)
|
||||
for(std::map<ChatLobbyMsgId,time_t>::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 ;
|
||||
|
||||
// also add the peer to the list of participating friends
|
||||
it->second.participating_friends.insert(item->PeerId()) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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<ChatLobbyMsgId,time_t>::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.
|
||||
{
|
||||
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 ;
|
||||
}
|
||||
|
||||
if(code == 0)
|
||||
{
|
||||
std::cerr << " No suitable message found in cache. Weird !!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
// Broadcast to all direct friends
|
||||
|
||||
std::list<std::string> ids ;
|
||||
mLinkMgr->getOnlineList(ids);
|
||||
|
||||
for(std::list<std::string>::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)
|
||||
{
|
||||
return ((uint64_t)lobby_id) ^ (uint64_t)msg_id ;
|
||||
}
|
||||
|
||||
void p3ChatService::getChatLobbyList(std::list<ChatLobbyInfo>& linfos)
|
||||
{
|
||||
// fill up a dummy list for now.
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
linfos.clear() ;
|
||||
|
||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::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)
|
||||
{
|
||||
#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 ;
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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) ;
|
||||
}
|
||||
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
|
||||
//
|
||||
// 1.1 - if the lobby is already setup, add the peer to the communicating peers.
|
||||
//
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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.
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void p3ChatService::getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites)
|
||||
{
|
||||
invites.clear() ;
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(std::map<ChatLobbyId,ChatLobbyInvite>::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)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Accepting chat lobby "<< lobby_id << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyInvite>::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 ;
|
||||
}
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << " Creating new Lobby entry." << std::endl;
|
||||
#endif
|
||||
|
||||
ChatLobbyEntry entry ;
|
||||
entry.participating_friends.insert(it->second.peer_id) ;
|
||||
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 ;
|
||||
|
||||
_lobby_invites_queue.erase(it) ; // remove the invite from cache.
|
||||
|
||||
// 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 ;
|
||||
item->msg_id = 0 ;
|
||||
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 ;
|
||||
|
||||
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);
|
||||
|
||||
// send AKN item
|
||||
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 ;
|
||||
}
|
||||
|
||||
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 ******/
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Denying chat lobby invite to "<< lobby_id << std::endl;
|
||||
#endif
|
||||
std::map<ChatLobbyId,ChatLobbyInvite>::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) ;
|
||||
}
|
||||
|
||||
ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::list<std::string>& invited_friends)
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Creating a new Chat lobby !!" << std::endl;
|
||||
#endif
|
||||
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()) ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << " New (unique) ID: " << std::hex << lobby_id << std::dec << std::endl;
|
||||
#endif
|
||||
|
||||
ChatLobbyEntry entry ;
|
||||
entry.participating_friends.clear() ;
|
||||
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 ;
|
||||
}
|
||||
|
||||
for(std::list<std::string>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
|
||||
invitePeerToLobby(lobby_id,*it) ;
|
||||
|
||||
return lobby_id ;
|
||||
}
|
||||
|
||||
void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *item)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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())
|
||||
{
|
||||
std::cerr << "Chat lobby " << item->lobby_id << " does not exist ! Can't unsubscribe!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
for(std::set<std::string>::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 ;
|
||||
}
|
||||
}
|
||||
|
||||
void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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<std::string>::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<std::string,ChatLobbyId>::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)
|
||||
{
|
||||
_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 ******/
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "getting nickname for chat lobby "<< std::hex << lobby_id << std::dec << std::endl;
|
||||
#endif
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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 ******/
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Changing nickname for chat lobby " << std::hex << lobby_id << std::dec << " to " << nick << std::endl;
|
||||
#endif
|
||||
std::map<ChatLobbyId,ChatLobbyEntry>::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 ;
|
||||
}
|
||||
|
||||
void p3ChatService::cleanLobbyCaches()
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "Cleaning chat lobby caches." << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
for(std::map<ChatLobbyId,ChatLobbyEntry>::iterator it = _chat_lobbys.begin();it!=_chat_lobbys.end();++it)
|
||||
for(std::map<ChatLobbyMsgId,time_t>::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<ChatLobbyMsgId,time_t>::iterator tmp(it2) ;
|
||||
++tmp ;
|
||||
it->second.msg_cache.erase(it2) ;
|
||||
it2 = tmp ;
|
||||
}
|
||||
else
|
||||
++it2 ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,6 +153,20 @@ 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<ChatLobbyInfo, std::allocator<ChatLobbyInfo> >&) ;
|
||||
bool acceptLobbyInvite(const ChatLobbyId& id) ;
|
||||
void denyLobbyInvite(const ChatLobbyId& id) ;
|
||||
void getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites) ;
|
||||
void invitePeerToLobby(const ChatLobbyId&, const std::string&) ;
|
||||
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<std::string>& invited_friends) ;
|
||||
|
||||
protected:
|
||||
/************* from p3Config *******************/
|
||||
virtual RsSerialiser *setupSerialiser() ;
|
||||
@ -198,6 +212,20 @@ 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*) ;
|
||||
bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ;
|
||||
void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ;
|
||||
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
|
||||
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;
|
||||
void sendConnectionChallenge(ChatLobbyId id) ;
|
||||
void handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem*) ;
|
||||
void cleanLobbyCaches() ;
|
||||
|
||||
static std::string makeVirtualPeerId(ChatLobbyId) ;
|
||||
static uint64_t makeConnexionChallengeCode(ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ;
|
||||
|
||||
void locked_printDebugInfo() const ;
|
||||
RsChatAvatarItem *makeOwnAvatarItem() ;
|
||||
RsChatStatusItem *makeOwnCustomStateStringItem() ;
|
||||
|
||||
@ -214,6 +242,20 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
|
||||
std::string _custom_status_string ;
|
||||
std::map<std::string,StateStringInfo> _state_strings ;
|
||||
|
||||
class ChatLobbyEntry: public ChatLobbyInfo
|
||||
{
|
||||
public:
|
||||
std::map<ChatLobbyMsgId,time_t> msg_cache ;
|
||||
std::string virtual_peer_id ;
|
||||
int connexion_challenge_count ;
|
||||
};
|
||||
|
||||
std::map<ChatLobbyId,ChatLobbyEntry> _chat_lobbys ;
|
||||
std::map<ChatLobbyId,ChatLobbyInvite> _lobby_invites_queue ;
|
||||
std::map<std::string,ChatLobbyId> _lobby_ids ;
|
||||
std::string _default_nick_name ;
|
||||
time_t last_lobby_challenge_time ; // prevents bruteforce attack
|
||||
};
|
||||
|
||||
class p3ChatService::StateStringInfo
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#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<RsChatMsgItem*>(&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<RsChatMsgItem >(); REPORT("Serialise/Deserialise RsChatMsgItem");
|
||||
test_RsItem<RsChatMsgItem >(); REPORT("Serialise/Deserialise RsPrivateChatMsgConfigItem");
|
||||
test_RsItem<RsChatLobbyMsgItem >(); REPORT("Serialise/Deserialise RsChatLobbyMsgItem");
|
||||
test_RsItem<RsChatLobbyInviteItem >(); REPORT("Serialise/Deserialise RsChatLobbyInviteItem");
|
||||
test_RsItem<RsChatStatusItem >(); REPORT("Serialise/Deserialise RsChatStatusItem");
|
||||
test_RsItem<RsChatAvatarItem >(); REPORT("Serialise/Deserialise RsChatAvatarItem");
|
||||
test_RsItem<RsMsgItem >(); REPORT("Serialise/Deserialise RsMsgItem");
|
||||
|
@ -270,6 +270,8 @@ HEADERS += rshare.h \
|
||||
gui/profile/StatusMessage.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 \
|
||||
@ -407,6 +409,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\
|
||||
@ -530,6 +533,8 @@ SOURCES += main.cpp \
|
||||
gui/channels/ShareKey.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 \
|
||||
|
@ -311,6 +311,28 @@ void FriendsDialog::updateStatusString(const QString& peer_id, const QString& st
|
||||
QTimer::singleShot(5000,this,SLOT(resetStatusBar())) ;
|
||||
}
|
||||
|
||||
void FriendsDialog::readChatLobbyInvites()
|
||||
{
|
||||
std::list<ChatLobbyInvite> invites ;
|
||||
rsMsgs->getPendingChatLobbyInvites(invites) ;
|
||||
|
||||
for(std::list<ChatLobbyInvite>::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 ) ;
|
||||
|
||||
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 ) ;
|
||||
}
|
||||
|
||||
void FriendsDialog::updatePeerStatusString(const QString& peer_id,const QString& status_string,bool is_private_chat)
|
||||
{
|
||||
if(is_private_chat)
|
||||
|
@ -57,6 +57,7 @@ public slots:
|
||||
void insertChat();
|
||||
void setChatInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
|
||||
void resetStatusBar() ;
|
||||
void readChatLobbyInvites() ;
|
||||
|
||||
void fileHashingFinished(QList<HashedFile> hashedFiles);
|
||||
|
||||
|
79
retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp
Normal file
79
retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/****************************************************************
|
||||
*
|
||||
* 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 <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QScrollBar>
|
||||
#include <QCloseEvent>
|
||||
#include <QColorDialog>
|
||||
#include <QDateTime>
|
||||
#include <QFontDialog>
|
||||
#include <QDir>
|
||||
#include <QBuffer>
|
||||
#include <QTextCodec>
|
||||
#include <QSound>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "util/misc.h"
|
||||
#include "rshare.h"
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsmsgs.h>
|
||||
#include <retroshare/rsstatus.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "ChatLobbyDialog.h"
|
||||
|
||||
/** Default constructor */
|
||||
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) ;
|
||||
|
||||
QObject::connect(this,SIGNAL(close()),this,SLOT(closeAndAsk())) ;
|
||||
}
|
||||
|
||||
/** Destructor. */
|
||||
ChatLobbyDialog::~ChatLobbyDialog()
|
||||
{
|
||||
// announce leaving of lobby
|
||||
|
||||
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) ;
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::setNickName(const QString& nick)
|
||||
{
|
||||
rsMsgs->setNickNameForChatLobby(lobby_id,nick.toStdString()) ;
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::updateStatus(const QString &peer_id, int status)
|
||||
{
|
||||
// For now. We need something more efficient to tell when the lobby is disconnected.
|
||||
//
|
||||
}
|
||||
|
66
retroshare-gui/src/gui/chat/ChatLobbyDialog.h
Normal file
66
retroshare-gui/src/gui/chat/ChatLobbyDialog.h
Normal file
@ -0,0 +1,66 @@
|
||||
/****************************************************************
|
||||
* 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 <retroshare/rsmsgs.h>
|
||||
#include "ChatStyle.h"
|
||||
#include "gui/style/RSStyle.h"
|
||||
#include "PopupChatDialog.h"
|
||||
|
||||
class ChatLobbyDialog: public PopupChatDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
/** Default constructor */
|
||||
ChatLobbyDialog(const std::string& id,const ChatLobbyId& lid, 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();
|
||||
|
||||
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&) ;
|
||||
|
||||
private:
|
||||
ChatLobbyId lobby_id ;
|
||||
};
|
||||
|
||||
#endif
|
204
retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp
Normal file
204
retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp
Normal file
@ -0,0 +1,204 @@
|
||||
/****************************************************************
|
||||
* 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 <QMessageBox>
|
||||
#include <algorithm>
|
||||
|
||||
#include <retroshare/rsmsgs.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
|
||||
#include "gui/common/PeerDefs.h"
|
||||
#include "gui/chat/PopupChatDialog.h"
|
||||
|
||||
CreateLobbyDialog::CreateLobbyDialog(const std::list<std::string>& 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);
|
||||
|
||||
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 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( ) ) );
|
||||
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);
|
||||
checkTextFields() ;
|
||||
}
|
||||
|
||||
|
||||
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 ;
|
||||
|
||||
// set nick name !
|
||||
|
||||
rsMsgs->setNickNameForChatLobby(id,ui->nickName_LE->text().toStdString()) ;
|
||||
|
||||
// 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<std::string>& friend_list)
|
||||
{
|
||||
if (!rsPeers)
|
||||
{
|
||||
/* not ready yet! */
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<std::string> peers;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
mShareList.clear() ;
|
||||
rsPeers->getFriendList(peers);
|
||||
|
||||
/* get a link to the table */
|
||||
QTreeWidget *shareWidget = ui->keyShareList;
|
||||
|
||||
QList<QTreeWidgetItem *> 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<std::string>::const_iterator it2(friend_list.begin());it2!=friend_list.end();++it2)
|
||||
if(*it == *it2)
|
||||
{
|
||||
item -> setCheckState(0, Qt::Checked);
|
||||
mShareList.push_back(*it) ;
|
||||
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<std::string>::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;
|
||||
}
|
||||
|
41
retroshare-gui/src/gui/chat/CreateLobbyDialog.h
Normal file
41
retroshare-gui/src/gui/chat/CreateLobbyDialog.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef SHAREKEY_H
|
||||
#define SHAREKEY_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "ui_CreateLobbyDialog.h"
|
||||
|
||||
class CreateLobbyDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/*
|
||||
*@param chanId The channel id to send request for
|
||||
*/
|
||||
CreateLobbyDialog(const std::list<std::string>& 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<std::string>&);
|
||||
|
||||
Ui::CreateLobbyDialog *ui;
|
||||
|
||||
std::string mGrpId;
|
||||
std::list<std::string> mShareList;
|
||||
int mGrpType;
|
||||
|
||||
private slots:
|
||||
|
||||
void createLobby();
|
||||
void checkTextFields();
|
||||
void cancel();
|
||||
void togglePersonItem(QTreeWidgetItem* item, int col);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SHAREKEY_H
|
300
retroshare-gui/src/gui/chat/CreateLobbyDialog.ui
Normal file
300
retroshare-gui/src/gui/chat/CreateLobbyDialog.ui
Normal file
@ -0,0 +1,300 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CreateLobbyDialog</class>
|
||||
<widget class="QDialog" name="CreateLobbyDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>586</width>
|
||||
<height>532</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Create Chat Lobby</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="verticalSpacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>239</width>
|
||||
<height>49</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QFrame#frame{background-image: url(:/images/connect/connectFriendBanner.png);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="margin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../images.qrc">:/images/user/agt_forum64.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="tlShareKey">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><!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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="html">
|
||||
<string><!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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Lobby name:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Your nick name:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lobbyName_LE"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="nickName_LE"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string><!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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDockWidget" name="contactsdockWidget">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>52487</width>
|
||||
<height>524287</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeIncrement">
|
||||
<size>
|
||||
<width>220</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>check peers you would like to share private publish key with</string>
|
||||
</property>
|
||||
<property name="floating">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="features">
|
||||
<set>QDockWidget::NoDockWidgetFeatures</set>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Invited friends</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QGridLayout" name="_2">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeWidget" name="keyShareList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>4</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>1677215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeIncrement">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Contacts:</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="shareButton">
|
||||
<property name="text">
|
||||
<string>Create</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
@ -33,6 +33,7 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "PopupChatDialog.h"
|
||||
#include "ChatLobbyDialog.h"
|
||||
#include "PopupChatWindow.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
#include "util/misc.h"
|
||||
@ -125,7 +126,7 @@ PopupChatDialog::PopupChatDialog(const std::string &id, const QString &name, QWi
|
||||
|
||||
connect(ui.hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
|
||||
|
||||
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)));
|
||||
@ -261,16 +262,35 @@ 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))
|
||||
{
|
||||
std::list<ChatLobbyInfo> linfos;
|
||||
rsMsgs->getChatLobbyList(linfos) ;
|
||||
|
||||
for(std::list<ChatLobbyInfo>::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,6 +357,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()){
|
||||
@ -344,10 +372,16 @@ void PopupChatDialog::chatFriend(const std::string &id)
|
||||
}
|
||||
std::cerr<<" popup dialog chat friend 1"<<std::endl;
|
||||
|
||||
ChatLobbyId lid ;
|
||||
if(rsMsgs->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;
|
||||
|
||||
@ -682,7 +716,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);
|
||||
}
|
||||
@ -695,6 +730,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
|
||||
*/
|
||||
@ -905,6 +945,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();
|
||||
|
@ -46,6 +46,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);
|
||||
@ -58,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 */
|
||||
@ -142,6 +144,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;
|
||||
};
|
||||
|
@ -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"
|
||||
@ -292,143 +293,177 @@ 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("<strong>" + tr("Group") + "</strong>");
|
||||
break;
|
||||
case TYPE_GPG:
|
||||
//this is a GPG key
|
||||
textLabel->setText("<strong>" + tr("Friend") + "</strong>");
|
||||
break;
|
||||
case TYPE_SSL:
|
||||
//this is a SSL key
|
||||
textLabel->setText("<strong>" + tr("Location") + "</strong>");
|
||||
break;
|
||||
}
|
||||
// define header
|
||||
switch (type) {
|
||||
case TYPE_GROUP:
|
||||
//this is a GPG key
|
||||
textLabel->setText("<strong>" + tr("Group") + "</strong>");
|
||||
break;
|
||||
case TYPE_GPG:
|
||||
//this is a GPG key
|
||||
textLabel->setText("<strong>" + tr("Friend") + "</strong>");
|
||||
break;
|
||||
case TYPE_SSL:
|
||||
//this is a SSL key
|
||||
textLabel->setText("<strong>" + tr("Location") + "</strong>");
|
||||
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("Chat lobbies")) ;
|
||||
|
||||
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()));
|
||||
mnu->addAction(QIcon(IMAGE_ADDFRIEND),tr("create new"),this,SLOT(createchatlobby())) ;
|
||||
|
||||
if (type == TYPE_GPG) {
|
||||
contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Recommend this Friend to..."), this, SLOT(recommendfriend()));
|
||||
}
|
||||
// Get existing lobbies
|
||||
//
|
||||
std::list<ChatLobbyInfo> cl_infos ;
|
||||
rsMsgs->getChatLobbyList(cl_infos) ;
|
||||
|
||||
contextMnu.addAction(QIcon(IMAGE_CONNECT), tr("Connect To Friend"), this, SLOT(connectfriend()));
|
||||
for(std::list<ChatLobbyInfo>::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;
|
||||
|
||||
if (type == TYPE_GPG) {
|
||||
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
|
||||
}
|
||||
QMenu *mnu2 = mnu->addMenu(QIcon(IMAGE_CHAT), QString::fromUtf8((*it).lobby_name.c_str())) ;
|
||||
|
||||
QAction *action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste Friend Link"), this, SLOT(pastePerson()));
|
||||
if (RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) {
|
||||
action->setDisabled(true);
|
||||
}
|
||||
QAction* inviteToLobbyAction = new QAction(tr("Invite this friend"), mnu2);
|
||||
inviteToLobbyAction->setData(QString::number((*it).lobby_id));
|
||||
connect(inviteToLobbyAction, SIGNAL(triggered()), this, SLOT(inviteToLobby()));
|
||||
mnu2->addAction(inviteToLobbyAction);
|
||||
|
||||
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()));
|
||||
}
|
||||
QAction* showLobbyAction = new QAction(tr("Show"), mnu2);
|
||||
showLobbyAction->setData(QString::number((*it).lobby_id));
|
||||
connect(showLobbyAction, SIGNAL(triggered()), this, SLOT(showLobby()));
|
||||
mnu2->addAction(showLobbyAction);
|
||||
|
||||
if (mShowGroups && type == TYPE_GPG) {
|
||||
QMenu* addToGroupMenu = NULL;
|
||||
QMenu* moveToGroupMenu = NULL;
|
||||
QAction* unsubscribeToLobbyAction = new QAction(tr("Unsubscribe"), mnu2);
|
||||
unsubscribeToLobbyAction->setData(QString::number((*it).lobby_id));
|
||||
connect(unsubscribeToLobbyAction, SIGNAL(triggered()), this, SLOT(unsubscribeToLobby()));
|
||||
mnu2->addAction(unsubscribeToLobbyAction);
|
||||
}
|
||||
|
||||
std::list<RsGroupInfo> groupInfoList;
|
||||
rsPeers->getGroupInfoList(groupInfoList);
|
||||
contextMnu.addAction(QIcon(IMAGE_MSG), tr("Message Friend"), this, SLOT(msgfriend()));
|
||||
|
||||
GroupDefs::sortByName(groupInfoList);
|
||||
contextMnu.addSeparator();
|
||||
|
||||
std::string gpgId = getRsId(c);
|
||||
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()));
|
||||
|
||||
QTreeWidgetItem *parent = c->parent();
|
||||
if (type == TYPE_GPG) {
|
||||
contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Recommend this Friend to..."), this, SLOT(recommendfriend()));
|
||||
}
|
||||
|
||||
bool foundGroup = false;
|
||||
// add action for all groups, except the own group
|
||||
for (std::list<RsGroupInfo>::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);
|
||||
}
|
||||
contextMnu.addAction(QIcon(IMAGE_CONNECT), tr("Connect To Friend"), this, SLOT(connectfriend()));
|
||||
|
||||
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 (type == TYPE_GPG) {
|
||||
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
|
||||
}
|
||||
|
||||
if (addToGroupMenu || moveToGroupMenu || foundGroup) {
|
||||
QMenu *groupsMenu = contextMnu.addMenu(QIcon(IMAGE_GROUP16), tr("Groups"));
|
||||
QAction *action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste Friend Link"), this, SLOT(pastePerson()));
|
||||
if (RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) {
|
||||
action->setDisabled(true);
|
||||
}
|
||||
|
||||
if (addToGroupMenu) {
|
||||
groupsMenu->addMenu(addToGroupMenu);
|
||||
}
|
||||
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) {
|
||||
groupsMenu->addMenu(moveToGroupMenu);
|
||||
}
|
||||
if (mShowGroups && type == TYPE_GPG) {
|
||||
QMenu* addToGroupMenu = NULL;
|
||||
QMenu* moveToGroupMenu = NULL;
|
||||
|
||||
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()));
|
||||
}
|
||||
std::list<RsGroupInfo> groupInfoList;
|
||||
rsPeers->getGroupInfoList(groupInfoList);
|
||||
|
||||
QAction *removeFromAllGroups = groupsMenu->addAction(tr("Remove from all groups"));
|
||||
removeFromAllGroups->setData("");
|
||||
connect(removeFromAllGroups, SIGNAL(triggered()), this, SLOT(removeFromGroup()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GroupDefs::sortByName(groupInfoList);
|
||||
|
||||
std::string gpgId = getRsId(c);
|
||||
|
||||
QTreeWidgetItem *parent = c->parent();
|
||||
|
||||
bool foundGroup = false;
|
||||
// add action for all groups, except the own group
|
||||
for (std::list<RsGroupInfo>::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 +1406,80 @@ void FriendList::configurefriend()
|
||||
ConfCertDialog::showIt(getRsId(getCurrentPeer()), ConfCertDialog::PageDetails);
|
||||
}
|
||||
|
||||
void FriendList::showLobby()
|
||||
{
|
||||
std::string lobby_id = qobject_cast<QAction*>(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<QAction*>(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<br>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();
|
||||
|
||||
if (c == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (c->type() != TYPE_SSL) {
|
||||
// wrong type
|
||||
return;
|
||||
}
|
||||
|
||||
std::string lobby_id = qobject_cast<QAction*>(sender())->data().toString().toStdString();
|
||||
|
||||
if(lobby_id.empty())
|
||||
return;
|
||||
|
||||
std::string peer_id = getRsId(c) ;
|
||||
|
||||
// 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()
|
||||
{
|
||||
QTreeWidgetItem *c = getCurrentPeer();
|
||||
|
||||
if (c == NULL)
|
||||
return;
|
||||
|
||||
std::list<std::string> friend_list ;
|
||||
|
||||
std::string peer_id = getRsId(c) ;
|
||||
friend_list.push_back(peer_id) ;
|
||||
|
||||
CreateLobbyDialog(friend_list).exec() ;
|
||||
}
|
||||
|
||||
void FriendList::addToGroup()
|
||||
{
|
||||
QTreeWidgetItem *c = getCurrentPeer();
|
||||
|
@ -122,6 +122,11 @@ private slots:
|
||||
|
||||
void editGroup();
|
||||
void removeGroup();
|
||||
|
||||
void inviteToLobby();
|
||||
void createchatlobby();
|
||||
void unsubscribeToLobby();
|
||||
void showLobby();
|
||||
};
|
||||
|
||||
#endif // FRIENDLIST_H
|
||||
|
@ -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 ;
|
||||
|
@ -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);
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "rsharesettings.h"
|
||||
|
||||
#include <retroshare/rshistory.h>
|
||||
#include <retroshare/rsmsgs.h>
|
||||
|
||||
#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()
|
||||
|
@ -521,35 +521,89 @@
|
||||
<property name="title">
|
||||
<string>Chat Settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_emoteprivchat">
|
||||
<property name="text">
|
||||
<string>Enable Emoticons Privat Chat</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_emoteprivchat">
|
||||
<property name="text">
|
||||
<string>Enable Emoticons Privat Chat</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_emotegroupchat">
|
||||
<property name="text">
|
||||
<string>Enable Emoticons Group Chat</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="sendMessageWithCtrlReturn">
|
||||
<property name="text">
|
||||
<string>Send message with Ctrl+Return</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Default nickname for chat lobbies:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Maximum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="chatLobbyNick_LE">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_emotegroupchat">
|
||||
<property name="text">
|
||||
<string>Enable Emoticons Group Chat</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="sendMessageWithCtrlReturn">
|
||||
<property name="text">
|
||||
<string>Send message with Ctrl+Return</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBoxIRCColors">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
|
@ -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) ));
|
||||
|
Loading…
x
Reference in New Issue
Block a user