Listening to message status changes, sending READ status updates
This commit is contained in:
@ -3,6 +3,7 @@ package envoy.client.ui;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -19,9 +20,11 @@ import envoy.client.ui.list.ComponentList;
|
||||
import envoy.client.ui.settings.SettingsScreen;
|
||||
import envoy.client.util.EnvoyLog;
|
||||
import envoy.data.Message;
|
||||
import envoy.data.Message.MessageStatus;
|
||||
import envoy.data.MessageBuilder;
|
||||
import envoy.data.User;
|
||||
import envoy.event.EventBus;
|
||||
import envoy.event.MessageStatusChangeEvent;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
@ -173,7 +176,12 @@ public class ChatWindow extends JFrame {
|
||||
currentChat = localDb.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get();
|
||||
|
||||
// Read current Chat
|
||||
currentChat.read();
|
||||
try {
|
||||
currentChat.read(client);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.WARNING, "Could notify server about message status change", e);
|
||||
}
|
||||
|
||||
// Set chat title
|
||||
textPane.setText(currentChat.getRecipient().getName());
|
||||
@ -213,6 +221,26 @@ public class ChatWindow extends JFrame {
|
||||
repaint();
|
||||
});
|
||||
|
||||
// Listen to message status changes
|
||||
EventBus.getInstance().register(MessageStatusChangeEvent.class, (evt) -> {
|
||||
final long id = ((MessageStatusChangeEvent) evt).getId();
|
||||
final MessageStatus status = (MessageStatus) evt.get();
|
||||
|
||||
for (Chat c : localDb.getChats())
|
||||
for (Message m : c.getModel())
|
||||
if (m.getId() == id) {
|
||||
|
||||
// Update message status
|
||||
m.setStatus(status);
|
||||
|
||||
// Update model and scroll down if current chat
|
||||
if (c == currentChat) {
|
||||
messageList.setModel(currentChat.getModel());
|
||||
scrollPane.setChatOpened(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
revalidate();
|
||||
}
|
||||
|
||||
@ -286,10 +314,7 @@ public class ChatWindow extends JFrame {
|
||||
if (!localDb.getIdGenerator().hasNext()) client.requestIdGenerator();
|
||||
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Error sending message:\n" + e.toString(),
|
||||
"Message sending error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
JOptionPane.showMessageDialog(this, "Error sending message:\n" + e.toString(), "Message sending error", JOptionPane.ERROR_MESSAGE);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -320,9 +345,7 @@ public class ChatWindow extends JFrame {
|
||||
* @param client the {@link Client} used to send and receive messages
|
||||
* @since Envoy v0.2-alpha
|
||||
*/
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
public void setClient(Client client) { this.client = client; }
|
||||
|
||||
/**
|
||||
* Sets the {@link LocalDb} used by this {@link ChatWindow}. After
|
||||
|
Reference in New Issue
Block a user