Skip to content

Labb3#36

Closed
gitnes94 wants to merge 7 commits intomainfrom
labb3
Closed

Labb3#36
gitnes94 wants to merge 7 commits intomainfrom
labb3

Conversation

@gitnes94
Copy link

@gitnes94 gitnes94 commented Nov 17, 2025

Summary by CodeRabbit

  • New Features

    • Added a complete chat interface with message sending and display capabilities.
    • Implemented file attachment functionality for sharing files.
    • Added online/offline status indicator to track connection state.
  • Configuration

    • Added environment file support for configuration management.
    • Added server configuration file for connection settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR transforms a JavaFX template into a functional chat application. It introduces chat UI components, a network client for HTTP-based message exchange with Ntfy services, message models, environment variable loading, comprehensive test coverage, and updates build configuration to support Java 25, Jackson, and modern testing frameworks.

Changes

Cohort / File(s) Summary
Build & Configuration
.gitignore, pom.xml, ntfy-server.yml, module-info.java, README.md
Updated .gitignore to include .env files; overhauled pom.xml with JUnit 5, Mockito, Jackson, WireMock dependencies and updated JavaFX/compiler plugins; added server configuration in ntfy-server.yml; renamed module to com.example.javafxchatapp with new exports and dependencies (java.net.http, Jackson); added "Author" section to README.
Chat UI & Controller
src/main/java/com/example/controller/ChatController.java, src/main/resources/com/example/ChatView.fxml
Introduced ChatController with @FXML-bound ListView, TextField, and Label for message display, input, and status. Handles message display with emoji formatting, async message sending, file attachment via FileChooser, and status updates (online/offline). Created ChatView.fxml FXML layout with VBox-based chat UI, message scrollpane, input bar, and styling.
Chat Model & Data
src/main/java/com/example/model/ChatModel.java, src/main/java/com/example/model/NtfyMessage.java
Added ChatModel managing chat state via NtfyHttpClient, determining base URL from properties/environment, and exposing observable message list; includes methods to connect, send text/files, and format file sizes. Introduced NtfyMessage Java record with topic, message, event, attachment fields and convenience constructors for Jackson deserialization.
Network Implementation
src/main/java/com/example/network/ChatNetworkClient.java, src/main/java/com/example/network/NtfyHttpClient.java
Created ChatNetworkClient interface defining async send, sendFile, and subscribe methods with a nested Subscription for managing streams. Implemented NtfyHttpClient using HttpClient for synchronous POST/PUT operations and async server-sent event streaming via line-by-line JSON parsing.
Application Entry & Utilities
src/main/java/com/example/HelloFX.java, src/main/java/com/example/HelloController.java, src/main/java/com/example/HelloModel.java, src/main/java/com/example/util/EnvLoader.java
Updated HelloFX to call EnvLoader.load(), load ChatView.fxml, set title to "Java25 Chat App", and narrow thrown exception to IOException. Removed JavaDoc comments from HelloController and HelloModel (no logic changes). Added EnvLoader utility to parse and load key=value pairs from .env files into system properties.
Tests
src/test/java/com/example/model/ChatModelTest.java, src/test/java/com/example/model/NtfyMessageTest.java
Added ChatModelTest with three tests covering message creation, event field validation, and attachment handling. Added NtfyMessageTest with JUnit 5 tests for constructor behavior, JSON deserialization/serialization, unknown field ignoring, and null value handling.

Sequence Diagram(s)

sequenceDiagram
    actor User as Chat User
    participant UI as ChatController
    participant Model as ChatModel
    participant NC as NtfyHttpClient
    participant Server as Ntfy Server
    
    rect rgb(220, 240, 255)
    Note over User,Server: Send Message Flow
    User->>UI: Type message & click Send
    activate UI
    UI->>UI: handleSendButtonAction (Task)
    UI->>Model: sendMessage(text)
    activate Model
    Model->>NC: send(baseUrl, NtfyMessage)
    activate NC
    NC->>Server: POST /myChatTopic (JSON)
    Server-->>NC: 200 OK
    NC-->>Model: (success)
    deactivate NC
    Model-->>UI: (async complete)
    deactivate Model
    UI->>UI: Clear input, updateStatusOnline()
    UI-->>User: Display status
    deactivate UI
    end
    
    rect rgb(240, 220, 255)
    Note over User,Server: Receive Message Flow (async)
    NC->>Server: GET /myChatTopic/json (stream)
    activate NC
    Server-->>NC: SSE line: {"event":"message",...}
    NC->>Model: onMessage callback (NtfyMessage)
    activate Model
    Model->>Model: Platform.runLater()
    Model->>UI: messageListView.add("🌸 {msg}")
    activate UI
    UI->>UI: ListCell renders, auto-scroll
    UI-->>User: Message appears
    deactivate UI
    deactivate Model
    deactivate NC
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • pom.xml: Comprehensive dependency and plugin overhaul; verify Java 21 compatibility, test framework versions, and JavaFX/Surefire configurations.
  • ChatModel.java & NtfyHttpClient.java: Core business logic for message handling and async streaming; verify URL resolution, error handling, thread safety with Platform.runLater().
  • module-info.java: Module system refactoring with new requires and opens directives; ensure all exports/opens align with network and Jackson reflection needs.
  • ChatController.java: UI event binding and async Task management; verify no UI thread blocks and proper error propagation.
  • ChatView.fxml: Layout and fx:id bindings; confirm all controller references and styling are correct.

Possibly related PRs

  • PR #33: Removes/rewrites the same chat classes (ChatController, ChatModel, NtfyHttpClient) and associated tests; direct overlap suggesting iteration or conflicting changes.
  • PR #27: Adds chat UI components and network functionality (ChatController, ChatModel, ChatView.fxml) and requires java.net.http; parallel implementation of similar features.
  • PR #32: Updates pom.xml build configuration and adds chat UI/model resources; shared build and chat infrastructure modifications.

Poem

🐰 A hoppy hop, a message sent,
Through wires swift, the words were bent.
From Java springs a chat so bright,
With sakura blooms and network might!
🌸 The rabbit codes with gleeful hops 🎉

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daa1037 and 35286d5.

📒 Files selected for processing (17)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • ntfy-server.yml (1 hunks)
  • pom.xml (1 hunks)
  • src/main/java/com/example/HelloController.java (0 hunks)
  • src/main/java/com/example/HelloFX.java (1 hunks)
  • src/main/java/com/example/HelloModel.java (1 hunks)
  • src/main/java/com/example/controller/ChatController.java (1 hunks)
  • src/main/java/com/example/model/ChatModel.java (1 hunks)
  • src/main/java/com/example/model/NtfyMessage.java (1 hunks)
  • src/main/java/com/example/network/ChatNetworkClient.java (1 hunks)
  • src/main/java/com/example/network/NtfyHttpClient.java (1 hunks)
  • src/main/java/com/example/util/EnvLoader.java (1 hunks)
  • src/main/java/module-info.java (1 hunks)
  • src/main/resources/com/example/ChatView.fxml (1 hunks)
  • src/test/java/com/example/model/ChatModelTest.java (1 hunks)
  • src/test/java/com/example/model/NtfyMesageTest.java (1 hunks)

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.

@gitnes94 gitnes94 closed this Nov 17, 2025
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