Improve ignoring of messages

This commit is contained in:
Michael 2023-01-09 16:23:39 +00:00
parent 214838ea3b
commit 840f25cc5c
9 changed files with 121 additions and 21 deletions

View file

@ -374,6 +374,22 @@ function item_content(App $a)
Contact\User::setBlocked($item['author-id'], DI::userSession()->getLocalUserId(), true);
if (DI::mode()->isAjax()) {
// ajax return: [<item id>, 0 (no perm) | <owner id>]
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);
} else {
item_redirect_after_action($item, $args->get(3));
}
break;
case 'ignore':
$item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]);
if (empty($item['author-id'])) {
throw new HTTPException\NotFoundException('Item not found');
}
Contact\User::setIgnored($item['author-id'], DI::userSession()->getLocalUserId(), true);
if (DI::mode()->isAjax()) {
// ajax return: [<item id>, 0 (no perm) | <owner id>]
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);

View file

@ -245,6 +245,7 @@ class Page implements ArrayAccess
'$generator' => 'Friendica' . ' ' . App::VERSION,
'$delitem' => $l10n->t('Delete this item?'),
'$blockAuthor' => $l10n->t('Block this author? They won\'t be able to follow you nor see your public posts, and you won\'t be able to see their posts and their notifications.'),
'$ignoreAuthor' => $l10n->t('Ignore this author? You won\'t be able to see their posts and their notifications.'),
'$update_interval' => $interval,
'$shortcut_icon' => $shortcut_icon,
'$touch_icon' => $touch_icon,

View file

@ -1333,6 +1333,19 @@ class Item
$transmit = $notify || ($posted_item['visible'] && ($parent_origin || $posted_item['origin']));
if ($transmit) {
if ($posted_item['uid'] && Contact\User::isBlocked($posted_item['author-id'], $posted_item['uid'])) {
Logger::info('Message from blocked author will not be relayed', ['item' => $posted_item['id'], 'uri' => $posted_item['uri'], 'cid' => $posted_item['author-id']]);
$transmit = false;
}
if ($transmit && $posted_item['uid'] && Contact\User::isBlocked($posted_item['owner-id'], $posted_item['uid'])) {
Logger::info('Message from blocked owner will not be relayed', ['item' => $posted_item['id'], 'uri' => $posted_item['uri'], 'cid' => $posted_item['owner-id']]);
$transmit = false;
}
if ($transmit && !empty($posted_item['causer-id']) && $posted_item['uid'] && Contact\User::isBlocked($posted_item['causer-id'], $posted_item['uid'])) {
Logger::info('Message from blocked causer will not be relayed', ['item' => $posted_item['id'], 'uri' => $posted_item['uri'], 'cid' => $posted_item['causer-id']]);
$transmit = false;
}
// Don't relay participation messages
if (($posted_item['verb'] == Activity::FOLLOW) &&
(!$posted_item['origin'] || ($posted_item['author-id'] != Contact::getPublicIdByUserId($uid)))) {
@ -3720,7 +3733,17 @@ class Item
return false;
}
if (!empty($item['causer-id']) && ($item['gravity'] === self::GRAVITY_PARENT) && Contact\User::isIgnored($item['causer-id'], $user_id)) {
if (!empty($item['author-id']) && Contact\User::isIgnored($item['author-id'], $user_id)) {
Logger::notice('Author is ignored by user', ['author-link' => $item['author-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
if (!empty($item['owner-id']) && Contact\User::isIgnored($item['owner-id'], $user_id)) {
Logger::notice('Owner is ignored by user', ['owner-link' => $item['owner-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
if (!empty($item['causer-id']) && Contact\User::isIgnored($item['causer-id'], $user_id)) {
Logger::notice('Causer is ignored by user', ['causer-link' => $item['causer-link'] ?? $item['causer-id'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}

View file

@ -412,13 +412,13 @@ class Post
AND NOT `author-blocked` AND NOT `owner-blocked`
AND (NOT `causer-blocked` OR `causer-id` = ? OR `causer-id` IS NULL) AND NOT `contact-blocked`
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
OR `self` OR `gravity` != ? OR `contact-uid` = ?)
OR `self` OR `contact-uid` = ?)
AND NOT `" . $view . "`.`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `hidden`)
AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `author-id`)
AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `owner-id`)
AND NOT (`gravity` = ? AND `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `author-id`))
AND NOT (`gravity` = ? AND `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `owner-id`))",
0, Contact::SHARING, Contact::FRIEND, Item::GRAVITY_PARENT, 0, $uid, $uid, $uid, Item::GRAVITY_PARENT, $uid, Item::GRAVITY_PARENT, $uid]);
AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `author-id`)
AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `owner-id`)",
0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid, $uid, $uid]);
$select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));

View file

@ -133,7 +133,8 @@ class UserNotification
public static function setNotification(int $uri_id, int $uid)
{
$fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity', 'vid', 'gravity',
'private', 'contact-id', 'thr-parent', 'thr-parent-id', 'parent-uri-id', 'parent-uri', 'author-id', 'verb'];
'contact-id', 'author-id', 'owner-id', 'causer-id',
'private', 'thr-parent', 'thr-parent-id', 'parent-uri-id', 'parent-uri', 'verb'];
$item = Post::selectFirst($fields, ['uri-id' => $uri_id, 'uid' => $uid, 'origin' => false]);
if (!DBA::isResult($item)) {
return;
@ -174,6 +175,18 @@ class UserNotification
*/
private static function setNotificationForUser(array $item, int $uid)
{
if (Contact\User::isBlocked($item['author-id'], $uid) || Contact\User::isIgnored($item['author-id'], $uid) || Contact\User::isCollapsed($item['author-id'], $uid)) {
return;
}
if (Contact\User::isBlocked($item['owner-id'], $uid) || Contact\User::isIgnored($item['owner-id'], $uid) || Contact\User::isCollapsed($item['owner-id'], $uid)) {
return;
}
if (!empty($item['causer-id']) && (Contact\User::isBlocked($item['causer-id'], $uid) || Contact\User::isIgnored($item['causer-id'], $uid) || Contact\User::isCollapsed($item['causer-id'], $uid))) {
return;
}
if (Post\ThreadUser::getIgnored($item['parent-uri-id'], $uid)) {
return;
}

View file

@ -191,7 +191,7 @@ class Post
$pinned = '';
$pin = false;
$star = false;
$ignore = false;
$ignore_thread = false;
$ispinned = 'unpinned';
$isstarred = 'unstarred';
$indent = '';
@ -248,6 +248,7 @@ class Post
$drop = false;
$block = false;
$ignore = false;
if (DI::userSession()->getLocalUserId()) {
$drop = [
'dropping' => $dropping,
@ -263,6 +264,11 @@ class Post
'block' => DI::l10n()->t('Block %s', $item['author-name']),
'author_id' => $item['author-id'],
];
$ignore = [
'ignoring' => true,
'ignore' => DI::l10n()->t('Ignore %s', $item['author-name']),
'author_id' => $item['author-id'],
];
}
$filer = DI::userSession()->getLocalUserId() ? DI::l10n()->t('Save to folder') : false;
@ -327,14 +333,14 @@ class Post
if ($this->isToplevel()) {
if (DI::userSession()->getLocalUserId()) {
$ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], DI::userSession()->getLocalUserId());
if ($item['mention'] || $ignored) {
$ignore = [
$ignored_thread = PostModel\ThreadUser::getIgnored($item['uri-id'], DI::userSession()->getLocalUserId());
if ($item['mention'] || $ignored_thread) {
$ignore_thread = [
'do' => DI::l10n()->t('Ignore thread'),
'undo' => DI::l10n()->t('Unignore thread'),
'toggle' => DI::l10n()->t('Toggle ignore status'),
'classdo' => $ignored ? 'hidden' : '',
'classundo' => $ignored ? '' : 'hidden',
'classdo' => $ignored_thread ? 'hidden' : '',
'classundo' => $ignored_thread ? '' : 'hidden',
'ignored' => DI::l10n()->t('Ignored'),
];
}
@ -518,12 +524,13 @@ class Post
'pinned' => $pinned,
'isstarred' => $isstarred,
'star' => $star,
'ignore' => $ignore,
'ignore' => $ignore_thread,
'tagger' => $tagger,
'filer' => $filer,
'language' => $languages,
'drop' => $drop,
'block' => $block,
'ignore_author' => $ignore,
'vote' => $buttons,
'like_html' => $responses['like']['output'],
'dislike_html' => $responses['dislike']['output'],

View file

@ -202,6 +202,10 @@ function confirmBlock() {
return confirm(aStr.blockAuthor);
}
function confirmIgnore() {
return confirm(aStr.ignoreAuthor);
}
/**
* Hide and removes an item element from the DOM after the deletion url is
* successful, restore it else.
@ -258,4 +262,34 @@ function blockAuthor(url, elementId) {
});
}
}
/**
* Ignored an author and hide and removes an item element from the DOM after the block is
* successful, restore it else.
*
* @param {string} url The item removal URL
* @param {string} elementId The DOM id of the item element
* @returns {undefined}
*/
function ignoreAuthor(url, elementId) {
if (confirmIgnore()) {
$("body").css("cursor", "wait");
var $el = $(document.getElementById(elementId));
$el.fadeTo("fast", 0.33, function () {
$.get(url)
.then(function () {
$el.remove();
})
.fail(function () {
// @todo Show related error message
$el.show();
})
.always(function () {
$("body").css("cursor", "auto");
});
});
}
}
// @license-end

View file

@ -8,5 +8,6 @@ They are loaded into the html <head> so that js functions can use them *}}
var aStr = {
'delitem' : "{{$delitem|escape:'javascript' nofilter}}",
'blockAuthor' : "{{$blockAuthor|escape:'javascript' nofilter}}",
'ignoreAuthor' : "{{$ignoreAuthor|escape:'javascript' nofilter}}",
};
</script>

View file

@ -404,6 +404,11 @@ as the value of $top_child_total (this is done at the end of this file)
<a class="btn-link navicon block" href="javascript:blockAuthor('item/block/{{$item.id}}/{{$item.return}}', 'item-{{$item.guid}}');" title="{{$item.block.block}}"><i class="fa fa-ban" aria-hidden="true"></i> {{$item.block.block}}</a>
</li>
{{/if}}
{{if $item.ignore_author}}
<li role="menuitem">
<a class="btn-link navicon ignore" href="javascript:ignoreAuthor('item/ignore/{{$item.id}}/{{$item.return}}', 'item-{{$item.guid}}');" title="{{$item.ignore_author.ignore}}"><i class="fa fa-ban" aria-hidden="true"></i> {{$item.ignore_author.ignore}}</a>
</li>
{{/if}}
</ul>
<img id="like-rotator-{{$item.id}}" class="like-rotator" src="images/rotator.gif" alt="{{$item.wait}}" title="{{$item.wait}}" style="display: none;" />
</span>