Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/BackgroundJob/GenerateUserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OCA\Notifications\Model\Settings;
use OCA\Notifications\Model\SettingsMapper;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IDBConnection;
Expand All @@ -22,6 +23,7 @@ public function __construct(
private readonly IDBConnection $connection,
private readonly IUserManager $userManager,
private readonly SettingsMapper $settingsMapper,
private readonly IAppConfig $appConfig,
) {
parent::__construct($time);

Expand All @@ -31,6 +33,18 @@ public function __construct(

#[\Override]
protected function run($argument): void {
$update = $this->connection->getQueryBuilder();
$update->update('notifications_settings')
->set('next_send_time', $update->createNamedParameter(1))
->where($update->expr()->eq('next_send_time', $update->createNamedParameter(0)))
->andWhere($update->expr()->neq('batch_time', $update->createNamedParameter(Settings::EMAIL_SEND_OFF)));

$batchTime = $this->appConfig->getAppValueInt('setting_batchtime');
if ($batchTime === Settings::EMAIL_SEND_OFF) {
$update->andWhere($update->expr()->neq('batch_time', $update->createNamedParameter(Settings::EMAIL_SEND_DEFAULT)));
}
$update->executeStatement();

$query = $this->connection->getQueryBuilder();
$query->select('notification_id')
->from('notifications')
Expand All @@ -42,7 +56,7 @@ protected function run($argument): void {
$result->closeCursor();

$this->userManager->callForSeenUsers(function (IUser $user) use ($maxId): void {
if ($user->isEnabled()) {
if (!$user->isEnabled()) {
return;
}

Expand Down
10 changes: 9 additions & 1 deletion lib/Model/SettingsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Services\IAppConfig;
use OCP\DB\Exception as DBException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
Expand All @@ -22,7 +23,10 @@
* @method list<Settings> findEntities(IQueryBuilder $query)
*/
class SettingsMapper extends QBMapper {
public function __construct(IDBConnection $db) {
public function __construct(
IDBConnection $db,
protected readonly IAppConfig $appConfig,
) {
parent::__construct($db, 'notifications_settings', Settings::class);
}

Expand All @@ -43,6 +47,10 @@ public function getSettingsByUser(string $userId): Settings {
$settings = new Settings();
$settings->setUserId($userId);
$settings->setBatchTime(Settings::EMAIL_SEND_DEFAULT);
$batchTime = $this->appConfig->getAppValueInt('setting_batchtime');
if ($batchTime !== Settings::EMAIL_SEND_OFF) {
$settings->setNextSendTime(1);
}
/** @var Settings $settings */
$settings = $this->insert($settings);

Expand Down
8 changes: 5 additions & 3 deletions lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public function getForm(): TemplateResponse {
$settingBatchTime = $this->appConfig->getAppValueInt('setting_batchtime');
}
} catch (DoesNotExistException) {
$settingBatchTime = $this->appConfig->getAppValueInt('setting_batchtime');

$settings = new Settings();
$settings->setUserId($user->getUID());
$settings->setBatchTime(Settings::EMAIL_SEND_DEFAULT);
$settings->setNextSendTime(1);
if ($settingBatchTime !== Settings::EMAIL_SEND_OFF) {
$settings->setNextSendTime(1);
}
$this->settingsMapper->insert($settings);

$settingBatchTime = $this->appConfig->getAppValueInt('setting_batchtime');
}

$defaultSoundNotification = $this->appConfig->getAppValueBool('sound_notification');
Expand Down
Loading