mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Implement jsonRpc command
Co-authored-by: technillogue <technillogue@gmail.com> Closes #668
This commit is contained in:
parent
6c00054407
commit
a8bbdb54d0
20 changed files with 863 additions and 31 deletions
|
@ -1,10 +1,20 @@
|
|||
package org.asamk.signal.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupIdFormatException;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Util {
|
||||
|
||||
private Util() {
|
||||
|
@ -18,6 +28,22 @@ public class Util {
|
|||
return string;
|
||||
}
|
||||
|
||||
public static String dashSeparatedToCamelCaseString(String s) {
|
||||
var parts = s.split("-");
|
||||
return toCamelCaseString(Arrays.asList(parts));
|
||||
}
|
||||
|
||||
private static String toCamelCaseString(List<String> strings) {
|
||||
if (strings.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
return strings.get(0) + strings.stream()
|
||||
.skip(1)
|
||||
.filter(s -> s.length() > 0)
|
||||
.map(s -> Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase(Locale.ROOT))
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
|
||||
public static String formatSafetyNumber(String digits) {
|
||||
final var partCount = 12;
|
||||
var partSize = digits.length() / partCount;
|
||||
|
@ -35,4 +61,11 @@ public class Util {
|
|||
public static String getLegacyIdentifier(final SignalServiceAddress address) {
|
||||
return address.getNumber().or(() -> address.getUuid().get().toString());
|
||||
}
|
||||
|
||||
public static ObjectMapper createJsonObjectMapper() {
|
||||
var objectMapper = new ObjectMapper();
|
||||
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY);
|
||||
objectMapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue