Skip to content

feat: friends panel#3990

Merged
evanpelle merged 1 commit into
mainfrom
friends
May 23, 2026
Merged

feat: friends panel#3990
evanpelle merged 1 commit into
mainfrom
friends

Conversation

@evanpelle
Copy link
Copy Markdown
Collaborator

@evanpelle evanpelle commented May 22, 2026

Description:

Add Friends tab to Account modal

Summary

  • Adds a "Friends" tab to the Account modal, alongside Account / Stats / Games.
  • New <friends-list> Lit component covering the full friend lifecycle: send request, accept / deny incoming, withdraw outgoing, remove friend, paginated list with "Load more".
  • New FriendsApi.ts wrapping GET/POST/DELETE /friends* endpoints with typed error codes (not_found / conflict / bad_request / request_failed).
  • Zod schemas for the friend API responses in core/ApiSchemas.ts.
  • Translations under a new friends.* block in en.json.

Friends and pending requests are displayed by public ID via copy-button, matching the existing clan convention.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

evan

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Review Change Stack

Walkthrough

Adds a friends system: Zod API schemas, a client-side Friends API, a LitElement FriendsList UI with pagination and request actions, and AccountModal integration plus new English translations.

Changes

Friends Feature Implementation

Layer / File(s) Summary
Friend API Schemas and Types
src/core/ApiSchemas.ts
Exports Zod schemas and types for FriendEntry, FriendRequestsResponse, paginated FriendsListResponse, and SendFriendRequestResponse with status values.
Friends API Client
src/client/FriendsApi.ts
Adds friendsFetch() helper, FriendActionError union, and functions: fetchFriendRequests(), fetchFriends(page, limit), sendFriendRequest(), acceptFriendRequest(), deleteFriendRequest(), removeFriend(). Maps HTTP statuses to error keys and validates responses with Zod.
FriendsList Web Component
src/client/components/FriendsList.ts
New friends-list LitElement: loads incoming/outgoing requests and paginated friends, supports send/accept/deny/withdraw/remove actions with concurrency guards, toast messages, refresh/pagination, and renders add/requests/friends sections.
AccountModal Integration and Translations
src/client/AccountModal.ts, resources/lang/en.json
Adds a friends tab to AccountModal rendering <friends-list myPublicId="..."> and inserts English translation keys for the friends UI, actions, states, and errors.

Sequence Diagram

sequenceDiagram
  participant User
  participant FriendsList
  participant FriendsApi
  participant Server
  User->>FriendsList: open friends tab
  FriendsList->>FriendsApi: fetchFriendRequests()
  FriendsList->>FriendsApi: fetchFriends(page, limit)
  FriendsApi->>Server: GET /friends/requests
  FriendsApi->>Server: GET /friends?page=X&limit=Y
  Server-->>FriendsApi: requests / paginated friends
  FriendsList->>User: render lists
  User->>FriendsList: sendFriendRequest(publicId)
  FriendsList->>FriendsApi: sendFriendRequest(publicId)
  FriendsApi->>Server: POST /friends/requests/{publicId}
  Server-->>FriendsApi: status (requested|accepted) or error
  FriendsApi-->>FriendsList: response or FriendActionError
  FriendsList->>FriendsList: update state, show toast
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🤝 New tab, new friends, IDs in a line,
Requests fly, accept or decline,
Pages load more as the list grows long,
Toasts sing success, and errors move on,
Connections formed, neat and fine.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—adding a friends panel feature to the application with a new tab in the Account modal.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the friends feature implementation including the component, API, schemas, and translations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/client/components/FriendsList.ts`:
- Around line 117-123: After mutating local lists (e.g., this.incoming,
this.friends, this.friendsTotal) in the accept/remove handlers, reset the
component's pagination cache/state and re-fetch the first page instead of only
editing the local arrays to avoid later duplicate/missing rows; specifically,
after the local update (the block that modifies this.incoming, this.friends and
this.friendsTotal), clear whatever pagination buffers you maintain (e.g., pages
array, nextCursor/currentPage) and invoke loadMore() (or a refreshFriends()
helper) to reload from the server so the client and paginated server state stay
in sync.

In `@src/core/ApiSchemas.ts`:
- Around line 221-248: Add unit tests that validate FriendEntrySchema,
FriendRequestsResponseSchema, FriendsListResponseSchema, and
SendFriendRequestResponseSchema: for FriendEntrySchema test a valid object with
publicId string and createdAt ISO datetime and invalid cases (missing publicId,
bad createdAt); for FriendRequestsResponseSchema test valid payloads where
incoming/outgoing are arrays of valid FriendEntry objects and invalid cases
(non-array, invalid entries); for FriendsListResponseSchema test a valid payload
with results array of FriendEntry objects and numeric total/page/limit and
invalid cases (missing/negative/non-numeric pagination fields, non-array
results, invalid entries); and for SendFriendRequestResponseSchema test accepted
valid enum values "requested" and "accepted" plus invalid string values. Use the
schema parse/validation methods in your test harness to assert success for valid
fixtures and thrown/failed validation for each invalid fixture, referencing the
schema symbols FriendEntrySchema, FriendRequestsResponseSchema,
FriendsListResponseSchema, and SendFriendRequestResponseSchema to locate the
code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a87f5d49-6e0e-4a30-828b-bc458b146182

📥 Commits

Reviewing files that changed from the base of the PR and between b486caa and c0ef9b0.

📒 Files selected for processing (5)
  • resources/lang/en.json
  • src/client/AccountModal.ts
  • src/client/FriendsApi.ts
  • src/client/components/FriendsList.ts
  • src/core/ApiSchemas.ts

Comment thread src/client/components/FriendsList.ts
Comment thread src/core/ApiSchemas.ts
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management May 22, 2026
@evanpelle evanpelle changed the title friends feat: friends panel May 22, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/core/ApiSchemas.ts (1)

221-248: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add tests for the new core friend schemas before merge.

These new src/core contracts were added without matching tests in the provided changes.

As per coding guidelines: "All changes to src/core/ must include tests".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/ApiSchemas.ts` around lines 221 - 248, Add unit tests for the new
core schemas: FriendEntrySchema, FriendRequestsResponseSchema,
FriendsListResponseSchema, and SendFriendRequestResponseSchema. For each schema
write tests that validate successful parsing of a correct example payload and
that invalid payloads fail validation (missing required fields, wrong types,
empty arrays where applicable); specifically test FriendEntrySchema for publicId
(string) and createdAt (ISO datetime), FriendRequestsResponseSchema for
incoming/outgoing arrays of FriendEntrySchema, FriendsListResponseSchema for
results array plus numeric total/page/limit, and SendFriendRequestResponseSchema
for the enum values "requested" and "accepted". Use the project’s existing test
framework and schema parsing helpers to assert both .parse() success and that
.safeParse()/errors catch invalid inputs.
🧹 Nitpick comments (1)
src/client/FriendsApi.ts (1)

