UI improvements.

This commit is contained in:
Mikunj 2019-10-11 12:37:45 +11:00
parent b676c25930
commit 4657b79179
5 changed files with 28 additions and 8 deletions

View File

@ -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);

View File

@ -52,9 +52,17 @@ public class Address implements Parcelable, Comparable<Address> {
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<Address> {
return Address.fromSerialized(external);
}
public static @NonNull Address fromPublicChatGroupID(@NonNull String serialized) {
return new Address(serialized, true);
}
public static @NonNull List<Address> fromSerializedList(@NonNull String serialized, char delimiter) {
String[] escapedAddresses = DelimiterUtil.split(serialized, delimiter);
List<Address> addresses = new LinkedList<>();
@ -131,7 +143,7 @@ public class Address implements Parcelable, Comparable<Address> {
}
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");

View File

@ -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;

View File

@ -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)

View File

@ -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
}