Fix file not being sent (3)
This commit is contained in:
parent
dc32071529
commit
9237649b60
3 changed files with 6 additions and 10 deletions
|
@ -195,7 +195,7 @@ public class PeerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface MessageReceivedCallback {
|
public interface MessageReceivedCallback {
|
||||||
void onMessageReceived(Object msg);
|
void onMessageReceived(Object msg) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface MessageSentCallback {
|
public interface MessageSentCallback {
|
||||||
|
|
|
@ -138,6 +138,9 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
||||||
assert !((Message) msg).getRecipient().id.equals(id);
|
assert !((Message) msg).getRecipient().id.equals(id);
|
||||||
|
|
||||||
Log.v(this.getClass().getSimpleName(), "Message text: " + ((Message) msg).getText());
|
Log.v(this.getClass().getSimpleName(), "Message text: " + ((Message) msg).getText());
|
||||||
|
if (msg instanceof FileMessage) {
|
||||||
|
((FileMessage) msg).storeFile();
|
||||||
|
}
|
||||||
history.addMessage((Message) msg, errorCallback);
|
history.addMessage((Message) msg, errorCallback);
|
||||||
} else if (msg instanceof UsernameTakenException) {
|
} else if (msg instanceof UsernameTakenException) {
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package fr.insa.clavardator;
|
package fr.insa.clavardator;
|
||||||
|
|
||||||
import fr.insa.clavardator.chat.FileMessage;
|
|
||||||
import fr.insa.clavardator.chat.Message;
|
import fr.insa.clavardator.chat.Message;
|
||||||
import fr.insa.clavardator.db.DatabaseController;
|
import fr.insa.clavardator.db.DatabaseController;
|
||||||
import fr.insa.clavardator.users.UserInformation;
|
import fr.insa.clavardator.users.UserInformation;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -51,8 +49,8 @@ public class DatabaseTest {
|
||||||
new Date(1609843556862L), "Ça va ?"), latch3::countDown, Assertions::fail);
|
new Date(1609843556862L), "Ça va ?"), latch3::countDown, Assertions::fail);
|
||||||
db.addMessage(new Message(new UserInformation("2", "Arnaud"), new UserInformation("1", "Yohan"),
|
db.addMessage(new Message(new UserInformation("2", "Arnaud"), new UserInformation("1", "Yohan"),
|
||||||
new Date(1609843556863L), "Ouais et toi ?"), latch3::countDown, Assertions::fail);
|
new Date(1609843556863L), "Ouais et toi ?"), latch3::countDown, Assertions::fail);
|
||||||
db.addMessage(new FileMessage(new UserInformation("1", "Yohan"), new UserInformation("2", "Arnaud"),
|
db.addMessage(new Message(new UserInformation("1", "Yohan"), new UserInformation("2", "Arnaud"),
|
||||||
new Date(1609843556864L), "Super !", "clavardator_test.db"), latch3::countDown, Assertions::fail);
|
new Date(1609843556864L), "Super !"), latch3::countDown, Assertions::fail);
|
||||||
latch3.await();
|
latch3.await();
|
||||||
|
|
||||||
CountDownLatch latch4 = new CountDownLatch(2);
|
CountDownLatch latch4 = new CountDownLatch(2);
|
||||||
|
@ -81,11 +79,6 @@ public class DatabaseTest {
|
||||||
assertEquals("1", history.get(3).getRecipient().id);
|
assertEquals("1", history.get(3).getRecipient().id);
|
||||||
assertEquals("Arnaud", history.get(3).getSender().getUsername());
|
assertEquals("Arnaud", history.get(3).getSender().getUsername());
|
||||||
assertEquals("Yohan", history.get(3).getRecipient().getUsername());
|
assertEquals("Yohan", history.get(3).getRecipient().getUsername());
|
||||||
|
|
||||||
String path = FileMessage.STORED_FILES_FOLDER + File.separatorChar + ((FileMessage) history.get(4)).getFileName();
|
|
||||||
File file = new File(path);
|
|
||||||
assertTrue(file.exists());
|
|
||||||
file.delete();
|
|
||||||
latch4.countDown();
|
latch4.countDown();
|
||||||
}, Assertions::fail);
|
}, Assertions::fail);
|
||||||
latch4.await();
|
latch4.await();
|
||||||
|
|
Loading…
Reference in a new issue