Merge pull request #3764 from annando/contact-blocked

Preparation for the possibility to globally block contacts
This commit is contained in:
Tobias Diekershoff 2017-10-07 13:10:39 +00:00 committed by GitHub
commit 0f1b27db1e
3 changed files with 54 additions and 1 deletions

View File

@ -695,6 +695,44 @@ function get_contact($url, $uid = 0, $no_update = false) {
return $contact_id;
}
/**
* @brief Checks if the contact is blocked
*
* @param int $cid contact id
*
* @return boolean Is the contact blocked?
*/
function blockedContact($cid) {
if ($cid == 0) {
return false;
}
$blocked = dba::select('contact', array('blocked'), array('id' => $cid), array('limit' => 1));
if (!dbm::is_result($blocked)) {
return false;
}
return (bool)$blocked['blocked'];
}
/**
* @brief Checks if the contact is hidden
*
* @param int $cid contact id
*
* @return boolean Is the contact hidden?
*/
function hiddenContact($cid) {
if ($cid == 0) {
return false;
}
$hidden = dba::select('contact', array('hidden'), array('id' => $cid), array('limit' => 1));
if (!dbm::is_result($hidden)) {
return false;
}
return (bool)$hidden['hidden'];
}
/**
* @brief Returns posts from a given gcontact
*

View File

@ -761,10 +761,20 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
$arr["author-id"] = get_contact($arr["author-link"], 0);
}
if (blockedContact($arr["author-id"])) {
logger('Contact '.$arr["author-id"].' is blocked, item '.$arr["uri"].' will not be stored');
return 0;
}
if ($arr["owner-id"] == 0) {
$arr["owner-id"] = get_contact($arr["owner-link"], 0);
}
if (blockedContact($arr["owner-id"])) {
logger('Contact '.$arr["owner-id"].' is blocked, item '.$arr["uri"].' will not be stored');
return 0;
}
if ($arr['guid'] != "") {
// Checking if there is already an item with the same guid
logger('checking for an item for user '.$arr['uid'].' on network '.$arr['network'].' with the guid '.$arr['guid'], LOGGER_DEBUG);

View File

@ -32,7 +32,7 @@ function add_thread($itemid, $onlyshadow = false) {
* @param integer $itemid Item ID that should be added
*/
function add_shadow_thread($itemid) {
$items = q("SELECT `uid`, `wall`, `private`, `moderated`, `visible`, `contact-id`, `deleted`, `network`
$items = q("SELECT `uid`, `wall`, `private`, `moderated`, `visible`, `contact-id`, `deleted`, `network`, `author-id`, `owner-id`
FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!dbm::is_result($items)) {
@ -56,6 +56,11 @@ function add_shadow_thread($itemid) {
return;
}
// Is the public contact configured as hidden?
if (hiddenContact($item["owner-id"]) || hiddenContact($item["author-id"])) {
return;
}
// Only do these checks if the post isn't a wall post
if (!$item["wall"]) {
// Check, if hide-friends is activated - then don't do a shadow entry