mirror of
https://github.com/friendica/friendica
synced 2024-11-17 20:23:40 +00:00
Issue 11566: More detailled notification configuration
This commit is contained in:
parent
b1afcb5ebf
commit
57b8708425
10 changed files with 338 additions and 240 deletions
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2022.05-rc (Siberian Iris)
|
||||
-- DB_UPDATE_VERSION 1465
|
||||
-- DB_UPDATE_VERSION 1466
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -1416,7 +1416,7 @@ CREATE TABLE IF NOT EXISTS `post-thread-user` (
|
|||
CREATE TABLE IF NOT EXISTS `post-user-notification` (
|
||||
`uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
|
||||
`uid` mediumint unsigned NOT NULL COMMENT 'Owner id which owns this copy of the item',
|
||||
`notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
|
||||
`notification-type` smallint unsigned NOT NULL DEFAULT 0 COMMENT '',
|
||||
PRIMARY KEY(`uid`,`uri-id`),
|
||||
INDEX `uri-id` (`uri-id`),
|
||||
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
|
||||
|
|
|
@ -10,7 +10,7 @@ Fields
|
|||
| ----------------- | --------------------------------------------------------- | ------------------ | ---- | --- | ------- | ----- |
|
||||
| uri-id | Id of the item-uri table entry that contains the item uri | int unsigned | NO | PRI | NULL | |
|
||||
| uid | Owner id which owns this copy of the item | mediumint unsigned | NO | PRI | NULL | |
|
||||
| notification-type | | tinyint unsigned | NO | | 0 | |
|
||||
| notification-type | | smallint unsigned | NO | | 0 | |
|
||||
|
||||
Indexes
|
||||
------------
|
||||
|
|
|
@ -34,7 +34,6 @@ use Friendica\Model\Post;
|
|||
use Friendica\Model\Subscription;
|
||||
use Friendica\Model\Tag;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Navigation\Notifications;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -51,6 +50,7 @@ class UserNotification
|
|||
const TYPE_ACTIVITY_PARTICIPATION = 32;
|
||||
const TYPE_DIRECT_THREAD_COMMENT = 64;
|
||||
const TYPE_SHARED = 128;
|
||||
const TYPE_FOLLOW = 256;
|
||||
|
||||
/**
|
||||
* Insert a new user notification entry
|
||||
|
@ -268,6 +268,14 @@ class UserNotification
|
|||
}
|
||||
}
|
||||
|
||||
if (($item['verb'] != Activity::ANNOUNCE) && self::checkFollowParticipation($item, $contacts)) {
|
||||
$notification_type = $notification_type | self::TYPE_FOLLOW;
|
||||
if (!$notified) {
|
||||
self::insertNotificationByItem(self::TYPE_FOLLOW, $uid, $item);
|
||||
$notified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (($item['verb'] != Activity::ANNOUNCE) && self::checkActivityParticipation($item, $contacts)) {
|
||||
$notification_type = $notification_type | self::TYPE_ACTIVITY_PARTICIPATION;
|
||||
if (!$notified) {
|
||||
|
@ -535,6 +543,20 @@ class UserNotification
|
|||
return Post::exists($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user follows this thread
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $contacts Array of contact IDs
|
||||
* @return bool The user follows the thread
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function checkFollowParticipation(array $item, array $contacts): bool
|
||||
{
|
||||
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_ACTIVITY, 'verb' => Activity::FOLLOW];
|
||||
return Post::exists($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user had interacted in this thread (Like, Dislike, ...)
|
||||
*
|
||||
|
|
|
@ -267,6 +267,25 @@ class Account extends BaseSettings
|
|||
|
||||
DI::pConfig()->set(local_user(), 'system', 'notify_announce', $notify_announce);
|
||||
|
||||
$notify_type = 0;
|
||||
|
||||
if (!empty($request['notify_tagged'])) {
|
||||
$notify_type = $notify_type | 3;
|
||||
}
|
||||
if (!empty($request['notify_direct_comment'])) {
|
||||
$notify_type = $notify_type | 72;
|
||||
}
|
||||
if (!empty($request['notify_thread_comment'])) {
|
||||
$notify_type = $notify_type | 4;
|
||||
}
|
||||
if (!empty($request['notify_comment_participation'])) {
|
||||
$notify_type = $notify_type | 16;
|
||||
}
|
||||
if (!empty($request['notify_activity_participation'])) {
|
||||
$notify_type = $notify_type | 32;
|
||||
}
|
||||
DI::pConfig()->set(local_user(), 'system', 'notify_type', $notify_type);
|
||||
|
||||
DI::pConfig()->set(local_user(), 'system', 'email_textonly', !empty($request['email_textonly']));
|
||||
DI::pConfig()->set(local_user(), 'system', 'detailed_notif', !empty($request['detailed_notif']));
|
||||
DI::pConfig()->set(local_user(), 'system', 'notify_ignored', !empty($request['notify_ignored']));
|
||||
|
@ -524,6 +543,8 @@ class Account extends BaseSettings
|
|||
/* Installed langs */
|
||||
$lang_choices = DI::l10n()->getAvailableLanguages();
|
||||
|
||||
$notify_type = DI::pConfig()->get(local_user(), 'system', 'notify_type', 3 | 72 | 4 | 16 | 32);
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('settings/account.tpl');
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
'$ptitle' => DI::l10n()->t('Account Settings'),
|
||||
|
@ -593,6 +614,12 @@ class Account extends BaseSettings
|
|||
'$notify_like' => ['notify_like', DI::l10n()->t('Someone liked your content'), DI::pConfig()->get(local_user(), 'system', 'notify_like'), ''],
|
||||
'$notify_announce' => ['notify_announce', DI::l10n()->t('Someone shared your content'), DI::pConfig()->get(local_user(), 'system', 'notify_announce'), ''],
|
||||
|
||||
'$notify_tagged' => ['notify_tagged', DI::l10n()->t('Someone tagged you'), $notify_type & 3, ''],
|
||||
'$notify_direct_comment' => ['notify_direct_comment', DI::l10n()->t('Someone directly commented on your post'), $notify_type & 72, ''],
|
||||
'$notify_thread_comment' => ['notify_thread_comment', DI::l10n()->t('Someone commented on your thread'), $notify_type & 4, ''],
|
||||
'$notify_comment_participation' => ['notify_comment_participation', DI::l10n()->t('Someone commented in a thread where you commented'), $notify_type & 16, ''],
|
||||
'$notify_activity_participation' => ['notify_activity_participation', DI::l10n()->t('Someone commented on a thread where you interacted'), $notify_type & 32, ''],
|
||||
|
||||
'$desktop_notifications' => ['desktop_notifications', DI::l10n()->t('Activate desktop notifications'), false, DI::l10n()->t('Show desktop popup on new notifications')],
|
||||
|
||||
'$email_textonly' => [
|
||||
|
|
|
@ -148,7 +148,7 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
|||
return $message;
|
||||
}
|
||||
|
||||
if (in_array($Notification->type, [Post\UserNotification::TYPE_THREAD_COMMENT, Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_EXPLICIT_TAGGED])) {
|
||||
if (in_array($Notification->type, [Post\UserNotification::TYPE_THREAD_COMMENT, Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_FOLLOW, Post\UserNotification::TYPE_EXPLICIT_TAGGED])) {
|
||||
$item = Post::selectFirst([], ['uri-id' => $Notification->parentUriId, 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
||||
if (empty($item)) {
|
||||
$this->logger->info('Parent post not found', ['uri-id' => $Notification->parentUriId]);
|
||||
|
@ -175,7 +175,7 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
|||
}
|
||||
}
|
||||
|
||||
if (in_array($Notification->type, [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_SHARED])) {
|
||||
if (in_array($Notification->type, [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_FOLLOW, Post\UserNotification::TYPE_SHARED])) {
|
||||
$author = Contact::getById($item['author-id'], ['id', 'name', 'url', 'contact-type']);
|
||||
if (empty($author)) {
|
||||
$this->logger->info('Author not found', ['author' => $item['author-id']]);
|
||||
|
@ -276,6 +276,7 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
|||
|
||||
case Post\UserNotification::TYPE_COMMENT_PARTICIPATION:
|
||||
case Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION:
|
||||
case Post\UserNotification::TYPE_FOLLOW;
|
||||
if (($causer['id'] == $author['id']) && ($title != '')) {
|
||||
$msg = $l10n->t('%1$s commented in their thread %2$s');
|
||||
} elseif ($causer['id'] == $author['id']) {
|
||||
|
|
|
@ -663,7 +663,7 @@ class Notify extends BaseRepository
|
|||
$type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
|
||||
}
|
||||
|
||||
if (!in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE])) {
|
||||
if (in_array($Notification->type, [Model\Post\UserNotification::TYPE_FOLLOW])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -675,6 +675,24 @@ class Notify extends BaseRepository
|
|||
return true;
|
||||
}
|
||||
|
||||
$notify_type = $this->pConfig->get(local_user(), 'system', 'notify_type', 3 | 72 | 4 | 16 | 32);
|
||||
|
||||
if (($notify_type & 3) && in_array($Notification->type, [Model\Post\UserNotification::TYPE_EXPLICIT_TAGGED, Model\Post\UserNotification::TYPE_IMPLICIT_TAGGED])) {
|
||||
return true;
|
||||
}
|
||||
if (($notify_type & 72) && in_array($Notification->type, [Model\Post\UserNotification::TYPE_DIRECT_COMMENT, Model\Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT])) {
|
||||
return true;
|
||||
}
|
||||
if (($notify_type & 4) && in_array($Notification->type, [Model\Post\UserNotification::TYPE_THREAD_COMMENT])) {
|
||||
return true;
|
||||
}
|
||||
if (($notify_type & 16) && in_array($Notification->type, [Model\Post\UserNotification::TYPE_COMMENT_PARTICIPATION])) {
|
||||
return true;
|
||||
}
|
||||
if (($notify_type & 32) && in_array($Notification->type, [Model\Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1465);
|
||||
define('DB_UPDATE_VERSION', 1466);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -1430,7 +1430,7 @@ return [
|
|||
"fields" => [
|
||||
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
|
||||
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
|
||||
"notification-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
"notification-type" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["uid", "uri-id"],
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -109,6 +109,11 @@
|
|||
<div class="group">
|
||||
{{include file="field_checkbox.tpl" field=$notify_like}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_announce}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_tagged}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_direct_comment}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_thread_comment}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_comment_participation}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_activity_participation}}
|
||||
</div>
|
||||
|
||||
{{include file="field_checkbox.tpl" field=$email_textonly}}
|
||||
|
|
|
@ -160,6 +160,11 @@
|
|||
<div class="group">
|
||||
{{include file="field_checkbox.tpl" field=$notify_like}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_announce}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_tagged}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_direct_comment}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_thread_comment}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_comment_participation}}
|
||||
{{include file="field_checkbox.tpl" field=$notify_activity_participation}}
|
||||
</div>
|
||||
|
||||
{{include file="field_checkbox.tpl" field=$email_textonly}}
|
||||
|
|
Loading…
Reference in a new issue