mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-28 10:32:22 -04:00
added backend for distant message and distant chat filtering based on contact list
This commit is contained in:
parent
f5c2aa31e3
commit
140205108a
20 changed files with 373 additions and 180 deletions
|
@ -212,6 +212,13 @@ uint32_t p3IdService::idAuthenPolicy()
|
|||
|
||||
return policy;
|
||||
}
|
||||
|
||||
bool p3IdService::isARegularContact(const RsGxsId& id)
|
||||
{
|
||||
RsStackMutex stack(mIdMtx);
|
||||
return mContacts.find(id) != mContacts.end() ;
|
||||
}
|
||||
|
||||
bool p3IdService::setAsRegularContact(const RsGxsId& id,bool b)
|
||||
{
|
||||
std::set<RsGxsId>::iterator it = mContacts.find(id) ;
|
||||
|
|
|
@ -266,6 +266,7 @@ virtual bool getRecognTagRequest(const RsGxsId &id, const std::string &comment,
|
|||
uint16_t tag_class, uint16_t tag_type, std::string &tag);
|
||||
|
||||
virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ;
|
||||
virtual bool isARegularContact(const RsGxsId& id) ;
|
||||
|
||||
/**************** RsGixs Implementation ***************/
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ p3MsgService::p3MsgService(p3ServiceControl *sc, p3IdService *id_serv)
|
|||
|
||||
mShouldEnableDistantMessaging = true ;
|
||||
mDistantMessagingEnabled = false ;
|
||||
mDistantMessagePermissions = RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NONE ;
|
||||
|
||||
/* Initialize standard tag types */
|
||||
if(sc)
|
||||
|
@ -468,6 +469,10 @@ bool p3MsgService::saveList(bool& cleanup, std::list<RsItem*>& itemList)
|
|||
kv.key = "DISTANT_MESSAGES_ENABLED" ;
|
||||
kv.value = mShouldEnableDistantMessaging?"YES":"NO" ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
kv.key = "DISTANT_MESSAGE_PERMISSION_FLAGS" ;
|
||||
kv.value = RsUtil::NumberToString(mDistantMessagePermissions) ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
itemList.push_back(vitem) ;
|
||||
|
||||
|
@ -558,13 +563,13 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
|||
mMsgUniqueId = mitem->msgId + 1;
|
||||
}
|
||||
items.push_back(mitem);
|
||||
}
|
||||
else if (NULL != (grm = dynamic_cast<RsMsgGRouterMap *>(*it)))
|
||||
{
|
||||
// merge.
|
||||
for(std::map<GRouterMsgPropagationId,uint32_t>::const_iterator it(grm->ongoing_msgs.begin());it!=grm->ongoing_msgs.end();++it)
|
||||
_ongoing_messages.insert(*it) ;
|
||||
}
|
||||
}
|
||||
else if (NULL != (grm = dynamic_cast<RsMsgGRouterMap *>(*it)))
|
||||
{
|
||||
// merge.
|
||||
for(std::map<GRouterMsgPropagationId,uint32_t>::const_iterator it(grm->ongoing_msgs.begin());it!=grm->ongoing_msgs.end();++it)
|
||||
_ongoing_messages.insert(*it) ;
|
||||
}
|
||||
else if(NULL != (mtt = dynamic_cast<RsMsgTagType *>(*it)))
|
||||
{
|
||||
// delete standard tags as they are now save in config
|
||||
|
@ -574,7 +579,7 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
|||
}
|
||||
else
|
||||
{
|
||||
delete mTags[mtt->tagId];
|
||||
delete mTags[mtt->tagId];
|
||||
mTags.erase(tagIt);
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType* >(mtt->tagId, mtt));
|
||||
}
|
||||
|
@ -586,7 +591,7 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
|||
}
|
||||
else if(NULL != (msi = dynamic_cast<RsMsgSrcId *>(*it)))
|
||||
{
|
||||
srcIdMsgMap.insert(std::pair<uint32_t, RsPeerId>(msi->msgId, msi->srcId));
|
||||
srcIdMsgMap.insert(std::pair<uint32_t, RsPeerId>(msi->msgId, msi->srcId));
|
||||
mSrcIds.insert(std::pair<uint32_t, RsMsgSrcId*>(msi->msgId, msi)); // does not need to be kept
|
||||
}
|
||||
else if(NULL != (msp = dynamic_cast<RsMsgParentId *>(*it)))
|
||||
|
@ -598,13 +603,33 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
|||
|
||||
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 == "DISTANT_MESSAGES_ENABLED")
|
||||
{
|
||||
if(kit->key == "DISTANT_MESSAGES_ENABLED")
|
||||
{
|
||||
#ifdef MSG_DEBUG
|
||||
std::cerr << "Loaded config default nick name for distant chat: " << kit->value << std::endl ;
|
||||
#endif
|
||||
mShouldEnableDistantMessaging = (kit->value == "YES") ;
|
||||
}
|
||||
mShouldEnableDistantMessaging = (kit->value == "YES") ;
|
||||
}
|
||||
if(kit->key == "DISTANT_MESSAGE_PERMISSION_FLAGS")
|
||||
{
|
||||
#ifdef MSG_DEBUG
|
||||
std::cerr << "Loaded distant message permission flags: " << kit->value << std::endl ;
|
||||
#endif
|
||||
if (!kit->value.empty())
|
||||
{
|
||||
std::istringstream is(kit->value) ;
|
||||
|
||||
uint32_t tmp ;
|
||||
is >> tmp ;
|
||||
|
||||
if(tmp < 3)
|
||||
mDistantMessagePermissions = tmp ;
|
||||
else
|
||||
std::cerr << "(EE) Invalid value read for DistantMessagePermission flags in config: " << tmp << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1791,6 +1816,32 @@ void p3MsgService::notifyDataStatus(const GRouterMsgPropagationId& id,uint32_t d
|
|||
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD);
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
bool p3MsgService::acceptDataFromPeer(const RsGxsId& to_gxs_id)
|
||||
{
|
||||
if(mDistantMessagePermissions & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_NON_CONTACTS)
|
||||
return (rsIdentity!=NULL) && rsIdentity->isARegularContact(to_gxs_id) ;
|
||||
|
||||
if(mDistantMessagePermissions & RS_DISTANT_MESSAGING_CONTACT_PERMISSION_FLAG_FILTER_EVERYBODY)
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void p3MsgService::setDistantMessagingPermissionFlags(uint32_t flags)
|
||||
{
|
||||
if(flags != mDistantMessagePermissions)
|
||||
{
|
||||
mDistantMessagePermissions = flags ;
|
||||
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t p3MsgService::getDistantMessagingPermissionFlags()
|
||||
{
|
||||
return mDistantMessagePermissions ;
|
||||
}
|
||||
|
||||
void p3MsgService::receiveGRouterData(const RsGxsId& destination_key, const RsGxsId& signing_key,GRouterServiceId& client_id,uint8_t *data,uint32_t data_size)
|
||||
{
|
||||
std::cerr << "p3MsgService::receiveGRouterData(): received message item of size " << data_size << ", for key " << destination_key << std::endl;
|
||||
|
|
|
@ -126,8 +126,9 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
|
|||
};
|
||||
void enableDistantMessaging(bool b) ;
|
||||
bool distantMessagingEnabled() ;
|
||||
void setDistantMessagingPermissionFlags(uint32_t flags) {}
|
||||
uint32_t getDistantMessagingPermissionFlags() { return 0 ;}
|
||||
|
||||
void setDistantMessagingPermissionFlags(uint32_t flags) ;
|
||||
uint32_t getDistantMessagingPermissionFlags() ;
|
||||
|
||||
private:
|
||||
void sendDistantMsgItem(RsMsgItem *msgitem) ;
|
||||
|
@ -139,6 +140,7 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
|
|||
|
||||
// Overloaded from GRouterClientService
|
||||
|
||||
virtual bool acceptDataFromPeer(const RsGxsId& gxs_id) ;
|
||||
virtual void receiveGRouterData(const RsGxsId& destination_key,const RsGxsId& signing_key, GRouterServiceId &client_id, uint8_t *data, uint32_t data_size) ;
|
||||
virtual void notifyDataStatus(const GRouterMsgPropagationId& msg_id,uint32_t data_status) ;
|
||||
|
||||
|
@ -205,6 +207,7 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor,
|
|||
std::string config_dir;
|
||||
|
||||
bool mDistantMessagingEnabled ;
|
||||
uint32_t mDistantMessagePermissions ;
|
||||
bool mShouldEnableDistantMessaging ;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue