Applied suggestions from @delvh
This commit is contained in:
parent
8bb6b051b9
commit
973fd69cf2
@ -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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
* @param receivedMessageStatusChangeCache an event cache containing all
|
|
||||||
* received messageStatusChangeEvents
|
|
||||||
* from the server that can be 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 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
|
||||||
|
* persist
|
||||||
* the current
|
* the current
|
||||||
* {@link IDGenerator}
|
* {@link IDGenerator}
|
||||||
* @param receivedMessageCache a message cache containing all unread
|
* @param receivedMessageCache a message cache containing all
|
||||||
|
* unread
|
||||||
* messages
|
* messages
|
||||||
* from the server that can be relayed
|
* from the server that can be
|
||||||
|
* relayed
|
||||||
* after
|
* after
|
||||||
* initialization
|
* initialization
|
||||||
* @param receivedGroupMessageCache a groupMessage cache containing all
|
* @param receivedGroupMessageCache a groupMessage cache containing
|
||||||
|
* all
|
||||||
* unread
|
* unread
|
||||||
* groupMessages
|
* groupMessages
|
||||||
* from the server that can be relayed
|
* from the server that can be
|
||||||
|
* relayed
|
||||||
* after
|
* after
|
||||||
* initialization
|
* initialization
|
||||||
* @param receivedMessageStatusChangeCache an event cache containing all
|
* @param receivedMessageStatusChangeCache an event cache containing all
|
||||||
* received messageStatusChangeEvents
|
* received
|
||||||
* from the server that can be relayed
|
* messageStatusChangeEvents
|
||||||
|
* 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 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
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -77,17 +77,25 @@ public final class LoginScene {
|
|||||||
*
|
*
|
||||||
* @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
|
||||||
|
* offline
|
||||||
* login
|
* login
|
||||||
* @param receivedMessageCache the cache storing messages received
|
* @param receivedMessageCache the cache storing messages
|
||||||
|
* received
|
||||||
* during
|
* during
|
||||||
* the handshake
|
* the handshake
|
||||||
* @param receivedGroupMessageCache the cache storing groupMessages
|
* @param receivedGroupMessageCache the cache storing groupMessages
|
||||||
* received during the handshake
|
* received during the handshake
|
||||||
* @param receivedMessageStatusChangeCache the cache storing
|
* @param receivedMessageStatusChangeCache the cache storing
|
||||||
* messageStatusChangeEvents received
|
* messageStatusChangeEvents
|
||||||
|
* received
|
||||||
* during handshake
|
* during handshake
|
||||||
* @param sceneContext the scene context used to initialize
|
* @param receivedGroupMessageStatusChangeCache the cache storing
|
||||||
|
* groupMessageStatusChangeEvents
|
||||||
|
* received
|
||||||
|
* during handshake
|
||||||
|
* @param sceneContext the scene context used to
|
||||||
|
* initialize
|
||||||
* the chat
|
* the chat
|
||||||
* scene
|
* scene
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
|
Reference in New Issue
Block a user