Skip to content

Commit

Permalink
feat: Add feature flag for notify push to test on nightly more easily
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Jul 18, 2024
1 parent fe164c2 commit f468541
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
3 changes: 2 additions & 1 deletion lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class ApiService {
public function __construct(
private IRequest $request,
private ConfigService $configService,
private SessionService $sessionService,
private DocumentService $documentService,
private EncodingService $encodingService,
Expand Down Expand Up @@ -193,7 +194,7 @@ public function push(Session $session, Document $document, int $version, array $
}

private function addToPushQueue(Document $document, array $steps): void {
if ($this->queue === null) {
if ($this->queue === null || !$this->configService->isNotifyPushSyncEnabled()) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public function isRichWorkspaceEnabledForUser(?string $userId): bool {
}
return $this->config->getUserValue($userId, Application::APP_NAME, 'workspace_enabled', '1') === '1';
}

public function isNotifyPushSyncEnabled(): bool {
return $this->appConfig->getValueBool(Application::APP_NAME, 'notify_push');

}
}
5 changes: 5 additions & 0 deletions lib/Service/InitialStateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public function provideState(): void {
];
}, $this->textProcessingManager->getAvailableTaskTypes()),
);

$this->initialState->provideInitialState(
'notify_push',
$this->configService->isNotifyPushSyncEnabled(),
);
}

public function provideFileId(int $fileId): void {
Expand Down
32 changes: 10 additions & 22 deletions src/services/NotifyService.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
/*
* @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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/>.
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import mitt from 'mitt'
import { listen } from '@nextcloud/notify_push'
import { loadState } from '@nextcloud/initial-state'

if (!window._nc_text_notify) {
const useNotifyPush = listen('text_steps', (messageType, messageBody) => {
window._nc_text_notify?.emit('notify_push', { messageType, messageBody })
})
const isPushEnabled = loadState('text', 'notify_push', false)
const useNotifyPush = isPushEnabled
? listen('text_steps', (messageType, messageBody) => {
window._nc_text_notify?.emit('notify_push', { messageType, messageBody })
})
: undefined
window._nc_text_notify = useNotifyPush ? mitt() : null
}

Expand Down

0 comments on commit f468541

Please sign in to comment.