-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1074 from nextcloud/MailNotifications
Sending unseen notifications as email periodically. Includes a new us…
- Loading branch information
Showing
21 changed files
with
1,315 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*! | ||
* The buffer module from node.js, for the browser. | ||
* | ||
* @author Feross Aboukhadijeh <[email protected]> <http://feross.org> | ||
* @license MIT | ||
*/ | ||
|
||
/*! | ||
* Vue.js v2.6.14 | ||
* (c) 2014-2021 Evan You | ||
* Released under the MIT License. | ||
*/ | ||
|
||
/** | ||
* @copyright Copyright (c) 2019 Greta Doci <[email protected]> | ||
* | ||
* @author Greta Doci <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program 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. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
/** | ||
* @copyright Copyright (c) 2021 Julien Barnoin <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program 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. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2021 Joas Schilling <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program 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. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Notifications\BackgroundJob; | ||
|
||
use OCA\Notifications\Model\Settings; | ||
use OCA\Notifications\Model\SettingsMapper; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\BackgroundJob\TimedJob; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\IDBConnection; | ||
use OCP\IUser; | ||
use OCP\IUserManager; | ||
|
||
class GenerateUserSettings extends TimedJob { | ||
/** @var IDBConnection */ | ||
private $connection; | ||
/** @var IUserManager */ | ||
private $userManager; | ||
/** @var SettingsMapper */ | ||
private $settingsMapper; | ||
|
||
public function __construct( | ||
ITimeFactory $time, | ||
IDBConnection $connection, | ||
IUserManager $userManager, | ||
SettingsMapper $settingsMapper | ||
) { | ||
parent::__construct($time); | ||
|
||
$this->connection = $connection; | ||
$this->userManager = $userManager; | ||
$this->settingsMapper = $settingsMapper; | ||
|
||
// run every day | ||
$this->setInterval(24 * 60 * 60); | ||
} | ||
|
||
protected function run($argument): void { | ||
$query = $this->connection->getQueryBuilder(); | ||
$query->selectAlias('id', 'max_id') | ||
->from('notifications') | ||
->orderBy('id', 'DESC') | ||
->setMaxResults(1); | ||
|
||
$result = $query->executeQuery(); | ||
$maxId = (int) $result->fetchOne(); | ||
$result->closeCursor(); | ||
|
||
$this->userManager->callForSeenUsers(function (IUser $user) use ($maxId) { | ||
if ($user->isEnabled()) { | ||
return; | ||
} | ||
|
||
try { | ||
$this->settingsMapper->getSettingsByUser($user->getUID()); | ||
} catch (DoesNotExistException $e) { | ||
$settings = new Settings(); | ||
$settings->setUserId($user->getUID()); | ||
$settings->setNextSendTime(1); | ||
$settings->setBatchTime(Settings::EMAIL_SEND_3HOURLY); | ||
$settings->setLastSendId($maxId); | ||
$this->settingsMapper->insert($settings); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2021 Julien Barnoin <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program 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. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Notifications\BackgroundJob; | ||
|
||
use OCP\BackgroundJob\TimedJob; | ||
use OCA\Notifications\MailNotifications; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
|
||
class SendNotificationMails extends TimedJob { | ||
|
||
/** @var MailNotifications */ | ||
protected $mailNotifications; | ||
/** @var bool */ | ||
protected $isCLI; | ||
|
||
public function __construct(ITimeFactory $timeFactory, | ||
MailNotifications $mailNotifications, | ||
bool $isCLI) { | ||
parent::__construct($timeFactory); | ||
|
||
$this->mailNotifications = $mailNotifications; | ||
$this->isCLI = $isCLI; | ||
} | ||
|
||
protected function run($argument): void { | ||
$time = $this->time->getTime(); | ||
$batchSize = $this->isCLI ? MailNotifications::BATCH_SIZE_CLI : MailNotifications::BATCH_SIZE_WEB; | ||
$this->mailNotifications->sendEmails($batchSize, $time); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2021 Julien Barnoin <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program 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. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Notifications\Controller; | ||
|
||
use OCA\Notifications\Model\SettingsMapper; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\IRequest; | ||
|
||
class SettingsController extends OCSController { | ||
/** @var SettingsMapper */ | ||
protected $settingsMapper; | ||
|
||
/** @var string */ | ||
protected $userId; | ||
|
||
public function __construct(string $appName, | ||
IRequest $request, | ||
SettingsMapper $settingsMapper, | ||
string $userId) { | ||
parent::__construct($appName, $request); | ||
$this->settingsMapper = $settingsMapper; | ||
$this->userId = $userId; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* | ||
* @param int $batchSetting | ||
* @return DataResponse | ||
*/ | ||
public function personal(int $batchSetting): DataResponse { | ||
$this->settingsMapper->setBatchSettingForUser($this->userId, $batchSetting); | ||
return new DataResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.