mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-03 04:50:37 +00:00
merge in infra's cleanup
This commit is contained in:
commit
8f58d056ad
4 changed files with 26 additions and 52 deletions
|
@ -35,6 +35,12 @@ configurations {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tasks.withType<AbstractArchiveTask>().configureEach {
|
||||||
|
isPreserveFileTimestamps = false
|
||||||
|
isReproducibleFileOrder = true
|
||||||
|
}
|
||||||
|
|
||||||
tasks.withType<JavaCompile> {
|
tasks.withType<JavaCompile> {
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
|
|
||||||
|
@ -130,7 +129,6 @@ public class SendCommand implements DbusCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println(Arrays.toString(ns.getList("recipient").toArray()));
|
|
||||||
var timestamp = signal.sendMessage(messageText, attachments, recipients);
|
var timestamp = signal.sendMessage(messageText, attachments, recipients);
|
||||||
writer.println("{}", timestamp);
|
writer.println("{}", timestamp);
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
|
|
|
@ -8,9 +8,13 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
import org.asamk.signal.JsonReceiveMessageHandler;
|
import org.asamk.signal.JsonReceiveMessageHandler;
|
||||||
|
import org.asamk.signal.JsonWriter;
|
||||||
|
import org.asamk.signal.OutputType;
|
||||||
import org.asamk.signal.ReceiveMessageHandler;
|
import org.asamk.signal.ReceiveMessageHandler;
|
||||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
|
@ -19,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
|
@ -32,6 +37,7 @@ class JsonInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
class InputReader implements Runnable {
|
class InputReader implements Runnable {
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(InputReader.class);
|
||||||
|
|
||||||
private volatile boolean alive = true;
|
private volatile boolean alive = true;
|
||||||
private final Manager m;
|
private final Manager m;
|
||||||
|
@ -66,11 +72,11 @@ class InputReader implements Runnable {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// verbosity flag? better yet, json acknowledgement with timestamp or message id?
|
// verbosity flag? better yet, json acknowledgement with timestamp or message id?
|
||||||
System.out.println("sentMessage '" + command.content + "' to " + command.recipient);
|
|
||||||
this.m.sendMessage(command.content, attachments, recipients);
|
this.m.sendMessage(command.content, attachments, recipients);
|
||||||
|
logger.info("sentMessage '" + command.content + "' to " + command.recipient);
|
||||||
} catch (AssertionError | AttachmentInvalidException | InvalidNumberException e) {
|
} catch (AssertionError | AttachmentInvalidException | InvalidNumberException e) {
|
||||||
System.err.println("error in sending message");
|
logger.error("Error in sending message", e);
|
||||||
e.printStackTrace(System.out);
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} /* elif (command.commandName == "sendTyping") {
|
} /* elif (command.commandName == "sendTyping") {
|
||||||
getMessageSender().sendTyping(signalServiceAddress?, ....)
|
getMessageSender().sendTyping(signalServiceAddress?, ....)
|
||||||
|
@ -87,19 +93,26 @@ class InputReader implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StdioCommand implements LocalCommand {
|
public class StdioCommand implements LocalCommand {
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(StdioCommand.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attachToSubparser(final Subparser subparser) {
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
subparser.addArgument("--ignore-attachments")
|
subparser.addArgument("--ignore-attachments")
|
||||||
.help("Don’t download attachments of received messages.")
|
.help("Don’t download attachments of received messages.")
|
||||||
.action(Arguments.storeTrue());
|
.action(Arguments.storeTrue());
|
||||||
subparser.addArgument("--json") // should maybe remove this
|
subparser.addArgument("--json")
|
||||||
.help("Output received messages in json format, one json object per line.")
|
.help("WARNING: This parameter is now deprecated! Please use the global \"--output=json\" option instead.\n\nOutput received messages in json format, one json object per line.")
|
||||||
.action(Arguments.storeTrue());
|
.action(Arguments.storeTrue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<OutputType> getSupportedOutputTypes() {
|
||||||
|
return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(final Namespace ns, final Manager m) {
|
public void handleCommand(final Namespace ns, final Manager m) {
|
||||||
|
var inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
|
||||||
boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
|
boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
|
||||||
InputReader reader = new InputReader(m);
|
InputReader reader = new InputReader(m);
|
||||||
Thread readerThread = new Thread(reader);
|
Thread readerThread = new Thread(reader);
|
||||||
|
@ -109,7 +122,7 @@ public class StdioCommand implements LocalCommand {
|
||||||
TimeUnit.HOURS,
|
TimeUnit.HOURS,
|
||||||
false,
|
false,
|
||||||
ignoreAttachments,
|
ignoreAttachments,
|
||||||
ns.getBoolean("json") ? new JsonReceiveMessageHandler(m) : new ReceiveMessageHandler(m)
|
inJson ? new JsonReceiveMessageHandler(m) : new ReceiveMessageHandler(m)
|
||||||
/*true*/);
|
/*true*/);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Error while receiving messages: " + e.getMessage());
|
System.err.println("Error while receiving messages: " + e.getMessage());
|
||||||
|
|
|
@ -6,29 +6,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
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.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
//class JsonReaction {
|
|
||||||
// String emoji; // unicode?
|
|
||||||
// String targetAuthor;
|
|
||||||
// long targetTimestamp;
|
|
||||||
// boolean isRemove;
|
|
||||||
// JsonReaction (SignalServiceDataMessage.Reaction reaction) {
|
|
||||||
// this.emoji = reaction.getEmoji();
|
|
||||||
// // comment on this line from ReceiveMessageHandler: todo resolve
|
|
||||||
// this.targetAuthor = reaction.getTargetAuthor().getLegacyIdentifier();
|
|
||||||
// this.targetTimestamp = reaction.getTargetSentTimestamp();
|
|
||||||
// this.isRemove = reaction.isRemove();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
class JsonDataMessage {
|
class JsonDataMessage {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
@ -119,29 +100,6 @@ class JsonDataMessage {
|
||||||
} else {
|
} else {
|
||||||
this.attachments = List.of();
|
this.attachments = List.of();
|
||||||
}
|
}
|
||||||
/*if (dataMessage.getReaction().isPresent()) { // not sure if json reactions have been properly implemented elsewhere
|
|
||||||
final SignalServiceDataMessage.Reaction reaction = dataMessage.getReaction().get();
|
|
||||||
this.reaction = new JsonReaction(reaction);
|
|
||||||
this.emoji = reaction.getEmoji();
|
|
||||||
this.targetAuthor = reaction.getTargetAuthor().getLegacyIdentifier();
|
|
||||||
this.targetTimestamp = reaction.getTargetSentTimestamp();
|
|
||||||
} else {
|
|
||||||
this.reaction = null;
|
|
||||||
this.emoji = "";
|
|
||||||
this.targetAuthor = "";
|
|
||||||
this.targetTimestamp = 0;
|
|
||||||
}
|
|
||||||
if (message.getQuote().isPresent()) {
|
|
||||||
SignalServiceDataMessage.Quote quote = message.getQuote().get();
|
|
||||||
System.out.println("Quote: (" + quote.getId() + ")");
|
|
||||||
// there doesn't seem to be any way to find a message's id?
|
|
||||||
System.out.println(" Author: " + quote.getAuthor().getLegacyIdentifier());
|
|
||||||
System.out.println(" Text: " + quote.getText());
|
|
||||||
}
|
|
||||||
if (message.isExpirationUpdate()) {
|
|
||||||
System.out.println("Is Expiration update: " + message.isExpirationUpdate());
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
this.sticker = dataMessage.getSticker().isPresent() ? new JsonSticker(dataMessage.getSticker().get()) : null;
|
this.sticker = dataMessage.getSticker().isPresent() ? new JsonSticker(dataMessage.getSticker().get()) : null;
|
||||||
|
|
||||||
if (dataMessage.getSharedContacts().isPresent()) {
|
if (dataMessage.getSharedContacts().isPresent()) {
|
||||||
|
@ -169,8 +127,7 @@ class JsonDataMessage {
|
||||||
contacts = null;
|
contacts = null;
|
||||||
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
attachments = messageReceived.getAttachments().stream().map(JsonAttachment::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
// i don't understand what SyncMessages are so i'm going to ignore them
|
|
||||||
// i think it only matters if you have multiple devices on your end
|
|
||||||
public JsonDataMessage(Signal.SyncMessageReceived messageReceived) {
|
public JsonDataMessage(Signal.SyncMessageReceived messageReceived) {
|
||||||
timestamp = messageReceived.getTimestamp();
|
timestamp = messageReceived.getTimestamp();
|
||||||
message = messageReceived.getMessage();
|
message = messageReceived.getMessage();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue