diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index f028b65c09..2c750649fd 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -37,6 +37,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule; +import org.thoughtcrime.securesms.groups.GroupManager; import org.thoughtcrime.securesms.jobmanager.DependencyInjector; import org.thoughtcrime.securesms.jobmanager.JobManager; import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer; @@ -396,11 +397,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc // TODO: Implement } - public void startLongPollingIfNeeded() { - setUpLongPollingIfNeeded(); - if (lokiLongPoller != null) { lokiLongPoller.startIfNeeded(); } - } - private void setUpLongPollingIfNeeded() { if (lokiLongPoller != null) return; String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this); @@ -418,5 +414,17 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } }); } + + public void startLongPollingIfNeeded() { + setUpLongPollingIfNeeded(); + if (lokiLongPoller != null) { lokiLongPoller.startIfNeeded(); } + } + + public void setUpPublicChatIfNeeded() { + boolean isPublicChatSetUp = TextSecurePreferences.isPublicChatSetUp(this); + if (isPublicChatSetUp) return; + GroupManager.createGroup(this, new HashSet<>(), null, "Loki Public Chat", false); + TextSecurePreferences.markPublicChatSetUp(this); + } // endregion } diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java index 4f3d64d465..4426c200d5 100644 --- a/src/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java @@ -81,6 +81,9 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit protected void onPreCreate() { dynamicTheme.onCreate(this); dynamicLanguage.onCreate(this); + if (TextSecurePreferences.getLocalNumber(this) != null) { + ApplicationContext.getInstance(this).setUpPublicChatIfNeeded(); + } } @Override diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java index 416d88dc45..b8bbc48e2c 100644 --- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java +++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java @@ -12,12 +12,10 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; -import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraintObserver; -import org.thoughtcrime.securesms.logging.Log; - import org.greenrobot.eventbus.EventBus; -import network.loki.messenger.R; +import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraintObserver; import org.thoughtcrime.securesms.lock.RegistrationLockReminders; +import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference; import org.whispersystems.libsignal.util.Medium; @@ -28,6 +26,8 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import network.loki.messenger.R; + public class TextSecurePreferences { private static final String TAG = TextSecurePreferences.class.getSimpleName(); @@ -1127,6 +1127,7 @@ public class TextSecurePreferences { } } + // region Loki public static long getBackgroundPollTime(Context context) { return getLongPreference(context, "background_poll_time", 0L); } @@ -1134,4 +1135,13 @@ public class TextSecurePreferences { public static void setBackgroundPollTime(Context context, long backgroundPollTime) { setLongPreference(context, "background_poll_time", backgroundPollTime); } + + public static boolean isPublicChatSetUp(Context context) { + return getBooleanPreference(context, "is_public_chat_set_up", false); + } + + public static void markPublicChatSetUp(Context context) { + setBooleanPreference(context, "is_public_chat_set_up", true); + } + // endregion }