Add missing display name update & message fetch

pull/35/head
Niels Andriesse 5 years ago
parent 4a613df52d
commit cbad885586

@ -186,7 +186,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
mixpanel.trackMap(event, properties);
return Unit.INSTANCE;
};
// Loki - Set up public chat manager
lokiPublicChatManager = new LokiPublicChatManager(this);
}
@ -198,6 +198,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
KeyCachingService.onAppForegrounded(this);
// Loki - Start long polling if needed
startLongPollingIfNeeded();
lokiPublicChatManager.startPollersIfNeeded();
setUpStorageAPIIfNeeded();
}
@ -261,7 +262,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
LokiUserDatabase userDatabase = DatabaseFactory.getLokiUserDatabase(this);
lokiPublicChatAPI = new LokiPublicChatAPI(userHexEncodedPublicKey, userPrivateKey, apiDatabase, userDatabase);
}
return lokiPublicChatAPI;
}
@ -501,20 +501,20 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
return new LokiRSSFeed("loki.network.messenger-updates.feed", "https://loki.network/category/messenger-updates/feed", "Loki Messenger Updates", false);
}
public void createGroupChatsIfNeeded() {
List<LokiPublicChat> defaultChats = LokiPublicChatAPI.Companion.getDefaultChats(BuildConfig.DEBUG);
for (LokiPublicChat chat : defaultChats) {
long threadID = GroupManager.getThreadId(chat.getId(), this);
String migrationKey = chat.getId() + "_migrated";
public void createDefaultPublicChatsIfNeeded() {
List<LokiPublicChat> defaultPublicChats = LokiPublicChatAPI.Companion.getDefaultChats(BuildConfig.DEBUG);
for (LokiPublicChat publiChat : defaultPublicChats) {
long threadID = GroupManager.getThreadId(publiChat.getId(), this);
String migrationKey = publiChat.getId() + "_migrated";
boolean isChatMigrated = TextSecurePreferences.getBooleanPreference(this, migrationKey, false);
boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, chat.getId());
if (!isChatSetUp || !chat.isDeletable()) {
lokiPublicChatManager.addChat(chat.getServer(), chat.getChannel(), chat.getDisplayName());
TextSecurePreferences.markChatSetUp(this, chat.getId());
boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, publiChat.getId());
if (!isChatSetUp || !publiChat.isDeletable()) {
lokiPublicChatManager.addChat(publiChat.getServer(), publiChat.getChannel(), publiChat.getDisplayName());
TextSecurePreferences.markChatSetUp(this, publiChat.getId());
TextSecurePreferences.setBooleanPreference(this, migrationKey, true);
} else if (threadID > -1 && !isChatMigrated) {
// Migrate the old public chats.
DatabaseFactory.getLokiThreadDatabase(this).setPublicChat(chat, threadID);
// Migrate the old public chats
DatabaseFactory.getLokiThreadDatabase(this).setPublicChat(publiChat, threadID);
TextSecurePreferences.setBooleanPreference(this, migrationKey, true);
}
}
@ -572,10 +572,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadID), true, observer);
}
public void startGroupChatPollersIfNeeded() {
lokiPublicChatManager.startPollersIfNeeded();
}
public void startRSSFeedPollersIfNeeded() {
createRSSFeedPollersIfNeeded();
if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.startIfNeeded();

@ -187,7 +187,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY));
this.findPreference(PREFERENCE_CATEGORY_QR_CODE)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_QR_CODE));
Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE);
// Hide if this is a slave device
linkDevicePreference.setVisible(isMasterDevice);

@ -82,9 +82,9 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
dynamicLanguage.onCreate(this);
if (TextSecurePreferences.getLocalNumber(this) != null) {
ApplicationContext application = ApplicationContext.getInstance(this);
application.createGroupChatsIfNeeded();
application.createDefaultPublicChatsIfNeeded();
application.createRSSFeedsIfNeeded();
application.startGroupChatPollersIfNeeded();
application.getLokiPublicChatManager().startPollersIfNeeded();
application.startRSSFeedPollersIfNeeded();
}
}

