Check friendship - #692
This commit is contained in:
parent
18ea5fdf37
commit
03b5f154f1
|
@ -1081,20 +1081,22 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
|
||||
tabLayout.getTabAt(0).select();
|
||||
toot.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getApplicationContext(), TootActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
toot.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
CrossActions.doCrossReply(BaseMainActivity.this, null, null, false);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
toot.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getApplicationContext(), TootActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
toot.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
CrossActions.doCrossReply(BaseMainActivity.this, null, null, false);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
//Image loader configuration
|
||||
|
||||
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
|
@ -1120,6 +1122,18 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
popup.getMenuInflater()
|
||||
.inflate(R.menu.main, popup.getMenu());
|
||||
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
|
||||
MenuItem action_about_instance = popup.getMenu().findItem(R.id.action_about_instance);
|
||||
if( action_about_instance != null)
|
||||
action_about_instance.setVisible(false);
|
||||
MenuItem action_size = popup.getMenu().findItem(R.id.action_size);
|
||||
if( action_size != null)
|
||||
action_size.setVisible(false);
|
||||
MenuItem action_export = popup.getMenu().findItem(R.id.action_export);
|
||||
if( action_export != null)
|
||||
action_export.setVisible(false);
|
||||
}
|
||||
|
||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -1285,6 +1299,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
|
||||
optionInfo.setVisibility(View.GONE);
|
||||
MenuFloating.tags = new ArrayList<>();
|
||||
updateHeaderAccountInfo(activity, account, headerLayout);
|
||||
//Locked account can see follow request
|
||||
|
|
|
@ -259,7 +259,10 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
}else {
|
||||
changeDrawableColor(getApplicationContext(), R.drawable.ic_lock_outline,R.color.mastodonC4);
|
||||
}
|
||||
new RetrieveRelationshipAsyncTask(getApplicationContext(), accountId, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
String accountIdRelation = accountId;
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE)
|
||||
accountIdRelation = account.getUuid()+"@" + account.getHost();
|
||||
new RetrieveRelationshipAsyncTask(getApplicationContext(), accountIdRelation, ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
String urlHeader = account.getHeader();
|
||||
if (urlHeader != null && urlHeader.startsWith("/")) {
|
||||
|
|
|
@ -16,9 +16,14 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
|
||||
import fr.gouv.etalab.mastodon.client.PeertubeAPI;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRelationshipInterface;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +37,7 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private String accountId;
|
||||
private Relationship relationship;
|
||||
private OnRetrieveRelationshipInterface listener;
|
||||
private API api;
|
||||
private Error error;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public RetrieveRelationshipAsyncTask(Context context, String accountId, OnRetrieveRelationshipInterface onRetrieveRelationshipInterface){
|
||||
|
@ -43,14 +48,23 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
api = new API(this.contextReference.get());
|
||||
relationship = api.getRelationship(accountId);
|
||||
|
||||
if(MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
API api = new API(this.contextReference.get());
|
||||
relationship = api.getRelationship(accountId);
|
||||
error = api.getError();
|
||||
}else {
|
||||
PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
|
||||
relationship = new Relationship();
|
||||
relationship.setFollowing(api.isFollowing(accountId));
|
||||
error = api.getError();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveRelationship(relationship, api.getError());
|
||||
listener.onRetrieveRelationship(relationship, error);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3584,6 +3584,7 @@ public class API {
|
|||
Account account = new Account();
|
||||
try {
|
||||
account.setId(resobj.get("id").toString());
|
||||
account.setUuid(resobj.get("id").toString());
|
||||
account.setUsername(resobj.get("username").toString());
|
||||
account.setAcct(resobj.get("acct").toString());
|
||||
account.setDisplay_name(resobj.get("display_name").toString());
|
||||
|
|
|
@ -70,6 +70,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
|
|||
public class Account implements Parcelable {
|
||||
|
||||
private String id;
|
||||
private String uuid;
|
||||
private String username;
|
||||
private SpannableString displayNameSpan;
|
||||
private String acct;
|
||||
|
@ -279,6 +280,14 @@ public class Account implements Parcelable {
|
|||
this.social = social;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
|
||||
public enum followAction{
|
||||
FOLLOW,
|
||||
|
|
|
@ -283,22 +283,21 @@ public class PeertubeAPI {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a relationship between the authenticated account and an account
|
||||
* @param accountId String account fetched
|
||||
* @param uri String accounts fetched
|
||||
* @return Relationship entity
|
||||
*/
|
||||
public Relationship getRelationship(String accountId) {
|
||||
|
||||
List<Relationship> relationships;
|
||||
Relationship relationship = null;
|
||||
public boolean isFollowing(String uri) {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("id",accountId);
|
||||
|
||||
params.put("uris", uri);
|
||||
List<Relationship> relationships = new ArrayList<>();
|
||||
try {
|
||||
String response = new HttpsConnection(context).get(getAbsoluteUrl("/accounts/relationships"), 60, params, prefKeyOauthTokenT);
|
||||
relationships = parseRelationshipResponse(new JSONArray(response));
|
||||
if( relationships != null && relationships.size() > 0)
|
||||
relationship = relationships.get(0);
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/users/me/subscriptions/exist"), 60, params, prefKeyOauthTokenT);
|
||||
return new JSONObject(response).getBoolean(uri);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
@ -310,47 +309,7 @@ public class PeertubeAPI {
|
|||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return relationship;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a relationship between the authenticated account and an account
|
||||
* @param accounts ArrayList<Account> accounts fetched
|
||||
* @return Relationship entity
|
||||
*/
|
||||
public APIResponse getRelationship(List<Account> accounts) {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if( accounts != null && accounts.size() > 0 ) {
|
||||
StringBuilder parameters = new StringBuilder();
|
||||
for(Account account: accounts)
|
||||
parameters.append("id[]=").append(account.getId()).append("&");
|
||||
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(5));
|
||||
params.put("id[]", parameters.toString());
|
||||
List<Relationship> relationships = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/accounts/relationships"), 60, params, prefKeyOauthTokenT);
|
||||
relationships = parseRelationshipResponse(new JSONArray(response));
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setRelationships(relationships);
|
||||
}
|
||||
|
||||
return apiResponse;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1601,7 +1560,7 @@ public class PeertubeAPI {
|
|||
action = String.format("/statuses/%s/unreblog", targetedId);
|
||||
break;
|
||||
case FOLLOW:
|
||||
action = String.format("/accounts/%s/follow", targetedId);
|
||||
action = String.format("/users/me/subscriptions/%s", targetedId);
|
||||
break;
|
||||
case REMOTE_FOLLOW:
|
||||
action = "/follows";
|
||||
|
@ -1609,7 +1568,7 @@ public class PeertubeAPI {
|
|||
params.put("uri", targetedId);
|
||||
break;
|
||||
case UNFOLLOW:
|
||||
action = String.format("/accounts/%s/unfollow", targetedId);
|
||||
action = String.format("/users/me/subscriptions/%s", targetedId);
|
||||
break;
|
||||
case BLOCK:
|
||||
action = String.format("/accounts/%s/block", targetedId);
|
||||
|
@ -3505,6 +3464,7 @@ public class PeertubeAPI {
|
|||
Account account = new Account();
|
||||
try {
|
||||
account.setId(accountObject.get("id").toString());
|
||||
account.setUuid(accountObject.get("uuid").toString());
|
||||
account.setUsername(accountObject.get("name").toString());
|
||||
account.setAcct(accountObject.get("name").toString()+"@" + accountObject.get("host"));
|
||||
account.setDisplay_name(accountObject.get("name").toString());
|
||||
|
|
Loading…
Reference in New Issue