allow to schedule with another account

This commit is contained in:
Thomas 2020-07-30 10:23:19 +02:00
parent ffcb75cc74
commit 4edaa45986
3 changed files with 19 additions and 13 deletions

View File

@ -1878,16 +1878,18 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = accountReply!=null?accountReply.getId():account.getId();
String instance = accountReply!=null?accountReply.getInstance():account.getInstance();
try { try {
if (currentToId == -1) { if (currentToId == -1) {
currentToId = new StatusStoredDAO(BasePixelfedComposeActivity.this, db).insertStatus(toot, null); currentToId = new StatusStoredDAO(BasePixelfedComposeActivity.this, db).insertStatus(toot, null, userId, instance);
} else { } else {
StoredStatus storedStatus = new StatusStoredDAO(BasePixelfedComposeActivity.this, db).getStatus(currentToId); StoredStatus storedStatus = new StatusStoredDAO(BasePixelfedComposeActivity.this, db).getStatus(currentToId);
if (storedStatus != null) { if (storedStatus != null) {
new StatusStoredDAO(BasePixelfedComposeActivity.this, db).updateStatus(currentToId, toot); new StatusStoredDAO(BasePixelfedComposeActivity.this, db).updateStatus(currentToId, toot);
} else { //Might have been deleted, so it needs insertion } else { //Might have been deleted, so it needs insertion
new StatusStoredDAO(BasePixelfedComposeActivity.this, db).insertStatus(toot, null); new StatusStoredDAO(BasePixelfedComposeActivity.this, db).insertStatus(toot, null, userId, instance);
} }
} }
if (message) if (message)

View File

@ -2051,7 +2051,7 @@ public abstract class BaseTootActivity extends BaseActivity implements UploadSta
} }
else { else {
toot.setScheduled_at(timestamp); toot.setScheduled_at(timestamp);
new PostStatusAsyncTask(BaseTootActivity.this, social, account, toot, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new PostStatusAsyncTask(BaseTootActivity.this, social, accountReply!=null?accountReply:account, toot, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
} }
@ -2126,9 +2126,6 @@ public abstract class BaseTootActivity extends BaseActivity implements UploadSta
MenuItem itemRestore = menu.findItem(R.id.action_restore); MenuItem itemRestore = menu.findItem(R.id.action_restore);
if (itemRestore != null) if (itemRestore != null)
itemRestore.setVisible(false); itemRestore.setVisible(false);
MenuItem itemSchedule = menu.findItem(R.id.action_schedule);
if (itemSchedule != null)
itemSchedule.setVisible(false);
MenuItem itemStore = menu.findItem(R.id.action_store); MenuItem itemStore = menu.findItem(R.id.action_store);
if (itemStore != null) if (itemStore != null)
itemStore.setVisible(false); itemStore.setVisible(false);
@ -3478,16 +3475,18 @@ public abstract class BaseTootActivity extends BaseActivity implements UploadSta
if (tootReply != null) if (tootReply != null)
toot.setIn_reply_to_id(tootReply.getId()); toot.setIn_reply_to_id(tootReply.getId());
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
//TODO: insert should be done with connected account
String userId = accountReply!=null?accountReply.getId():account.getId();
String instance = accountReply!=null?accountReply.getInstance():account.getInstance();
try { try {
if (currentToId == -1) { if (currentToId == -1) {
currentToId = new StatusStoredDAO(BaseTootActivity.this, db).insertStatus(toot, tootReply); currentToId = new StatusStoredDAO(BaseTootActivity.this, db).insertStatus(toot, tootReply, userId, instance);
} else { } else {
StoredStatus storedStatus = new StatusStoredDAO(BaseTootActivity.this, db).getStatus(currentToId); StoredStatus storedStatus = new StatusStoredDAO(BaseTootActivity.this, db).getStatus(currentToId);
if (storedStatus != null) { if (storedStatus != null) {
new StatusStoredDAO(BaseTootActivity.this, db).updateStatus(currentToId, toot); new StatusStoredDAO(BaseTootActivity.this, db).updateStatus(currentToId, toot);
} else { //Might have been deleted, so it needs insertion } else { //Might have been deleted, so it needs insertion
new StatusStoredDAO(BaseTootActivity.this, db).insertStatus(toot, tootReply); new StatusStoredDAO(BaseTootActivity.this, db).insertStatus(toot, tootReply, userId, instance);
} }
} }
if (message) if (message)

View File

@ -45,6 +45,9 @@ public class StatusStoredDAO {
this.db = db; this.db = db;
} }
public long insertStatus(Status status, Status statusReply) {
return insertStatus(status, statusReply, null, null);
}
//------- INSERTIONS ------- //------- INSERTIONS -------
@ -54,13 +57,15 @@ public class StatusStoredDAO {
* @param status Status * @param status Status
* @return boolean * @return boolean
*/ */
public long insertStatus(Status status, Status statusReply) { public long insertStatus(Status status, Status statusReply, String userId, String instance) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
String serializedStatus = Helper.statusToStringStorage(status); String serializedStatus = Helper.statusToStringStorage(status);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); if( instance == null || userId == null) {
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String instance = Helper.getLiveInstance(context); userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
instance = Helper.getLiveInstance(context);
}
if (userId == null || instance == null) if (userId == null || instance == null)
return -1; return -1;
if (statusReply != null) { if (statusReply != null) {