Follow request Friendica
This commit is contained in:
parent
b5da435115
commit
d22eda3cb2
|
@ -239,7 +239,15 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
statusCode = gnuapi.statusAction(status);
|
||||
else if (apiAction == API.StatusAction.MUTE_NOTIFICATIONS)
|
||||
statusCode = gnuapi.muteNotifications(targetedId, muteNotifications);
|
||||
else
|
||||
else if (apiAction == API.StatusAction.AUTHORIZE || apiAction == API.StatusAction.REJECT) {
|
||||
//This part uses the Mastodon API
|
||||
API api;
|
||||
if (account != null)
|
||||
api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
else
|
||||
api = new API(contextReference.get());
|
||||
statusCode = api.postAction(apiAction, targetedId);
|
||||
} else
|
||||
statusCode = gnuapi.postAction(apiAction, targetedId);
|
||||
error = gnuapi.getError();
|
||||
}
|
||||
|
|
|
@ -19,10 +19,8 @@ import android.os.AsyncTask;
|
|||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.client.API;
|
||||
import app.fedilab.android.client.APIResponse;
|
||||
import app.fedilab.android.client.GNUAPI;
|
||||
import app.fedilab.android.interfaces.OnRetrieveAccountsInterface;
|
||||
|
||||
|
||||
|
@ -47,11 +45,7 @@ public class RetrieveFollowRequestSentAsyncTask extends AsyncTask<Void, Void, Vo
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
apiResponse = new API(this.contextReference.get()).getFollowRequest(max_id);
|
||||
}else{
|
||||
apiResponse = new GNUAPI(this.contextReference.get()).getFollowRequest(max_id);
|
||||
}
|
||||
apiResponse = new API(this.contextReference.get()).getFollowRequest(max_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -4475,11 +4475,8 @@ public class API {
|
|||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -268,6 +268,7 @@ public class GNUAPI {
|
|||
}
|
||||
//Retrieves mentions
|
||||
List<Mention> mentions = new ArrayList<>();
|
||||
Helper.largeLog( resobj.toString());
|
||||
if (resobj.has("attentions")) {
|
||||
JSONArray arrayMention = resobj.getJSONArray("attentions");
|
||||
if (arrayMention != null) {
|
||||
|
@ -1641,55 +1642,6 @@ public class GNUAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves follow requests for the authenticated account *synchronously*
|
||||
*
|
||||
* @param max_id String id max
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getFollowRequest(String max_id) {
|
||||
return getFollowRequest(max_id, null, accountPerPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves follow requests for the authenticated account *synchronously*
|
||||
*
|
||||
* @param max_id String id max
|
||||
* @param since_id String since the id
|
||||
* @param limit int limit - max value 40
|
||||
* @return APIResponse
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private APIResponse getFollowRequest(String max_id, String since_id, int limit) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (max_id != null)
|
||||
params.put("max_id", max_id);
|
||||
if (since_id != null)
|
||||
params.put("since_id", since_id);
|
||||
if (0 > limit || limit > 40)
|
||||
limit = 40;
|
||||
params.put("limit", String.valueOf(limit));
|
||||
accounts = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/friendships/incoming.json"), 60, params, prefKeyOauthTokenT);
|
||||
params = new HashMap<>();
|
||||
params.put("user_id", response.replace("[","").replace("]",""));
|
||||
response = httpsConnection.get(getAbsoluteUrl("/users/lookup.json"), 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
accounts = parseAccountResponse(new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setAccounts(accounts);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves favourited status for the authenticated account *synchronously*
|
||||
*
|
||||
|
@ -2242,6 +2194,39 @@ public class GNUAPI {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Accounts and feeds when searching *synchronously*
|
||||
*
|
||||
* @param query String search
|
||||
* @return Results
|
||||
*/
|
||||
public APIResponse search2(String query) {
|
||||
Results results = new Results();
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
apiResponse = new APIResponse();
|
||||
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
|
||||
params.put("q", query);
|
||||
else
|
||||
try {
|
||||
params.put("q", URLEncoder.encode(query, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
params.put("q", query);
|
||||
}
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/search.json"), 60, params, prefKeyOauthTokenT);
|
||||
List<Status> statuses = parseStatuses(context, new JSONArray(response));
|
||||
results.setStatuses(statuses);
|
||||
apiResponse.setResults(results);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Accounts and feeds when searching *synchronously*
|
||||
*
|
||||
|
@ -2571,6 +2556,11 @@ public class GNUAPI {
|
|||
return Helper.instanceWithProtocol(this.context, this.instance) + "/api" + action;
|
||||
}
|
||||
|
||||
private String getAbsoluteMastodonUrl(String action) {
|
||||
return Helper.instanceWithProtocol(this.context, this.instance) + "/api/v1" + action;
|
||||
}
|
||||
|
||||
|
||||
private String getAbsoluteRemoteUrl(String instance, String action) {
|
||||
return Helper.instanceWithProtocol(this.context, instance) + "/api" + action;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class AccountsFollowRequestAdapter extends RecyclerView.Adapter implement
|
|||
holder.btn_authorize.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.green_1), PorterDuff.Mode.MULTIPLY);
|
||||
holder.btn_reject.getBackground().setColorFilter(ContextCompat.getColor(context, R.color.red_1), PorterDuff.Mode.MULTIPLY);
|
||||
//TODO: check if Friendica has a way to accept/deny follow requests
|
||||
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
holder.btn_authorize.setVisibility(View.GONE);
|
||||
holder.btn_reject.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -37,17 +37,20 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.BaseActivity;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.activities.ShowAccountActivity;
|
||||
import app.fedilab.android.activities.ShowConversationActivity;
|
||||
import app.fedilab.android.activities.TootActivity;
|
||||
import app.fedilab.android.asynctasks.PostActionAsyncTask;
|
||||
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import app.fedilab.android.client.API;
|
||||
import app.fedilab.android.client.APIResponse;
|
||||
import app.fedilab.android.client.Entities.Account;
|
||||
import app.fedilab.android.client.Entities.Mention;
|
||||
import app.fedilab.android.client.Entities.Results;
|
||||
import app.fedilab.android.client.Entities.Status;
|
||||
import app.fedilab.android.client.GNUAPI;
|
||||
import app.fedilab.android.drawers.AccountsSearchAdapter;
|
||||
import app.fedilab.android.drawers.PixelfedListAdapter;
|
||||
import app.fedilab.android.drawers.StatusListAdapter;
|
||||
|
@ -94,7 +97,7 @@ public class CrossActions {
|
|||
for (Account account : accountstmp) {
|
||||
String mentionAcct = (mention.getAcct().contains("@")) ? mention.getAcct() : mention.getAcct() + "@" + currentAccount.getInstance();
|
||||
if ((account.getAcct() + "@" + account.getInstance()).equals(mentionAcct) && !addedAccount.contains(account.getId() + "|" + account.getAcct())) {
|
||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA"))
|
||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA") || account.getSocial().equals("FRIENDICA"))
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +106,7 @@ public class CrossActions {
|
|||
Account tootOwner = status.getAccount();
|
||||
String mentionAcct = (tootOwner.getAcct().contains("@")) ? tootOwner.getAcct() : tootOwner.getAcct() + "@" + currentAccount.getInstance();
|
||||
if ((account.getAcct() + "@" + account.getInstance()).equals(mentionAcct) && !addedAccount.contains(account.getId() + "|" + account.getAcct())) {
|
||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA"))
|
||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA")|| account.getSocial().equals("FRIENDICA"))
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +332,7 @@ public class CrossActions {
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
|
||||
String url = remoteAccount.getUrl();
|
||||
if (url == null) {
|
||||
if (remoteAccount.getHost() != null && remoteAccount.getAcct().split("@").length > 1) //Peertube compatibility
|
||||
|
@ -337,7 +340,14 @@ public class CrossActions {
|
|||
else
|
||||
url = "https://" + remoteAccount.getInstance() + "/@" + remoteAccount.getAcct();
|
||||
}
|
||||
APIResponse apiResponse = api.search2(url, null, null);
|
||||
APIResponse apiResponse;
|
||||
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
GNUAPI api = new GNUAPI(contextReference.get(), account.getInstance(), account.getToken());
|
||||
apiResponse = api.search(remoteAccount.getAcct()+"@"+remoteAccount.getInstance());
|
||||
} else {
|
||||
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
apiResponse = api.search2(url, null, null);
|
||||
}
|
||||
response = apiResponse.getResults();
|
||||
return null;
|
||||
}
|
||||
|
@ -414,8 +424,15 @@ public class CrossActions {
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
APIResponse apiResponse = api.search(remoteStatus.getUrl());
|
||||
|
||||
APIResponse apiResponse;
|
||||
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
|
||||
GNUAPI api = new GNUAPI(contextReference.get(), account.getInstance(), account.getToken());
|
||||
apiResponse = api.search2(remoteStatus.getUrl());
|
||||
} else {
|
||||
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
apiResponse = api.search(remoteStatus.getUrl());
|
||||
}
|
||||
response = apiResponse.getResults();
|
||||
return null;
|
||||
}
|
||||
|
@ -626,7 +643,7 @@ public class CrossActions {
|
|||
protected Void doInBackground(Void... voids) {
|
||||
|
||||
|
||||
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
|
||||
String uri;
|
||||
if (status.getReblog() != null) {
|
||||
if (status.getReblog().getUri().startsWith("http"))
|
||||
|
@ -639,9 +656,18 @@ public class CrossActions {
|
|||
else
|
||||
uri = status.getUrl();
|
||||
}
|
||||
APIResponse search = api.search(uri);
|
||||
if (search != null && search.getResults() != null) {
|
||||
remoteStatuses = search.getResults().getStatuses();
|
||||
if( account.getSocial().compareTo("FRIENDICA") != 0 ) {
|
||||
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
APIResponse search = api.search(uri);
|
||||
if (search != null && search.getResults() != null) {
|
||||
remoteStatuses = search.getResults().getStatuses();
|
||||
}
|
||||
}else{
|
||||
GNUAPI api = new GNUAPI(contextReference.get(), account.getInstance(), account.getToken());
|
||||
APIResponse search = api.search2(uri);
|
||||
if (search != null && search.getResults() != null) {
|
||||
remoteStatuses = search.getResults().getStatuses();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ public class AccountDAO {
|
|||
public List<Account> getAllAccountCrossAction() {
|
||||
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_SOCIAL + " != 'PEERTUBE' AND " + Sqlite.COL_SOCIAL + " != 'FRIENDICA' AND " + Sqlite.COL_SOCIAL + " != 'GNU' AND " +Sqlite.COL_OAUTHTOKEN + " != 'null'", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
|
||||
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_SOCIAL + " != 'PEERTUBE' AND " + Sqlite.COL_SOCIAL + " != 'GNU' AND " +Sqlite.COL_OAUTHTOKEN + " != 'null'", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
|
||||
return cursorToListUser(c);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue