Skip to content

added presence api update#1489

Open
ArnabChatterjee20k wants to merge 3 commits intomasterfrom
presence-api
Open

added presence api update#1489
ArnabChatterjee20k wants to merge 3 commits intomasterfrom
presence-api

Conversation

@ArnabChatterjee20k
Copy link
Copy Markdown
Member

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR adds a createPresence API to the Realtime service across all SDK templates (Flutter, Android, Apple, Web), backed by a new WebSocket mock server that handles the presence message type. It also makes the additional-properties field name configurable via the x-additional-properties-key OpenAPI extension, replacing the hardcoded data field across every model template.

  • createPresence implementation: Each platform adds a FIFO queue of in-flight presence requests correlated to server responses via the ordered single WebSocket connection; handleResponseError correctly drains the queue on server-error frames.
  • additionalPropertiesKey templating: Swagger2.php extracts x-additional-properties-key (default 'data') and all model templates propagate it, maintaining backward compatibility for models that don't set the extension.
  • Flutter test reliability: subscribeTo defers _createSocket() via Future.delayed(Duration.zero, ...), so _websok is still null when createPresenceTo immediately checks it \u2014 the presence test will always fall into its catch block and report \"Realtime presence:failed\".

Confidence Score: 3/5

Not safe to merge without fixing the Flutter test (always fails) and the unresolved socket-close handling gaps across all four platforms.

The Flutter presence test is structurally broken: subscribe schedules WebSocket creation asynchronously, so _websok is always null when createPresence is called on the next line, causing an immediate throw and a permanent "Realtime presence:failed". Additionally, connection-drop paths (onDone/onError in Flutter, onClosing/onFailure in Android, onClose/onError delegates in Swift, close event and disconnect() in Web) all skip draining in-flight presence requests, leaving callers permanently suspended.

tests/languages/flutter/tests.dart (always-failing presence test), and the four Realtime service templates for socket-close handling of pending presence requests.

Important Files Changed

Filename Overview
mock-server/src/Utopia/Realtime/Protocol.php New file: implements authentication, subscribe, unsubscribe, presence, and ping handlers for the mock WebSocket server; protocol shapes match what SDKs expect.
src/Spec/Swagger2.php Adds additionalPropertiesKey (sourced from x-additional-properties-key, default 'data') to model definitions, enabling configurable additional-properties field names across all SDK templates.
templates/flutter/lib/src/realtime_mixin.dart.twig Adds createPresenceTo and FIFO presence-response correlation; handleError drains pending presence requests, but onDone/onError WebSocket stream callbacks still do not drain _pendingPresenceRequests.
templates/android/library/src/main/java/io/package/services/Realtime.kt.twig Adds createPresence suspend function with FIFO deferred queue; handleResponseError drains pending requests on error, but onClosing/onFailure socket callbacks do not drain pendingPresenceRequests.
templates/apple/Sources/Services/Realtime.swift.twig Adds createPresence async/throws with CheckedContinuation queue; handleResponseError drains pending continuations, but onClose/onError delegate callbacks do not resume pending continuations.
templates/web/src/services/realtime.ts.twig Adds createPresence returning a Promise; handleError drains pending requests, but the close socket event and disconnect() still do not drain pendingPresenceRequests.
tests/languages/flutter/tests.dart Adds presence test; the test always reports failure because subscribe schedules socket creation asynchronously and createPresence runs before _websok is set.

Comments Outside Diff (1)

  1. tests/languages/flutter/tests.dart, line 1477-1483 (link)

    P1 Flutter presence test always fails — _websok is null when createPresence is called

    subscribeTo (called by subscribe) schedules _createSocket() via Future.delayed(Duration.zero, ...), so the WebSocket factory hasn't run yet when execution reaches await createPresence(...). createPresenceTo checks if (ws == null …) synchronously — _websok is still null — and throws immediately, so the catch block always prints "Realtime presence:failed".

    The fix is to await something that guarantees the socket is open before calling createPresence. A small Future.delayed(Duration.zero) trampoline after subscribe (to let the event loop fire _createSocket) is the minimal change; ideally the subscribe API itself should expose a "connected" signal.

Reviews (3): Last reviewed commit: "added presence api tests and mock server" | Re-trigger Greptile


return completer.future;
}
} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing newline at end of file

The file no longer ends with a newline. Most linters and git tools flag this; adding a trailing newline keeps the file consistent with the rest of the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant