Improved block behaviour

This commit is contained in:
Michael 2024-10-20 07:50:08 +00:00
parent 7e84699bdd
commit d867d73a23
18 changed files with 309 additions and 128 deletions

View file

@ -1590,11 +1590,15 @@ class Contact
*/
public static function getPostsFromId(int $cid, int $uid, bool $only_media = false, string $last_created = null): string
{
$contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
$contact = DBA::selectFirst('contact', ['contact-type', 'network', 'name', 'nick'], ['id' => $cid]);
if (!DBA::isResult($contact)) {
return '';
}
if (Contact\User::isIsBlocked($cid, $uid)) {
return DI::l10n()->t('%s has blocked you', $contact['name'] ?: $contact['nick']);
}
if (empty($contact["network"]) || in_array($contact["network"], Protocol::FEDERATED)) {
$condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))", $uid];
} else {
@ -1658,11 +1662,15 @@ class Contact
*/
public static function getThreadsFromId(int $cid, int $uid, int $update = 0, int $parent = 0, string $last_created = ''): string
{
$contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
$contact = DBA::selectFirst('contact', ['contact-type', 'network', 'name', 'nick'], ['id' => $cid]);
if (!DBA::isResult($contact)) {
return '';
}
if (Contact\User::isIsBlocked($cid, $uid)) {
return DI::l10n()->t('%s has blocked you', $contact['name'] ?: $contact['nick']);
}
if (empty($contact["network"]) || in_array($contact["network"], Protocol::FEDERATED)) {
$condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))", $uid];
} else {

View file

@ -9,7 +9,7 @@ namespace Friendica\Model\Contact;
use Exception;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
@ -140,13 +140,21 @@ class User
$contact = Contact::getById($cdata['public']);
if ($blocked) {
Protocol::block($contact, $uid);
Worker::add(Worker::PRIORITY_HIGH, 'Contact\Block', $cid, $uid);
} else {
Protocol::unblock($contact, $uid);
Worker::add(Worker::PRIORITY_HIGH, 'Contact\Unblock', $cid, $uid);
}
if ($cdata['user'] != 0) {
DBA::update('contact', ['blocked' => $blocked], ['id' => $cdata['user'], 'pending' => false]);
if ($blocked) {
$contact = Contact::getById($cdata['user']);
if (!empty($contact)) {
// Mastodon-expected behavior: relationship is severed on block
Contact::terminateFriendship($contact);
}
}
}
DBA::update('user-contact', ['blocked' => $blocked], ['cid' => $cdata['public'], 'uid' => $uid], true);

View file

@ -465,7 +465,7 @@ class Post
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
OR `self` OR `contact-uid` = ?)
AND NOT EXISTS(SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `uri-id` = " . DBA::quoteIdentifier($view) . ".`uri-id` AND `hidden`)
AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` IN (`author-id`, `owner-id`) AND (`blocked` OR `ignored`))
AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` IN (`author-id`, `owner-id`) AND (`blocked` OR `ignored` OR `is-blocked`))
AND NOT EXISTS(SELECT `gsid` FROM `user-gserver` WHERE `uid` = ? AND `gsid` IN (`author-gsid`, `owner-gsid`, `causer-gsid`) AND `ignored`)",
0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid]);