2019-10-19 09:59:45 +02:00
|
|
|
package envoy.client;
|
|
|
|
|
2019-10-27 17:25:58 +01:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
2019-10-19 09:59:45 +02:00
|
|
|
import javax.swing.DefaultListModel;
|
|
|
|
|
|
|
|
import envoy.schema.Message;
|
2019-10-19 12:10:52 +02:00
|
|
|
import envoy.schema.User;
|
2019-10-19 09:59:45 +02:00
|
|
|
|
2019-12-20 20:25:54 +01:00
|
|
|
/**
|
|
|
|
* Represents a chat between two {@link User}s <br>
|
|
|
|
* as a list of {@link Message} objects.
|
|
|
|
* <br>
|
|
|
|
* Project: <strong>envoy-client</strong><br>
|
|
|
|
* File: <strong>Chat.java</strong><br>
|
|
|
|
* Created: <strong>19 Oct 2019</strong><br>
|
|
|
|
*
|
|
|
|
* @author Maximilian Käfer
|
|
|
|
* @author Leon Hofmeister
|
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-27 17:25:58 +01:00
|
|
|
public class Chat implements Serializable {
|
2019-10-19 09:59:45 +02:00
|
|
|
|
2019-10-27 17:25:58 +01:00
|
|
|
private static final long serialVersionUID = -7751248474547242056L;
|
2019-10-31 22:11:50 +01:00
|
|
|
|
2019-10-19 12:10:52 +02:00
|
|
|
private User recipient;
|
|
|
|
private DefaultListModel<Message> model = new DefaultListModel<>();
|
|
|
|
|
2019-10-27 20:23:36 +01:00
|
|
|
/**
|
|
|
|
* Provides the list of messages that the recipient receives.<br>
|
|
|
|
* Saves the Messages in the corresponding chat at that Point.
|
2019-12-20 20:25:54 +01:00
|
|
|
*
|
2019-10-27 20:23:36 +01:00
|
|
|
* @param recipient the user who receives the messages
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public Chat(User recipient) { this.recipient = recipient; }
|
|
|
|
|
2019-10-27 20:23:36 +01:00
|
|
|
/**
|
|
|
|
* @return the recipient of a message
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public User getRecipient() { return recipient; }
|
|
|
|
|
2019-10-27 20:23:36 +01:00
|
|
|
/**
|
|
|
|
* Adds the received message at the current Point in the current chat
|
2019-12-20 20:25:54 +01:00
|
|
|
*
|
2019-10-27 20:23:36 +01:00
|
|
|
* @param message the message to add in said chat
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public void appendMessage(Message message) { model.addElement(message); }
|
|
|
|
|
2019-10-27 20:23:36 +01:00
|
|
|
/**
|
|
|
|
* @return all messages in the current chat
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public DefaultListModel<Message> getModel() { return model; }
|
|
|
|
}
|