Improve ignoring of messages
This commit is contained in:
parent
214838ea3b
commit
840f25cc5c
9 changed files with 121 additions and 21 deletions
16
mod/item.php
16
mod/item.php
|
@ -374,6 +374,22 @@ function item_content(App $a)
|
||||||
|
|
||||||
Contact\User::setBlocked($item['author-id'], DI::userSession()->getLocalUserId(), true);
|
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()) {
|
if (DI::mode()->isAjax()) {
|
||||||
// ajax return: [<item id>, 0 (no perm) | <owner id>]
|
// ajax return: [<item id>, 0 (no perm) | <owner id>]
|
||||||
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);
|
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);
|
||||||
|
|
|
@ -245,6 +245,7 @@ class Page implements ArrayAccess
|
||||||
'$generator' => 'Friendica' . ' ' . App::VERSION,
|
'$generator' => 'Friendica' . ' ' . App::VERSION,
|
||||||
'$delitem' => $l10n->t('Delete this item?'),
|
'$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.'),
|
'$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,
|
'$update_interval' => $interval,
|
||||||
'$shortcut_icon' => $shortcut_icon,
|
'$shortcut_icon' => $shortcut_icon,
|
||||||
'$touch_icon' => $touch_icon,
|
'$touch_icon' => $touch_icon,
|
||||||
|
|
|
@ -1333,6 +1333,19 @@ class Item
|
||||||
$transmit = $notify || ($posted_item['visible'] && ($parent_origin || $posted_item['origin']));
|
$transmit = $notify || ($posted_item['visible'] && ($parent_origin || $posted_item['origin']));
|
||||||
|
|
||||||
if ($transmit) {
|
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
|
// Don't relay participation messages
|
||||||
if (($posted_item['verb'] == Activity::FOLLOW) &&
|
if (($posted_item['verb'] == Activity::FOLLOW) &&
|
||||||
(!$posted_item['origin'] || ($posted_item['author-id'] != Contact::getPublicIdByUserId($uid)))) {
|
(!$posted_item['origin'] || ($posted_item['author-id'] != Contact::getPublicIdByUserId($uid)))) {
|
||||||
|
@ -3720,7 +3733,17 @@ class Item
|
||||||
return false;
|
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']]);
|
Logger::notice('Causer is ignored by user', ['causer-link' => $item['causer-link'] ?? $item['causer-id'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,13 +412,13 @@ class Post
|
||||||
AND NOT `author-blocked` AND NOT `owner-blocked`
|
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 `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 (?, ?)))
|
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 `" . $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 `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 `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 `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`))",
|
AND NOT `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]);
|
0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid, $uid, $uid]);
|
||||||
|
|
||||||
$select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
|
$select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,8 @@ class UserNotification
|
||||||
public static function setNotification(int $uri_id, int $uid)
|
public static function setNotification(int $uri_id, int $uid)
|
||||||
{
|
{
|
||||||
$fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity', 'vid', 'gravity',
|
$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]);
|
$item = Post::selectFirst($fields, ['uri-id' => $uri_id, 'uid' => $uid, 'origin' => false]);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
return;
|
return;
|
||||||
|
@ -174,6 +175,18 @@ class UserNotification
|
||||||
*/
|
*/
|
||||||
private static function setNotificationForUser(array $item, int $uid)
|
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)) {
|
if (Post\ThreadUser::getIgnored($item['parent-uri-id'], $uid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ class Post
|
||||||
$pinned = '';
|
$pinned = '';
|
||||||
$pin = false;
|
$pin = false;
|
||||||
$star = false;
|
$star = false;
|
||||||
$ignore = false;
|
$ignore_thread = false;
|
||||||
$ispinned = 'unpinned';
|
$ispinned = 'unpinned';
|
||||||
$isstarred = 'unstarred';
|
$isstarred = 'unstarred';
|
||||||
$indent = '';
|
$indent = '';
|
||||||
|
@ -246,8 +246,9 @@ class Post
|
||||||
// Showing the one or the other text, depending upon if we can only hide it or really delete it.
|
// Showing the one or the other text, depending upon if we can only hide it or really delete it.
|
||||||
$delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
|
$delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
|
||||||
|
|
||||||
$drop = false;
|
$drop = false;
|
||||||
$block = false;
|
$block = false;
|
||||||
|
$ignore = false;
|
||||||
if (DI::userSession()->getLocalUserId()) {
|
if (DI::userSession()->getLocalUserId()) {
|
||||||
$drop = [
|
$drop = [
|
||||||
'dropping' => $dropping,
|
'dropping' => $dropping,
|
||||||
|
@ -259,9 +260,14 @@ class Post
|
||||||
|
|
||||||
if (!$item['self'] && DI::userSession()->getLocalUserId()) {
|
if (!$item['self'] && DI::userSession()->getLocalUserId()) {
|
||||||
$block = [
|
$block = [
|
||||||
'blocking' => true,
|
'blocking' => true,
|
||||||
'block' => DI::l10n()->t('Block %s', $item['author-name']),
|
'block' => DI::l10n()->t('Block %s', $item['author-name']),
|
||||||
'author_id' => $item['author-id'],
|
'author_id' => $item['author-id'],
|
||||||
|
];
|
||||||
|
$ignore = [
|
||||||
|
'ignoring' => true,
|
||||||
|
'ignore' => DI::l10n()->t('Ignore %s', $item['author-name']),
|
||||||
|
'author_id' => $item['author-id'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,14 +333,14 @@ class Post
|
||||||
|
|
||||||
if ($this->isToplevel()) {
|
if ($this->isToplevel()) {
|
||||||
if (DI::userSession()->getLocalUserId()) {
|
if (DI::userSession()->getLocalUserId()) {
|
||||||
$ignored = PostModel\ThreadUser::getIgnored($item['uri-id'], DI::userSession()->getLocalUserId());
|
$ignored_thread = PostModel\ThreadUser::getIgnored($item['uri-id'], DI::userSession()->getLocalUserId());
|
||||||
if ($item['mention'] || $ignored) {
|
if ($item['mention'] || $ignored_thread) {
|
||||||
$ignore = [
|
$ignore_thread = [
|
||||||
'do' => DI::l10n()->t('Ignore thread'),
|
'do' => DI::l10n()->t('Ignore thread'),
|
||||||
'undo' => DI::l10n()->t('Unignore thread'),
|
'undo' => DI::l10n()->t('Unignore thread'),
|
||||||
'toggle' => DI::l10n()->t('Toggle ignore status'),
|
'toggle' => DI::l10n()->t('Toggle ignore status'),
|
||||||
'classdo' => $ignored ? 'hidden' : '',
|
'classdo' => $ignored_thread ? 'hidden' : '',
|
||||||
'classundo' => $ignored ? '' : 'hidden',
|
'classundo' => $ignored_thread ? '' : 'hidden',
|
||||||
'ignored' => DI::l10n()->t('Ignored'),
|
'ignored' => DI::l10n()->t('Ignored'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -518,12 +524,13 @@ class Post
|
||||||
'pinned' => $pinned,
|
'pinned' => $pinned,
|
||||||
'isstarred' => $isstarred,
|
'isstarred' => $isstarred,
|
||||||
'star' => $star,
|
'star' => $star,
|
||||||
'ignore' => $ignore,
|
'ignore' => $ignore_thread,
|
||||||
'tagger' => $tagger,
|
'tagger' => $tagger,
|
||||||
'filer' => $filer,
|
'filer' => $filer,
|
||||||
'language' => $languages,
|
'language' => $languages,
|
||||||
'drop' => $drop,
|
'drop' => $drop,
|
||||||
'block' => $block,
|
'block' => $block,
|
||||||
|
'ignore_author' => $ignore,
|
||||||
'vote' => $buttons,
|
'vote' => $buttons,
|
||||||
'like_html' => $responses['like']['output'],
|
'like_html' => $responses['like']['output'],
|
||||||
'dislike_html' => $responses['dislike']['output'],
|
'dislike_html' => $responses['dislike']['output'],
|
||||||
|
|
|
@ -202,6 +202,10 @@ function confirmBlock() {
|
||||||
return confirm(aStr.blockAuthor);
|
return confirm(aStr.blockAuthor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function confirmIgnore() {
|
||||||
|
return confirm(aStr.ignoreAuthor);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide and removes an item element from the DOM after the deletion url is
|
* Hide and removes an item element from the DOM after the deletion url is
|
||||||
* successful, restore it else.
|
* 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
|
// @license-end
|
||||||
|
|
|
@ -6,7 +6,8 @@ They are loaded into the html <head> so that js functions can use them *}}
|
||||||
|
|
||||||
var localUser = {{if $local_user}}{{$local_user}}{{else}}false{{/if}};
|
var localUser = {{if $local_user}}{{$local_user}}{{else}}false{{/if}};
|
||||||
var aStr = {
|
var aStr = {
|
||||||
'delitem' : "{{$delitem|escape:'javascript' nofilter}}",
|
'delitem' : "{{$delitem|escape:'javascript' nofilter}}",
|
||||||
'blockAuthor' : "{{$blockAuthor|escape:'javascript' nofilter}}",
|
'blockAuthor' : "{{$blockAuthor|escape:'javascript' nofilter}}",
|
||||||
|
'ignoreAuthor' : "{{$ignoreAuthor|escape:'javascript' nofilter}}",
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -404,7 +404,12 @@ 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>
|
<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>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
{{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;" />
|
<img id="like-rotator-{{$item.id}}" class="like-rotator" src="images/rotator.gif" alt="{{$item.wait}}" title="{{$item.wait}}" style="display: none;" />
|
||||||
</span>
|
</span>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
Loading…
Reference in a new issue