Skip to content

Commit

Permalink
add imminent events to webhook setting endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Jan 3, 2023
1 parent 6833e2e commit a55f1ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 20 additions & 1 deletion lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace OCA\Mattermost\Controller;

use DateTime;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -165,13 +166,14 @@ public function setConfig(array $values): DataResponse {
* @param string|null $calendar_event_updated_url
* @param string|null $calendar_event_created_url
* @param string|null $daily_summary_url
* @param string|null $imminent_events_url
* @param bool|null $enabled
* @param string|null $webhook_secret
* @return DataResponse
* @throws PreConditionNotMetException
*/
public function setWebhooksConfig(?string $calendar_event_updated_url = null, ?string $calendar_event_created_url = null,
?string $daily_summary_url = null,
?string $daily_summary_url = null, ?string $imminent_events_url = null,
?bool $enabled = null, ?string $webhook_secret = null): DataResponse {
$result = [];
if ($calendar_event_created_url !== null) {
Expand All @@ -186,6 +188,10 @@ public function setWebhooksConfig(?string $calendar_event_updated_url = null, ?s
$result['daily_summary_url'] = $daily_summary_url;
$this->config->setUserValue($this->userId, Application::APP_ID, Application::DAILY_SUMMARY_WEBHOOK_CONFIG_KEY, $daily_summary_url);
}
if ($imminent_events_url !== null) {
$result['imminent_events_url'] = $imminent_events_url;
$this->config->setUserValue($this->userId, Application::APP_ID, Application::IMMINENT_EVENTS_WEBHOOK_CONFIG_KEY, $imminent_events_url);
}
if ($enabled !== null) {
$result['enabled'] = $enabled;
$this->config->setUserValue($this->userId, Application::APP_ID, Application::WEBHOOKS_ENABLED_CONFIG_KEY, $enabled ? '1' : '0');
Expand All @@ -194,6 +200,19 @@ public function setWebhooksConfig(?string $calendar_event_updated_url = null, ?s
$result['webhook_secret'] = $webhook_secret;
$this->config->setUserValue($this->userId, Application::APP_ID, Application::WEBHOOK_SECRET_CONFIG_KEY, $webhook_secret);
}
if (empty(array_keys($result))) {
$result = [
'error' => 'You must set at least one valid setting.',
'valid_keys' => [
'enabled',
'webhook_secret',
'calendar_event_created_url',
'calendar_event_updated_url',
'daily_summary_url',
],
];
return new DataResponse($result, Http::STATUS_BAD_REQUEST);
}
return new DataResponse($result);
}

Expand Down
1 change: 0 additions & 1 deletion lib/Service/WebhookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ public function userImminentEventsWebhook(string $userId): ?array {

$userTimeZone = $this->getUserTimeZone($userId);

// check if it has already run today
$now = (new DateTimeImmutable())->setTimezone($userTimeZone);
$nowTs = $now->getTimestamp();
$lastImminentJobTimestamp = (int) $this->config->getUserValue($userId, Application::APP_ID, Application::IMMINENT_EVENTS_WEBHOOK_LAST_TS_CONFIG_KEY);
Expand Down

0 comments on commit a55f1ed

Please sign in to comment.