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 {
|
||||
void onMessageReceived(Object msg);
|
||||
void onMessageReceived(Object msg) throws IOException;
|
||||
}
|
||||
|
||||
public interface MessageSentCallback {
|
||||
|
|
|
@ -138,6 +138,9 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
|||
assert !((Message) msg).getRecipient().id.equals(id);
|
||||
|
||||
Log.v(this.getClass().getSimpleName(), "Message text: " + ((Message) msg).getText());
|
||||
if (msg instanceof FileMessage) {
|
||||
((FileMessage) msg).storeFile();
|
||||
}
|
||||
history.addMessage((Message) msg, errorCallback);
|
||||
} else if (msg instanceof UsernameTakenException) {
|
||||
disconnect();
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package fr.insa.clavardator;
|
||||
|
||||
import fr.insa.clavardator.chat.FileMessage;
|
||||
import fr.insa.clavardator.chat.Message;
|
||||
import fr.insa.clavardator.db.DatabaseController;
|
||||
import fr.insa.clavardator.users.UserInformation;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
@ -51,8 +49,8 @@ public class DatabaseTest {
|
|||
new Date(1609843556862L), "Ça va ?"), latch3::countDown, Assertions::fail);
|
||||
db.addMessage(new Message(new UserInformation("2", "Arnaud"), new UserInformation("1", "Yohan"),
|
||||
new Date(1609843556863L), "Ouais et toi ?"), latch3::countDown, Assertions::fail);
|
||||
db.addMessage(new FileMessage(new UserInformation("1", "Yohan"), new UserInformation("2", "Arnaud"),
|
||||
new Date(1609843556864L), "Super !", "clavardator_test.db"), latch3::countDown, Assertions::fail);
|
||||
db.addMessage(new Message(new UserInformation("1", "Yohan"), new UserInformation("2", "Arnaud"),
|
||||
new Date(1609843556864L), "Super !"), latch3::countDown, Assertions::fail);
|
||||
latch3.await();
|
||||
|
||||
CountDownLatch latch4 = new CountDownLatch(2);
|
||||
|
@ -81,11 +79,6 @@ public class DatabaseTest {
|
|||
assertEquals("1", history.get(3).getRecipient().id);
|
||||
assertEquals("Arnaud", history.get(3).getSender().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();
|
||||
}, Assertions::fail);
|
||||
latch4.await();
|
||||
|
|
Loading…
Reference in a new issue