diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java index 1ebaf41..161397a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java @@ -3,10 +3,13 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import ch.unibas.dmi.dbis.cs108.casono.client.network.ChatClient; import ch.unibas.dmi.dbis.cs108.casono.client.network.ClientService; import ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatBoxController; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; import org.jspecify.annotations.Nullable; -import java.util.*; - /** * responsible for the transferring of messages from the server to the ChatModel or from the * ChatViewController to the server diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java index 87c9b8f..69cdecb 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java @@ -1,10 +1,9 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.SimpleIntegerProperty; - import java.util.ArrayList; import java.util.function.Consumer; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; /** * ChatModel, stores the data for a specific chat @@ -48,6 +47,7 @@ public class ChatModel { /** * Returns the type of chat this model represents. + * * @return The {@link ChatType}. */ public ChatType getChattype() { @@ -55,8 +55,8 @@ public class ChatModel { } /** - * Adds a new message to the history and notifies all registered listeners. - * This method is synchronized to ensure thread safety when updating the message list. + * Adds a new message to the history and notifies all registered listeners. This method is + * synchronized to ensure thread safety when updating the message list. * * @param msg The {@link Message} to be added. */ @@ -76,6 +76,7 @@ public class ChatModel { /** * Returns the target user for this chat, primarily used for whispers. + * * @return The target username or null. */ public String getTarget() { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java index f2ab7d2..8ed83b8 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java @@ -3,16 +3,13 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.RequestParameter; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBodyBuilder; -import org.jspecify.annotations.NonNull; - import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; +import org.jspecify.annotations.NonNull; -/** - * Message Object for internal handling of Chat-Messages - */ +/** Message Object for internal handling of Chat-Messages */ public class Message { private final ChatType type; private final String message; @@ -22,15 +19,15 @@ public class Message { public String target = null; /** - * Constructs a Message with a provided timestamp. Typically used when - * reconstructing messages received from the server. + * Constructs a Message with a provided timestamp. Typically used when reconstructing messages + * received from the server. * - * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). - * @param lobbyId The ID of the lobby, or -1 if not applicable. - * @param sender The username of the message creator. - * @param target The username of the recipient (required for whispers, otherwise null). + * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). + * @param lobbyId The ID of the lobby, or -1 if not applicable. + * @param sender The username of the message creator. + * @param target The username of the recipient (required for whispers, otherwise null). * @param timestamp The formatted time string (e.g., "HH:mm"). - * @param message The actual text content of the message. + * @param message The actual text content of the message. */ public Message( ChatType type, @@ -48,13 +45,13 @@ public class Message { } /** - * Constructs a new Message for the current user. Automatically generates - * a timestamp based on the local system time ("HH:mm"). + * Constructs a new Message for the current user. Automatically generates a timestamp based on + * the local system time ("HH:mm"). * - * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). + * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). * @param lobbyId The ID of the lobby, or -1 if not applicable. - * @param sender The username of the current user. - * @param target The username of the recipient (for whispers). + * @param sender The username of the current user. + * @param target The username of the recipient (for whispers). * @param message The actual text content to be sent. */ public Message(ChatType type, int lobbyId, String sender, String target, String message) { @@ -87,8 +84,8 @@ public class Message { } /** - * Formats the message object into a string representation compatible with - * the network protocol arguments. + * Formats the message object into a string representation compatible with the network protocol + * arguments. * * @return A formatted string containing all message attributes for server transmission. */ @@ -110,8 +107,8 @@ public class Message { } /** - * Parses a list of network request parameters to reconstruct a Message object. - * Handles different chat types (GLOBAL, LOBBY, WHISPER) and their specific requirements. + * Parses a list of network request parameters to reconstruct a Message object. Handles + * different chat types (GLOBAL, LOBBY, WHISPER) and their specific requirements. * * @param parameters A list of {@link RequestParameter} received from the network. * @return A new {@link Message} instance populated with the parsed data. @@ -120,27 +117,30 @@ public class Message { String typeString = getParString(parameters, "TYPE"); ChatType type = ChatType.valueOf(typeString); return switch (type) { - case GLOBAL -> new Message( - ChatType.GLOBAL, - -1, - getParString(parameters, "USER"), - null, - getParString(parameters, "TIME"), - getParString(parameters, "TEXT")); - case LOBBY -> new Message( - ChatType.LOBBY, - Integer.parseInt(getParString(parameters, "GAME")), - getParString(parameters, "USER"), - null, - getParString(parameters, "TIME"), - getParString(parameters, "TEXT")); - case WHISPER -> new Message( - ChatType.WHISPER, - Integer.parseInt(getParString(parameters, "GAME", "-1")), - getParString(parameters, "USER"), - getParString(parameters, "TARGET"), - getParString(parameters, "TIME"), - getParString(parameters, "TEXT")); + case GLOBAL -> + new Message( + ChatType.GLOBAL, + -1, + getParString(parameters, "USER"), + null, + getParString(parameters, "TIME"), + getParString(parameters, "TEXT")); + case LOBBY -> + new Message( + ChatType.LOBBY, + Integer.parseInt(getParString(parameters, "GAME")), + getParString(parameters, "USER"), + null, + getParString(parameters, "TIME"), + getParString(parameters, "TEXT")); + case WHISPER -> + new Message( + ChatType.WHISPER, + Integer.parseInt(getParString(parameters, "GAME", "-1")), + getParString(parameters, "USER"), + getParString(parameters, "TARGET"), + getParString(parameters, "TIME"), + getParString(parameters, "TEXT")); }; } @@ -158,7 +158,8 @@ public class Message { } /** - * Helper method to extract a specific parameter value by its key, with a fallback default value. + * Helper method to extract a specific parameter value by its key, with a fallback default + * value. * * @param parameters The list of parameters to search. * @param keyString The key to look for. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java index 833ffb8..4ede0c1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java @@ -3,9 +3,6 @@ package ch.unibas.dmi.dbis.cs108.casono.client.network; import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.RequestParameter; import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.RawPacket; import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TcpTransport; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.IOException; import java.net.Socket; import java.util.ArrayList; @@ -17,6 +14,8 @@ import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * The ClientService class is responsible for managing the connection to the server, sending @@ -35,11 +34,11 @@ public class ClientService { private final Logger logger; /** - * Constructs a ClientService with the given server IP and port. It establishes - * a socket connection to the server and initializes the TcpTransport and - * ExecutorService for communication. + * Constructs a ClientService with the given server IP and port. It establishes a socket + * connection to the server and initializes the TcpTransport and ExecutorService for + * communication. * - * @param ip The IP address of the server to connect to. + * @param ip The IP address of the server to connect to. * @param port The port number of the server to connect to. */ public ClientService(String ip, int port) { @@ -64,8 +63,8 @@ public class ClientService { "(?\\w+)=(('(?([^']|\\')+)')|(?[+-]?[\\d\\w:]+))"); /** - * Removes escape characters from a string, specifically converting escaped - * single quotes (\') back to regular single quotes ('). + * Removes escape characters from a string, specifically converting escaped single quotes (\') + * back to regular single quotes ('). * * @param input The escaped string to process. * @return The unescaped string. @@ -75,9 +74,9 @@ public class ClientService { } /** - * Converts a list of raw string parameters into a list of {@link RequestParameter} objects. - * It uses a regex matcher to distinguish between quoted strings (which are unescaped) - * and primitive values. + * Converts a list of raw string parameters into a list of {@link RequestParameter} objects. It + * uses a regex matcher to distinguish between quoted strings (which are unescaped) and + * primitive values. * * @param input A list of raw strings to be parsed. * @return A list of parsed {@link RequestParameter} objects. @@ -102,13 +101,14 @@ public class ClientService { } /** - * Sends a command to the server and processes the multi-line response. - * It handles the protocol handshake (expecting +OK), strips leading tabs from - * response lines, and collects them until the "END" marker is reached. + * Sends a command to the server and processes the multi-line response. It handles the protocol + * handshake (expecting +OK), strips leading tabs from response lines, and collects them until + * the "END" marker is reached. * * @param message The raw command string to be sent to the transport layer. * @return A list of response lines received from the server (excluding protocol markers). - * @throws RuntimeException if the server responds with an error or if a communication failure occurs. + * @throws RuntimeException if the server responds with an error or if a communication failure + * occurs. */ protected List processCommand(String message) { List response = new ArrayList<>(); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java index 65e38fe..618d309 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java @@ -3,6 +3,9 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatController; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatType; +import java.io.IOException; +import java.net.URL; +import java.util.List; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; @@ -13,10 +16,6 @@ import javafx.scene.control.TabPane; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; -import java.io.IOException; -import java.net.URL; -import java.util.List; - public class ChatBoxController { private String username; @@ -41,9 +40,9 @@ public class ChatBoxController { } /** - * Initializes the chat interface by creating the global chat model and - * adding the corresponding "GLOBAL" tab to the interface. - * It also registers the global chat in the {@link ChatController}'s model map. + * Initializes the chat interface by creating the global chat model and adding the corresponding + * "GLOBAL" tab to the interface. It also registers the global chat in the {@link + * ChatController}'s model map. */ @FXML public void initialize() { @@ -56,9 +55,8 @@ public class ChatBoxController { } /** - * Adds a specific user to the list of available whisper targets. - * Creates a new menu item for the user and defines the action to open - * a private chat tab when selected. + * Adds a specific user to the list of available whisper targets. Creates a new menu item for + * the user and defines the action to open a private chat tab when selected. * * @param targetUserName The username of the person to be added to the whisper list. */ @@ -70,8 +68,8 @@ public class ChatBoxController { } /** - * Creates a new private (whisper) chat model for a specific target user, - * registers it within the chat system, and opens a new chat tab. + * Creates a new private (whisper) chat model for a specific target user, registers it within + * the chat system, and opens a new chat tab. * * @param target The username of the recipient for the private messages. */ @@ -84,9 +82,9 @@ public class ChatBoxController { } /** - * Dynamically loads a new chat tab from an FXML resource and attaches it - * to the TabPane. It initializes a {@link ChatViewController} for the tab - * and sets up a listener to display incoming messages in real-time. + * Dynamically loads a new chat tab from an FXML resource and attaches it to the TabPane. It + * initializes a {@link ChatViewController} for the tab and sets up a listener to display + * incoming messages in real-time. * * @param title The title to be displayed on the tab header. * @param chatModel The {@link ChatModel} containing the data and logic for this specific chat. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java index 879427f..397e8f3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java @@ -3,6 +3,8 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatController; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel; import ch.unibas.dmi.dbis.cs108.casono.client.chat.Message; +import java.net.URL; +import java.util.ResourceBundle; import javafx.application.Platform; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -13,9 +15,6 @@ import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import java.net.URL; -import java.util.ResourceBundle; - /** Responsible for the presentation of the ChatModel to the Client */ public class ChatViewController implements Initializable { @@ -44,11 +43,11 @@ public class ChatViewController implements Initializable { this.username = username; this.chatModel = chatModel; } + /** - * Initializes the controller after the FXML root element has been processed. - * Sets up event handlers for sending messages via the input field or button - * and ensures the ScrollPane automatically scrolls to the bottom when new - * messages are added. + * Initializes the controller after the FXML root element has been processed. Sets up event + * handlers for sending messages via the input field or button and ensures the ScrollPane + * automatically scrolls to the bottom when new messages are added. * * @param location The location used to resolve relative paths for the root object. * @param resourceBundle The resources used to localize the root object. @@ -61,9 +60,9 @@ public class ChatViewController implements Initializable { } /** - * Retrieves the text from the input field, creates a new {@link Message} object - * using the current model state, and passes it to the {@link ChatController} - * for network transmission. The input field is cleared after sending. + * Retrieves the text from the input field, creates a new {@link Message} object using the + * current model state, and passes it to the {@link ChatController} for network transmission. + * The input field is cleared after sending. */ public void sendMessage() { String message = inputField.getText().trim(); @@ -81,10 +80,9 @@ public class ChatViewController implements Initializable { } /** - * Displays a message in the chat interface. This method creates a new Label - * for the message text and adds it to the message container. - * It uses {@link Platform#runLater(Runnable)} to ensure the UI update - * happens on the JavaFX Application Thread. + * Displays a message in the chat interface. This method creates a new Label for the message + * text and adds it to the message container. It uses {@link Platform#runLater(Runnable)} to + * ensure the UI update happens on the JavaFX Application Thread. * * @param msg The {@link Message} object containing the content and metadata to display. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java index 46203c4..dcfe216 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java @@ -11,8 +11,8 @@ public class GetMessageCountHandler extends CommandHandler { /** - * Parses a raw {@link PrimitiveRequest} into a {@link GetMessageCountRequest}. - * This method wraps the request context from the network layer into a - * structured message count request object. + * Parses a raw {@link PrimitiveRequest} into a {@link GetMessageCountRequest}. This method + * wraps the request context from the network layer into a structured message count request + * object. * * @param primitiveRequest The raw request containing parameters and context from the network. * @return A new {@link GetMessageCountRequest} instance. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java index 93f99c5..a1d0f7d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java @@ -5,9 +5,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo public class GetMessageCountRequest extends Request { /** - * Constructs a new GetMessageCountRequest with the specified request context. - * This request is used by a client to query the number of pending messages - * currently waiting in their server-side queue. + * Constructs a new GetMessageCountRequest with the specified request context. This request is + * used by a client to query the number of pending messages currently waiting in their + * server-side queue. * * @param context The {@link RequestContext} associated with this request. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java index 87c212d..a58edd6 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java @@ -6,9 +6,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder. public class GetMessageCountResponse extends SuccessResponse { /** - * Constructs a new GetMessageCountResponse. It creates a response body - * containing the "COUNT" parameter and associates it with the original - * request context. + * Constructs a new GetMessageCountResponse. It creates a response body containing the "COUNT" + * parameter and associates it with the original request context. * * @param context The {@link RequestContext} of the original request. * @param count The number of pending messages to be returned to the client. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java index f024d24..deb5773 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java @@ -6,7 +6,6 @@ import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserRegistry; import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandHandler; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorResponse; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher; - import java.util.Optional; public class GetNextMessageHandler extends CommandHandler { @@ -22,11 +21,12 @@ public class GetNextMessageHandler extends CommandHandler super(responseDispatcher); this.userRegistry = userRegistry; } + /** - * Executes the request to retrieve the next message for a specific user. - * It identifies the user via their session ID, dequeues the next available message, - * and dispatches a {@link GetNextMessageResponse}. If the user cannot be identified, - * an {@link ErrorResponse} is sent instead. + * Executes the request to retrieve the next message for a specific user. It identifies the user + * via their session ID, dequeues the next available message, and dispatches a {@link + * GetNextMessageResponse}. If the user cannot be identified, an {@link ErrorResponse} is sent + * instead. * * @param request The {@link GetNextMessageRequest} containing the session and context. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java index e75577c..185c5b5 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java @@ -6,10 +6,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor. public class GetNextMessageParser implements CommandParser { /** - * Parses a raw {@link PrimitiveRequest} into a {@link GetNextMessageRequest}. - * This method initializes a parameter accessor (though not currently used - * for extraction) and returns a structured request object containing - * the original request context. + * Parses a raw {@link PrimitiveRequest} into a {@link GetNextMessageRequest}. This method + * initializes a parameter accessor (though not currently used for extraction) and returns a + * structured request object containing the original request context. * * @param primitiveRequest The raw request containing parameters and context from the network. * @return A new {@link GetNextMessageRequest} instance. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java index 77c8b57..76f6678 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java @@ -5,9 +5,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo public class GetNextMessageRequest extends Request { /** - * Constructs a new GetNextMessageRequest with the specified request context. - * This request is typically used by a client to poll or retrieve the next - * available message from the server's queue. + * Constructs a new GetNextMessageRequest with the specified request context. This request is + * typically used by a client to poll or retrieve the next available message from the server's + * queue. * * @param context The {@link RequestContext} associated with this request. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java index ecb3c12..1fd9378 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java @@ -7,9 +7,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder. public class GetNextMessageResponse extends SuccessResponse { /** - * Constructs a new GetNextMessageResponse. It converts the provided {@link Message} - * into a network-compatible response body and associates it with the original - * request context. + * Constructs a new GetNextMessageResponse. It converts the provided {@link Message} into a + * network-compatible response body and associates it with the original request context. * * @param context The {@link RequestContext} of the request being answered. * @param msg The {@link Message} to be sent back to the client. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java index 805afcc..0bf5b95 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java @@ -22,8 +22,8 @@ public class SendMessageHandler extends CommandHandler { /** * Processes a message send request. This method extracts the message from the request, - * broadcasts it to all connected users, and dispatches a success response (OK) - * back to the sender. + * broadcasts it to all connected users, and dispatches a success response (OK) back to the + * sender. * * @param request The {@link SendMessageRequest} containing the message and context. */ @@ -36,8 +36,8 @@ public class SendMessageHandler extends CommandHandler { } /** - * Distributes a message to every user currently registered in the system. - * Each user's message queue is updated with the new message. + * Distributes a message to every user currently registered in the system. Each user's message + * queue is updated with the new message. * * @param message The {@link Message} object to be broadcast. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java index c13ac3d..eb8cf95 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java @@ -7,9 +7,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Primitive public class SendMessageParser implements CommandParser { /** - * Parses a raw {@link PrimitiveRequest} into a specific {@link SendMessageRequest}. - * This method extracts the message details from the request parameters and - * wraps them along with the request context into a structured request object. + * Parses a raw {@link PrimitiveRequest} into a specific {@link SendMessageRequest}. This method + * extracts the message details from the request parameters and wraps them along with the + * request context into a structured request object. * * @param primitiveRequest The raw request containing parameters and context from the network. * @return A structured {@link SendMessageRequest} containing the parsed {@link Message}. diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java index 15b81d7..6088f22 100644 --- a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java @@ -3,7 +3,7 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import javafx.application.Application; public class Chat { - public static void main(String[] args) { - Application.launch(ChatApplication.class); - } + public static void main(String[] args) { + Application.launch(ChatApplication.class); + } } diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java index c44f4fd..6974c0d 100644 --- a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java @@ -3,13 +3,12 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import ch.unibas.dmi.dbis.cs108.casono.client.network.ClientService; import ch.unibas.dmi.dbis.cs108.casono.client.network.CoreClient; import ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatBoxController; +import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; -import java.io.IOException; - public class ChatApplication extends Application { private static final int SCENE_WIDTH = 1200; @@ -21,30 +20,19 @@ public class ChatApplication extends Application { public ChatApplication() {} public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/ui-structure/components/chatui/chatbox.fxml")); + FXMLLoader fxmlLoader = + new FXMLLoader( + getClass().getResource("/ui-structure/components/chatui/chatbox.fxml")); ClientService clientService = new ClientService(ip, port); CoreClient coreClient = new CoreClient(clientService); - // TODO login UI coreClient.login(username); ChatController chatController = new ChatController(username, clientService); ChatBoxController chatBoxController = new ChatBoxController(username, chatController); fxmlLoader.setController(chatBoxController); - /*fxmlLoader.setControllerFactory(type -> { - if (type == ChatBoxController.class) { - return chatController.getChatBoxController(); - } else { - try { - return type.getConstructor().newInstance(); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } - });*/ Scene scene = new Scene(fxmlLoader.load(), SCENE_WIDTH, SCENE_HEIGHT); stage.setTitle("Chat"); stage.setScene(scene); stage.show(); } - }