Minor improvements to the demo Application and a fix for when the ACK is empty

This commit is contained in:
Christian Basler 2016-04-25 08:13:46 +02:00
parent 61890b3da9
commit a0505f5704
4 changed files with 14 additions and 12 deletions

View File

@ -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),

View File

@ -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'
}

View File

@ -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: ", "")));

View File

@ -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);