Set up public chat as needed

This commit is contained in:
Niels Andriesse 2019-08-05 12:08:23 +10:00
parent 56f8fd2c20
commit 787b74ad1f
3 changed files with 30 additions and 9 deletions

View File

@ -37,6 +37,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule; import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule; import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule;
import org.thoughtcrime.securesms.groups.GroupManager;
import org.thoughtcrime.securesms.jobmanager.DependencyInjector; import org.thoughtcrime.securesms.jobmanager.DependencyInjector;
import org.thoughtcrime.securesms.jobmanager.JobManager; import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer; import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer;
@ -396,11 +397,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
// TODO: Implement // TODO: Implement
} }
public void startLongPollingIfNeeded() {
setUpLongPollingIfNeeded();
if (lokiLongPoller != null) { lokiLongPoller.startIfNeeded(); }
}
private void setUpLongPollingIfNeeded() { private void setUpLongPollingIfNeeded() {
if (lokiLongPoller != null) return; if (lokiLongPoller != null) return;
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this); 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 // endregion
} }

View File

@ -81,6 +81,9 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
protected void onPreCreate() { protected void onPreCreate() {
dynamicTheme.onCreate(this); dynamicTheme.onCreate(this);
dynamicLanguage.onCreate(this); dynamicLanguage.onCreate(this);
if (TextSecurePreferences.getLocalNumber(this) != null) {
ApplicationContext.getInstance(this).setUpPublicChatIfNeeded();
}
} }
@Override @Override

View File

@ -12,12 +12,10 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat; 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 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.lock.RegistrationLockReminders;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference; import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference;
import org.whispersystems.libsignal.util.Medium; import org.whispersystems.libsignal.util.Medium;
@ -28,6 +26,8 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import network.loki.messenger.R;
public class TextSecurePreferences { public class TextSecurePreferences {
private static final String TAG = TextSecurePreferences.class.getSimpleName(); private static final String TAG = TextSecurePreferences.class.getSimpleName();
@ -1127,6 +1127,7 @@ public class TextSecurePreferences {
} }
} }
// region Loki
public static long getBackgroundPollTime(Context context) { public static long getBackgroundPollTime(Context context) {
return getLongPreference(context, "background_poll_time", 0L); return getLongPreference(context, "background_poll_time", 0L);
} }
@ -1134,4 +1135,13 @@ public class TextSecurePreferences {
public static void setBackgroundPollTime(Context context, long backgroundPollTime) { public static void setBackgroundPollTime(Context context, long backgroundPollTime) {
setLongPreference(context, "background_poll_time", 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
} }