Style: Apply Spotless
This commit is contained in:
@@ -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.ChatClient;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.network.ClientService;
|
import ch.unibas.dmi.dbis.cs108.casono.client.network.ClientService;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatBoxController;
|
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 org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* responsible for the transferring of messages from the server to the ChatModel or from the
|
* responsible for the transferring of messages from the server to the ChatModel or from the
|
||||||
* ChatViewController to the server
|
* ChatViewController to the server
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.client.chat;
|
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.ArrayList;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import javafx.beans.property.IntegerProperty;
|
||||||
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ChatModel, stores the data for a specific chat
|
* ChatModel, stores the data for a specific chat
|
||||||
@@ -48,6 +47,7 @@ public class ChatModel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of chat this model represents.
|
* Returns the type of chat this model represents.
|
||||||
|
*
|
||||||
* @return The {@link ChatType}.
|
* @return The {@link ChatType}.
|
||||||
*/
|
*/
|
||||||
public ChatType getChattype() {
|
public ChatType getChattype() {
|
||||||
@@ -55,8 +55,8 @@ public class ChatModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new message to the history and notifies all registered listeners.
|
* Adds a new message to the history and notifies all registered listeners. This method is
|
||||||
* This method is synchronized to ensure thread safety when updating the message list.
|
* synchronized to ensure thread safety when updating the message list.
|
||||||
*
|
*
|
||||||
* @param msg The {@link Message} to be added.
|
* @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.
|
* Returns the target user for this chat, primarily used for whispers.
|
||||||
|
*
|
||||||
* @return The target username or null.
|
* @return The target username or null.
|
||||||
*/
|
*/
|
||||||
public String getTarget() {
|
public String getTarget() {
|
||||||
|
|||||||
@@ -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.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.ResponseBody;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBodyBuilder;
|
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.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
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 {
|
public class Message {
|
||||||
private final ChatType type;
|
private final ChatType type;
|
||||||
private final String message;
|
private final String message;
|
||||||
@@ -22,8 +19,8 @@ public class Message {
|
|||||||
public String target = null;
|
public String target = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Message with a provided timestamp. Typically used when
|
* Constructs a Message with a provided timestamp. Typically used when reconstructing messages
|
||||||
* reconstructing messages received from the server.
|
* received from the server.
|
||||||
*
|
*
|
||||||
* @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 lobbyId The ID of the lobby, or -1 if not applicable.
|
||||||
@@ -48,8 +45,8 @@ public class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Message for the current user. Automatically generates
|
* Constructs a new Message for the current user. Automatically generates a timestamp based on
|
||||||
* a timestamp based on the local system time ("HH:mm").
|
* 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 lobbyId The ID of the lobby, or -1 if not applicable.
|
||||||
@@ -87,8 +84,8 @@ public class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the message object into a string representation compatible with
|
* Formats the message object into a string representation compatible with the network protocol
|
||||||
* the network protocol arguments.
|
* arguments.
|
||||||
*
|
*
|
||||||
* @return A formatted string containing all message attributes for server transmission.
|
* @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.
|
* Parses a list of network request parameters to reconstruct a Message object. Handles
|
||||||
* Handles different chat types (GLOBAL, LOBBY, WHISPER) and their specific requirements.
|
* different chat types (GLOBAL, LOBBY, WHISPER) and their specific requirements.
|
||||||
*
|
*
|
||||||
* @param parameters A list of {@link RequestParameter} received from the network.
|
* @param parameters A list of {@link RequestParameter} received from the network.
|
||||||
* @return A new {@link Message} instance populated with the parsed data.
|
* @return A new {@link Message} instance populated with the parsed data.
|
||||||
@@ -120,21 +117,24 @@ public class Message {
|
|||||||
String typeString = getParString(parameters, "TYPE");
|
String typeString = getParString(parameters, "TYPE");
|
||||||
ChatType type = ChatType.valueOf(typeString);
|
ChatType type = ChatType.valueOf(typeString);
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
case GLOBAL -> new Message(
|
case GLOBAL ->
|
||||||
|
new Message(
|
||||||
ChatType.GLOBAL,
|
ChatType.GLOBAL,
|
||||||
-1,
|
-1,
|
||||||
getParString(parameters, "USER"),
|
getParString(parameters, "USER"),
|
||||||
null,
|
null,
|
||||||
getParString(parameters, "TIME"),
|
getParString(parameters, "TIME"),
|
||||||
getParString(parameters, "TEXT"));
|
getParString(parameters, "TEXT"));
|
||||||
case LOBBY -> new Message(
|
case LOBBY ->
|
||||||
|
new Message(
|
||||||
ChatType.LOBBY,
|
ChatType.LOBBY,
|
||||||
Integer.parseInt(getParString(parameters, "GAME")),
|
Integer.parseInt(getParString(parameters, "GAME")),
|
||||||
getParString(parameters, "USER"),
|
getParString(parameters, "USER"),
|
||||||
null,
|
null,
|
||||||
getParString(parameters, "TIME"),
|
getParString(parameters, "TIME"),
|
||||||
getParString(parameters, "TEXT"));
|
getParString(parameters, "TEXT"));
|
||||||
case WHISPER -> new Message(
|
case WHISPER ->
|
||||||
|
new Message(
|
||||||
ChatType.WHISPER,
|
ChatType.WHISPER,
|
||||||
Integer.parseInt(getParString(parameters, "GAME", "-1")),
|
Integer.parseInt(getParString(parameters, "GAME", "-1")),
|
||||||
getParString(parameters, "USER"),
|
getParString(parameters, "USER"),
|
||||||
@@ -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 parameters The list of parameters to search.
|
||||||
* @param keyString The key to look for.
|
* @param keyString The key to look for.
|
||||||
|
|||||||
@@ -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.command.parsing.RequestParameter;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.RawPacket;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.RawPacket;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TcpTransport;
|
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.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -17,6 +14,8 @@ import java.util.concurrent.Future;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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
|
* The ClientService class is responsible for managing the connection to the server, sending
|
||||||
@@ -35,9 +34,9 @@ public class ClientService {
|
|||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ClientService with the given server IP and port. It establishes
|
* Constructs a ClientService with the given server IP and port. It establishes a socket
|
||||||
* a socket connection to the server and initializes the TcpTransport and
|
* connection to the server and initializes the TcpTransport and ExecutorService for
|
||||||
* ExecutorService for communication.
|
* 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.
|
* @param port The port number of the server to connect to.
|
||||||
@@ -64,8 +63,8 @@ public class ClientService {
|
|||||||
"(?<key>\\w+)=(('(?<string>([^']|\\')+)')|(?<primVal>[+-]?[\\d\\w:]+))");
|
"(?<key>\\w+)=(('(?<string>([^']|\\')+)')|(?<primVal>[+-]?[\\d\\w:]+))");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes escape characters from a string, specifically converting escaped
|
* Removes escape characters from a string, specifically converting escaped single quotes (\')
|
||||||
* single quotes (\') back to regular single quotes (').
|
* back to regular single quotes (').
|
||||||
*
|
*
|
||||||
* @param input The escaped string to process.
|
* @param input The escaped string to process.
|
||||||
* @return The unescaped string.
|
* @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.
|
* Converts a list of raw string parameters into a list of {@link RequestParameter} objects. It
|
||||||
* It uses a regex matcher to distinguish between quoted strings (which are unescaped)
|
* uses a regex matcher to distinguish between quoted strings (which are unescaped) and
|
||||||
* and primitive values.
|
* primitive values.
|
||||||
*
|
*
|
||||||
* @param input A list of raw strings to be parsed.
|
* @param input A list of raw strings to be parsed.
|
||||||
* @return A list of parsed {@link RequestParameter} objects.
|
* @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.
|
* Sends a command to the server and processes the multi-line response. It handles the protocol
|
||||||
* It handles the protocol handshake (expecting +OK), strips leading tabs from
|
* handshake (expecting +OK), strips leading tabs from response lines, and collects them until
|
||||||
* response lines, and collects them until the "END" marker is reached.
|
* the "END" marker is reached.
|
||||||
*
|
*
|
||||||
* @param message The raw command string to be sent to the transport layer.
|
* @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).
|
* @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<String> processCommand(String message) {
|
protected List<String> processCommand(String message) {
|
||||||
List<String> response = new ArrayList<>();
|
List<String> response = new ArrayList<>();
|
||||||
|
|||||||
+13
-15
@@ -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.ChatController;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel;
|
import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatType;
|
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.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
@@ -13,10 +16,6 @@ import javafx.scene.control.TabPane;
|
|||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ChatBoxController {
|
public class ChatBoxController {
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
@@ -41,9 +40,9 @@ public class ChatBoxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the chat interface by creating the global chat model and
|
* Initializes the chat interface by creating the global chat model and adding the corresponding
|
||||||
* adding the corresponding "GLOBAL" tab to the interface.
|
* "GLOBAL" tab to the interface. It also registers the global chat in the {@link
|
||||||
* It also registers the global chat in the {@link ChatController}'s model map.
|
* ChatController}'s model map.
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
@@ -56,9 +55,8 @@ public class ChatBoxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a specific user to the list of available whisper targets.
|
* Adds a specific user to the list of available whisper targets. Creates a new menu item for
|
||||||
* Creates a new menu item for the user and defines the action to open
|
* the user and defines the action to open a private chat tab when selected.
|
||||||
* a private chat tab when selected.
|
|
||||||
*
|
*
|
||||||
* @param targetUserName The username of the person to be added to the whisper list.
|
* @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,
|
* Creates a new private (whisper) chat model for a specific target user, registers it within
|
||||||
* registers it within the chat system, and opens a new chat tab.
|
* the chat system, and opens a new chat tab.
|
||||||
*
|
*
|
||||||
* @param target The username of the recipient for the private messages.
|
* @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
|
* Dynamically loads a new chat tab from an FXML resource and attaches it to the TabPane. It
|
||||||
* to the TabPane. It initializes a {@link ChatViewController} for the tab
|
* initializes a {@link ChatViewController} for the tab and sets up a listener to display
|
||||||
* and sets up a listener to display incoming messages in real-time.
|
* incoming messages in real-time.
|
||||||
*
|
*
|
||||||
* @param title The title to be displayed on the tab header.
|
* @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.
|
* @param chatModel The {@link ChatModel} containing the data and logic for this specific chat.
|
||||||
|
|||||||
+12
-14
@@ -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.ChatController;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel;
|
import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.chat.Message;
|
import ch.unibas.dmi.dbis.cs108.casono.client.chat.Message;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
@@ -13,9 +15,6 @@ import javafx.scene.control.TextField;
|
|||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
/** Responsible for the presentation of the ChatModel to the Client */
|
/** Responsible for the presentation of the ChatModel to the Client */
|
||||||
public class ChatViewController implements Initializable {
|
public class ChatViewController implements Initializable {
|
||||||
|
|
||||||
@@ -44,11 +43,11 @@ public class ChatViewController implements Initializable {
|
|||||||
this.username = username;
|
this.username = username;
|
||||||
this.chatModel = chatModel;
|
this.chatModel = chatModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the controller after the FXML root element has been processed.
|
* Initializes the controller after the FXML root element has been processed. Sets up event
|
||||||
* Sets up event handlers for sending messages via the input field or button
|
* handlers for sending messages via the input field or button and ensures the ScrollPane
|
||||||
* and ensures the ScrollPane automatically scrolls to the bottom when new
|
* automatically scrolls to the bottom when new messages are added.
|
||||||
* messages are added.
|
|
||||||
*
|
*
|
||||||
* @param location The location used to resolve relative paths for the root object.
|
* @param location The location used to resolve relative paths for the root object.
|
||||||
* @param resourceBundle The resources used to localize 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
|
* Retrieves the text from the input field, creates a new {@link Message} object using the
|
||||||
* using the current model state, and passes it to the {@link ChatController}
|
* current model state, and passes it to the {@link ChatController} for network transmission.
|
||||||
* for network transmission. The input field is cleared after sending.
|
* The input field is cleared after sending.
|
||||||
*/
|
*/
|
||||||
public void sendMessage() {
|
public void sendMessage() {
|
||||||
String message = inputField.getText().trim();
|
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
|
* Displays a message in the chat interface. This method creates a new Label for the message
|
||||||
* for the message text and adds it to the message container.
|
* text and adds it to the message container. It uses {@link Platform#runLater(Runnable)} to
|
||||||
* It uses {@link Platform#runLater(Runnable)} to ensure the UI update
|
* ensure the UI update happens on the JavaFX Application Thread.
|
||||||
* happens on the JavaFX Application Thread.
|
|
||||||
*
|
*
|
||||||
* @param msg The {@link Message} object containing the content and metadata to display.
|
* @param msg The {@link Message} object containing the content and metadata to display.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+5
-6
@@ -11,8 +11,8 @@ public class GetMessageCountHandler extends CommandHandler<GetMessageCountReques
|
|||||||
private final UserRegistry userRegistry;
|
private final UserRegistry userRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new GetMessageCountHandler with the necessary response dispatcher
|
* Constructs a new GetMessageCountHandler with the necessary response dispatcher and user
|
||||||
* and user registry.
|
* registry.
|
||||||
*
|
*
|
||||||
* @param responseDispatcher The dispatcher used to send the count or error back to the client.
|
* @param responseDispatcher The dispatcher used to send the count or error back to the client.
|
||||||
* @param userRegistry The registry used to identify the user and access their message queue.
|
* @param userRegistry The registry used to identify the user and access their message queue.
|
||||||
@@ -24,10 +24,9 @@ public class GetMessageCountHandler extends CommandHandler<GetMessageCountReques
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a request to retrieve the number of pending messages for a user.
|
* Processes a request to retrieve the number of pending messages for a user. It looks up the
|
||||||
* It looks up the user by their session ID; if found, it dispatches a
|
* user by their session ID; if found, it dispatches a {@link GetMessageCountResponse}
|
||||||
* {@link GetMessageCountResponse} containing the current count. Otherwise,
|
* containing the current count. Otherwise, it dispatches an {@link ErrorResponse}.
|
||||||
* it dispatches an {@link ErrorResponse}.
|
|
||||||
*
|
*
|
||||||
* @param request The {@link GetMessageCountRequest} containing the session details.
|
* @param request The {@link GetMessageCountRequest} containing the session details.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+3
-3
@@ -6,9 +6,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.
|
|||||||
|
|
||||||
public class GetMessageCountParser implements CommandParser<GetMessageCountRequest> {
|
public class GetMessageCountParser implements CommandParser<GetMessageCountRequest> {
|
||||||
/**
|
/**
|
||||||
* Parses a raw {@link PrimitiveRequest} into a {@link GetMessageCountRequest}.
|
* Parses a raw {@link PrimitiveRequest} into a {@link GetMessageCountRequest}. This method
|
||||||
* This method wraps the request context from the network layer into a
|
* wraps the request context from the network layer into a structured message count request
|
||||||
* structured message count request object.
|
* object.
|
||||||
*
|
*
|
||||||
* @param primitiveRequest The raw request containing parameters and context from the network.
|
* @param primitiveRequest The raw request containing parameters and context from the network.
|
||||||
* @return A new {@link GetMessageCountRequest} instance.
|
* @return A new {@link GetMessageCountRequest} instance.
|
||||||
|
|||||||
+3
-3
@@ -5,9 +5,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo
|
|||||||
|
|
||||||
public class GetMessageCountRequest extends Request {
|
public class GetMessageCountRequest extends Request {
|
||||||
/**
|
/**
|
||||||
* Constructs a new GetMessageCountRequest with the specified request context.
|
* Constructs a new GetMessageCountRequest with the specified request context. This request is
|
||||||
* This request is used by a client to query the number of pending messages
|
* used by a client to query the number of pending messages currently waiting in their
|
||||||
* currently waiting in their server-side queue.
|
* server-side queue.
|
||||||
*
|
*
|
||||||
* @param context The {@link RequestContext} associated with this request.
|
* @param context The {@link RequestContext} associated with this request.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+2
-3
@@ -6,9 +6,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.
|
|||||||
|
|
||||||
public class GetMessageCountResponse extends SuccessResponse {
|
public class GetMessageCountResponse extends SuccessResponse {
|
||||||
/**
|
/**
|
||||||
* Constructs a new GetMessageCountResponse. It creates a response body
|
* Constructs a new GetMessageCountResponse. It creates a response body containing the "COUNT"
|
||||||
* containing the "COUNT" parameter and associates it with the original
|
* parameter and associates it with the original request context.
|
||||||
* request context.
|
|
||||||
*
|
*
|
||||||
* @param context The {@link RequestContext} of the original request.
|
* @param context The {@link RequestContext} of the original request.
|
||||||
* @param count The number of pending messages to be returned to the client.
|
* @param count The number of pending messages to be returned to the client.
|
||||||
|
|||||||
+5
-5
@@ -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.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.ErrorResponse;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class GetNextMessageHandler extends CommandHandler<GetNextMessageRequest> {
|
public class GetNextMessageHandler extends CommandHandler<GetNextMessageRequest> {
|
||||||
@@ -22,11 +21,12 @@ public class GetNextMessageHandler extends CommandHandler<GetNextMessageRequest>
|
|||||||
super(responseDispatcher);
|
super(responseDispatcher);
|
||||||
this.userRegistry = userRegistry;
|
this.userRegistry = userRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request to retrieve the next message for a specific user.
|
* Executes the request to retrieve the next message for a specific user. It identifies the user
|
||||||
* It identifies the user via their session ID, dequeues the next available message,
|
* via their session ID, dequeues the next available message, and dispatches a {@link
|
||||||
* and dispatches a {@link GetNextMessageResponse}. If the user cannot be identified,
|
* GetNextMessageResponse}. If the user cannot be identified, an {@link ErrorResponse} is sent
|
||||||
* an {@link ErrorResponse} is sent instead.
|
* instead.
|
||||||
*
|
*
|
||||||
* @param request The {@link GetNextMessageRequest} containing the session and context.
|
* @param request The {@link GetNextMessageRequest} containing the session and context.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+3
-4
@@ -6,10 +6,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.
|
|||||||
|
|
||||||
public class GetNextMessageParser implements CommandParser<GetNextMessageRequest> {
|
public class GetNextMessageParser implements CommandParser<GetNextMessageRequest> {
|
||||||
/**
|
/**
|
||||||
* Parses a raw {@link PrimitiveRequest} into a {@link GetNextMessageRequest}.
|
* Parses a raw {@link PrimitiveRequest} into a {@link GetNextMessageRequest}. This method
|
||||||
* This method initializes a parameter accessor (though not currently used
|
* initializes a parameter accessor (though not currently used for extraction) and returns a
|
||||||
* for extraction) and returns a structured request object containing
|
* structured request object containing the original request context.
|
||||||
* the original request context.
|
|
||||||
*
|
*
|
||||||
* @param primitiveRequest The raw request containing parameters and context from the network.
|
* @param primitiveRequest The raw request containing parameters and context from the network.
|
||||||
* @return A new {@link GetNextMessageRequest} instance.
|
* @return A new {@link GetNextMessageRequest} instance.
|
||||||
|
|||||||
+3
-3
@@ -5,9 +5,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo
|
|||||||
|
|
||||||
public class GetNextMessageRequest extends Request {
|
public class GetNextMessageRequest extends Request {
|
||||||
/**
|
/**
|
||||||
* Constructs a new GetNextMessageRequest with the specified request context.
|
* Constructs a new GetNextMessageRequest with the specified request context. This request is
|
||||||
* This request is typically used by a client to poll or retrieve the next
|
* typically used by a client to poll or retrieve the next available message from the server's
|
||||||
* available message from the server's queue.
|
* queue.
|
||||||
*
|
*
|
||||||
* @param context The {@link RequestContext} associated with this request.
|
* @param context The {@link RequestContext} associated with this request.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+2
-3
@@ -7,9 +7,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.
|
|||||||
|
|
||||||
public class GetNextMessageResponse extends SuccessResponse {
|
public class GetNextMessageResponse extends SuccessResponse {
|
||||||
/**
|
/**
|
||||||
* Constructs a new GetNextMessageResponse. It converts the provided {@link Message}
|
* Constructs a new GetNextMessageResponse. It converts the provided {@link Message} into a
|
||||||
* into a network-compatible response body and associates it with the original
|
* network-compatible response body and associates it with the original request context.
|
||||||
* request context.
|
|
||||||
*
|
*
|
||||||
* @param context The {@link RequestContext} of the request being answered.
|
* @param context The {@link RequestContext} of the request being answered.
|
||||||
* @param msg The {@link Message} to be sent back to the client.
|
* @param msg The {@link Message} to be sent back to the client.
|
||||||
|
|||||||
+4
-4
@@ -22,8 +22,8 @@ public class SendMessageHandler extends CommandHandler<SendMessageRequest> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a message send request. This method extracts the message from the request,
|
* 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)
|
* broadcasts it to all connected users, and dispatches a success response (OK) back to the
|
||||||
* back to the sender.
|
* sender.
|
||||||
*
|
*
|
||||||
* @param request The {@link SendMessageRequest} containing the message and context.
|
* @param request The {@link SendMessageRequest} containing the message and context.
|
||||||
*/
|
*/
|
||||||
@@ -36,8 +36,8 @@ public class SendMessageHandler extends CommandHandler<SendMessageRequest> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Distributes a message to every user currently registered in the system.
|
* Distributes a message to every user currently registered in the system. Each user's message
|
||||||
* Each user's message queue is updated with the new message.
|
* queue is updated with the new message.
|
||||||
*
|
*
|
||||||
* @param message The {@link Message} object to be broadcast.
|
* @param message The {@link Message} object to be broadcast.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+3
-3
@@ -7,9 +7,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Primitive
|
|||||||
public class SendMessageParser implements CommandParser<SendMessageRequest> {
|
public class SendMessageParser implements CommandParser<SendMessageRequest> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a raw {@link PrimitiveRequest} into a specific {@link SendMessageRequest}.
|
* Parses a raw {@link PrimitiveRequest} into a specific {@link SendMessageRequest}. This method
|
||||||
* This method extracts the message details from the request parameters and
|
* extracts the message details from the request parameters and wraps them along with the
|
||||||
* wraps them along with the request context into a structured request object.
|
* request context into a structured request object.
|
||||||
*
|
*
|
||||||
* @param primitiveRequest The raw request containing parameters and context from the network.
|
* @param primitiveRequest The raw request containing parameters and context from the network.
|
||||||
* @return A structured {@link SendMessageRequest} containing the parsed {@link Message}.
|
* @return A structured {@link SendMessageRequest} containing the parsed {@link Message}.
|
||||||
|
|||||||
@@ -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.ClientService;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.network.CoreClient;
|
import ch.unibas.dmi.dbis.cs108.casono.client.network.CoreClient;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatBoxController;
|
import ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatBoxController;
|
||||||
|
import java.io.IOException;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class ChatApplication extends Application {
|
public class ChatApplication extends Application {
|
||||||
|
|
||||||
private static final int SCENE_WIDTH = 1200;
|
private static final int SCENE_WIDTH = 1200;
|
||||||
@@ -21,30 +20,19 @@ public class ChatApplication extends Application {
|
|||||||
public ChatApplication() {}
|
public ChatApplication() {}
|
||||||
|
|
||||||
public void start(Stage stage) throws IOException {
|
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);
|
ClientService clientService = new ClientService(ip, port);
|
||||||
CoreClient coreClient = new CoreClient(clientService);
|
CoreClient coreClient = new CoreClient(clientService);
|
||||||
// TODO login UI
|
|
||||||
coreClient.login(username);
|
coreClient.login(username);
|
||||||
ChatController chatController = new ChatController(username, clientService);
|
ChatController chatController = new ChatController(username, clientService);
|
||||||
ChatBoxController chatBoxController = new ChatBoxController(username, chatController);
|
ChatBoxController chatBoxController = new ChatBoxController(username, chatController);
|
||||||
fxmlLoader.setController(chatBoxController);
|
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);
|
Scene scene = new Scene(fxmlLoader.load(), SCENE_WIDTH, SCENE_HEIGHT);
|
||||||
stage.setTitle("Chat");
|
stage.setTitle("Chat");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user