diff --git a/core/src/main/java/ch/dissem/bitmessage/entity/Plaintext.java b/core/src/main/java/ch/dissem/bitmessage/entity/Plaintext.java index c7f23ce..b34206a 100644 --- a/core/src/main/java/ch/dissem/bitmessage/entity/Plaintext.java +++ b/core/src/main/java/ch/dissem/bitmessage/entity/Plaintext.java @@ -62,7 +62,7 @@ public class Plaintext implements Streamable { encoding = builder.encoding; message = builder.message; ackData = builder.ackData; - if (builder.ackMessage != null) { + if (builder.ackMessage != null && builder.ackMessage.length > 0) { ackMessage = Factory.getObjectMessage( 3, new ByteArrayInputStream(builder.ackMessage), diff --git a/demo/build.gradle b/demo/build.gradle index d87b0f3..c1571ed 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -31,6 +31,7 @@ dependencies { compile 'org.slf4j:slf4j-simple:1.7.12' compile 'args4j:args4j:2.32' compile 'com.h2database:h2:1.4.190' + compile 'org.apache.commons:commons-lang3:3.4' testCompile 'junit:junit:4.11' testCompile 'org.mockito:mockito-core:1.10.19' } diff --git a/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java b/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java index 2c0246e..89b91dc 100644 --- a/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java +++ b/demo/src/main/java/ch/dissem/bitmessage/demo/Application.java @@ -25,10 +25,10 @@ import ch.dissem.bitmessage.entity.valueobject.Label; import ch.dissem.bitmessage.networking.DefaultNetworkHandler; import ch.dissem.bitmessage.ports.MemoryNodeRegistry; import ch.dissem.bitmessage.repository.*; +import org.apache.commons.lang3.text.WordUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.util.List; import java.util.stream.Collectors; @@ -56,13 +56,7 @@ public class Application { .networkHandler(new DefaultNetworkHandler()) .cryptography(new BouncyCryptography()) .port(48444) - .listener(plaintext -> { - try { - System.out.println(new String(plaintext.getMessage(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - LOG.error(e.getMessage(), e); - } - }) + .listener(plaintext -> System.out.println("New Message from " + plaintext.getFrom() + ": " + plaintext.getSubject())) .build(); if (syncServer == null) { @@ -288,7 +282,13 @@ public class Application { int i = 0; for (Label label : labels) { i++; - System.out.println(i + ") " + label + " [" + ctx.messages().countUnread(label) + "]"); + System.out.print(i + ") " + label); + int unread = ctx.messages().countUnread(label); + if (unread > 0) { + System.out.println(" [" + unread + "]"); + } else { + System.out.println(); + } } System.out.println("a) Archive"); System.out.println(); @@ -370,7 +370,7 @@ public class Application { System.out.println("To: " + message.getTo()); System.out.println("Subject: " + message.getSubject()); System.out.println(); - System.out.println(message.getText()); + System.out.println(WordUtils.wrap(message.getText(), 120)); System.out.println(); System.out.println(message.getLabels().stream().map(Label::toString).collect( Collectors.joining(", ", "Labels: ", ""))); diff --git a/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcMessageRepository.java b/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcMessageRepository.java index e043e7e..8f94d03 100644 --- a/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcMessageRepository.java +++ b/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcMessageRepository.java @@ -105,7 +105,8 @@ public class JdbcMessageRepository extends JdbcHelper implements MessageReposito try ( Connection connection = config.getConnection(); Statement stmt = connection.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT count(*) FROM Message WHERE " + where) + ResultSet rs = stmt.executeQuery("SELECT count(*) FROM Message WHERE " + where + + " ORDER BY received DESC") ) { if (rs.next()) { return rs.getInt(1);