mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Patch (modified) from Phenom to allow auto-subscribe to chat lobbies
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6466 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9f88917ac1
commit
7414659bd9
@ -57,6 +57,7 @@ template<int n> class t_RsFlags32
|
|||||||
#define FLAGS_TAG_FILE_STORAGE 0x184738
|
#define FLAGS_TAG_FILE_STORAGE 0x184738
|
||||||
#define FLAGS_TAG_FILE_SEARCH 0xf29ba5
|
#define FLAGS_TAG_FILE_SEARCH 0xf29ba5
|
||||||
#define FLAGS_TAG_SERVICE_PERM 0x380912
|
#define FLAGS_TAG_SERVICE_PERM 0x380912
|
||||||
|
#define FLAGS_TAG_SERVICE_CHAT 0x839042
|
||||||
|
|
||||||
// Flags for requesting transfers, ask for turtle, cache, speed, etc.
|
// Flags for requesting transfers, ask for turtle, cache, speed, etc.
|
||||||
//
|
//
|
||||||
@ -74,3 +75,7 @@ typedef t_RsFlags32<FLAGS_TAG_FILE_SEARCH > FileSearchFlags ;
|
|||||||
//
|
//
|
||||||
typedef t_RsFlags32<FLAGS_TAG_SERVICE_PERM > ServicePermissionFlags ;
|
typedef t_RsFlags32<FLAGS_TAG_SERVICE_PERM > ServicePermissionFlags ;
|
||||||
|
|
||||||
|
// Flags for chat lobbies
|
||||||
|
//
|
||||||
|
typedef t_RsFlags32<FLAGS_TAG_SERVICE_CHAT > ChatLobbyFlags ;
|
||||||
|
|
||||||
|
@ -77,6 +77,8 @@
|
|||||||
#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC 1 /* lobby is visible by friends. Friends can connect.*/
|
#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC 1 /* lobby is visible by friends. Friends can connect.*/
|
||||||
#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE 2 /* lobby invisible by friends. Peers on invitation only .*/
|
#define RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE 2 /* lobby invisible by friends. Peers on invitation only .*/
|
||||||
|
|
||||||
|
const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE( 0x00000001 ) ;
|
||||||
|
|
||||||
typedef uint64_t ChatLobbyId ;
|
typedef uint64_t ChatLobbyId ;
|
||||||
typedef uint64_t ChatLobbyMsgId ;
|
typedef uint64_t ChatLobbyMsgId ;
|
||||||
typedef std::string ChatLobbyNickName ;
|
typedef std::string ChatLobbyNickName ;
|
||||||
@ -321,6 +323,8 @@ virtual bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::stri
|
|||||||
virtual bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,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 setDefaultNickNameForChatLobby(const std::string& nick) = 0;
|
||||||
virtual bool getDefaultNickNameForChatLobby(std::string& nick) = 0 ;
|
virtual bool getDefaultNickNameForChatLobby(std::string& nick) = 0 ;
|
||||||
|
virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe) = 0 ;
|
||||||
|
virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id) = 0 ;
|
||||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<std::string>& invited_friends,uint32_t lobby_privacy_type) = 0 ;
|
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<std::string>& invited_friends,uint32_t lobby_privacy_type) = 0 ;
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
@ -332,6 +332,17 @@ ChatLobbyId p3Msgs::createChatLobby(const std::string& lobby_name,const std::str
|
|||||||
return mChatSrv->createChatLobby(lobby_name,lobby_topic,invited_friends,privacy_type) ;
|
return mChatSrv->createChatLobby(lobby_name,lobby_topic,invited_friends,privacy_type) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3Msgs::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe)
|
||||||
|
{
|
||||||
|
mChatSrv->setLobbyAutoSubscribe(lobby_id, autoSubscribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3Msgs::getLobbyAutoSubscribe(const ChatLobbyId& lobby_id)
|
||||||
|
{
|
||||||
|
return mChatSrv->getLobbyAutoSubscribe(lobby_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool p3Msgs::acceptLobbyInvite(const ChatLobbyId& id)
|
bool p3Msgs::acceptLobbyInvite(const ChatLobbyId& id)
|
||||||
{
|
{
|
||||||
return mChatSrv->acceptLobbyInvite(id) ;
|
return mChatSrv->acceptLobbyInvite(id) ;
|
||||||
|
@ -185,6 +185,8 @@ class p3Msgs: public RsMsgs
|
|||||||
virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ;
|
virtual bool getNickNameForChatLobby(const ChatLobbyId&,std::string& nick) ;
|
||||||
virtual bool setDefaultNickNameForChatLobby(const std::string&) ;
|
virtual bool setDefaultNickNameForChatLobby(const std::string&) ;
|
||||||
virtual bool getDefaultNickNameForChatLobby(std::string& nick) ;
|
virtual bool getDefaultNickNameForChatLobby(std::string& nick) ;
|
||||||
|
virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe);
|
||||||
|
virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
|
||||||
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
|
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
|
||||||
|
|
||||||
virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) ;
|
virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) ;
|
||||||
|
@ -211,8 +211,18 @@ std::ostream& RsPrivateChatDistantInviteConfigItem::print(std::ostream &out, uin
|
|||||||
printRsItemEnd(out, "RsPrivateChatDistantInviteConfigItem", indent);
|
printRsItemEnd(out, "RsPrivateChatDistantInviteConfigItem", indent);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
std::ostream& RsChatLobbyConfigItem::print(std::ostream &out, uint16_t indent)
|
||||||
|
{
|
||||||
|
printRsItemBase(out, "RsChatLobbyConfigItem", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
printIndent(out, int_Indent);
|
||||||
|
out << "lobby_Id: " << lobby_Id << std::endl;
|
||||||
|
out << "flags : " << flags << std::endl;
|
||||||
|
|
||||||
|
printRsItemEnd(out, "RsChatLobbyConfigItem", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
std::ostream& RsChatStatusItem::print(std::ostream &out, uint16_t indent)
|
std::ostream& RsChatStatusItem::print(std::ostream &out, uint16_t indent)
|
||||||
{
|
{
|
||||||
printRsItemBase(out, "RsChatStatusItem", indent);
|
printRsItemBase(out, "RsChatStatusItem", indent);
|
||||||
@ -281,6 +291,7 @@ RsItem *RsChatSerialiser::deserialise(void *data, uint32_t *pktsize)
|
|||||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem(data,*pktsize) ;
|
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem(data,*pktsize) ;
|
||||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_deprecated: return new RsChatLobbyListItem_deprecated(data,*pktsize) ;
|
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_deprecated: return new RsChatLobbyListItem_deprecated(data,*pktsize) ;
|
||||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_deprecated2:return new RsChatLobbyListItem_deprecated2(data,*pktsize) ;
|
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_deprecated2:return new RsChatLobbyListItem_deprecated2(data,*pktsize) ;
|
||||||
|
case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem(data,*pktsize) ;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Unknown packet type in chat!" << std::endl ;
|
std::cerr << "Unknown packet type in chat!" << std::endl ;
|
||||||
return NULL ;
|
return NULL ;
|
||||||
@ -441,6 +452,16 @@ uint32_t RsChatAvatarItem::serial_size()
|
|||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
uint32_t RsChatLobbyConfigItem::serial_size()
|
||||||
|
{
|
||||||
|
uint32_t s = 8; /* header */
|
||||||
|
s += 8;/* lobby_Id */
|
||||||
|
s += 4;/* flags */
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************/
|
||||||
|
|
||||||
RsChatAvatarItem::~RsChatAvatarItem()
|
RsChatAvatarItem::~RsChatAvatarItem()
|
||||||
{
|
{
|
||||||
@ -942,6 +963,43 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize)
|
||||||
|
{
|
||||||
|
uint32_t tlvsize = serial_size() ;
|
||||||
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
if (pktsize < tlvsize)
|
||||||
|
return false; /* not enough space */
|
||||||
|
|
||||||
|
pktsize = tlvsize;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
|
||||||
|
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "RsChatLobbyConfigItem::serialiseItem() Header: " << ok << std::endl;
|
||||||
|
std::cerr << "RsChatLobbyConfigItem::serialiseItem() Size: " << tlvsize << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
/* add mandatory parts first */
|
||||||
|
ok &= setRawUInt64(data, tlvsize, &offset, lobby_Id);
|
||||||
|
ok &= setRawUInt32(data, tlvsize, &offset, flags );
|
||||||
|
|
||||||
|
if (offset != tlvsize)
|
||||||
|
{
|
||||||
|
ok = false;
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "RsChatLobbyConfigItem::serialise() Size Error! " << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/,uint8_t subtype)
|
RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/,uint8_t subtype)
|
||||||
: RsChatItem(subtype)
|
: RsChatItem(subtype)
|
||||||
{
|
{
|
||||||
@ -1234,6 +1292,25 @@ RsPrivateChatDistantInviteConfigItem::RsPrivateChatDistantInviteConfigItem(void
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||||
}
|
}
|
||||||
|
RsChatLobbyConfigItem::RsChatLobbyConfigItem(void *data,uint32_t /*size*/)
|
||||||
|
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG)
|
||||||
|
{
|
||||||
|
uint32_t offset = 8; // skip the header
|
||||||
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
bool ok = true ;
|
||||||
|
|
||||||
|
/* get mandatory parts first */
|
||||||
|
ok &= getRawUInt64(data, rssize, &offset, &lobby_Id);
|
||||||
|
ok &= getRawUInt32(data, rssize, &offset, &flags);
|
||||||
|
|
||||||
|
#ifdef CHAT_DEBUG
|
||||||
|
std::cerr << "Building new chat msg config 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 ;
|
||||||
|
}
|
||||||
|
|
||||||
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
||||||
void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const std::string &/*peerId*/, uint32_t confFlags)
|
void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const std::string &/*peerId*/, uint32_t confFlags)
|
||||||
|
@ -66,6 +66,7 @@ const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_EVENT = 0x10 ;
|
|||||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_deprecated2 = 0x11 ; // to be removed (deprecated since 02 Dec. 2012)
|
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_deprecated2 = 0x11 ; // to be removed (deprecated since 02 Dec. 2012)
|
||||||
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST = 0x12 ;
|
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_LIST = 0x12 ;
|
||||||
const uint8_t RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG = 0x13 ;
|
const uint8_t RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG = 0x13 ;
|
||||||
|
const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG = 0x15 ;
|
||||||
|
|
||||||
// for defining tags themselves and msg tags
|
// for defining tags themselves and msg tags
|
||||||
const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03;
|
const uint8_t RS_PKT_SUBTYPE_MSG_TAG_TYPE = 0x03;
|
||||||
@ -337,7 +338,23 @@ class RsPrivateChatDistantInviteConfigItem: public RsChatItem
|
|||||||
uint32_t time_of_validity ;
|
uint32_t time_of_validity ;
|
||||||
uint32_t last_hit_time ;
|
uint32_t last_hit_time ;
|
||||||
};
|
};
|
||||||
|
class RsChatLobbyConfigItem: public RsChatItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsChatLobbyConfigItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG) { lobby_Id = 0; }
|
||||||
|
RsChatLobbyConfigItem(void *data,uint32_t size) ; // deserialization
|
||||||
|
|
||||||
|
virtual ~RsChatLobbyConfigItem() {}
|
||||||
|
|
||||||
|
virtual void clear() { lobby_Id = 0; }
|
||||||
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
uint64_t lobby_Id;
|
||||||
|
uint32_t flags ;
|
||||||
|
};
|
||||||
|
|
||||||
// This class contains activity info for the sending peer: active, idle, typing, etc.
|
// This class contains activity info for the sending peer: active, idle, typing, etc.
|
||||||
//
|
//
|
||||||
|
@ -399,6 +399,11 @@ void p3ChatService::locked_printDebugInfo() const
|
|||||||
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
|
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
|
||||||
std::cerr << " With friend: " << *it2 << std::endl;
|
std::cerr << " With friend: " << *it2 << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cerr << "Chat lobby flags: " << std::endl;
|
||||||
|
|
||||||
|
for( std::map<ChatLobbyId,ChatLobbyFlags>::const_iterator it(_known_lobbies_flags.begin()) ;it!=_known_lobbies_flags.end();++it)
|
||||||
|
std::cerr << " \"" << std::hex << it->first << "\" flags = " << it->second << std::dec << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id)
|
bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id)
|
||||||
@ -840,6 +845,8 @@ void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem_deprecated2 *ite
|
|||||||
}
|
}
|
||||||
void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
||||||
{
|
{
|
||||||
|
std::list<ChatLobbyId> chatLobbyToSubscribe;
|
||||||
|
|
||||||
{
|
{
|
||||||
time_t now = time(NULL) ;
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
@ -851,7 +858,7 @@ void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
|||||||
|
|
||||||
rec.lobby_id = item->lobby_ids[i] ;
|
rec.lobby_id = item->lobby_ids[i] ;
|
||||||
rec.lobby_name = item->lobby_names[i] ;
|
rec.lobby_name = item->lobby_names[i] ;
|
||||||
rec.lobby_topic = item->lobby_topics[i] ;
|
rec.lobby_topic = item->lobby_topics[i] ;
|
||||||
rec.participating_friends.insert(item->PeerId()) ;
|
rec.participating_friends.insert(item->PeerId()) ;
|
||||||
|
|
||||||
if(_should_reset_lobby_counts)
|
if(_should_reset_lobby_counts)
|
||||||
@ -861,9 +868,21 @@ void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
|
|||||||
|
|
||||||
rec.last_report_time = now ;
|
rec.last_report_time = now ;
|
||||||
rec.lobby_privacy_level = item->lobby_privacy_levels[i] ;
|
rec.lobby_privacy_level = item->lobby_privacy_levels[i] ;
|
||||||
|
|
||||||
|
std::map<ChatLobbyId,ChatLobbyFlags>::const_iterator it(_known_lobbies_flags.find(item->lobby_ids[i])) ;
|
||||||
|
|
||||||
|
if(it != _known_lobbies_flags.end() && (it->second & RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE))
|
||||||
|
{
|
||||||
|
ChatLobbyId clid = item->lobby_ids[i];
|
||||||
|
chatLobbyToSubscribe.push_back(clid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<ChatLobbyId>::iterator it;
|
||||||
|
for (it = chatLobbyToSubscribe.begin(); it != chatLobbyToSubscribe.end(); it++)
|
||||||
|
joinVisibleChatLobby(*it);
|
||||||
|
|
||||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
||||||
_should_reset_lobby_counts = false ;
|
_should_reset_lobby_counts = false ;
|
||||||
}
|
}
|
||||||
@ -1782,6 +1801,11 @@ bool p3ChatService::loadList(std::list<RsItem*>& load)
|
|||||||
_default_nick_name = kit->value ;
|
_default_nick_name = kit->value ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsChatLobbyConfigItem *cas = NULL ;
|
||||||
|
|
||||||
|
if(NULL != (cas = dynamic_cast<RsChatLobbyConfigItem*>(*it)))
|
||||||
|
_known_lobbies_flags[cas->lobby_Id] = ChatLobbyFlags(cas->flags) ;
|
||||||
|
|
||||||
// delete unknown items
|
// delete unknown items
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
@ -1855,6 +1879,17 @@ bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& list)
|
|||||||
|
|
||||||
list.push_back(vitem) ;
|
list.push_back(vitem) ;
|
||||||
|
|
||||||
|
/* Save Lobby Auto Subscribe */
|
||||||
|
for(std::map<ChatLobbyId,ChatLobbyFlags>::const_iterator it=_known_lobbies_flags.begin();it!=_known_lobbies_flags.end();++it)
|
||||||
|
{
|
||||||
|
RsChatLobbyConfigItem *cas = new RsChatLobbyConfigItem ;
|
||||||
|
cas->lobby_Id=it->first;
|
||||||
|
cas->flags=it->second.toUInt32();
|
||||||
|
|
||||||
|
list.push_back(cas) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2747,6 +2782,25 @@ bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const st
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3ChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe)
|
||||||
|
{
|
||||||
|
if(autoSubscribe)
|
||||||
|
_known_lobbies_flags[lobby_id] |= RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
|
||||||
|
else
|
||||||
|
_known_lobbies_flags[lobby_id] &= ~RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
|
||||||
|
|
||||||
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
|
||||||
|
IndicateConfigChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3ChatService::getLobbyAutoSubscribe(const ChatLobbyId& lobby_id)
|
||||||
|
{
|
||||||
|
if(_known_lobbies_flags.find(lobby_id) == _known_lobbies_flags.end()) // keep safe about default values form std::map
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return _known_lobbies_flags[lobby_id] & RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
|
||||||
|
}
|
||||||
|
|
||||||
void p3ChatService::cleanLobbyCaches()
|
void p3ChatService::cleanLobbyCaches()
|
||||||
{
|
{
|
||||||
#ifdef CHAT_DEBUG
|
#ifdef CHAT_DEBUG
|
||||||
@ -3127,7 +3181,7 @@ void p3ChatService::sendTurtleData(RsChatItem *item)
|
|||||||
gitem->data_bytes = malloc(gitem->data_size) ;
|
gitem->data_bytes = malloc(gitem->data_size) ;
|
||||||
|
|
||||||
memcpy(gitem->data_bytes ,&IV,8) ;
|
memcpy(gitem->data_bytes ,&IV,8) ;
|
||||||
memcpy(gitem->data_bytes+8,encrypted_data,encrypted_size) ;
|
memcpy(& (((uint8_t*)gitem->data_bytes)[8]),encrypted_data,encrypted_size) ;
|
||||||
|
|
||||||
delete[] encrypted_data ;
|
delete[] encrypted_data ;
|
||||||
delete item ;
|
delete item ;
|
||||||
|
@ -169,6 +169,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
|||||||
bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ;
|
bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ;
|
||||||
bool setDefaultNickNameForChatLobby(const std::string& nick) ;
|
bool setDefaultNickNameForChatLobby(const std::string& nick) ;
|
||||||
bool getDefaultNickNameForChatLobby(std::string& nick) ;
|
bool getDefaultNickNameForChatLobby(std::string& nick) ;
|
||||||
|
void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe);
|
||||||
|
bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
|
||||||
void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ;
|
void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ;
|
||||||
ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic, const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
|
ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic, const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
|
||||||
|
|
||||||
@ -286,12 +288,18 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
|||||||
time_t last_connexion_challenge_time ;
|
time_t last_connexion_challenge_time ;
|
||||||
time_t last_keep_alive_packet_time ;
|
time_t last_keep_alive_packet_time ;
|
||||||
std::set<std::string> previously_known_peers ;
|
std::set<std::string> previously_known_peers ;
|
||||||
|
uint32_t flags ;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<ChatLobbyId,ChatLobbyEntry> _chat_lobbys ;
|
std::map<ChatLobbyId,ChatLobbyEntry> _chat_lobbys ;
|
||||||
std::map<ChatLobbyId,ChatLobbyInvite> _lobby_invites_queue ;
|
std::map<ChatLobbyId,ChatLobbyInvite> _lobby_invites_queue ;
|
||||||
std::map<ChatLobbyId,VisibleChatLobbyRecord> _visible_lobbies ;
|
std::map<ChatLobbyId,VisibleChatLobbyRecord> _visible_lobbies ;
|
||||||
std::map<std::string,ChatLobbyId> _lobby_ids ;
|
std::map<std::string,ChatLobbyId> _lobby_ids ;
|
||||||
|
std::map<ChatLobbyId,ChatLobbyFlags> _known_lobbies_flags ; // flags for all lobbies, including the ones that are not known. So we can't
|
||||||
|
// store them in _chat_lobbies (subscribed lobbies) nor _visible_lobbies.
|
||||||
|
// Known flags:
|
||||||
|
// RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE
|
||||||
|
|
||||||
std::string _default_nick_name ;
|
std::string _default_nick_name ;
|
||||||
float _time_shift_average ;
|
float _time_shift_average ;
|
||||||
time_t last_lobby_challenge_time ; // prevents bruteforce attack
|
time_t last_lobby_challenge_time ; // prevents bruteforce attack
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#define ROLE_ID Qt::UserRole + 1
|
#define ROLE_ID Qt::UserRole + 1
|
||||||
#define ROLE_SUBSCRIBED Qt::UserRole + 2
|
#define ROLE_SUBSCRIBED Qt::UserRole + 2
|
||||||
#define ROLE_PRIVACYLEVEL Qt::UserRole + 3
|
#define ROLE_PRIVACYLEVEL Qt::UserRole + 3
|
||||||
|
#define ROLE_AUTOSUBSCRIBE Qt::UserRole + 4
|
||||||
|
|
||||||
|
|
||||||
#define TYPE_FOLDER 0
|
#define TYPE_FOLDER 0
|
||||||
#define TYPE_LOBBY 1
|
#define TYPE_LOBBY 1
|
||||||
@ -38,6 +40,7 @@
|
|||||||
#define IMAGE_PEER_LEAVING ":images/user/remove_user24.png"
|
#define IMAGE_PEER_LEAVING ":images/user/remove_user24.png"
|
||||||
#define IMAGE_TYPING ":images/typing.png"
|
#define IMAGE_TYPING ":images/typing.png"
|
||||||
#define IMAGE_MESSAGE ":images/chat.png"
|
#define IMAGE_MESSAGE ":images/chat.png"
|
||||||
|
#define IMAGE_AUTOSUBSCRIBE ":images/accepted16.png"
|
||||||
|
|
||||||
ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags)
|
ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags)
|
||||||
: RsAutoUpdatePage(5000, parent, flags)
|
: RsAutoUpdatePage(5000, parent, flags)
|
||||||
@ -138,6 +141,11 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint)
|
|||||||
} else {
|
} else {
|
||||||
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Subscribe"), this, SLOT(subscribeItem()));
|
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Subscribe"), this, SLOT(subscribeItem()));
|
||||||
}
|
}
|
||||||
|
if (item->data(COLUMN_DATA, ROLE_AUTOSUBSCRIBE).toBool()) {
|
||||||
|
contextMnu.addAction(QIcon(IMAGE_AUTOSUBSCRIBE), tr("Remove Auto Subscribe"), this, SLOT(autoSubscribeItem()));
|
||||||
|
} else {
|
||||||
|
contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Add Auto Subscribe"), this, SLOT(autoSubscribeItem()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contextMnu.children().count() == 0) {
|
if (contextMnu.children().count() == 0) {
|
||||||
@ -152,7 +160,7 @@ void ChatLobbyWidget::lobbyChanged()
|
|||||||
updateDisplay();
|
updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateItem(QTreeWidgetItem *item, ChatLobbyId id, const std::string &name, const std::string &topic, int count, bool subscribed)
|
static void updateItem(QTreeWidgetItem *item, ChatLobbyId id, const std::string &name, const std::string &topic, int count, bool subscribed, bool autoSubscribe)
|
||||||
{
|
{
|
||||||
item->setText(COLUMN_NAME, QString::fromUtf8(name.c_str()));
|
item->setText(COLUMN_NAME, QString::fromUtf8(name.c_str()));
|
||||||
item->setData(COLUMN_NAME, ROLE_SORT, QString::fromUtf8(name.c_str()));
|
item->setData(COLUMN_NAME, ROLE_SORT, QString::fromUtf8(name.c_str()));
|
||||||
@ -172,6 +180,7 @@ static void updateItem(QTreeWidgetItem *item, ChatLobbyId id, const std::string
|
|||||||
|
|
||||||
item->setData(COLUMN_DATA, ROLE_ID, (qulonglong)id);
|
item->setData(COLUMN_DATA, ROLE_ID, (qulonglong)id);
|
||||||
item->setData(COLUMN_DATA, ROLE_SUBSCRIBED, subscribed);
|
item->setData(COLUMN_DATA, ROLE_SUBSCRIBED, subscribed);
|
||||||
|
item->setData(COLUMN_DATA, ROLE_AUTOSUBSCRIBE, autoSubscribe);
|
||||||
|
|
||||||
QColor color = QApplication::palette().color(QPalette::Active, QPalette::Text);
|
QColor color = QApplication::palette().color(QPalette::Active, QPalette::Text);
|
||||||
if (!subscribed) {
|
if (!subscribed) {
|
||||||
@ -311,7 +320,23 @@ void ChatLobbyWidget::updateDisplay()
|
|||||||
subscribed = true;
|
subscribed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed);
|
bool autoSubscribe = rsMsgs->getLobbyAutoSubscribe(lobby.lobby_id);
|
||||||
|
|
||||||
|
if (autoSubscribe && subscribed)
|
||||||
|
{
|
||||||
|
if(_lobby_infos.find(lobby.lobby_id) == _lobby_infos.end())
|
||||||
|
{
|
||||||
|
if (item == lobbyTreeWidget->currentItem())
|
||||||
|
{
|
||||||
|
ChatDialog::chatFriend(vpid) ;
|
||||||
|
}else{
|
||||||
|
ChatDialog::chatFriend(vpid,false) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed, autoSubscribe);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// time_t now = time(NULL) ;
|
// time_t now = time(NULL) ;
|
||||||
@ -358,7 +383,9 @@ void ChatLobbyWidget::updateDisplay()
|
|||||||
// item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE));
|
// item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.nick_names.size(), true);
|
bool autoSubscribe = rsMsgs->getLobbyAutoSubscribe(lobby.lobby_id);
|
||||||
|
|
||||||
|
updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.nick_names.size(), true, autoSubscribe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,11 +426,23 @@ static void subscribeLobby(QTreeWidgetItem *item)
|
|||||||
if (rsMsgs->joinVisibleChatLobby(id)) {
|
if (rsMsgs->joinVisibleChatLobby(id)) {
|
||||||
std::string vpeer_id;
|
std::string vpeer_id;
|
||||||
if (rsMsgs->getVirtualPeerId(id, vpeer_id)) {
|
if (rsMsgs->getVirtualPeerId(id, vpeer_id)) {
|
||||||
ChatDialog::chatFriend(vpeer_id) ;
|
ChatDialog::chatFriend(vpeer_id,true) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatLobbyWidget::autoSubscribeLobby(QTreeWidgetItem *item)
|
||||||
|
{
|
||||||
|
if (item == NULL && item->type() != TYPE_LOBBY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
|
||||||
|
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
|
||||||
|
rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
|
||||||
|
if (!isAutoSubscribe) subscribeLobby(item);
|
||||||
|
}
|
||||||
|
|
||||||
void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
|
void ChatLobbyWidget::showBlankPage(ChatLobbyId id)
|
||||||
{
|
{
|
||||||
// show the default blank page.
|
// show the default blank page.
|
||||||
@ -439,6 +478,11 @@ void ChatLobbyWidget::subscribeItem()
|
|||||||
subscribeLobby(lobbyTreeWidget->currentItem());
|
subscribeLobby(lobbyTreeWidget->currentItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatLobbyWidget::autoSubscribeItem()
|
||||||
|
{
|
||||||
|
autoSubscribeLobby(lobbyTreeWidget->currentItem());
|
||||||
|
}
|
||||||
|
|
||||||
QTreeWidgetItem *ChatLobbyWidget::getTreeWidgetItem(ChatLobbyId id)
|
QTreeWidgetItem *ChatLobbyWidget::getTreeWidgetItem(ChatLobbyId id)
|
||||||
{
|
{
|
||||||
for(int p=0;p<2;++p)
|
for(int p=0;p<2;++p)
|
||||||
@ -539,6 +583,9 @@ void ChatLobbyWidget::unsubscribeChatLobby(ChatLobbyId id)
|
|||||||
ChatDialog::closeChat(vpeer_id);
|
ChatDialog::closeChat(vpeer_id);
|
||||||
|
|
||||||
rsMsgs->unsubscribeChatLobby(id);
|
rsMsgs->unsubscribeChatLobby(id);
|
||||||
|
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
|
||||||
|
if (isAutoSubscribe) rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatLobbyWidget::updateCurrentLobby()
|
void ChatLobbyWidget::updateCurrentLobby()
|
||||||
@ -605,7 +652,7 @@ void ChatLobbyWidget::readChatLobbyInvites()
|
|||||||
|
|
||||||
std::string vpid;
|
std::string vpid;
|
||||||
if(rsMsgs->getVirtualPeerId((*it).lobby_id,vpid )) {
|
if(rsMsgs->getVirtualPeerId((*it).lobby_id,vpid )) {
|
||||||
ChatDialog::chatFriend(vpid);
|
ChatDialog::chatFriend(vpid,true);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "No lobby known with id 0x" << std::hex << (*it).lobby_id << std::dec << std::endl;
|
std::cerr << "No lobby known with id 0x" << std::hex << (*it).lobby_id << std::dec << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,11 @@ protected slots:
|
|||||||
void updateMessageChanged(ChatLobbyId);
|
void updateMessageChanged(ChatLobbyId);
|
||||||
void updatePeerEntering(ChatLobbyId);
|
void updatePeerEntering(ChatLobbyId);
|
||||||
void updatePeerLeaving(ChatLobbyId);
|
void updatePeerLeaving(ChatLobbyId);
|
||||||
|
void autoSubscribeItem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void autoSubscribeLobby(QTreeWidgetItem *item);
|
||||||
|
|
||||||
RSTreeWidgetItemCompareRole *compareRole;
|
RSTreeWidgetItemCompareRole *compareRole;
|
||||||
QTreeWidgetItem *privateLobbyItem;
|
QTreeWidgetItem *privateLobbyItem;
|
||||||
QTreeWidgetItem *publicLobbyItem;
|
QTreeWidgetItem *publicLobbyItem;
|
||||||
|
@ -95,7 +95,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
|
|||||||
ChatLobbyId lobby_id = 0;
|
ChatLobbyId lobby_id = 0;
|
||||||
|
|
||||||
if (rsMsgs->isLobbyId(peerId, lobby_id)) {
|
if (rsMsgs->isLobbyId(peerId, lobby_id)) {
|
||||||
chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags
|
// chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t distant_peer_status ;
|
uint32_t distant_peer_status ;
|
||||||
@ -211,7 +211,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ void ChatDialog::chatFriend(const std::string &peerId)
|
/*static*/ void ChatDialog::chatFriend(const std::string &peerId, const bool forceFocus)
|
||||||
{
|
{
|
||||||
if (peerId.empty()){
|
if (peerId.empty()){
|
||||||
return;
|
return;
|
||||||
@ -222,14 +222,13 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
|
|||||||
|
|
||||||
if(rsMsgs->getDistantChatStatus(peerId,distant_peer_status,distant_chat_pgp_id))
|
if(rsMsgs->getDistantChatStatus(peerId,distant_peer_status,distant_chat_pgp_id))
|
||||||
{
|
{
|
||||||
getChat(peerId,RS_CHAT_OPEN | RS_CHAT_FOCUS); // use own flags
|
getChat(peerId, forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN ); // use own flags
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatLobbyId lid;
|
ChatLobbyId lid;
|
||||||
if (rsMsgs->isLobbyId(peerId, lid)) {
|
if (rsMsgs->isLobbyId(peerId, lid)) {
|
||||||
getChat(peerId, RS_CHAT_OPEN | RS_CHAT_FOCUS);
|
getChat(peerId, (forceFocus ? (RS_CHAT_OPEN | RS_CHAT_FOCUS) : RS_CHAT_OPEN));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsPeerDetails detail;
|
RsPeerDetails detail;
|
||||||
@ -245,7 +244,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
|
|||||||
|
|
||||||
if (sslIds.size() == 1) {
|
if (sslIds.size() == 1) {
|
||||||
// chat with the one ssl id (online or offline)
|
// chat with the one ssl id (online or offline)
|
||||||
getChat(sslIds.front(), RS_CHAT_OPEN | RS_CHAT_FOCUS);
|
getChat(sslIds.front(), forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +257,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
|
|||||||
|
|
||||||
if (onlineIds.size() == 1) {
|
if (onlineIds.size() == 1) {
|
||||||
// chat with the online ssl id
|
// chat with the online ssl id
|
||||||
getChat(onlineIds.front(), RS_CHAT_OPEN | RS_CHAT_FOCUS);
|
getChat(onlineIds.front(), forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +266,7 @@ void ChatDialog::init(const std::string &peerId, const QString &title)
|
|||||||
mb.setWindowIcon(QIcon(":/images/rstray3.png"));
|
mb.setWindowIcon(QIcon(":/images/rstray3.png"));
|
||||||
mb.exec();
|
mb.exec();
|
||||||
} else {
|
} else {
|
||||||
getChat(peerId, RS_CHAT_OPEN | RS_CHAT_FOCUS);
|
getChat(peerId, forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
static ChatDialog *getExistingChat(const std::string &peerId);
|
static ChatDialog *getExistingChat(const std::string &peerId);
|
||||||
static ChatDialog *getChat(const std::string &peerId, uint chatflags);
|
static ChatDialog *getChat(const std::string &peerId, uint chatflags);
|
||||||
static void cleanupChat();
|
static void cleanupChat();
|
||||||
static void chatFriend(const std::string &peerId);
|
static void chatFriend(const std::string &peerId, bool forceFocus = true);
|
||||||
static void closeChat(const std::string &peerId);
|
static void closeChat(const std::string &peerId);
|
||||||
static void chatChanged(int list, int type);
|
static void chatChanged(int list, int type);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user