mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Add null check and change some formatting
This commit is contained in:
parent
58db3cbd53
commit
67f62947c6
5 changed files with 28 additions and 41 deletions
|
@ -449,7 +449,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
System.out.println("Quote: (" + quote.getId() + ")");
|
||||
System.out.println(" Author: " + m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier());
|
||||
System.out.println(" Text: " + quote.getText());
|
||||
if (quote.getMentions().size() > 0) {
|
||||
if (quote.getMentions() != null && quote.getMentions().size() > 0) {
|
||||
System.out.println(" Mentions: ");
|
||||
for (SignalServiceDataMessage.Mention mention : quote.getMentions()) {
|
||||
printMention(mention, m);
|
||||
|
@ -488,15 +488,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
|
||||
private void printMention(SignalServiceDataMessage.Mention mention, Manager m) {
|
||||
System.out.println("- "
|
||||
+ m.resolveSignalServiceAddress(
|
||||
new SignalServiceAddress(mention.getUuid(), null)
|
||||
).getLegacyIdentifier()
|
||||
+ ": "
|
||||
+ mention.getStart()
|
||||
+ " (length: "
|
||||
+ mention.getLength()
|
||||
+ ")");
|
||||
System.out.println("- " + m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(), null))
|
||||
.getLegacyIdentifier() + ": " + mention.getStart() + " (length: " + mention.getLength() + ")");
|
||||
}
|
||||
|
||||
private void printAttachment(SignalServiceAttachment attachment) {
|
||||
|
|
|
@ -2,12 +2,10 @@ package org.asamk.signal.json;
|
|||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -45,20 +43,22 @@ class JsonDataMessage {
|
|||
this.quote = new JsonQuote(dataMessage.getQuote().get(), m);
|
||||
}
|
||||
if (dataMessage.getMentions().isPresent()) {
|
||||
this.mentions = new ArrayList<>(dataMessage.getMentions().get().size());
|
||||
for (SignalServiceDataMessage.Mention mention : dataMessage.getMentions().get()) {
|
||||
this.mentions.add(new JsonMention(mention, m));
|
||||
}
|
||||
this.mentions = dataMessage.getMentions()
|
||||
.get()
|
||||
.stream()
|
||||
.map(mention -> new JsonMention(mention, m))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.mentions = new ArrayList<>();
|
||||
this.mentions = List.of();
|
||||
}
|
||||
if (dataMessage.getAttachments().isPresent()) {
|
||||
this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size());
|
||||
for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) {
|
||||
this.attachments.add(new JsonAttachment(attachment));
|
||||
}
|
||||
this.attachments = dataMessage.getAttachments()
|
||||
.get()
|
||||
.stream()
|
||||
.map(JsonAttachment::new)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.attachments = new ArrayList<>();
|
||||
this.attachments = List.of();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,12 +11,9 @@ public class JsonMention {
|
|||
int length;
|
||||
|
||||
JsonMention(SignalServiceDataMessage.Mention mention, Manager m) {
|
||||
this.name = m.resolveSignalServiceAddress(
|
||||
new SignalServiceAddress(mention.getUuid(), null)
|
||||
).getLegacyIdentifier();
|
||||
this.name = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(), null))
|
||||
.getLegacyIdentifier();
|
||||
this.start = mention.getStart();
|
||||
this.length = mention.getLength();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JsonQuote {
|
||||
|
||||
|
@ -20,23 +21,20 @@ public class JsonQuote {
|
|||
this.author = m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier();
|
||||
this.text = quote.getText();
|
||||
|
||||
if (quote.getMentions().size() > 0) {
|
||||
this.mentions = new ArrayList<>(quote.getMentions().size());
|
||||
|
||||
for (SignalServiceDataMessage.Mention quotedMention: quote.getMentions()){
|
||||
this.mentions.add(new JsonMention(quotedMention, m));
|
||||
}
|
||||
if (quote.getMentions() != null && quote.getMentions().size() > 0) {
|
||||
this.mentions = quote.getMentions()
|
||||
.stream()
|
||||
.map(quotedMention -> new JsonMention(quotedMention, m))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (quote.getAttachments().size() > 0) {
|
||||
this.attachments = new ArrayList<>(quote.getAttachments().size());
|
||||
|
||||
for (SignalServiceDataMessage.Quote.QuotedAttachment quotedAttachment : quote.getAttachments()) {
|
||||
this.attachments.add(new JsonQuotedAttachment(quotedAttachment));
|
||||
}
|
||||
this.attachments = quote.getAttachments()
|
||||
.stream()
|
||||
.map(JsonQuotedAttachment::new)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
this.attachments = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,7 @@ public class JsonQuotedAttachment {
|
|||
filename = quotedAttachment.getFileName();
|
||||
if (quotedAttachment.getThumbnail() != null) {
|
||||
thumbnail = new JsonAttachment(quotedAttachment.getThumbnail());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
thumbnail = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue