diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 17fd512b39..b55ee706df 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -254,7 +254,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } public @Nullable LokiGroupChatAPI getLokiGroupChatAPI() { - if (lokiGroupChatAPI == null && TextSecurePreferences.isPushRegistered(this)) { + if (lokiGroupChatAPI == null && IdentityKeyUtil.hasIdentityKey(this)) { String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this); byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize(); LokiAPIDatabase apiDatabase = DatabaseFactory.getLokiAPIDatabase(this); diff --git a/src/org/thoughtcrime/securesms/database/Address.java b/src/org/thoughtcrime/securesms/database/Address.java index f70033991c..40d8a2ebd5 100644 --- a/src/org/thoughtcrime/securesms/database/Address.java +++ b/src/org/thoughtcrime/securesms/database/Address.java @@ -52,9 +52,17 @@ public class Address implements Parcelable, Comparable
{ private final String address; + // Loki - Special flag to indicate whether this address is meant to representing a public chat or not + private Boolean isPublicChat; + private Address(@NonNull String address) { + this(address, false); + } + + private Address(@NonNull String address, Boolean isPublicChat) { if (address == null) throw new AssertionError(address); this.address = address; + this.isPublicChat = isPublicChat; } public Address(Parcel in) { @@ -69,6 +77,10 @@ public class Address implements Parcelable, Comparable
{ return Address.fromSerialized(external); } + public static @NonNull Address fromPublicChatGroupID(@NonNull String serialized) { + return new Address(serialized, true); + } + public static @NonNull List
fromSerializedList(@NonNull String serialized, char delimiter) { String[] escapedAddresses = DelimiterUtil.split(serialized, delimiter); List
addresses = new LinkedList<>(); @@ -131,7 +143,7 @@ public class Address implements Parcelable, Comparable
{ } public @NonNull String toPhoneString() { - if (!isPhone()) { + if (!isPhone() && !isPublicChat) { if (isEmail()) throw new AssertionError("Not e164, is email"); if (isGroup()) throw new AssertionError("Not e164, is group"); throw new AssertionError("Not e164, unknown"); diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 8793474558..6885505cd8 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -292,7 +292,9 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { long threadID = GroupManager.getThreadIdFromGroupId(groupId, context); LokiGroupChat chat = DatabaseFactory.getLokiThreadDatabase(context).getGroupChat(threadID); if (chat != null) { - result.add(Address.fromSerialized(chat.getServer())); + // We need to somehow maintain information that will allow the sender to map + // a Recipient to the correct public chat thread, and so this might be a bit hacky + result.add(Address.fromPublicChatGroupID(groupId)); } return result; diff --git a/src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt b/src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt index 174396f2e0..26f57edf38 100644 --- a/src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/AddPublicChatActivity.kt @@ -58,8 +58,8 @@ class AddPublicChatActivity : PassphraseRequiredActionBarActivity() { val inputMethodManager = getSystemService(BaseActionBarActivity.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow(serverUrlEditText.windowToken, 0) - val url = serverUrlEditText.text.toString().toLowerCase() - if (!Patterns.WEB_URL.matcher(url).matches()) { return Toast.makeText(this, R.string.fragment_add_public_chat_invalid_url_message, Toast.LENGTH_SHORT).show() } + val url = serverUrlEditText.text.toString().toLowerCase().replace("http://", "https://") + if (!Patterns.WEB_URL.matcher(url).matches() || !url.startsWith("https://")) { return Toast.makeText(this, R.string.fragment_add_public_chat_invalid_url_message, Toast.LENGTH_SHORT).show() } setButtonEnabled(false) diff --git a/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt b/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt index 6ee7c68480..13e70b6a33 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt @@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.loki import android.content.Context import android.database.ContentObserver +import android.text.TextUtils import nl.komponents.kovenant.Promise import nl.komponents.kovenant.functional.bind import nl.komponents.kovenant.functional.map @@ -10,7 +11,9 @@ import org.thoughtcrime.securesms.crypto.IdentityKeyUtil import org.thoughtcrime.securesms.database.DatabaseContentProviders import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.groups.GroupManager +import org.thoughtcrime.securesms.util.GroupUtil import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.thoughtcrime.securesms.util.Util import org.whispersystems.signalservice.loki.api.LokiGroupChat import org.whispersystems.signalservice.loki.api.LokiGroupChatAPI import java.util.HashSet @@ -56,10 +59,13 @@ class LokiPublicChatManager(private val context: Context) { threadID = result.threadId } DatabaseFactory.getLokiThreadDatabase(context).setGroupChat(chat, threadID) - startPollersIfNeeded() - // Set our name on the server - ApplicationContext.getInstance(context).lokiGroupChatAPI?.setDisplayName(server, TextSecurePreferences.getProfileName(context)) + val displayName = TextSecurePreferences.getProfileName(context) + if (!TextUtils.isEmpty(displayName)) { + ApplicationContext.getInstance(context).lokiGroupChatAPI?.setDisplayName(server, displayName) + } + // Start polling + Util.runOnMain{ startPollersIfNeeded() } return chat }