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; encoding = builder.encoding;
message = builder.message; message = builder.message;
ackData = builder.ackData; ackData = builder.ackData;
if (builder.ackMessage != null) { if (builder.ackMessage != null && builder.ackMessage.length > 0) {
ackMessage = Factory.getObjectMessage( ackMessage = Factory.getObjectMessage(
3, 3,
new ByteArrayInputStream(builder.ackMessage), new ByteArrayInputStream(builder.ackMessage),

View File

@ -31,6 +31,7 @@ dependencies {
compile 'org.slf4j:slf4j-simple:1.7.12' compile 'org.slf4j:slf4j-simple:1.7.12'
compile 'args4j:args4j:2.32' compile 'args4j:args4j:2.32'
compile 'com.h2database:h2:1.4.190' compile 'com.h2database:h2:1.4.190'
compile 'org.apache.commons:commons-lang3:3.4'
testCompile 'junit:junit:4.11' testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.10.19' 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.networking.DefaultNetworkHandler;
import ch.dissem.bitmessage.ports.MemoryNodeRegistry; import ch.dissem.bitmessage.ports.MemoryNodeRegistry;
import ch.dissem.bitmessage.repository.*; import ch.dissem.bitmessage.repository.*;
import org.apache.commons.lang3.text.WordUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -56,13 +56,7 @@ public class Application {
.networkHandler(new DefaultNetworkHandler()) .networkHandler(new DefaultNetworkHandler())
.cryptography(new BouncyCryptography()) .cryptography(new BouncyCryptography())
.port(48444) .port(48444)
.listener(plaintext -> { .listener(plaintext -> System.out.println("New Message from " + plaintext.getFrom() + ": " + plaintext.getSubject()))
try {
System.out.println(new String(plaintext.getMessage(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
LOG.error(e.getMessage(), e);
}
})
.build(); .build();
if (syncServer == null) { if (syncServer == null) {
@ -288,7 +282,13 @@ public class Application {
int i = 0; int i = 0;
for (Label label : labels) { for (Label label : labels) {
i++; 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("a) Archive");
System.out.println(); System.out.println();
@ -370,7 +370,7 @@ public class Application {
System.out.println("To: " + message.getTo()); System.out.println("To: " + message.getTo());
System.out.println("Subject: " + message.getSubject()); System.out.println("Subject: " + message.getSubject());
System.out.println(); System.out.println();
System.out.println(message.getText()); System.out.println(WordUtils.wrap(message.getText(), 120));
System.out.println(); System.out.println();
System.out.println(message.getLabels().stream().map(Label::toString).collect( System.out.println(message.getLabels().stream().map(Label::toString).collect(
Collectors.joining(", ", "Labels: ", ""))); Collectors.joining(", ", "Labels: ", "")));

View File

@ -105,7 +105,8 @@ public class JdbcMessageRepository extends JdbcHelper implements MessageReposito
try ( try (
Connection connection = config.getConnection(); Connection connection = config.getConnection();
Statement stmt = connection.createStatement(); 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()) { if (rs.next()) {
return rs.getInt(1); return rs.getInt(1);