Skip to content

feat(chat): scaffold StartChat with a required idempotency key - #1473

Merged
bmc08gt merged 2 commits into
code/cashfrom
feat/chat-start-idempotency-key
Sep 16, 2026
Merged

bmc08gt merged 2 commits into
code/cashfrom
feat/chat-start-idempotency-key

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Draft: blocked on code-payments/flipcash2-client-protocol#14. This branch pins flipcash2-client-protocol 0.8.0, which is not on Maven Central yet, so CI cannot resolve it — expect com.flipcash:flipcash2-client-protocol:0.8.0 FAILED. It goes green once that PR merges and publishes.

What changed upstream

StartChatRequest gained a required idempotency_key (field 9), backed by a new 16-byte IdempotencyKey message. Nothing was removed and nothing was renumbered.

What this does

StartChat had never been scaffolded on Android — no ChatApi, ChatService, repository or controller method existed for it. So this adds the RPC through the full existing Api → Service → Repository → Controller chain, mirroring how joinChat/leaveChat are already wired, with the idempotency key required from the outermost entry point inward.

  • IdempotencyKey — a 16-byte @JvmInline value class with a SecureRandom-backed random(), matching BlobId's shape.
  • StartChatParameters — sealed interface with the Group variant the proto's parameters oneof currently carries.
  • StartChatError — the five Result cases plus Unrecognized/Other.
  • Domain→proto mappers for the key and the participation rules.
  • ChatController.startChat(parameters, idempotencyKey) takes the key as a required parameter with no default and no internal generation. That is deliberate: the server derives the chat's identity from caller plus key, so a key minted inside the call, fresh per attempt, would satisfy validation while producing exactly the duplicate chats the field exists to prevent. Forcing the caller to supply it keeps minting where the user's intent originates.

The signature covers the new field — setIdempotencyKey is chained before authenticate(owner), which signs buildPartial().

Scope left open

There is no group-chat-creation UI on code/cash to wire this into — NewChatScreen/NewChatViewModel only handle DM-by-handle, and ChatCoordinator.GroupOperations has only join/leave. startChat therefore has no caller above ChatController, so there is no retry path yet in which to reuse a key. The required parameter is what makes a future caller get it right rather than discover the constraint at runtime.

No tests were added for startChat itself. FakeChatRepository in ChatControllerTest gained a stub override, since adding the method to ChatRepository broke the only other implementer.

Builds

Built against the client repo through protoLocalRoot / protoLocalPackages=flipcash2, not a published artifact:

  • :services:flipcash:compileDebugKotlin — passes
  • :services:flipcash:compileDebugUnitTestKotlin — passes

No wider assembleDebug or :app build was run.

flipcash2 sync e1f4116c makes idempotency_key a required field on
StartChatRequest (upstream #102). Android had no StartChat call site
to update, so this scaffolds the full chain instead: ChatApi.startChat
builds and validates the request, ChatService maps the response Result
enum to a new StartChatError sealed class, ChatRepository /
InternalChatRepository add the domain-facing method, and
ChatController exposes it. New IdempotencyKey and StartChatParameters
domain types back the call.

idempotencyKey is a required ChatController.startChat parameter with
no default, so whichever caller originates a "create chat" action has
to mint and reuse the same key across its own retries; nothing here
generates one per call.

Compiles: services:flipcash:compileDebugKotlin and
compileDebugUnitTestKotlin against the local flipcash2-client-protocol
override.
StartChat needs the idempotency_key field that 0.8.0 adds. Blocked until that
version is on Maven Central.
@bmc08gt bmc08gt self-assigned this Sep 16, 2026
@github-actions github-actions Bot added area: network gRPC, connectivity, API, exchange rates area: build-system Gradle, convention plugins, build-logic type: feature New functionality labels Sep 16, 2026
@bmc08gt
bmc08gt marked this pull request as ready for review September 16, 2026 19:08
@bmc08gt
bmc08gt merged commit 08a6ff8 into code/cash Sep 16, 2026
4 of 5 checks passed
@bmc08gt
bmc08gt deleted the feat/chat-start-idempotency-key branch September 16, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build-system Gradle, convention plugins, build-logic area: network gRPC, connectivity, API, exchange rates type: feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant