Fix #332
This commit is contained in:
parent
bbd6aa8a1d
commit
c22ae0e49d
|
@ -260,18 +260,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
|
|
||||||
|
|
||||||
//Update the static variable which manages account type
|
//Update the static variable which manages account type
|
||||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON"))
|
Helper.setSoftware(account.getSocial(), true);
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
|
|
||||||
else if (account.getSocial().equals("PEERTUBE"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE;
|
|
||||||
else if (account.getSocial().equals("PIXELFED"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED;
|
|
||||||
else if (account.getSocial().equals("PLEROMA"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA;
|
|
||||||
else if (account.getSocial().equals("GNU"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
|
||||||
else if (account.getSocial().equals("FRIENDICA"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA;
|
|
||||||
countNewStatus = 0;
|
countNewStatus = 0;
|
||||||
countNewNotifications = 0;
|
countNewNotifications = 0;
|
||||||
|
|
||||||
|
|
|
@ -128,19 +128,7 @@ public class LoginActivity extends BaseActivity {
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
autofilledInstance = b.getString("instance", null);
|
autofilledInstance = b.getString("instance", null);
|
||||||
social = b.getString("social", null);
|
social = b.getString("social", null);
|
||||||
if (social != null) {
|
socialNetwork = Helper.setSoftware(instanceNodeInfo.getName(), false);
|
||||||
switch (social) {
|
|
||||||
case "MASTODON":
|
|
||||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
|
|
||||||
break;
|
|
||||||
case "PEERTUBE":
|
|
||||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE;
|
|
||||||
break;
|
|
||||||
case "GNU":
|
|
||||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
admin = b.getBoolean("admin", false);
|
admin = b.getBoolean("admin", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,27 +269,15 @@ public class LoginActivity extends BaseActivity {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
instanceNodeInfo = new API(LoginActivity.this).getNodeInfo(instance);
|
instanceNodeInfo = new API(LoginActivity.this).displayNodeInfo(instance);
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
connect_button.setEnabled(true);
|
connect_button.setEnabled(true);
|
||||||
if (instanceNodeInfo != null && instanceNodeInfo.getName() != null) {
|
if (instanceNodeInfo != null && instanceNodeInfo.getName() != null) {
|
||||||
switch (instanceNodeInfo.getName()) {
|
socialNetwork = Helper.setSoftware(instanceNodeInfo.getName(), false);
|
||||||
case "MASTODON":
|
|
||||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
|
if (instanceNodeInfo.getName().equals("PLEROMA") ||instanceNodeInfo.getName().equals("MASTODON") || instanceNodeInfo.getName().equals("PIXELFED")) {
|
||||||
break;
|
|
||||||
case "PIXELFED":
|
|
||||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED;
|
|
||||||
break;
|
|
||||||
case "PEERTUBE":
|
|
||||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE;
|
|
||||||
break;
|
|
||||||
case "GNU":
|
|
||||||
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (instanceNodeInfo.getName().equals("MASTODON") || instanceNodeInfo.getName().equals("PIXELFED")) {
|
|
||||||
client_id_for_webview = true;
|
client_id_for_webview = true;
|
||||||
retrievesClientId();
|
retrievesClientId();
|
||||||
} else {
|
} else {
|
||||||
|
@ -310,7 +286,7 @@ public class LoginActivity extends BaseActivity {
|
||||||
step_instance.setVisibility(View.GONE);
|
step_instance.setVisibility(View.GONE);
|
||||||
instance_chosen.setText(instance);
|
instance_chosen.setText(instance);
|
||||||
retrievesClientId();
|
retrievesClientId();
|
||||||
} else if (instanceNodeInfo.getName().equals("GNU")) {
|
} else if (instanceNodeInfo.getName().equals("GNU") || instanceNodeInfo.getName().equals("FRIENDICA")) {
|
||||||
step_login_credential.setVisibility(View.VISIBLE);
|
step_login_credential.setVisibility(View.VISIBLE);
|
||||||
step_instance.setVisibility(View.GONE);
|
step_instance.setVisibility(View.GONE);
|
||||||
instance_chosen.setText(instance);
|
instance_chosen.setText(instance);
|
||||||
|
@ -397,8 +373,6 @@ public class LoginActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
|
||||||
isLoadingInstance = false;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
isLoadingInstance = false;
|
isLoadingInstance = false;
|
||||||
}
|
}
|
||||||
|
@ -788,14 +762,12 @@ public class LoginActivity extends BaseActivity {
|
||||||
editor.apply();
|
editor.apply();
|
||||||
return false;
|
return false;
|
||||||
} else if (id == R.id.action_import_data) {
|
} else if (id == R.id.action_import_data) {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
if (ContextCompat.checkSelfPermission(LoginActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
|
||||||
if (ContextCompat.checkSelfPermission(LoginActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
|
PackageManager.PERMISSION_GRANTED) {
|
||||||
PackageManager.PERMISSION_GRANTED) {
|
ActivityCompat.requestPermissions(LoginActivity.this,
|
||||||
ActivityCompat.requestPermissions(LoginActivity.this,
|
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
TootActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
||||||
TootActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
|
|
@ -620,18 +620,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
||||||
|
|
||||||
if (social == null || accountReply != null) {
|
if (social == null || accountReply != null) {
|
||||||
//Update the static variable which manages account type
|
//Update the static variable which manages account type
|
||||||
if (account.getSocial() == null || account.getSocial().equals("MASTODON"))
|
social = Helper.setSoftware(account.getSocial(), false);
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
|
|
||||||
else if (account.getSocial().equals("PEERTUBE"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE;
|
|
||||||
else if (account.getSocial().equals("PIXELFED"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED;
|
|
||||||
else if (account.getSocial().equals("PLEROMA"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA;
|
|
||||||
else if (account.getSocial().equals("GNU"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
|
||||||
else if (account.getSocial().equals("FRIENDICA"))
|
|
||||||
social = UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA;
|
|
||||||
}
|
}
|
||||||
switch (social) {
|
switch (social) {
|
||||||
case GNU:
|
case GNU:
|
||||||
|
|
|
@ -88,11 +88,12 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
domain = split[2];
|
domain = split[2];
|
||||||
}
|
}
|
||||||
if (domain != null && username != null) {
|
if (domain != null && username != null) {
|
||||||
InstanceNodeInfo node = api.getNodeInfo(domain);
|
InstanceNodeInfo node = api.displayNodeInfo(domain);
|
||||||
String url = null;
|
String url = null;
|
||||||
if (node != null && node.getName() != null) {
|
if (node != null && node.getName() != null) {
|
||||||
switch (node.getName().trim()) {
|
switch (node.getName().trim()) {
|
||||||
case "MASTODON":
|
case "MASTODON":
|
||||||
|
case "PLEROMA":
|
||||||
url = "https://" + domain + "/@" + username;
|
url = "https://" + domain + "/@" + username;
|
||||||
break;
|
break;
|
||||||
case "PEERTUBE":
|
case "PEERTUBE":
|
||||||
|
@ -102,6 +103,7 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
url = "https://" + domain + "/" + username;
|
url = "https://" + domain + "/" + username;
|
||||||
break;
|
break;
|
||||||
case "GNU":
|
case "GNU":
|
||||||
|
case "FRIENDICA":
|
||||||
url = "https://" + domain + "/profile/" + username;
|
url = "https://" + domain + "/profile/" + username;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -578,121 +578,6 @@ public class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public InstanceNodeInfo getNodeInfo(String domain) {
|
|
||||||
|
|
||||||
//Try to guess URL scheme for the onion instance
|
|
||||||
String scheme = "https";
|
|
||||||
if (domain.endsWith(".onion")) {
|
|
||||||
try {
|
|
||||||
new HttpsConnection(context, domain).get("http://" + domain, 30, null, null);
|
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
editor.putString(Helper.SET_ONION_SCHEME + domain, "http");
|
|
||||||
scheme = "http";
|
|
||||||
editor.apply();
|
|
||||||
} catch (IOException | NoSuchAlgorithmException | KeyManagementException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
editor.putString(Helper.SET_ONION_SCHEME + domain, "https");
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String response;
|
|
||||||
InstanceNodeInfo instanceNodeInfo = new InstanceNodeInfo();
|
|
||||||
try {
|
|
||||||
response = new HttpsConnection(context, domain).get(scheme + "://" + domain + "/.well-known/nodeinfo", 30, null, null);
|
|
||||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("links");
|
|
||||||
ArrayList<NodeInfo> nodeInfos = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
int i = 0;
|
|
||||||
while (i < jsonArray.length()) {
|
|
||||||
|
|
||||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
|
||||||
NodeInfo nodeInfo = new NodeInfo();
|
|
||||||
nodeInfo.setHref(resobj.getString("href"));
|
|
||||||
nodeInfo.setRel(resobj.getString("rel"));
|
|
||||||
i++;
|
|
||||||
nodeInfos.add(nodeInfo);
|
|
||||||
}
|
|
||||||
if (nodeInfos.size() > 0) {
|
|
||||||
NodeInfo nodeInfo = nodeInfos.get(nodeInfos.size() - 1);
|
|
||||||
response = new HttpsConnection(context, this.instance).get(nodeInfo.getHref(), 30, null, null);
|
|
||||||
JSONObject resobj = new JSONObject(response);
|
|
||||||
JSONObject jsonObject = resobj.getJSONObject("software");
|
|
||||||
String name = null;
|
|
||||||
if (resobj.has("metadata") && resobj.getJSONObject("metadata").has("features")) {
|
|
||||||
JSONArray features = resobj.getJSONObject("metadata").getJSONArray("features");
|
|
||||||
if (!resobj.getJSONObject("metadata").isNull("features") && features.length() > 0) {
|
|
||||||
for (int counter = 0; counter < features.length(); counter++) {
|
|
||||||
if (features.getString(counter).toUpperCase().equals("MASTODON_API")) {
|
|
||||||
name = "MASTODON";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (name == null) {
|
|
||||||
if ( !jsonObject.isNull("name") ) {
|
|
||||||
name = jsonObject.getString("name").toUpperCase();
|
|
||||||
switch (name) {
|
|
||||||
case "PLEROMA":
|
|
||||||
name = "MASTODON";
|
|
||||||
break;
|
|
||||||
case "GNUSOCIAL":
|
|
||||||
case "HUBZILLA":
|
|
||||||
case "REDMATRIX":
|
|
||||||
case "FRIENDICA":
|
|
||||||
name = "GNU";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instanceNodeInfo.setName(name);
|
|
||||||
instanceNodeInfo.setVersion(jsonObject.getString("version"));
|
|
||||||
if( resobj.has("openRegistrations")) {
|
|
||||||
instanceNodeInfo.setOpenRegistrations(resobj.getBoolean("openRegistrations"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
setDefaultError(e);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
instanceNodeInfo.setConnectionError(true);
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchAlgorithmException | KeyManagementException | JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
|
||||||
try {
|
|
||||||
response = new HttpsConnection(context, this.instance).get(scheme + "://" + domain + "/api/v1/instance", 30, null, null);
|
|
||||||
JSONObject jsonObject = new JSONObject(response);
|
|
||||||
instanceNodeInfo.setName("MASTODON");
|
|
||||||
instanceNodeInfo.setVersion(jsonObject.getString("version"));
|
|
||||||
instanceNodeInfo.setOpenRegistrations(true);
|
|
||||||
} catch (IOException e1) {
|
|
||||||
instanceNodeInfo.setConnectionError(true);
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (NoSuchAlgorithmException | KeyManagementException | JSONException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
|
||||||
if( e1.getStatusCode() == 404) {
|
|
||||||
instanceNodeInfo.setName("GNU");
|
|
||||||
instanceNodeInfo.setVersion("unknown");
|
|
||||||
instanceNodeInfo.setOpenRegistrations(true);
|
|
||||||
e1.printStackTrace();
|
|
||||||
}else{
|
|
||||||
instanceNodeInfo.setName("MASTODON");
|
|
||||||
instanceNodeInfo.setVersion("3.0");
|
|
||||||
instanceNodeInfo.setOpenRegistrations(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return instanceNodeInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public InstanceNodeInfo displayNodeInfo(String domain) {
|
public InstanceNodeInfo displayNodeInfo(String domain) {
|
||||||
|
|
||||||
String response;
|
String response;
|
||||||
|
@ -888,6 +773,11 @@ public class API {
|
||||||
*/
|
*/
|
||||||
public Account verifyCredentials() {
|
public Account verifyCredentials() {
|
||||||
account = new Account();
|
account = new Account();
|
||||||
|
InstanceNodeInfo nodeinfo = displayNodeInfo(instance);
|
||||||
|
String social = null;
|
||||||
|
if( nodeinfo != null){
|
||||||
|
social = nodeinfo.getName();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
setError(500, new Throwable("An error occured!"));
|
setError(500, new Throwable("An error occured!"));
|
||||||
|
@ -895,9 +785,8 @@ public class API {
|
||||||
}
|
}
|
||||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, prefKeyOauthTokenT);
|
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, prefKeyOauthTokenT);
|
||||||
account = parseAccountResponse(context, new JSONObject(response));
|
account = parseAccountResponse(context, new JSONObject(response));
|
||||||
InstanceNodeInfo nodeinfo = displayNodeInfo(instance);
|
if( social != null ) {
|
||||||
if( nodeinfo != null && nodeinfo.getName() != null) {
|
account.setSocial(social.toUpperCase());
|
||||||
account.setSocial(nodeinfo.getName().toUpperCase());
|
|
||||||
}
|
}
|
||||||
if (account != null && account.getSocial() != null && account.getSocial().equals("PLEROMA")) {
|
if (account != null && account.getSocial() != null && account.getSocial().equals("PLEROMA")) {
|
||||||
isPleromaAdmin(account.getAcct());
|
isPleromaAdmin(account.getAcct());
|
||||||
|
@ -928,6 +817,9 @@ public class API {
|
||||||
try {
|
try {
|
||||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, targetedAccount.getToken());
|
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, targetedAccount.getToken());
|
||||||
account = parseAccountResponse(context, new JSONObject(response));
|
account = parseAccountResponse(context, new JSONObject(response));
|
||||||
|
if( social != null ) {
|
||||||
|
account.setSocial(social.toUpperCase());
|
||||||
|
}
|
||||||
if (account.getSocial().equals("PLEROMA")) {
|
if (account.getSocial().equals("PLEROMA")) {
|
||||||
isPleromaAdmin(account.getAcct());
|
isPleromaAdmin(account.getAcct());
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import app.fedilab.android.client.Entities.Application;
|
||||||
import app.fedilab.android.client.Entities.Attachment;
|
import app.fedilab.android.client.Entities.Attachment;
|
||||||
import app.fedilab.android.client.Entities.Conversation;
|
import app.fedilab.android.client.Entities.Conversation;
|
||||||
import app.fedilab.android.client.Entities.Error;
|
import app.fedilab.android.client.Entities.Error;
|
||||||
|
import app.fedilab.android.client.Entities.InstanceNodeInfo;
|
||||||
import app.fedilab.android.client.Entities.Mention;
|
import app.fedilab.android.client.Entities.Mention;
|
||||||
import app.fedilab.android.client.Entities.Notification;
|
import app.fedilab.android.client.Entities.Notification;
|
||||||
import app.fedilab.android.client.Entities.Relationship;
|
import app.fedilab.android.client.Entities.Relationship;
|
||||||
|
@ -181,19 +182,21 @@ public class GNUAPI {
|
||||||
*/
|
*/
|
||||||
public Account verifyCredentials() {
|
public Account verifyCredentials() {
|
||||||
account = new Account();
|
account = new Account();
|
||||||
|
InstanceNodeInfo nodeinfo = new API(context).displayNodeInfo(instance);
|
||||||
|
String social = null;
|
||||||
|
if( nodeinfo != null){
|
||||||
|
social = nodeinfo.getName();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/account/verify_credentials.json"), 60, null, prefKeyOauthTokenT);
|
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/account/verify_credentials.json"), 60, null, prefKeyOauthTokenT);
|
||||||
account = parseAccountResponse(context, new JSONObject(response));
|
account = parseAccountResponse(context, new JSONObject(response));
|
||||||
|
if( social != null ) {
|
||||||
|
account.setSocial(social.toUpperCase());
|
||||||
|
}
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
setError(e.getStatusCode(), e);
|
setError(e.getStatusCode(), e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (KeyManagementException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return account;
|
return account;
|
||||||
|
|
|
@ -46,6 +46,7 @@ import app.fedilab.android.client.Entities.Error;
|
||||||
import app.fedilab.android.client.Entities.Filters;
|
import app.fedilab.android.client.Entities.Filters;
|
||||||
import app.fedilab.android.client.Entities.HowToVideo;
|
import app.fedilab.android.client.Entities.HowToVideo;
|
||||||
import app.fedilab.android.client.Entities.Instance;
|
import app.fedilab.android.client.Entities.Instance;
|
||||||
|
import app.fedilab.android.client.Entities.InstanceNodeInfo;
|
||||||
import app.fedilab.android.client.Entities.Peertube;
|
import app.fedilab.android.client.Entities.Peertube;
|
||||||
import app.fedilab.android.client.Entities.PeertubeAccountNotification;
|
import app.fedilab.android.client.Entities.PeertubeAccountNotification;
|
||||||
import app.fedilab.android.client.Entities.PeertubeActorFollow;
|
import app.fedilab.android.client.Entities.PeertubeActorFollow;
|
||||||
|
@ -326,17 +327,19 @@ public class PeertubeAPI {
|
||||||
*/
|
*/
|
||||||
public Account verifyCredentials() {
|
public Account verifyCredentials() {
|
||||||
account = new Account();
|
account = new Account();
|
||||||
|
InstanceNodeInfo nodeinfo = new API(context).displayNodeInfo(instance);
|
||||||
|
String social = null;
|
||||||
|
if( nodeinfo != null){
|
||||||
|
social = nodeinfo.getName();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, prefKeyOauthTokenT);
|
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, prefKeyOauthTokenT);
|
||||||
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
||||||
account = parseAccountResponsePeertube(context, accountObject);
|
account = parseAccountResponsePeertube(context, accountObject);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
if( social != null ) {
|
||||||
e.printStackTrace();
|
account.setSocial(social.toUpperCase());
|
||||||
} catch (IOException e) {
|
}
|
||||||
e.printStackTrace();
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
} catch (KeyManagementException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
if (e.getStatusCode() == 401 || e.getStatusCode() == 403) {
|
if (e.getStatusCode() == 401 || e.getStatusCode() == 403) {
|
||||||
|
@ -363,13 +366,10 @@ public class PeertubeAPI {
|
||||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, targetedAccount.getToken());
|
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/me"), 60, null, targetedAccount.getToken());
|
||||||
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
JSONObject accountObject = new JSONObject(response).getJSONObject("account");
|
||||||
account = parseAccountResponsePeertube(context, accountObject);
|
account = parseAccountResponsePeertube(context, accountObject);
|
||||||
} catch (IOException e1) {
|
if( social != null ) {
|
||||||
e1.printStackTrace();
|
account.setSocial(social.toUpperCase());
|
||||||
} catch (NoSuchAlgorithmException e1) {
|
}
|
||||||
e1.printStackTrace();
|
} catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException e1) {
|
||||||
} catch (KeyManagementException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (JSONException e1) {
|
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
} catch (HttpsConnection.HttpsConnectionException e1) {
|
} catch (HttpsConnection.HttpsConnectionException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
|
|
@ -5000,4 +5000,36 @@ public class Helper {
|
||||||
return (lastRefresh == null || lastRefresh.before(dateAllowed));
|
return (lastRefresh == null || lastRefresh.before(dateAllowed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UpdateAccountInfoAsyncTask.SOCIAL setSoftware(String social, boolean updateSocial){
|
||||||
|
//Update the static variable which manages account type
|
||||||
|
if( updateSocial) {
|
||||||
|
if (social == null || social.equals("MASTODON"))
|
||||||
|
MainActivity.social = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
|
||||||
|
else if (social.equals("PEERTUBE"))
|
||||||
|
MainActivity.social = UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE;
|
||||||
|
else if (social.equals("PIXELFED"))
|
||||||
|
MainActivity.social = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED;
|
||||||
|
else if (social.equals("PLEROMA"))
|
||||||
|
MainActivity.social = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA;
|
||||||
|
else if (social.equals("GNU"))
|
||||||
|
MainActivity.social = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
||||||
|
else if (social.equals("FRIENDICA"))
|
||||||
|
MainActivity.social = UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA;
|
||||||
|
}
|
||||||
|
UpdateAccountInfoAsyncTask.SOCIAL socialNetwork = null;
|
||||||
|
if (social == null || social.equals("MASTODON"))
|
||||||
|
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.MASTODON;
|
||||||
|
else if (social.equals("PEERTUBE"))
|
||||||
|
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE;
|
||||||
|
else if (social.equals("PIXELFED"))
|
||||||
|
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED;
|
||||||
|
else if (social.equals("PLEROMA"))
|
||||||
|
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA;
|
||||||
|
else if (social.equals("GNU"))
|
||||||
|
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.GNU;
|
||||||
|
else if (social.equals("FRIENDICA"))
|
||||||
|
socialNetwork = UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA;
|
||||||
|
return socialNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue