mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
add getHttpResponse to Rpc
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.b44t.messenger.rpc;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
public class HttpResponse {
|
||||
// base64-encoded response body.
|
||||
private String blob;
|
||||
// MIME type, e.g. "text/plain" or "text/html".
|
||||
private String mimetype;
|
||||
// Encoding, e.g. "utf-8".
|
||||
private String encoding;
|
||||
|
||||
public HttpResponse(String blob, String mimetype, String encoding) {
|
||||
this.blob = blob;
|
||||
this.mimetype = mimetype;
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public byte[] getBlob() {
|
||||
if (blob == null) {
|
||||
return null;
|
||||
}
|
||||
return Base64.decode(blob, Base64.NO_WRAP | Base64.NO_PADDING);
|
||||
}
|
||||
|
||||
public String getMimetype() {
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
public String getEncoding() {
|
||||
return encoding;
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,10 @@ public class Rpc {
|
||||
return gson.fromJson(getResult("get_system_info"), mapType);
|
||||
}
|
||||
|
||||
public HttpResponse getHttpResponse(int accountId, String url) throws RpcException {
|
||||
return gson.fromJson(getResult("get_http_response", accountId, url), HttpResponse.class);
|
||||
}
|
||||
|
||||
|
||||
private static class Request {
|
||||
public String jsonrpc = "2.0";
|
||||
|
||||
@@ -9,7 +9,8 @@ import android.webkit.WebSettings;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcHttpResponse;
|
||||
import com.b44t.messenger.rpc.HttpResponse;
|
||||
import com.b44t.messenger.rpc.Rpc;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
@@ -25,6 +26,7 @@ public class FullMsgActivity extends WebViewActivity
|
||||
public static final String IS_CONTACT_REQUEST = "is_contact_request";
|
||||
private int msgId;
|
||||
private DcContext dcContext;
|
||||
private Rpc rpc;
|
||||
private boolean loadRemoteContent = false;
|
||||
private boolean isContactRequest;
|
||||
|
||||
@@ -60,6 +62,7 @@ public class FullMsgActivity extends WebViewActivity
|
||||
webView.getSettings().setAllowFileAccess(false);
|
||||
|
||||
dcContext = DcHelper.getContext(this);
|
||||
rpc = DcHelper.getRpc(this);
|
||||
msgId = getIntent().getIntExtra(MSG_ID_EXTRA, 0);
|
||||
String title = dcContext.getMsg(msgId).getSubject();
|
||||
if (title.isEmpty()) title = getString(R.string.chat_input_placeholder);
|
||||
@@ -178,10 +181,7 @@ public class FullMsgActivity extends WebViewActivity
|
||||
if (url == null) {
|
||||
throw new Exception("no url specified");
|
||||
}
|
||||
DcHttpResponse httpResponse = dcContext.getHttpResponse(url);
|
||||
if (httpResponse == null) {
|
||||
throw new Exception(dcContext.getLastError());
|
||||
}
|
||||
HttpResponse httpResponse = rpc.getHttpResponse(dcContext.getAccountId(), url);
|
||||
String mimeType = httpResponse.getMimetype();
|
||||
if (mimeType == null) {
|
||||
mimeType = "application/octet-stream";
|
||||
|
||||
Reference in New Issue
Block a user