forked from GNUsocial/gnu-social
[NOTIFICATION][DATABASE] Update user notification prefs table, implementation of Notification and define a base class for notification transport
This commit is contained in:
parent
df4d246ede
commit
2796ac5228
@ -200,15 +200,15 @@ class UserNotificationPrefs
|
||||
'name' => 'user_notification_prefs',
|
||||
'fields' => [
|
||||
'user_id' => ['type' => 'int', 'not null' => true],
|
||||
'service_name' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'name on this service'],
|
||||
'transport' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex xmpp, aim)'],
|
||||
'profile_id' => ['type' => 'int', 'default' => null, 'description' => 'If not null, settings are specific only to a given profiles'],
|
||||
'posts_by_followed' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify when a new notice by someone we follow is made'],
|
||||
'mention' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify when mentioned by someone we do not follow'],
|
||||
'follow' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify someone follows us'],
|
||||
'favorite' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify someone favorites a notice by us'],
|
||||
'transport' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex email. xmpp, aim)'],
|
||||
'target_profile_id' => ['type' => 'int', 'default' => null, 'description' => 'If not null, settings are specific only to a given profiles'],
|
||||
'notice_by_followed' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when a new notice by someone we follow is made'],
|
||||
'mention' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when mentioned by someone we do not follow'],
|
||||
'reply' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when someone replies to a notice made by us'],
|
||||
'follow' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone follows us'],
|
||||
'favorite' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone favorites a notice by us'],
|
||||
'nudge' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify someone nudges us'],
|
||||
'dm' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify someone sends us a direct message'],
|
||||
'dm' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone sends us a direct message'],
|
||||
'post_on_status_change' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Post a notice when our status in service changes'],
|
||||
'enable_posting' => ['type' => 'bool', 'default' => true, 'description' => 'Enable posting from this service'],
|
||||
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
|
||||
|
99
src/Util/Notification/AbstractTransport.php
Normal file
99
src/Util/Notification/AbstractTransport.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
// {{{ License
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// GNU social is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
// }}}
|
||||
|
||||
/**
|
||||
* Base class for Transports
|
||||
*
|
||||
* @package GNUsocial
|
||||
* @category Util
|
||||
*
|
||||
* @author Hugo Sales <hugo@fc.up.pt>
|
||||
* @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
namespace App\Util\Notification;
|
||||
|
||||
abstract class AbstractTransport
|
||||
{
|
||||
/**
|
||||
* Get the display name of this transport
|
||||
*/
|
||||
abstract public function getName(): string;
|
||||
|
||||
/**
|
||||
* Get the identifier used in code for this transport
|
||||
*/
|
||||
abstract public function getIdentifier(): string;
|
||||
|
||||
/**
|
||||
* Send a given Notification through this transport
|
||||
*/
|
||||
abstract public function send(Notification $n): bool;
|
||||
|
||||
/**
|
||||
* Get the display help message for one of the Notification-constants type
|
||||
*/
|
||||
public function getHelpMessage(int $t): string
|
||||
{
|
||||
switch ($t) {
|
||||
case Notification::NOTICE_BY_FOLLOWED:
|
||||
return _m('Send me alerts of mentions by those I follow through {name}', ['{name}' => $this->getName()]);
|
||||
case Notification::MENTION:
|
||||
return _m('Send me alerts of mentions through {name}', ['{name}' => $this->getName()]);
|
||||
case Notification::REPLY:
|
||||
return _m('Send me alerts of replies to my notice through {name}', ['{name}' => $this->getName()]);
|
||||
case Notification::FOLLOW:
|
||||
return _m('Send me alerts of new follows through {name}', ['{name}' => $this->getName()]);
|
||||
case Notification::FAVORITE:
|
||||
return _m('Send me alerts of new favorites on my notices through {name}', ['{name}' => $this->getName()]);
|
||||
case Notification::NUDGE:
|
||||
return _m('Send me alerts when someone calls for my attention through {name}', ['{name}' => $this->getName()]);
|
||||
case Notification::DM:
|
||||
return _m('Send me alerts of new direct messages through {name}', ['{name}' => $this->getName()]);
|
||||
default:
|
||||
throw new \InvalidArgumentException('Given an invalid Notification constant value');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display label message for one of the Notification-constants type
|
||||
*/
|
||||
public function getLabelMessage(int $t): string
|
||||
{
|
||||
switch ($t) {
|
||||
case Notification::NOTICE_BY_FOLLOWED:
|
||||
return _m('Notify me of new notices');
|
||||
case Notification::MENTION:
|
||||
return _m('Notify me of mentions');
|
||||
case Notification::REPLY:
|
||||
return _m('Notify me of replies');
|
||||
case Notification::FOLLOW:
|
||||
return _m('Notify me of new follows');
|
||||
case Notification::FAVORITE:
|
||||
return _m('Notify me of new favorites');
|
||||
case Notification::NUDGE:
|
||||
return _m('Notify me when nudged');
|
||||
case Notification::DM:
|
||||
return _m('Notify of new DMs');
|
||||
default:
|
||||
throw new \InvalidArgumentException('Given an invalid Notification constant value');
|
||||
}
|
||||
}
|
||||
}
|
60
src/Util/Notification/Notification.php
Normal file
60
src/Util/Notification/Notification.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
// {{{ License
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// GNU social is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
// }}}
|
||||
|
||||
/**
|
||||
* Common utility functions
|
||||
*
|
||||
* @package GNUsocial
|
||||
* @category Util
|
||||
*
|
||||
* @author Hugo Sales <hugo@fc.up.pt>
|
||||
* @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
namespace App\Util\Notification;
|
||||
|
||||
use App\Entity\Profile;
|
||||
|
||||
class Notification
|
||||
{
|
||||
public const NOTICE_BY_FOLLOWED = 1;
|
||||
public const MENTION = 2;
|
||||
public const REPLY = 3;
|
||||
public const FOLLOW = 4;
|
||||
public const FAVORITE = 5;
|
||||
public const NUDGE = 6;
|
||||
public const DM = 7;
|
||||
|
||||
/**
|
||||
* One of the above constants
|
||||
*/
|
||||
private int $type;
|
||||
|
||||
/**
|
||||
* Who caused this notification
|
||||
*/
|
||||
private Profile $profile;
|
||||
|
||||
public function __construct(int $type, Profile $profile)
|
||||
{
|
||||
$this->tyoe = $type;
|
||||
$this->profile = $profile;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user