Applied suggestions from @delvh

This commit is contained in:
DieGurke 2020-07-08 14:15:44 +02:00
parent d88f31a300
commit a8443e6a50
4 changed files with 88 additions and 62 deletions

View File

@ -11,6 +11,9 @@ import envoy.data.User;
import envoy.event.GroupMessageStatusChange; import envoy.event.GroupMessageStatusChange;
/** /**
* Represents a chat between a user and a group
* as a list of messages.
* <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>GroupChat.java</strong><br> * File: <strong>GroupChat.java</strong><br>
* Created: <strong>05.07.2020</strong><br> * Created: <strong>05.07.2020</strong><br>
@ -26,7 +29,7 @@ public class GroupChat extends Chat {
/** /**
* @param sender the user sending the messages * @param sender the user sending the messages
* @param recipient the user who receives the messages * @param recipient the group whose members receive the messages
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public GroupChat(User sender, Contact recipient) { public GroupChat(User sender, Contact recipient) {
@ -37,13 +40,13 @@ public class GroupChat extends Chat {
@Override @Override
public void read(WriteProxy writeProxy) throws IOException { public void read(WriteProxy writeProxy) throws IOException {
for (int i = messages.size() - 1; i >= 0; --i) { for (int i = messages.size() - 1; i >= 0; --i) {
final GroupMessage g = (GroupMessage) messages.get(i); final GroupMessage gmsg = (GroupMessage) messages.get(i);
if (g.getSenderID() != sender.getID()) { if (gmsg.getSenderID() != sender.getID()) {
if (g.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break; if (gmsg.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break;
else { else {
g.getMemberStatuses().replace(sender.getID(), MessageStatus.READ); gmsg.getMemberStatuses().replace(sender.getID(), MessageStatus.READ);
writeProxy writeProxy
.writeMessageStatusChange(new GroupMessageStatusChange(g.getID(), MessageStatus.READ, LocalDateTime.now(), sender.getID())); .writeMessageStatusChange(new GroupMessageStatusChange(gmsg.getID(), MessageStatus.READ, LocalDateTime.now(), sender.getID()));
} }
} }
} }

View File

@ -53,22 +53,26 @@ public class Client implements Closeable {
* will block for up to 5 seconds. If the handshake does exceed this time limit, * will block for up to 5 seconds. If the handshake does exceed this time limit,
* an exception is thrown. * an exception is thrown.
* *
* @param credentials the login credentials of the user * @param credentials the login credentials of the
* @param receivedMessageCache a message cache containing all unread * user
* messages * @param receivedMessageCache a message cache containing all
* from the server that can be relayed * unread messages from the server
* after * that can be relayed after
* initialization * initialization
* @param receivedGroupMessageCache a groupMessage cache containing all * @param receivedGroupMessageCache a groupMessage cache containing
* unread * all unread groupMessages from
* groupMessages * the server that can be relayed
* from the server that can be relayed * after initialization
* after * @param receivedMessageStatusChangeCache an event cache containing all
* initialization * received
* @param receivedMessageStatusChangeCache an event cache containing all * messageStatusChangeEvents from
* received messageStatusChangeEvents * the server that can be relayed
* from the server that can be relayed * after initialization
* after initialization * @param receivedGroupMessageStatusChangeCache an event cache containing all
* received
* groupMessageStatusChangeEvents
* from the server that can be
* relayed after initialization
* @throws TimeoutException if the server could not be reached * @throws TimeoutException if the server could not be reached
* @throws IOException if the login credentials could not be written * @throws IOException if the login credentials could not be written
* @throws InterruptedException if the current thread is interrupted while * @throws InterruptedException if the current thread is interrupted while
@ -131,24 +135,36 @@ public class Client implements Closeable {
* Initializes the {@link Receiver} used to process data sent from the server to * Initializes the {@link Receiver} used to process data sent from the server to
* this client. * this client.
* *
* @param localDB the local database used to persist * @param localDB the local database used to
* the current * persist
* {@link IDGenerator} * the current
* @param receivedMessageCache a message cache containing all unread * {@link IDGenerator}
* messages * @param receivedMessageCache a message cache containing all
* from the server that can be relayed * unread
* after * messages
* initialization * from the server that can be
* @param receivedGroupMessageCache a groupMessage cache containing all * relayed
* unread * after
* groupMessages * initialization
* from the server that can be relayed * @param receivedGroupMessageCache a groupMessage cache containing
* after * all
* initialization * unread
* @param receivedMessageStatusChangeCache an event cache containing all * groupMessages
* received messageStatusChangeEvents * from the server that can be
* from the server that can be relayed * relayed
* after initialization * after
* initialization
* @param receivedMessageStatusChangeCache an event cache containing all
* received
* messageStatusChangeEvents
* from the server that can be
* relayed
* after initialization
* @param receivedGroupMessageStatusChangeCache an event cache containing all
* received
* groupMessageStatusChangeEvents
* from the server that can be
* relayed after initialization
* @throws IOException if no {@link IDGenerator} is present and none could be * @throws IOException if no {@link IDGenerator} is present and none could be
* requested from the server * requested from the server
* @since Envoy Client v0.2-alpha * @since Envoy Client v0.2-alpha
@ -159,8 +175,8 @@ public class Client implements Closeable {
checkOnline(); checkOnline();
// Process incoming messages // Process incoming messages
final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor(); final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor();
final ReceivedGroupMessageProcessor receivedGroupMessageProcessor = new ReceivedGroupMessageProcessor(); final ReceivedGroupMessageProcessor receivedGroupMessageProcessor = new ReceivedGroupMessageProcessor();
final MessageStatusChangeProcessor messageStatusChangeProcessor = new MessageStatusChangeProcessor(); final MessageStatusChangeProcessor messageStatusChangeProcessor = new MessageStatusChangeProcessor();
final GroupMessageStatusChangeProcessor groupMessageStatusChangeProcessor = new GroupMessageStatusChangeProcessor(); final GroupMessageStatusChangeProcessor groupMessageStatusChangeProcessor = new GroupMessageStatusChangeProcessor();

View File

@ -29,8 +29,8 @@ import envoy.client.ui.listcell.ContactListCellFactory;
import envoy.client.ui.listcell.MessageControl; import envoy.client.ui.listcell.MessageControl;
import envoy.client.ui.listcell.MessageListCellFactory; import envoy.client.ui.listcell.MessageListCellFactory;
import envoy.data.*; import envoy.data.*;
import envoy.event.*;
import envoy.data.Attachment.AttachmentType; import envoy.data.Attachment.AttachmentType;
import envoy.event.*;
import envoy.event.contact.ContactOperation; import envoy.event.contact.ContactOperation;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
@ -135,7 +135,7 @@ public final class ChatScene implements Restorable {
eventBus.register(GroupMessageStatusChange.class, e -> localDB.getMessage(e.getID()).ifPresent(groupMessage -> { eventBus.register(GroupMessageStatusChange.class, e -> localDB.getMessage(e.getID()).ifPresent(groupMessage -> {
((GroupMessage) groupMessage).getMemberStatuses().replace(e.getMemberID(), e.get()); ((GroupMessage) groupMessage).getMemberStatuses().replace(e.getMemberID(), e.get());
// Update UI id in current chat // Update UI if in current chat
if (currentChat != null && groupMessage.getRecipientID() == currentChat.getRecipient().getID()) Platform.runLater(messageList::refresh); if (currentChat != null && groupMessage.getRecipientID() == currentChat.getRecipient().getID()) Platform.runLater(messageList::refresh);
})); }));
@ -355,9 +355,8 @@ public final class ChatScene implements Restorable {
} }
/** /**
* Sends a new message or groupMessage to the server based on the text entered * Sends a new {@link Message} or {@link GroupMessage} to the server based on
* in the * the text entered in the {@code messageTextArea} and the given attachment.
* messageTextArea.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */

