Feat/chat tests #317
@@ -2,8 +2,6 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat;
|
|||||||
|
|
||||||
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
|
||||||
@@ -12,7 +10,7 @@ import javafx.beans.property.SimpleIntegerProperty;
|
|||||||
*/
|
*/
|
||||||
public class ChatModel {
|
public class ChatModel {
|
||||||
|
|
||||||
private ArrayList<Consumer<Message>> listeners = new ArrayList<>();
|
private final ArrayList<Consumer<Message>> listeners = new ArrayList<>();
|
||||||
|
|
||||||
public ArrayList<Message> messages;
|
public ArrayList<Message> messages;
|
||||||
|
|
||||||
@@ -24,8 +22,6 @@ public class ChatModel {
|
|||||||
/** The person to send the message to If the chat is a whisper chat */
|
/** The person to send the message to If the chat is a whisper chat */
|
||||||
private String target;
|
private String target;
|
||||||
|
|
||||||
private final IntegerProperty count;
|
|
||||||
|
|
||||||
public int lobbyId;
|
public int lobbyId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,10 +33,9 @@ public class ChatModel {
|
|||||||
* @param target The username of the whisper recipient, or null for other chat types.
|
* @param target The username of the whisper recipient, or null for other chat types.
|
||||||
*/
|
*/
|
||||||
public ChatModel(ChatType chattype, String username, int lobbyId, String target) {
|
public ChatModel(ChatType chattype, String username, int lobbyId, String target) {
|
||||||
this.messages = new ArrayList<Message>();
|
this.messages = new ArrayList<>();
|
||||||
this.chattype = chattype;
|
this.chattype = chattype;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.count = new SimpleIntegerProperty(0);
|
|
||||||
this.lobbyId = lobbyId;
|
this.lobbyId = lobbyId;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
@@ -62,7 +57,7 @@ public class ChatModel {
|
|||||||
*/
|
*/
|
||||||
public synchronized void addMessage(Message msg) {
|
public synchronized void addMessage(Message msg) {
|
||||||
messages.add(msg);
|
messages.add(msg);
|
||||||
listeners.stream().forEach((l) -> l.accept(messages.getLast()));
|
listeners.forEach((l) -> l.accept(messages.getLast()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ public class Message {
|
|||||||
private final String message;
|
private final String message;
|
||||||
public String sender;
|
public String sender;
|
||||||
public String timestamp;
|
public String timestamp;
|
||||||
public int lobbyId = 0;
|
public int lobbyId;
|
||||||
public String target = null;
|
public String target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Message with a provided timestamp. Typically used when reconstructing messages
|
* Constructs a Message with a provided timestamp. Typically used when reconstructing messages
|
||||||
@@ -100,7 +100,7 @@ public class Message {
|
|||||||
* @return A formatted string containing all message attributes for server transmission.
|
* @return A formatted string containing all message attributes for server transmission.
|
||||||
*/
|
*/
|
||||||
public String toArgsString() {
|
public String toArgsString() {
|
||||||
String gameIdString = "";
|
String gameIdString;
|
||||||
if (lobbyId >= 0) {
|
if (lobbyId >= 0) {
|
||||||
gameIdString = " GAME=" + lobbyId;
|
gameIdString = " GAME=" + lobbyId;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -198,15 +198,6 @@ public class ChatBoxController {
|
|||||||
new ChatViewController(
|
new ChatViewController(
|
||||||
this.chatController, chatModel, this);
|
this.chatController, chatModel, this);
|
||||||
|
|
||||||
ChatKey chatKey;
|
|
||||||
if (chatType.equals(ChatType.WHISPER)) {
|
|
||||||
chatKey = new ChatKey(chatType, title);
|
|
||||||
} else {
|
|
||||||
chatKey = new ChatKey(chatType);
|
|
||||||
}
|
|
||||||
chatController.activeChatControllers.put(chatKey, chatViewController);
|
|
||||||
this.chatController, chatModel, this.username, this);
|
|
||||||
|
|
||||||
ChatKey chatKey;
|
ChatKey chatKey;
|
||||||
if (chatType.equals(ChatType.WHISPER)) {
|
if (chatType.equals(ChatType.WHISPER)) {
|
||||||
chatKey = new ChatKey(chatType, title);
|
chatKey = new ChatKey(chatType, title);
|
||||||
|
|||||||
Reference in New Issue
Block a user