Skip to content

Commit

Permalink
Add latest Threema capabilities (#31)
Browse files Browse the repository at this point in the history
Also make sure that the API call does not break when Threema adds new
capabilities in future.

Fixes #30
  • Loading branch information
marchof authored May 22, 2023
1 parent 26e72fb commit 5a607be
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/com/mountainminds/three4j/Gateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static com.mountainminds.three4j.HttpSupport.UNKNOWN_RESPONSE;
import static com.mountainminds.three4j.HttpSupport.blobBody;
import static java.util.Arrays.stream;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;

import java.io.IOException;
Expand All @@ -34,6 +36,7 @@
import java.net.http.HttpResponse.BodyHandler;
import java.net.http.HttpResponse.BodyHandlers;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -230,7 +233,18 @@ public PublicKey getPublicKey(ThreemaId threemaid) throws GatewayException, IOEx
* Currently known capabilities.
*/
public static enum Capability {
text, image, video, audio, file

text, image, video, audio, group, ballot, file, call, videocall, pfs, groupcall,

/** Capability not known by this Threema client implementation */
unknown;

private static final Map<String, Capability> BY_NAME = //
Arrays.stream(values()).collect(toMap(Enum::name, identity()));

static Capability of(String name) {
return BY_NAME.getOrDefault(name, unknown);
}
}

/**
Expand All @@ -245,7 +259,7 @@ public Set<Capability> getCapabilities(ThreemaId threemaid) throws GatewayExcept
var request = gwRequest(auth(), "capabilities", threemaid.getValue()).build();
var result = send(request, BodyHandlers.ofString(), DEFAULT_STATUS //
.error(STATUS_NOTFOUND, () -> "No matching ID for " + threemaid));
return stream(result.split(",")).map(Capability::valueOf).collect(toSet());
return stream(result.split(",")).map(Capability::of).collect(toSet());
}

/**
Expand Down

0 comments on commit 5a607be

Please sign in to comment.