diff options
Diffstat (limited to 'src/main')
3 files changed, 28 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java b/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java index 21711c647..ac790b10f 100644 --- a/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java +++ b/src/main/java/de/pixart/messenger/services/ChannelDiscoveryService.java @@ -5,12 +5,16 @@ import android.util.Log; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import de.pixart.messenger.Config; +import de.pixart.messenger.http.HttpConnectionManager; import de.pixart.messenger.http.services.MuclumbusService; +import okhttp3.OkHttpClient; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -21,19 +25,31 @@ public class ChannelDiscoveryService { private final XmppConnectionService service; - private final MuclumbusService muclumbusService; + private MuclumbusService muclumbusService; private final Cache<String, List<MuclumbusService.Room>> cache; public ChannelDiscoveryService(XmppConnectionService service) { this.service = service; + this.cache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); + } + + public void initializeMuclumbusService() { + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + if (service.useTorToConnect()) { + try { + builder.proxy(HttpConnectionManager.getProxy()); + } catch (IOException e) { + throw new RuntimeException("Unable to use Tor proxy", e); + } + } Retrofit retrofit = new Retrofit.Builder() + .client(builder.build()) .baseUrl(Config.CHANNEL_DISCOVERY) .addConverterFactory(GsonConverterFactory.create()) .callbackExecutor(Executors.newSingleThreadExecutor()) .build(); this.muclumbusService = retrofit.create(MuclumbusService.class); - this.cache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); } public void discover(String query, OnChannelSearchResultsFound onChannelSearchResultsFound) { @@ -67,7 +83,8 @@ public class ChannelDiscoveryService { @Override public void onFailure(Call<MuclumbusService.Rooms> call, Throwable throwable) { - + Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable); + listener.onChannelSearchResultsFound(Collections.emptyList()); } }); } catch (Exception e) { @@ -92,7 +109,8 @@ public class ChannelDiscoveryService { @Override public void onFailure(Call<MuclumbusService.SearchResult> call, Throwable throwable) { - throwable.printStackTrace(); + Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable); + listener.onChannelSearchResultsFound(Collections.emptyList()); } }); } diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 1456d5a8e..5917cc725 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -839,6 +839,10 @@ public class XmppConnectionService extends Service { editor.commit(); } + public void reinitializeMuclumbusService() { + mChannelDiscoveryService.initializeMuclumbusService(); + } + public void discoverChannels(String query, ChannelDiscoveryService.OnChannelSearchResultsFound onChannelSearchResultsFound) { mChannelDiscoveryService.discover(query, onChannelSearchResultsFound); } @@ -1153,6 +1157,7 @@ public class XmppConnectionService extends Service { if (Compatibility.runsTwentySix()) { mNotificationService.initializeChannels(); } + mChannelDiscoveryService.initializeMuclumbusService(); mForceDuringOnCreate.set(Compatibility.runsAndTargetsTwentySix(this)); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 9e321e079..e7beac1c6 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -469,6 +469,7 @@ public class SettingsActivity extends XmppActivity implements reconnectAccounts(); } else if (name.equals("use_tor")) { reconnectAccounts(); + xmppConnectionService.reinitializeMuclumbusService(); } else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) { xmppConnectionService.expireOldMessages(true); } else if (name.equals(THEME)) { |