mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-01 20:10:39 +00:00
parse json data
This commit is contained in:
parent
6d5cfa32e2
commit
711d59967f
5 changed files with 49 additions and 30 deletions
19
.idea/codeStyles/Project.xml
generated
19
.idea/codeStyles/Project.xml
generated
|
@ -1,19 +0,0 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<option name="LINE_SEPARATOR" value=" " />
|
|
||||||
<JavaCodeStyleSettings>
|
|
||||||
<option name="GENERATE_FINAL_LOCALS" value="true" />
|
|
||||||
<option name="GENERATE_FINAL_PARAMETERS" value="true" />
|
|
||||||
<option name="JD_P_AT_EMPTY_LINES" value="false" />
|
|
||||||
</JavaCodeStyleSettings>
|
|
||||||
<XML>
|
|
||||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
|
||||||
</XML>
|
|
||||||
<codeStyleSettings language="JAVA">
|
|
||||||
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
|
|
||||||
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
|
|
||||||
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
|
|
||||||
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
|
|
||||||
</codeStyleSettings>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
5
.idea/codeStyles/codeStyleConfig.xml
generated
|
@ -1,5 +0,0 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<state>
|
|
||||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
|
||||||
</state>
|
|
||||||
</component>
|
|
|
@ -2,8 +2,8 @@ apply plugin: 'java'
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_7
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
mainClassName = 'org.asamk.signal.Main'
|
mainClassName = 'org.asamk.signal.Main'
|
||||||
|
|
||||||
|
|
30
src/main/java/org/asamk/signal/JsonSendableMessage.java
Normal file
30
src/main/java/org/asamk/signal/JsonSendableMessage.java
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package org.asamk.signal;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class JsonSendableMessage {
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAttachments() {
|
||||||
|
return attachments;
|
||||||
|
}
|
||||||
|
|
||||||
|
String message;
|
||||||
|
|
||||||
|
public void setAttachments(List<String> attachments) {
|
||||||
|
if ( attachments == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.attachments = attachments.stream()
|
||||||
|
.map(i -> new String(Base64.getDecoder().decode(i)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> attachments;
|
||||||
|
}
|
|
@ -1,13 +1,12 @@
|
||||||
package org.asamk.signal.commands;
|
package org.asamk.signal.commands;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.sourceforge.argparse4j.impl.Arguments;
|
import net.sourceforge.argparse4j.impl.Arguments;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
import netscape.javascript.JSException;
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.AttachmentInvalidException;
|
import org.asamk.signal.*;
|
||||||
import org.asamk.signal.GroupIdFormatException;
|
|
||||||
import org.asamk.signal.GroupNotFoundException;
|
|
||||||
import org.asamk.signal.NotAGroupMemberException;
|
|
||||||
import org.asamk.signal.util.IOUtils;
|
import org.asamk.signal.util.IOUtils;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
|
@ -16,6 +15,7 @@ import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptio
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.*;
|
import static org.asamk.signal.util.ErrorUtils.*;
|
||||||
|
@ -87,6 +87,15 @@ public class SendCommand implements DbusCommand {
|
||||||
if (attachments == null) {
|
if (attachments == null) {
|
||||||
attachments = new ArrayList<>();
|
attachments = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check to see if message is a JSON
|
||||||
|
// { "messageText": "string", "attachments": [ "base64" ] }
|
||||||
|
if (messageText.startsWith("{")) {
|
||||||
|
JsonSendableMessage result = new ObjectMapper().readValue(messageText, JsonSendableMessage.class);
|
||||||
|
messageText = result.getMessage();
|
||||||
|
attachments = result.getAttachments();
|
||||||
|
}
|
||||||
|
|
||||||
if (ns.getString("group") != null) {
|
if (ns.getString("group") != null) {
|
||||||
byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
||||||
signal.sendGroupMessage(messageText, attachments, groupId);
|
signal.sendGroupMessage(messageText, attachments, groupId);
|
||||||
|
@ -119,6 +128,10 @@ public class SendCommand implements DbusCommand {
|
||||||
} catch (GroupIdFormatException e) {
|
} catch (GroupIdFormatException e) {
|
||||||
handleGroupIdFormatException(e);
|
handleGroupIdFormatException(e);
|
||||||
return 1;
|
return 1;
|
||||||
|
} catch (JSException e) {
|
||||||
|
// not sure how to deal with this.
|
||||||
|
e.printStackTrace();
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue