mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-13 21:29:56 +00:00
@@ -1,7 +1,5 @@
|
|||||||
package org.thoughtcrime.redphone.signaling;
|
package org.thoughtcrime.redphone.signaling;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.squareup.okhttp.MediaType;
|
import com.squareup.okhttp.MediaType;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import com.squareup.okhttp.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import com.squareup.okhttp.Request;
|
||||||
@@ -9,6 +7,7 @@ import com.squareup.okhttp.RequestBody;
|
|||||||
import com.squareup.okhttp.Response;
|
import com.squareup.okhttp.Response;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.thoughtcrime.securesms.util.Base64;
|
||||||
|
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||||
import org.whispersystems.textsecure.api.push.TrustStore;
|
import org.whispersystems.textsecure.api.push.TrustStore;
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ public class RedPhoneAccountManager {
|
|||||||
builder.header("Authorization", "Basic " + Base64.encodeBytes((login + ":" + password).getBytes()));
|
builder.header("Authorization", "Basic " + Base64.encodeBytes((login + ":" + password).getBytes()));
|
||||||
|
|
||||||
if (gcmId.isPresent()) {
|
if (gcmId.isPresent()) {
|
||||||
String body = new ObjectMapper().writeValueAsString(new RedPhoneGcmId(gcmId.get()));
|
String body = JsonUtils.toJson(new RedPhoneGcmId(gcmId.get()));
|
||||||
builder.put(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), body));
|
builder.put(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), body));
|
||||||
} else {
|
} else {
|
||||||
builder.delete();
|
builder.delete();
|
||||||
@@ -70,7 +69,7 @@ public class RedPhoneAccountManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createAccount(String verificationToken, RedPhoneAccountAttributes attributes) throws IOException {
|
public void createAccount(String verificationToken, RedPhoneAccountAttributes attributes) throws IOException {
|
||||||
String body = new ObjectMapper().writeValueAsString(attributes);
|
String body = JsonUtils.toJson(attributes);
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(baseUrl + "/api/v1/accounts/token/" + verificationToken)
|
.url(baseUrl + "/api/v1/accounts/token/" + verificationToken)
|
||||||
|
@@ -30,6 +30,7 @@ import org.thoughtcrime.redphone.signaling.signals.RingingSignal;
|
|||||||
import org.thoughtcrime.redphone.signaling.signals.ServerSignal;
|
import org.thoughtcrime.redphone.signaling.signals.ServerSignal;
|
||||||
import org.thoughtcrime.redphone.signaling.signals.Signal;
|
import org.thoughtcrime.redphone.signaling.signals.Signal;
|
||||||
import org.thoughtcrime.redphone.util.LineReader;
|
import org.thoughtcrime.redphone.util.LineReader;
|
||||||
|
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||||
import org.whispersystems.textsecure.api.push.TrustStore;
|
import org.whispersystems.textsecure.api.push.TrustStore;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -182,7 +183,7 @@ public class SignalingSocket {
|
|||||||
case 404: throw new NoSuchUserException("No such redphone user.");
|
case 404: throw new NoSuchUserException("No such redphone user.");
|
||||||
case 402: throw new ServerMessageException(new String(response.getBody()));
|
case 402: throw new ServerMessageException(new String(response.getBody()));
|
||||||
case 401: throw new LoginFailedException("Initiate threw 401");
|
case 401: throw new LoginFailedException("Initiate threw 401");
|
||||||
case 200: return new ObjectMapper().readValue(response.getBody(), SessionDescriptor.class);
|
case 200: return JsonUtils.fromJson(response.getBody(), SessionDescriptor.class);
|
||||||
default: throw new SignalingException("Unknown response: " + response.getStatusCode());
|
default: throw new SignalingException("Unknown response: " + response.getStatusCode());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@@ -15,6 +15,10 @@ public class JsonUtils {
|
|||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T fromJson(byte[] serialized, Class<T> clazz) throws IOException {
|
||||||
|
return fromJson(new String(serialized), clazz);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> T fromJson(String serialized, Class<T> clazz) throws IOException {
|
public static <T> T fromJson(String serialized, Class<T> clazz) throws IOException {
|
||||||
return objectMapper.readValue(serialized, clazz);
|
return objectMapper.readValue(serialized, clazz);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user