fix for all calls

This commit is contained in:
Thomas 2023-07-30 11:13:14 +02:00
parent ac290dec2b
commit bbb47626ce
23 changed files with 44 additions and 45 deletions

View File

@ -69,7 +69,7 @@ public class Nitter implements Serializable {
.proxy(Helper.getProxy(context))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED))
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null))
.addConverterFactory(SimpleXmlConverterFactory.create())
.client(okHttpClient)
.build();

View File

@ -259,14 +259,14 @@ public class CrossActionHelper {
}
private static MastodonSearchService init(Context context, @NonNull String instance) {
private static MastodonSearchService init(Context context, String instance) {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.proxy(Helper.getProxy(context))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v2/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v2/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
@ -493,9 +493,7 @@ public class CrossActionHelper {
* Fetch and federate the remote status
*/
public static void fetchAccountInRemoteInstance(@NonNull Context context, String acct, String instance, Callback callback) {
if (instance == null) {
return;
}
MastodonSearchService mastodonSearchService = init(context, instance);
new Thread(() -> {
Call<Results> resultsCall = mastodonSearchService.search(null, acct, null, "accounts", null, null, null, null, null, null, 1);

View File

@ -135,7 +135,7 @@ public class NotificationsHelper {
}
private static MastodonNotificationsService init(Context context, @NonNull String instance) {
private static MastodonNotificationsService init(Context context, String instance) {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
@ -143,7 +143,7 @@ public class NotificationsHelper {
.proxy(Helper.getProxy(context))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -131,14 +131,14 @@ public class PushNotifications {
slug + "/unifiedpush.connector", null);
}
private static MastodonNotificationsService init(@NonNull Context context, @NonNull String instance) {
private static MastodonNotificationsService init(@NonNull Context context, String instance) {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.proxy(Helper.getProxy(context.getApplicationContext()))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -97,9 +97,9 @@ public class ComposeWorker extends Worker {
.build();
}
private static MastodonStatusesService init(Context context, @NonNull String instance) {
private static MastodonStatusesService init(Context context, String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(getOkHttpClient(context))
.build();

View File

@ -252,7 +252,7 @@ public class FetchHomeWorker extends Worker {
private MastodonTimelinesService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -109,9 +109,9 @@ public class ScheduleBoostWorker extends Worker {
.build();
}
private MastodonStatusesService init(@NonNull String instance) {
private MastodonStatusesService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();

View File

@ -106,7 +106,7 @@ public class AccountsVM extends AndroidViewModel {
private MastodonAccountsService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
@ -115,7 +115,7 @@ public class AccountsVM extends AndroidViewModel {
private MastodonAccountsService initv2(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v2/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v2/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -63,18 +63,18 @@ public class AdminVM extends AndroidViewModel {
super(application);
}
private MastodonAdminService init(@NonNull String instance) {
private MastodonAdminService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonAdminService.class);
}
private MastodonAdminService initv2(@NonNull String instance) {
private MastodonAdminService initv2(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v2/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v2/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -51,9 +51,9 @@ public class AnnouncementsVM extends AndroidViewModel {
super(application);
}
private MastodonAnnouncementsService init(@NonNull String instance) {
private MastodonAnnouncementsService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -61,7 +61,7 @@ public class AppsVM extends AndroidViewModel {
private MastodonAppsService init(String instance) throws IllegalArgumentException {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -58,7 +58,7 @@ public class FiltersVM extends AndroidViewModel {
private MastodonFiltersService initV2(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v2/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v2/")
// .addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)

View File

@ -61,10 +61,10 @@ public class InstancesVM extends AndroidViewModel {
super(application);
}
private MastodonInstanceService init(@NonNull String instance) {
private MastodonInstanceService init(String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -53,7 +53,7 @@ public class NodeInfoVM extends AndroidViewModel {
private NodeInfoService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/")
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();

View File

@ -93,9 +93,9 @@ public class NotificationsVM extends AndroidViewModel {
}
}
private MastodonNotificationsService init(@NonNull String instance) {
private MastodonNotificationsService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -59,10 +59,10 @@ public class OauthVM extends AndroidViewModel {
super(application);
}
private MastodonAppsService init(@NonNull String instance) {
private MastodonAppsService init(String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -41,9 +41,9 @@ public class OembedVM extends AndroidViewModel {
super(application);
}
private MastodonOembedService init(@NonNull String instance) {
private MastodonOembedService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();

View File

@ -57,10 +57,10 @@ public class SearchVM extends AndroidViewModel {
super(application);
}
private MastodonSearchService init(@NonNull String instance) {
private MastodonSearchService init(String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v2/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v2/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -91,9 +91,9 @@ public class StatusesVM extends AndroidViewModel {
.build();
}
private MastodonStatusesService init(@NonNull String instance) {
private MastodonStatusesService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(getOkHttpClient())
.build();

View File

@ -64,7 +64,7 @@ public class TagVM extends AndroidViewModel {
private MastodonTagService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -158,7 +158,7 @@ public class TimelinesVM extends AndroidViewModel {
private MastodonTimelinesService initInstanceOnly(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED))
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
@ -167,7 +167,7 @@ public class TimelinesVM extends AndroidViewModel {
private MastodonTimelinesService initInstanceXMLOnly(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED))
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null))
.addConverterFactory(SimpleXmlConverterFactory.create())
.client(okHttpClient)
.build();
@ -176,7 +176,7 @@ public class TimelinesVM extends AndroidViewModel {
private MastodonTimelinesService init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -47,9 +47,9 @@ public class ActionsVM extends AndroidViewModel {
super(application);
}
private PleromaAPI init(@NonNull String instance) {
private PleromaAPI init(String instance) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) + "/api/v1/")
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null) + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();

View File

@ -44,6 +44,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.IDN;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
@ -253,7 +254,7 @@ public class RetrofitPeertubeAPI {
.proxy(app.fedilab.android.mastodon.helper.Helper.getProxy(_context.getApplicationContext()))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance)
.baseUrl("https://" + (instance != null ? IDN.toASCII(instance, IDN.ALLOW_UNASSIGNED) : null))
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();