2019-10-06 10:45:19 +02:00
|
|
|
package envoy.client;
|
|
|
|
|
|
|
|
import java.time.Instant;
|
|
|
|
import javax.ws.rs.client.ClientBuilder;
|
|
|
|
import javax.ws.rs.client.Entity;
|
|
|
|
import javax.ws.rs.client.WebTarget;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
import javax.xml.bind.Marshaller;
|
|
|
|
import javax.xml.datatype.DatatypeConfigurationException;
|
|
|
|
import javax.xml.datatype.DatatypeFactory;
|
2019-10-07 16:14:14 +02:00
|
|
|
|
2019-10-06 10:45:19 +02:00
|
|
|
import envoy.schema.Message;
|
2019-11-04 23:10:53 +01:00
|
|
|
import envoy.schema.Message.Metadata.MessageState;
|
2019-10-06 10:45:19 +02:00
|
|
|
import envoy.schema.ObjectFactory;
|
2019-11-04 23:10:53 +01:00
|
|
|
import envoy.schema.Sync;
|
2019-10-12 14:45:58 +02:00
|
|
|
import envoy.schema.User;
|
2019-10-06 10:45:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Project: <strong>envoy-client</strong><br>
|
2019-10-12 11:19:29 +02:00
|
|
|
* File: <strong>Client.java</strong><br>
|
2019-10-06 10:45:19 +02:00
|
|
|
* Created: <strong>28 Sep 2019</strong><br>
|
2019-10-12 08:19:00 +02:00
|
|
|
*
|
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @author Maximilian Käfer
|
2019-10-12 14:45:58 +02:00
|
|
|
* @author Leon Hofmeister
|
2019-10-12 08:19:00 +02:00
|
|
|
* @since Envoy 0.1
|
2019-10-06 10:45:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-10-12 11:19:29 +02:00
|
|
|
public class Client {
|
2019-10-06 10:45:19 +02:00
|
|
|
|
|
|
|
private ObjectFactory objectFactory = new ObjectFactory();
|
|
|
|
private DatatypeFactory datatypeFactory;
|
2019-10-12 11:19:29 +02:00
|
|
|
private Config config;
|
2019-10-19 12:10:52 +02:00
|
|
|
private User sender, recipient;
|
2019-10-06 10:45:19 +02:00
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
private Sync unreadMessagesSync = objectFactory.createSync();
|
|
|
|
public Sync sync = objectFactory.createSync();
|
|
|
|
public Sync readMessages = objectFactory.createSync();
|
|
|
|
|
2019-10-12 14:45:58 +02:00
|
|
|
public Client(Config config, String username) {
|
2019-10-12 11:19:29 +02:00
|
|
|
this.config = config;
|
2019-10-06 10:45:19 +02:00
|
|
|
try {
|
|
|
|
datatypeFactory = DatatypeFactory.newInstance();
|
|
|
|
} catch (DatatypeConfigurationException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-10-19 12:10:52 +02:00
|
|
|
sender = getUser(username);
|
2019-11-04 23:10:53 +01:00
|
|
|
System.out.println("ID: " + sender.getID());
|
2019-10-06 10:45:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-04 23:10:53 +01:00
|
|
|
* Creates a {@link Message} object serializable to XML.
|
2019-10-06 10:45:19 +02:00
|
|
|
*
|
2019-11-04 23:10:53 +01:00
|
|
|
* @param textContent The content (text) of the message
|
|
|
|
* @return prepared {@link Message} object
|
2019-10-06 10:45:19 +02:00
|
|
|
*/
|
2019-11-04 23:10:53 +01:00
|
|
|
public Message createMessage(String textContent) {
|
|
|
|
Message.Metadata metaData = objectFactory.createMessageMetadata();
|
|
|
|
metaData.setSender(sender.getID());
|
|
|
|
metaData.setRecipient(recipient.getID());
|
|
|
|
metaData.setState(MessageState.WAITING);
|
|
|
|
metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString()));
|
|
|
|
|
|
|
|
Message.Content content = objectFactory.createMessageContent();
|
|
|
|
content.setType("text");
|
|
|
|
content.setText(textContent);
|
2019-10-06 10:45:19 +02:00
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
Message message = objectFactory.createMessage();
|
|
|
|
message.setMetadata(metaData);
|
|
|
|
message.getContent().add(content);
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a {@link Sync} with all users on the server.
|
|
|
|
* @return Sync - List of all users on the server.
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
|
|
|
public Sync getUsersListXml() {
|
|
|
|
Sync sendSync = objectFactory.createSync();
|
|
|
|
User user = objectFactory.createUser();
|
|
|
|
user.setID(-1);
|
|
|
|
sendSync.getUsers().add(user);
|
|
|
|
|
|
|
|
javax.ws.rs.client.Client client = ClientBuilder.newClient();
|
|
|
|
WebTarget target = client.target(String
|
|
|
|
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0));
|
|
|
|
|
|
|
|
Response response = target.request().post(Entity.entity(sendSync, "application/xml"));
|
|
|
|
Sync returnSendSync = response.readEntity(Sync.class);
|
|
|
|
response.close();
|
|
|
|
client.close();
|
|
|
|
return returnSendSync;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a {@link User} with a specific name by name.
|
|
|
|
*
|
|
|
|
* @param name - the name of the {@link User}
|
|
|
|
* @return a {@link User} with the specified name
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
|
|
|
private User getUser(String name) {
|
|
|
|
Sync senderSync = objectFactory.createSync();
|
|
|
|
User user = objectFactory.createUser();
|
|
|
|
user.setName(name);
|
|
|
|
senderSync.getUsers().add(user);
|
|
|
|
|
|
|
|
javax.ws.rs.client.Client client = ClientBuilder.newClient();
|
|
|
|
WebTarget target = client.target(String
|
|
|
|
.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d", config.getServer(), config.getPort(), 0));
|
|
|
|
|
|
|
|
Response response = target.request().post(Entity.entity(senderSync, "application/xml"));
|
|
|
|
User returnSender = objectFactory.createUser();
|
|
|
|
Sync returnSenderSync = response.readEntity(Sync.class);
|
|
|
|
if (returnSenderSync.getUsers().size() == 1) {
|
|
|
|
returnSender = returnSenderSync.getUsers().get(0);
|
|
|
|
} else {
|
|
|
|
System.out.println("ERROR exiting...");
|
|
|
|
}
|
|
|
|
response.close();
|
|
|
|
client.close();
|
|
|
|
return returnSender;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends the "sync" Sync Object to the server and gets a "returnSync" Sync
|
|
|
|
* Object as response. <br>
|
|
|
|
* It is also used to get the own sender at the start of the client
|
|
|
|
* (Client sends "sync" Sync Object with single user in it(name: the name entered at login, id: 0, UserStatus:null))<br>
|
|
|
|
* and to get a complete list of all users saved on the server.
|
|
|
|
* (Client sends "sync" Sync Object with single user in it(name: "" (empty), id: -1, UserStatus:null)) <br>
|
|
|
|
* This method also processes the response Sync Object. <br>
|
|
|
|
* It sorts its users and messages by specific variables and does certain things
|
|
|
|
* with them. <br>
|
|
|
|
* <br>
|
|
|
|
* Messages: <br>
|
|
|
|
* -State SENT: Update Local message(s) with State WAITING (add Message ID and
|
|
|
|
* change State to SENT). (server sends these informations to the client if
|
|
|
|
* message(s) with State WAITING were successfully sent to the server)<br>
|
|
|
|
* -State RECEIVED, SenderID != 0: Adds the unread Messages returned from the
|
|
|
|
* server in the latest sync to the "unreadMessagesSync" Sync Object. <br>
|
|
|
|
* -State RECEIVED, SenderID == 0: Update message(s) in localDB to state RECEIVED.
|
|
|
|
* (server sends these informations to the client if the other client received
|
|
|
|
* the message(s).) <br>
|
|
|
|
* -State READ: Update message(s) in the LocalDB to state READ. (server sends these informations to the client if the other client read
|
|
|
|
* the message(s).) <br>
|
|
|
|
* <br>
|
|
|
|
* Users: <br>
|
|
|
|
* Updating UserStatus of all users in LocalDB. (Server sends all users with their updated UserStatus to the client.) <br>
|
|
|
|
*
|
|
|
|
* @param userId
|
|
|
|
* @param localDB
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
|
|
|
public void sendSync(long userId, LocalDB localDB) {
|
|
|
|
new Thread(() -> {
|
|
|
|
// Print sync XML to console
|
2019-10-06 10:45:19 +02:00
|
|
|
JAXBContext jc;
|
|
|
|
try {
|
|
|
|
jc = JAXBContext.newInstance("envoy.schema");
|
|
|
|
Marshaller m = jc.createMarshaller();
|
|
|
|
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
2019-11-04 23:10:53 +01:00
|
|
|
m.marshal(sync, System.out);
|
2019-10-06 10:45:19 +02:00
|
|
|
} catch (JAXBException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-11-04 23:10:53 +01:00
|
|
|
addWaitingMessagesToSync(localDB);
|
|
|
|
|
|
|
|
getSentStateMessagesFromLocalDB(localDB);
|
|
|
|
for (int i = 0; i < readMessages.getMessages().size(); i++) {
|
|
|
|
sync.getMessages().add(readMessages.getMessages().get(i));
|
|
|
|
}
|
|
|
|
readMessages.getMessages().clear();
|
2019-10-06 10:45:19 +02:00
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
// Send sync
|
2019-10-12 11:19:29 +02:00
|
|
|
javax.ws.rs.client.Client client = ClientBuilder.newClient();
|
|
|
|
WebTarget target = client
|
2019-11-04 23:10:53 +01:00
|
|
|
.target(String.format("%s:%d/envoy-server/rest/sync/syncData?userId=%d",
|
|
|
|
config.getServer(),
|
|
|
|
config.getPort(),
|
|
|
|
userId));
|
|
|
|
|
|
|
|
Response response = target.request().post(Entity.entity(sync, "application/xml"));
|
|
|
|
|
|
|
|
Sync returnSync = response.readEntity(Sync.class);
|
|
|
|
if (returnSync.getMessages().size() != 0) {
|
|
|
|
System.out.println("Message ID: " + returnSync.getMessages().get(0).getMetadata().getMessageId());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < returnSync.getMessages().size(); i++) {
|
|
|
|
|
|
|
|
// Print sync XML to console
|
|
|
|
JAXBContext jc2;
|
|
|
|
try {
|
|
|
|
jc2 = JAXBContext.newInstance("envoy.schema");
|
|
|
|
Marshaller m = jc2.createMarshaller();
|
|
|
|
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
|
|
|
m.marshal(returnSync, System.out);
|
|
|
|
} catch (JAXBException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0
|
|
|
|
&& returnSync.getMessages().get(i).getMetadata().getState() == MessageState.SENT) {
|
|
|
|
// Update Local Messages with State WAITING (add Message ID and change State to
|
|
|
|
// SENT)
|
|
|
|
for (int j = 0; j < sync.getMessages().size(); j++) {
|
|
|
|
if (j == i) {
|
|
|
|
sync.getMessages()
|
|
|
|
.get(j)
|
|
|
|
.getMetadata()
|
|
|
|
.setMessageId(returnSync.getMessages().get(j).getMetadata().getMessageId());
|
|
|
|
sync.getMessages()
|
|
|
|
.get(j)
|
|
|
|
.getMetadata()
|
|
|
|
.setState(returnSync.getMessages().get(j).getMetadata().getState());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0
|
|
|
|
&& returnSync.getMessages().get(i).getMetadata().getSender() != 0
|
|
|
|
&& returnSync.getMessages().get(i).getMetadata().getState() == MessageState.RECEIVED) {
|
|
|
|
// these are the unread Messages from the server
|
|
|
|
unreadMessagesSync.getMessages().add(returnSync.getMessages().get(i));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0
|
|
|
|
&& returnSync.getMessages().get(i).getMetadata().getSender() == 0
|
|
|
|
&& returnSync.getMessages().get(i).getMetadata().getState() == MessageState.RECEIVED) {
|
|
|
|
// Update Messages in localDB to state RECEIVED
|
|
|
|
for (int j = 0; j < localDB.getChats().size(); j++) {
|
|
|
|
if (localDB.getChats().get(j).getRecipient().getID() == returnSync.getMessages()
|
|
|
|
.get(i)
|
|
|
|
.getMetadata()
|
|
|
|
.getRecipient()) {
|
|
|
|
for (int k = 0; k < localDB.getChats().get(j).getModel().getSize(); k++) {
|
|
|
|
if (localDB.getChats()
|
|
|
|
.get(j)
|
|
|
|
.getModel()
|
|
|
|
.get(k)
|
|
|
|
.getMetadata()
|
|
|
|
.getMessageId() == returnSync.getMessages().get(i).getMetadata().getMessageId()) {
|
|
|
|
// Update Message in LocalDB
|
|
|
|
localDB.getChats()
|
|
|
|
.get(j)
|
|
|
|
.getModel()
|
|
|
|
.get(k)
|
|
|
|
.getMetadata()
|
|
|
|
.setState(returnSync.getMessages().get(j).getMetadata().getState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (returnSync.getMessages().get(i).getMetadata().getMessageId() != 0
|
|
|
|
&& returnSync.getMessages().get(i).getMetadata().getState() == MessageState.READ) {
|
|
|
|
// Update local Messages to state READ
|
|
|
|
System.out
|
|
|
|
.println("Message with ID: " + returnSync.getMessages().get(i).getMetadata().getMessageId()
|
|
|
|
+ "was initialized to be set to READ in localDB.");
|
|
|
|
for (int j = 0; j < localDB.getChats().size(); j++) {
|
|
|
|
if (localDB.getChats().get(j).getRecipient().getID() == returnSync.getMessages()
|
|
|
|
.get(i)
|
|
|
|
.getMetadata()
|
|
|
|
.getRecipient()) {
|
|
|
|
System.out.println(
|
|
|
|
"Chat with: " + localDB.getChats().get(j).getRecipient().getID() + "was selected.");
|
|
|
|
for (int k = 0; k < localDB.getChats().get(j).getModel().getSize(); k++) {
|
|
|
|
if (localDB.getChats()
|
|
|
|
.get(j)
|
|
|
|
.getModel()
|
|
|
|
.get(k)
|
|
|
|
.getMetadata()
|
|
|
|
.getMessageId() == returnSync.getMessages().get(i).getMetadata().getMessageId()) {
|
|
|
|
System.out.println("Message with ID: "
|
|
|
|
+ localDB.getChats().get(j).getModel().get(k).getMetadata().getMessageId()
|
|
|
|
+ "was selected.");
|
|
|
|
localDB.getChats()
|
|
|
|
.get(j)
|
|
|
|
.getModel()
|
|
|
|
.get(k)
|
|
|
|
.getMetadata()
|
|
|
|
.setState(returnSync.getMessages().get(i).getMetadata().getState());
|
|
|
|
System.out.println("Message State is now: " + localDB.getChats()
|
|
|
|
.get(j)
|
|
|
|
.getModel()
|
|
|
|
.get(k)
|
|
|
|
.getMetadata()
|
|
|
|
.getState()
|
|
|
|
.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updating UserStatus of all Users in LocalDB
|
|
|
|
for (int j = 0; j < returnSync.getUsers().size(); j++) {
|
|
|
|
for (int k = 0; k < localDB.getChats().size(); k++) {
|
|
|
|
if (localDB.getChats().get(k).getRecipient().getID() == returnSync.getUsers().get(j).getID()) {
|
|
|
|
|
|
|
|
localDB.getChats().get(k).getRecipient().setStatus(returnSync.getUsers().get(j).getStatus());
|
|
|
|
System.out.println(localDB.getChats().get(k).getRecipient().getStatus().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-12 11:19:29 +02:00
|
|
|
|
2019-10-06 10:45:19 +02:00
|
|
|
System.out.println("Response code: " + response.getStatus());
|
2019-11-04 23:10:53 +01:00
|
|
|
|
2019-10-06 10:45:19 +02:00
|
|
|
response.close();
|
|
|
|
client.close();
|
2019-11-04 23:10:53 +01:00
|
|
|
sync.getMessages().clear();
|
|
|
|
sync.getUsers().clear();
|
|
|
|
|
2019-10-06 10:45:19 +02:00
|
|
|
}).start();
|
2019-11-04 23:10:53 +01:00
|
|
|
System.out.println(sync.getMessages().size());
|
|
|
|
|
2019-10-06 10:45:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-04 23:10:53 +01:00
|
|
|
* Adds a message to the "sync" Sync object.
|
2019-10-06 10:45:19 +02:00
|
|
|
*
|
2019-11-04 23:10:53 +01:00
|
|
|
* @param message
|
|
|
|
* @since Envoy v0.1-alpha
|
2019-10-06 10:45:19 +02:00
|
|
|
*/
|
2019-11-04 23:10:53 +01:00
|
|
|
public void addMessageToSync(Message message) { sync.getMessages().add(message); }
|
2019-10-06 10:45:19 +02:00
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
/**
|
|
|
|
* Adds a user to the "sync" Sync object.
|
|
|
|
*
|
|
|
|
* @param user
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
|
|
|
public void addUserToSync(User user) { sync.getUsers().add(user); }
|
2019-10-06 10:45:19 +02:00
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
/**
|
|
|
|
* Adds the unread Messages returned from the server in the latest sync to the
|
|
|
|
* right chats in the LocalDB.
|
|
|
|
*
|
|
|
|
* @param localDB
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
|
|
|
public void addUnreadMessagesToLocalDB(LocalDB localDB) {
|
|
|
|
Sync unreadMessages = unreadMessagesSync;
|
|
|
|
for (int i = 0; i < unreadMessages.getMessages().size(); i++)
|
|
|
|
for (int j = 0; j < localDB.getChats().size(); j++)
|
|
|
|
if (localDB.getChats().get(j).getRecipient().getID() == unreadMessages.getMessages()
|
|
|
|
.get(i)
|
|
|
|
.getMetadata()
|
|
|
|
.getSender()) {
|
|
|
|
localDB.getChats().get(j).appendMessage(unreadMessages.getMessages().get(i));
|
|
|
|
}
|
2019-10-06 10:45:19 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
/**
|
|
|
|
* Gets all Messages with state SENT from the LocalDB and adds them to the
|
|
|
|
* "sync" Sync object.
|
|
|
|
*
|
|
|
|
* @param localDB
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
|
|
|
public void getSentStateMessagesFromLocalDB(LocalDB localDB) {
|
|
|
|
for (int i = 0; i < localDB.getChats().size(); i++) {
|
|
|
|
for (int j = 0; j < localDB.getChats().get(i).getModel().getSize(); j++) {
|
|
|
|
if (localDB.getChats().get(i).getModel().get(j).getMetadata().getState() == MessageState.SENT) {
|
|
|
|
addMessageToSync(localDB.getChats().get(i).getModel().get(j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-07 16:14:14 +02:00
|
|
|
}
|
2019-10-13 17:25:20 +02:00
|
|
|
|
2019-10-12 14:45:58 +02:00
|
|
|
/**
|
2019-11-04 23:10:53 +01:00
|
|
|
* Changes all Messages with State RECEIVED of a specific chat to State READ.
|
|
|
|
* <br>
|
|
|
|
* Adds these Messages to the "readMessages" Sync object.
|
2019-10-12 14:45:58 +02:00
|
|
|
*
|
2019-11-04 23:10:53 +01:00
|
|
|
* @param currentChat
|
2019-10-26 18:31:49 +02:00
|
|
|
* @since Envoy v0.1-alpha
|
2019-10-12 14:45:58 +02:00
|
|
|
*/
|
2019-11-04 23:10:53 +01:00
|
|
|
public void setMessagesToRead(Chat currentChat) {
|
|
|
|
for (int j = 0; j < currentChat.getModel().getSize(); j++) {
|
|
|
|
if (currentChat.getModel().get(j).getMetadata().getRecipient() != currentChat.getRecipient().getID()) {
|
|
|
|
if (currentChat.getModel().get(j).getMetadata().getState() == MessageState.RECEIVED) {
|
|
|
|
currentChat.getModel().get(j).getMetadata().setState(MessageState.READ);
|
|
|
|
readMessages.getMessages().add(currentChat.getModel().get(j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-12 14:45:58 +02:00
|
|
|
}
|
2019-10-13 17:25:20 +02:00
|
|
|
|
2019-10-26 18:31:49 +02:00
|
|
|
/**
|
2019-11-04 23:10:53 +01:00
|
|
|
* Adds a Message with State WAITING to a specific chat in the LocalDB.
|
2019-10-26 18:31:49 +02:00
|
|
|
*
|
2019-11-04 23:10:53 +01:00
|
|
|
* @param message
|
|
|
|
* @param currentChat
|
2019-10-26 18:31:49 +02:00
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-11-04 23:10:53 +01:00
|
|
|
public void addWaitingMessageToLocalDB(Message message, Chat currentChat) { currentChat.appendMessage(message); }
|
2019-10-26 18:31:49 +02:00
|
|
|
|
|
|
|
/**
|
2019-11-04 23:10:53 +01:00
|
|
|
* Adds all Messages with State WAITING from the LocalDB to the Sync.
|
2019-10-26 18:31:49 +02:00
|
|
|
*
|
2019-11-04 23:10:53 +01:00
|
|
|
* @param localDB
|
2019-10-26 18:31:49 +02:00
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-11-04 23:10:53 +01:00
|
|
|
public void addWaitingMessagesToSync(LocalDB localDB) {
|
|
|
|
for (int i = 0; i < localDB.getChats().size(); i++) {
|
|
|
|
for (int j = 0; j < localDB.getChats().get(i).getModel().getSize(); j++) {
|
|
|
|
if (localDB.getChats().get(i).getModel().get(j).getMetadata().getState() == MessageState.WAITING) {
|
|
|
|
// addMessageToSync(localDB.getChats().get(i).getModel().get(j));
|
|
|
|
System.out.println("Got Waiting Message");
|
|
|
|
sync.getMessages().add(0, localDB.getChats().get(i).getModel().get(j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-19 15:09:32 +02:00
|
|
|
}
|
|
|
|
|
2019-10-12 17:35:58 +02:00
|
|
|
/**
|
2019-11-04 23:10:53 +01:00
|
|
|
* @return the sender object that represents this client.
|
2019-10-26 18:31:49 +02:00
|
|
|
* @since Envoy v0.1-alpha
|
2019-10-12 17:35:58 +02:00
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public User getSender() { return sender; }
|
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
/**
|
|
|
|
* @return the current recipient of the current chat.
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public User getRecipient() { return recipient; }
|
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
/**
|
|
|
|
* Sets the recipient.
|
|
|
|
*
|
|
|
|
* @param recipient
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public void setRecipient(User recipient) { this.recipient = recipient; }
|
|
|
|
|
2019-11-04 23:10:53 +01:00
|
|
|
/**
|
|
|
|
* @return boolean weather the recipient is currently set.
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
2019-10-19 12:10:52 +02:00
|
|
|
public boolean hasRecipient() { return recipient != null; }
|
2019-11-04 23:10:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the "unreadMessagesSync" Sync object.
|
|
|
|
*
|
|
|
|
* @since Envoy v0.1-alpha
|
|
|
|
*/
|
|
|
|
public void clearUnreadMessagesSync() { unreadMessagesSync.getMessages().clear(); }
|
2019-09-30 09:53:16 +02:00
|
|
|
}
|