@ -380,8 +380,8 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
TextSecurePreferences.setProfileName(context, name);
LokiPublicChatAPI publicChatAPI = ApplicationContext.getInstance(context).getLokiPublicChatAPI();
if (publicChatAPI != null) {
Set<String> groupChatServers = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChatServers();
for (String server : groupChatServers) {
Set<String> servers = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChatServers();
for (String server : servers) {
publicChatAPI.setDisplayName(name, server);
}
}

@ -28,6 +28,7 @@ import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.signalservice.loki.api.LokiPublicChat;
@ -194,14 +195,15 @@ public class QuoteView extends FrameLayout implements RecipientModifiedListener
String quoteeDisplayName = author.toShortString();
// If we're in a group then try and use the display name in the group
if (conversationRecipient.isGroupRecipient()) {
long threadId = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(conversationRecipient);
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
if (publicChat != null) {
String senderDisplayName = DatabaseFactory.getLokiUserDatabase(getContext()).getServerDisplayName(publicChat.getId(), author.getAddress().serialize());
if (senderDisplayName != null) { quoteeDisplayName = senderDisplayName; }
}
long threadID = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(conversationRecipient);
String senderHexEncodedPublicKey = author.getAddress().serialize();
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadID);
if (senderHexEncodedPublicKey.equalsIgnoreCase(TextSecurePreferences.getLocalNumber(getContext()))) {
quoteeDisplayName = TextSecurePreferences.getProfileName(getContext());
} else if (publicChat != null) {
quoteeDisplayName = DatabaseFactory.getLokiUserDatabase(getContext()).getServerDisplayName(publicChat.getId(), senderHexEncodedPublicKey);
} else {
quoteeDisplayName = DatabaseFactory.getLokiUserDatabase(getContext()).getDisplayName(senderHexEncodedPublicKey);
}
authorView.setText(isOwnNumber ? getContext().getString(R.string.QuoteView_you) : quoteeDisplayName);

@ -131,7 +131,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
db.execSQL(LokiMessageDatabase.getCreateTableCommand());
db.execSQL(LokiThreadDatabase.getCreateFriendRequestTableCommand());
db.execSQL(LokiThreadDatabase.getCreateSessionResetTableCommand());
db.execSQL(LokiThreadDatabase.getCreateGroupChatMappingTableCommand());
db.execSQL(LokiThreadDatabase.getCreatePublicChatTableCommand());
db.execSQL(LokiUserDatabase.getCreateDisplayNameTableCommand());
db.execSQL(LokiUserDatabase.getCreateServerDisplayNameTableCommand());
@ -498,7 +498,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
if (oldVersion < lokiV3) {
db.execSQL(LokiAPIDatabase.getCreatePairingAuthorisationTableCommand());
db.execSQL(LokiThreadDatabase.getCreateGroupChatMappingTableCommand());
db.execSQL(LokiThreadDatabase.getCreatePublicChatTableCommand());
}
db.setTransactionSuccessful();

@ -5,7 +5,7 @@ import android.util.Patterns
import android.view.MenuItem
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import kotlinx.android.synthetic.main.fragment_add_public_chat.*
import kotlinx.android.synthetic.main.activity_add_public_chat.*
import network.loki.messenger.R
import nl.komponents.kovenant.ui.failUi
import nl.komponents.kovenant.ui.successUi
@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.util.DynamicTheme
import org.thoughtcrime.securesms.util.TextSecurePreferences
class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
private val dynamicTheme = DynamicTheme()
@ -24,8 +25,8 @@ class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
override fun onCreate(bundle: Bundle?, isReady: Boolean) {
supportActionBar!!.setTitle(R.string.fragment_add_public_chat_title)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
setContentView(R.layout.fragment_add_public_chat)
setButtonEnabled(true)
setContentView(R.layout.activity_add_public_chat)
updateUI(false)
addButton.setOnClickListener { addPublicChatIfPossible() }
}
@ -45,24 +46,29 @@ class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
private fun addPublicChatIfPossible() {
val inputMethodManager = getSystemService(BaseActionBarActivity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(urlEditText.windowToken, 0)
val url = urlEditText.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)
ApplicationContext.getInstance(this).lokiPublicChatManager.addChat(url, 1).successUi {
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()
}
updateUI(true)
val application = ApplicationContext.getInstance(this)
val channel: Long = 1
val displayName = TextSecurePreferences.getProfileName(this)
val lokiPublicChatAPI = application.lokiPublicChatAPI!!
application.lokiPublicChatManager.addChat(url, channel).successUi {
lokiPublicChatAPI.getMessages(channel, url)
lokiPublicChatAPI.setDisplayName(displayName, url)
finish()
}.failUi {
setButtonEnabled(true)
updateUI(false)
Toast.makeText(this, R.string.fragment_add_public_chat_connection_failed_message, Toast.LENGTH_SHORT).show()
}
}
private fun setButtonEnabled(enabled: Boolean) {
addButton.isEnabled = enabled
val text = if (enabled) R.string.fragment_add_public_chat_add_button_title_1 else R.string.fragment_add_public_chat_add_button_title_2
private fun updateUI(isConnecting: Boolean) {
addButton.isEnabled = !isConnecting
val text = if (isConnecting) R.string.fragment_add_public_chat_add_button_title_2 else R.string.fragment_add_public_chat_add_button_title_1
addButton.setText(text)
urlEditText.isEnabled = enabled
urlEditText.isEnabled = !isConnecting
}
}

@ -45,6 +45,10 @@ class DisplayNameActivity : BaseActionBarActivity() {
finish()
val publicChatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI
if (publicChatAPI != null) {
application.createDefaultPublicChatsIfNeeded()
application.createRSSFeedsIfNeeded()
application.lokiPublicChatManager.startPollersIfNeeded()
application.startRSSFeedPollersIfNeeded()
val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers()
servers.forEach { publicChatAPI.setDisplayName(name, it) }
}

@ -27,7 +27,7 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
public val publicChat = "public_chat"
@JvmStatic val createFriendRequestTableCommand = "CREATE TABLE $friendRequestTableName ($threadID INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
@JvmStatic val createSessionResetTableCommand = "CREATE TABLE $sessionResetTableName ($threadID INTEGER PRIMARY KEY, $sessionResetStatus INTEGER DEFAULT 0);"
@JvmStatic val createGroupChatMappingTableCommand = "CREATE TABLE $publicChatTableName ($threadID INTEGER PRIMARY KEY, $publicChat TEXT);"
@JvmStatic val createPublicChatTableCommand = "CREATE TABLE $publicChatTableName ($threadID INTEGER PRIMARY KEY, $publicChat TEXT);"
}
override fun getThreadID(hexEncodedPublicKey: String): Long {

Loading…
Cancel
Save