Skip to content

Commit

Permalink
feat: Pass through any steps
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Mar 13, 2024
1 parent 0cbda6d commit 576e874
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ public function push(Session $session, Document $document, int $version, array $
return new DataResponse([]);
}
try {
// could we just send out all incoming steps directly? without filtering out step1/2
$this->addToPushQueue($session, $document, [$awareness, ...$steps]);

Check failure on line 204 in lib/Service/ApiService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

DuplicateArrayKey

lib/Service/ApiService.php:204:63: DuplicateArrayKey: String keys are not supported in unpacked arrays (see https://psalm.dev/151)
// either keep sync request to fetch all steps to catch up missed ones
// or generate a sync1 message during save and send it to all clients
$result = $this->documentService->addStep($document, $session, $steps, $version, $token);
$this->addToPushQueue($session, $document, $version);
} catch (InvalidArgumentException $e) {
return new DataResponse($e->getMessage(), 422);
} catch (DoesNotExistException|NotPermittedException) {
Expand All @@ -211,10 +214,9 @@ public function push(Session $session, Document $document, int $version, array $
return new DataResponse($result);
}

private function addToPushQueue(Session $session, Document $document, int $version): void {
private function addToPushQueue(Session $session, Document $document, array $steps): void {
try {
$queue = Server::get(IQueue::class);
$syncResponse = $this->sync($session, $document, $version);
$sessions = $this->sessionService->getActiveSessions($document->getId());
$sessions = array_values(array_unique(array_map(fn ($session): ?string => $session['userId'], $sessions)));
foreach ($sessions as $userId) {
Expand All @@ -224,7 +226,7 @@ private function addToPushQueue(Session $session, Document $document, int $versi
'message' => 'text_steps',
'body' => [
'documentId' => $document->getId(),
'response' => $syncResponse->getData(),
'steps' => $steps,
],
]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/PollingBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PollingBackend {
this.fetcher = setInterval(this._fetchSteps.bind(this), 50)
document.addEventListener('visibilitychange', this.visibilitychange.bind(this))
this.#notifyPushBus = getNotifyBus()
this.#notifyPushBus?.on('notify_push', this.handleNotifyPush.bind(this))
// this.#notifyPushBus?.on('notify_push', this.handleNotifyPush.bind(this))
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ class PollingBackend {
}

disconnect() {
this.#notifyPushBus?.off('notify_push', this.handleNotifyPush)
// this.#notifyPushBus?.off('notify_push', this.handleNotifyPush)
clearInterval(this.fetcher)
this.fetcher = 0
document.removeEventListener('visibilitychange', this.visibilitychange.bind(this))
Expand Down
8 changes: 3 additions & 5 deletions src/services/WebSocketPolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio
if (messageBody.documentId !== fileId) {
return
}
messageBody.response.steps.forEach(steps => {
steps.data.forEach((s) => {
const data = decodeArrayBuffer(s?.step ?? s)
this.onmessage({ data })
})
messageBody.steps.forEach(step => {
const data = decodeArrayBuffer(step)
this.onmessage({ data })
})
})
this.url = url
Expand Down

0 comments on commit 576e874

Please sign in to comment.