55-63: ⚡ Quick win

Use friendsFetch in fetchFriends to avoid request drift.

fetchFriends duplicates auth/header logic instead of using the shared helper. Using one path is safer and easier to maintain.

Suggested refactor
-    const res = await fetch(url.toString(), {
-      headers: {
-        Accept: "application/json",
-        Authorization: await getAuthHeader(),
-      },
-    });
+    const res = await friendsFetch(
+      `/friends?page=${encodeURIComponent(String(page))}&limit=${encodeURIComponent(String(limit))}`,
+    );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/client/FriendsApi.ts` around lines 55 - 63, The fetchFriends function is
constructing the URL and duplicating auth/header logic instead of using the
shared friendsFetch helper; update fetchFriends to call friendsFetch for the
"/friends" endpoint (passing page and limit as query params or as the helper's
expected args) and remove the manual fetch/Authorization header code. Locate
fetchFriends and replace the new URL + fetch(...) block with a single await to
friendsFetch (or friendsFetch.get/post depending on the helper API), then
continue using the returned response as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/ApiSchemas.ts`:
- Around line 235-240: FriendsListResponseSchema currently uses z.number() for
total, page, and limit allowing floats and negatives; update
FriendsListResponseSchema to use z.number().int().min(...) with total:
.int().min(0), page: .int().min(1), limit: .int().min(1) so only valid integers
pass, and adjust any imports if needed; add unit tests for
FriendsListResponseSchema that assert valid payloads pass and invalid cases
(negative or zero/negative page/limit, non-integers for total/page/limit) fail
validation to cover the three constraints (reference FriendsListResponseSchema
and FriendEntrySchema in tests).

---

Duplicate comments:
In `@src/core/ApiSchemas.ts`:
- Around line 221-248: Add unit tests for the new core schemas:
FriendEntrySchema, FriendRequestsResponseSchema, FriendsListResponseSchema, and
SendFriendRequestResponseSchema. For each schema write tests that validate
successful parsing of a correct example payload and that invalid payloads fail
validation (missing required fields, wrong types, empty arrays where
applicable); specifically test FriendEntrySchema for publicId (string) and
createdAt (ISO datetime), FriendRequestsResponseSchema for incoming/outgoing
arrays of FriendEntrySchema, FriendsListResponseSchema for results array plus
numeric total/page/limit, and SendFriendRequestResponseSchema for the enum
values "requested" and "accepted". Use the project’s existing test framework and
schema parsing helpers to assert both .parse() success and that
.safeParse()/errors catch invalid inputs.

---

Nitpick comments:
In `@src/client/FriendsApi.ts`:
- Around line 55-63: The fetchFriends function is constructing the URL and
duplicating auth/header logic instead of using the shared friendsFetch helper;
update fetchFriends to call friendsFetch for the "/friends" endpoint (passing
page and limit as query params or as the helper's expected args) and remove the
manual fetch/Authorization header code. Locate fetchFriends and replace the new
URL + fetch(...) block with a single await to friendsFetch (or
friendsFetch.get/post depending on the helper API), then continue using the
returned response as before.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b12b3c6-e6d7-4b68-a41b-1d0a3dbfe826

📥 Commits

Reviewing files that changed from the base of the PR and between c0ef9b0 and 44d7e08.

📒 Files selected for processing (5)
  • resources/lang/en.json
  • src/client/AccountModal.ts
  • src/client/FriendsApi.ts
  • src/client/components/FriendsList.ts
  • src/core/ApiSchemas.ts
✅ Files skipped from review due to trivial changes (1)
  • resources/lang/en.json

Comment thread src/core/ApiSchemas.ts
@evanpelle evanpelle added this to the v32 milestone May 23, 2026
@evanpelle evanpelle marked this pull request as ready for review May 23, 2026 15:08
@evanpelle evanpelle requested a review from a team as a code owner May 23, 2026 15:08
@evanpelle evanpelle merged commit fd6cd76 into main May 23, 2026
15 of 16 checks passed
@github-project-automation github-project-automation Bot moved this from Development to Complete in OpenFront Release Management May 23, 2026
@evanpelle evanpelle deleted the friends branch May 23, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

1 participant