View File

@ -75,21 +75,29 @@ public final class LoginScene {
/** /**
* Loads the login dialog using the FXML file {@code LoginDialog.fxml}. * Loads the login dialog using the FXML file {@code LoginDialog.fxml}.
* *
* @param client the client used to perform the * @param client the client used to perform the
* handshake * handshake
* @param localDB the local database used for offline * @param localDB the local database used for
* login * offline
* @param receivedMessageCache the cache storing messages received * login
* during * @param receivedMessageCache the cache storing messages
* the handshake * received
* @param receivedGroupMessageCache the cache storing groupMessages * during
* received during the handshake * the handshake
* @param receivedMessageStatusChangeCache the cache storing * @param receivedGroupMessageCache the cache storing groupMessages
* messageStatusChangeEvents received * received during the handshake
* during handshake * @param receivedMessageStatusChangeCache the cache storing
* @param sceneContext the scene context used to initialize * messageStatusChangeEvents
* the chat * received
* scene * during handshake
* @param receivedGroupMessageStatusChangeCache the cache storing
* groupMessageStatusChangeEvents
* received
* during handshake
* @param sceneContext the scene context used to
* initialize
* the chat
* scene
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void initializeData(Client client, LocalDB localDB, Cache<Message> receivedMessageCache, Cache<GroupMessage> receivedGroupMessageCache, public void initializeData(Client client, LocalDB localDB, Cache<Message> receivedMessageCache, Cache<GroupMessage> receivedGroupMessageCache,