Fix media attachment with cross-account posts
This commit is contained in:
parent
ae9a44b15f
commit
48ff9a99a2
|
@ -468,7 +468,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
picture_scrollview.setVisibility(View.VISIBLE);
|
||||
toot_picture.setEnabled(false);
|
||||
toot_it.setEnabled(false);
|
||||
new HttpsConnection(TootActivity.this, instance).upload(bs, fileMention, accountReply!=null?accountReply.getToken():null, TootActivity.this);
|
||||
new HttpsConnection(TootActivity.this, instance).upload(bs, fileMention, account, TootActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -810,7 +810,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
}
|
||||
picture_scrollview.setVisibility(View.VISIBLE);
|
||||
try {
|
||||
new asyncPicture(TootActivity.this, accountReply, fileUri).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new asyncPicture(TootActivity.this, account, fileUri).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
count++;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -895,9 +895,9 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
String mime = cr.getType(data.getData());
|
||||
if(mime != null && (mime.toLowerCase().contains("video") || mime.toLowerCase().contains("gif")) ) {
|
||||
InputStream inputStream = getContentResolver().openInputStream(data.getData());
|
||||
new HttpsConnection(TootActivity.this, instance).upload(inputStream, filename, accountReply!=null?accountReply.getToken():null, TootActivity.this);
|
||||
new HttpsConnection(TootActivity.this, instance).upload(inputStream, filename, account, TootActivity.this);
|
||||
} else if(mime != null && mime.toLowerCase().contains("image")) {
|
||||
new asyncPicture(TootActivity.this, accountReply, data.getData()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new asyncPicture(TootActivity.this, account, data.getData()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else {
|
||||
Toasty.error(getApplicationContext(),getString(R.string.toot_select_image_error),Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -916,7 +916,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
toot_content.setSelection(toot_content.getText().length());
|
||||
}
|
||||
}else if (requestCode == TAKE_PHOTO && resultCode == RESULT_OK) {
|
||||
new asyncPicture(TootActivity.this, accountReply, photoFileUri).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new asyncPicture(TootActivity.this, account, photoFileUri).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -937,13 +937,13 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
ByteArrayInputStream bs;
|
||||
WeakReference<Activity> activityWeakReference;
|
||||
android.net.Uri uriFile;
|
||||
Account accountReply;
|
||||
Account account;
|
||||
boolean error = false;
|
||||
|
||||
asyncPicture(Activity activity, Account accountReply, android.net.Uri uri){
|
||||
asyncPicture(Activity activity, Account account, android.net.Uri uri){
|
||||
this.activityWeakReference = new WeakReference<>(activity);
|
||||
this.uriFile = uri;
|
||||
this.accountReply = accountReply;
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -980,7 +980,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
toot_it.setEnabled(false);
|
||||
String filename = Helper.getFileName(this.activityWeakReference.get(), uriFile);
|
||||
filesMap.put(filename, uriFile);
|
||||
new HttpsConnection(this.activityWeakReference.get(), instance).upload(bs, filename, accountReply != null ? accountReply.getToken() : null, (TootActivity) this.activityWeakReference.get());
|
||||
new HttpsConnection(this.activityWeakReference.get(), instance).upload(bs, filename,account, (TootActivity) this.activityWeakReference.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1003,9 +1003,9 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
String mime = cr.getType(imageUri);
|
||||
if(mime != null && (mime.toLowerCase().contains("video") || mime.toLowerCase().contains("gif")) ) {
|
||||
InputStream inputStream = getContentResolver().openInputStream(imageUri);
|
||||
new HttpsConnection(TootActivity.this, instance).upload(inputStream, filename, accountReply!=null?accountReply.getToken():null, TootActivity.this);
|
||||
new HttpsConnection(TootActivity.this, instance).upload(inputStream, filename, account, TootActivity.this);
|
||||
} else if(mime != null && mime.toLowerCase().contains("image")) {
|
||||
new asyncPicture(TootActivity.this, accountReply, intent.getData()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new asyncPicture(TootActivity.this, account, intent.getData()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else {
|
||||
Toasty.error(getApplicationContext(),getString(R.string.toot_select_image_error),Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -1557,17 +1557,17 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
}
|
||||
if( timestamp == null)
|
||||
if( scheduledstatus == null)
|
||||
new PostStatusAsyncTask(getApplicationContext(), accountReply, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostStatusAsyncTask(getApplicationContext(), account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else {
|
||||
toot.setScheduled_at(Helper.dateToString(scheduledstatus.getScheduled_date()));
|
||||
scheduledstatus.setStatus(toot);
|
||||
isScheduled = true;
|
||||
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.DELETESCHEDULED, scheduledstatus, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostStatusAsyncTask(getApplicationContext(), accountReply, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostStatusAsyncTask(getApplicationContext(), account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
else {
|
||||
toot.setScheduled_at(timestamp);
|
||||
new PostStatusAsyncTask(getApplicationContext(), accountReply, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostStatusAsyncTask(getApplicationContext(), account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1799,7 +1799,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
toot_picture_container.setVisibility(View.VISIBLE);
|
||||
toot_picture.setEnabled(false);
|
||||
toot_it.setEnabled(false);
|
||||
new HttpsConnection(TootActivity.this, instance).upload(bs, filename, accountReply!=null?accountReply.getToken():null, TootActivity.this);
|
||||
new HttpsConnection(TootActivity.this, instance).upload(bs, filename, account, TootActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1859,7 +1859,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new UpdateDescriptionAttachmentAsyncTask(getApplicationContext(), attachment.getId(), input.getText().toString(), accountReply,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new UpdateDescriptionAttachmentAsyncTask(getApplicationContext(), attachment.getId(), input.getText().toString(), account,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
attachment.setDescription(input.getText().toString());
|
||||
addBorder();
|
||||
dialog.dismiss();
|
||||
|
@ -2007,7 +2007,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
if( apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0)
|
||||
toot.setIn_reply_to_id(apiResponse.getStatuses().get(0).getId());
|
||||
toot.setContent(tootContent);
|
||||
new PostStatusAsyncTask(getApplicationContext(), accountReply, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostStatusAsyncTask(getApplicationContext(), account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
return;
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.SharedPreferences;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
@ -204,7 +203,6 @@ public class API {
|
|||
editor.apply();
|
||||
}
|
||||
}
|
||||
Log.v(Helper.TAG,"scheme: " + scheme);
|
||||
String response;
|
||||
InstanceNodeInfo instanceNodeInfo = new InstanceNodeInfo();
|
||||
try {
|
||||
|
|
|
@ -1221,8 +1221,14 @@ public class HttpsConnection {
|
|||
* @param inputStream InputStream of the file to upload
|
||||
* @param listener - OnRetrieveAttachmentInterface: listener to send information about attachment once uploaded.
|
||||
*/
|
||||
public void upload(final InputStream inputStream, String fname, String tokenUsed, final OnRetrieveAttachmentInterface listener) {
|
||||
public void upload(final InputStream inputStream, String fname, Account account, final OnRetrieveAttachmentInterface listener) {
|
||||
final String fileName = FileNameCleaner.cleanFileName(fname);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
if( account == null){
|
||||
return;
|
||||
}
|
||||
this.instance = account.getInstance();
|
||||
String token = account.getToken();
|
||||
if( Helper.getLiveInstanceWithProtocol(context).startsWith("https://")) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
|
@ -1232,15 +1238,6 @@ public class HttpsConnection {
|
|||
String twoHyphens = "--";
|
||||
String boundary = "*****" + Long.toString(System.currentTimeMillis()) + "*****";
|
||||
String lineEnd = "\r\n";
|
||||
String token;
|
||||
if( tokenUsed == null)
|
||||
token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
else
|
||||
token = tokenUsed;
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
|
||||
URL url;
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
|
||||
url = new URL("https://" + account.getInstance() + "/api/v1/media");
|
||||
|
@ -1406,11 +1403,6 @@ public class HttpsConnection {
|
|||
String twoHyphens = "--";
|
||||
String boundary = "*****" + Long.toString(System.currentTimeMillis()) + "*****";
|
||||
String lineEnd = "\r\n";
|
||||
String token;
|
||||
if( tokenUsed == null)
|
||||
token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
else
|
||||
token = tokenUsed;
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package app.fedilab.android.client;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
@ -60,7 +57,6 @@ public class TLSSocketFactory extends SSLSocketFactory {
|
|||
sslContext.init(null, trustAllCerts, null);
|
||||
|
||||
}
|
||||
Log.v(Helper.TAG,instance + " -> " + isOnion);
|
||||
sSLSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue