mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-20 15:51:30 +00:00
Add missing display name update & message fetch
This commit is contained in:
parent
4a613df52d
commit
cbad885586
@ -186,7 +186,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
mixpanel.trackMap(event, properties);
|
mixpanel.trackMap(event, properties);
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
};
|
};
|
||||||
|
// Loki - Set up public chat manager
|
||||||
lokiPublicChatManager = new LokiPublicChatManager(this);
|
lokiPublicChatManager = new LokiPublicChatManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,6 +198,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
KeyCachingService.onAppForegrounded(this);
|
KeyCachingService.onAppForegrounded(this);
|
||||||
// Loki - Start long polling if needed
|
// Loki - Start long polling if needed
|
||||||
startLongPollingIfNeeded();
|
startLongPollingIfNeeded();
|
||||||
|
lokiPublicChatManager.startPollersIfNeeded();
|
||||||
setUpStorageAPIIfNeeded();
|
setUpStorageAPIIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +262,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
LokiUserDatabase userDatabase = DatabaseFactory.getLokiUserDatabase(this);
|
LokiUserDatabase userDatabase = DatabaseFactory.getLokiUserDatabase(this);
|
||||||
lokiPublicChatAPI = new LokiPublicChatAPI(userHexEncodedPublicKey, userPrivateKey, apiDatabase, userDatabase);
|
lokiPublicChatAPI = new LokiPublicChatAPI(userHexEncodedPublicKey, userPrivateKey, apiDatabase, userDatabase);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lokiPublicChatAPI;
|
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);
|
return new LokiRSSFeed("loki.network.messenger-updates.feed", "https://loki.network/category/messenger-updates/feed", "Loki Messenger Updates", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createGroupChatsIfNeeded() {
|
public void createDefaultPublicChatsIfNeeded() {
|
||||||
List<LokiPublicChat> defaultChats = LokiPublicChatAPI.Companion.getDefaultChats(BuildConfig.DEBUG);
|
List<LokiPublicChat> defaultPublicChats = LokiPublicChatAPI.Companion.getDefaultChats(BuildConfig.DEBUG);
|
||||||
for (LokiPublicChat chat : defaultChats) {
|
for (LokiPublicChat publiChat : defaultPublicChats) {
|
||||||
long threadID = GroupManager.getThreadId(chat.getId(), this);
|
long threadID = GroupManager.getThreadId(publiChat.getId(), this);
|
||||||
String migrationKey = chat.getId() + "_migrated";
|
String migrationKey = publiChat.getId() + "_migrated";
|
||||||
boolean isChatMigrated = TextSecurePreferences.getBooleanPreference(this, migrationKey, false);
|
boolean isChatMigrated = TextSecurePreferences.getBooleanPreference(this, migrationKey, false);
|
||||||
boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, chat.getId());
|
boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, publiChat.getId());
|
||||||
if (!isChatSetUp || !chat.isDeletable()) {
|
if (!isChatSetUp || !publiChat.isDeletable()) {
|
||||||
lokiPublicChatManager.addChat(chat.getServer(), chat.getChannel(), chat.getDisplayName());
|
lokiPublicChatManager.addChat(publiChat.getServer(), publiChat.getChannel(), publiChat.getDisplayName());
|
||||||
TextSecurePreferences.markChatSetUp(this, chat.getId());
|
TextSecurePreferences.markChatSetUp(this, publiChat.getId());
|
||||||
TextSecurePreferences.setBooleanPreference(this, migrationKey, true);
|
TextSecurePreferences.setBooleanPreference(this, migrationKey, true);
|
||||||
} else if (threadID > -1 && !isChatMigrated) {
|
} else if (threadID > -1 && !isChatMigrated) {
|
||||||
// Migrate the old public chats.
|
// Migrate the old public chats
|
||||||
DatabaseFactory.getLokiThreadDatabase(this).setPublicChat(chat, threadID);
|
DatabaseFactory.getLokiThreadDatabase(this).setPublicChat(publiChat, threadID);
|
||||||
TextSecurePreferences.setBooleanPreference(this, migrationKey, true);
|
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);
|
this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadID), true, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startGroupChatPollersIfNeeded() {
|
|
||||||
lokiPublicChatManager.startPollersIfNeeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startRSSFeedPollersIfNeeded() {
|
public void startRSSFeedPollersIfNeeded() {
|
||||||
createRSSFeedPollersIfNeeded();
|
createRSSFeedPollersIfNeeded();
|
||||||
if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.startIfNeeded();
|
if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.startIfNeeded();
|
||||||
|
@ -187,7 +187,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
|||||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY));
|
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY));
|
||||||
this.findPreference(PREFERENCE_CATEGORY_QR_CODE)
|
this.findPreference(PREFERENCE_CATEGORY_QR_CODE)
|
||||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_QR_CODE));
|
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_QR_CODE));
|
||||||
|
|
||||||
Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE);
|
Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE);
|
||||||
// Hide if this is a slave device
|
// Hide if this is a slave device
|
||||||
linkDevicePreference.setVisible(isMasterDevice);
|
linkDevicePreference.setVisible(isMasterDevice);
|
||||||
|
@ -82,9 +82,9 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
|||||||
dynamicLanguage.onCreate(this);
|
dynamicLanguage.onCreate(this);
|
||||||
if (TextSecurePreferences.getLocalNumber(this) != null) {
|
if (TextSecurePreferences.getLocalNumber(this) != null) {
|
||||||
ApplicationContext application = ApplicationContext.getInstance(this);
|
ApplicationContext application = ApplicationContext.getInstance(this);
|
||||||
application.createGroupChatsIfNeeded();
|
application.createDefaultPublicChatsIfNeeded();
|
||||||
application.createRSSFeedsIfNeeded();
|
application.createRSSFeedsIfNeeded();
|
||||||
application.startGroupChatPollersIfNeeded();
|
application.getLokiPublicChatManager().startPollersIfNeeded();
|
||||||
application.startRSSFeedPollersIfNeeded();
|
application.startRSSFeedPollersIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,8 +380,8 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
|||||||
TextSecurePreferences.setProfileName(context, name);
|
TextSecurePreferences.setProfileName(context, name);
|
||||||
LokiPublicChatAPI publicChatAPI = ApplicationContext.getInstance(context).getLokiPublicChatAPI();
|
LokiPublicChatAPI publicChatAPI = ApplicationContext.getInstance(context).getLokiPublicChatAPI();
|
||||||
if (publicChatAPI != null) {
|
if (publicChatAPI != null) {
|
||||||
Set<String> groupChatServers = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChatServers();
|
Set<String> servers = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChatServers();
|
||||||
for (String server : groupChatServers) {
|
for (String server : servers) {
|
||||||
publicChatAPI.setDisplayName(name, server);
|
publicChatAPI.setDisplayName(name, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import org.thoughtcrime.securesms.mms.Slide;
|
|||||||
import org.thoughtcrime.securesms.mms.SlideDeck;
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiPublicChat;
|
import org.whispersystems.signalservice.loki.api.LokiPublicChat;
|
||||||
@ -194,14 +195,15 @@ public class QuoteView extends FrameLayout implements RecipientModifiedListener
|
|||||||
|
|
||||||
String quoteeDisplayName = author.toShortString();
|
String quoteeDisplayName = author.toShortString();
|
||||||
|
|
||||||
// If we're in a group then try and use the display name in the group
|
long threadID = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(conversationRecipient);
|
||||||
if (conversationRecipient.isGroupRecipient()) {
|
String senderHexEncodedPublicKey = author.getAddress().serialize();
|
||||||
long threadId = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(conversationRecipient);
|
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadID);
|
||||||
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
if (senderHexEncodedPublicKey.equalsIgnoreCase(TextSecurePreferences.getLocalNumber(getContext()))) {
|
||||||
if (publicChat != null) {
|
quoteeDisplayName = TextSecurePreferences.getProfileName(getContext());
|
||||||
String senderDisplayName = DatabaseFactory.getLokiUserDatabase(getContext()).getServerDisplayName(publicChat.getId(), author.getAddress().serialize());
|
} else if (publicChat != null) {
|
||||||
if (senderDisplayName != null) { quoteeDisplayName = senderDisplayName; }
|
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);
|
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(LokiMessageDatabase.getCreateTableCommand());
|
||||||
db.execSQL(LokiThreadDatabase.getCreateFriendRequestTableCommand());
|
db.execSQL(LokiThreadDatabase.getCreateFriendRequestTableCommand());
|
||||||
db.execSQL(LokiThreadDatabase.getCreateSessionResetTableCommand());
|
db.execSQL(LokiThreadDatabase.getCreateSessionResetTableCommand());
|
||||||
db.execSQL(LokiThreadDatabase.getCreateGroupChatMappingTableCommand());
|
db.execSQL(LokiThreadDatabase.getCreatePublicChatTableCommand());
|
||||||
db.execSQL(LokiUserDatabase.getCreateDisplayNameTableCommand());
|
db.execSQL(LokiUserDatabase.getCreateDisplayNameTableCommand());
|
||||||
db.execSQL(LokiUserDatabase.getCreateServerDisplayNameTableCommand());
|
db.execSQL(LokiUserDatabase.getCreateServerDisplayNameTableCommand());
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
if (oldVersion < lokiV3) {
|
if (oldVersion < lokiV3) {
|
||||||
db.execSQL(LokiAPIDatabase.getCreatePairingAuthorisationTableCommand());
|
db.execSQL(LokiAPIDatabase.getCreatePairingAuthorisationTableCommand());
|
||||||
db.execSQL(LokiThreadDatabase.getCreateGroupChatMappingTableCommand());
|
db.execSQL(LokiThreadDatabase.getCreatePublicChatTableCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
|
@ -5,7 +5,7 @@ import android.util.Patterns
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Toast
|
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 network.loki.messenger.R
|
||||||
import nl.komponents.kovenant.ui.failUi
|
import nl.komponents.kovenant.ui.failUi
|
||||||
import nl.komponents.kovenant.ui.successUi
|
import nl.komponents.kovenant.ui.successUi
|
||||||
@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.ApplicationContext
|
|||||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme
|
import org.thoughtcrime.securesms.util.DynamicTheme
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
|
|
||||||
class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
|
class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
|
||||||
private val dynamicTheme = DynamicTheme()
|
private val dynamicTheme = DynamicTheme()
|
||||||
@ -24,8 +25,8 @@ class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
override fun onCreate(bundle: Bundle?, isReady: Boolean) {
|
override fun onCreate(bundle: Bundle?, isReady: Boolean) {
|
||||||
supportActionBar!!.setTitle(R.string.fragment_add_public_chat_title)
|
supportActionBar!!.setTitle(R.string.fragment_add_public_chat_title)
|
||||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||||
setContentView(R.layout.fragment_add_public_chat)
|
setContentView(R.layout.activity_add_public_chat)
|
||||||
setButtonEnabled(true)
|
updateUI(false)
|
||||||
addButton.setOnClickListener { addPublicChatIfPossible() }
|
addButton.setOnClickListener { addPublicChatIfPossible() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,24 +46,29 @@ class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
private fun addPublicChatIfPossible() {
|
private fun addPublicChatIfPossible() {
|
||||||
val inputMethodManager = getSystemService(BaseActionBarActivity.INPUT_METHOD_SERVICE) as InputMethodManager
|
val inputMethodManager = getSystemService(BaseActionBarActivity.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
inputMethodManager.hideSoftInputFromWindow(urlEditText.windowToken, 0)
|
inputMethodManager.hideSoftInputFromWindow(urlEditText.windowToken, 0)
|
||||||
|
|
||||||
val url = urlEditText.text.toString().toLowerCase().replace("http://", "https://")
|
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() }
|
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)
|
}
|
||||||
|
updateUI(true)
|
||||||
ApplicationContext.getInstance(this).lokiPublicChatManager.addChat(url, 1).successUi {
|
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()
|
finish()
|
||||||
}.failUi {
|
}.failUi {
|
||||||
setButtonEnabled(true)
|
updateUI(false)
|
||||||
Toast.makeText(this, R.string.fragment_add_public_chat_connection_failed_message, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.fragment_add_public_chat_connection_failed_message, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setButtonEnabled(enabled: Boolean) {
|
private fun updateUI(isConnecting: Boolean) {
|
||||||
addButton.isEnabled = enabled
|
addButton.isEnabled = !isConnecting
|
||||||
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
|
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)
|
addButton.setText(text)
|
||||||
urlEditText.isEnabled = enabled
|
urlEditText.isEnabled = !isConnecting
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -45,6 +45,10 @@ class DisplayNameActivity : BaseActionBarActivity() {
|
|||||||
finish()
|
finish()
|
||||||
val publicChatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI
|
val publicChatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI
|
||||||
if (publicChatAPI != null) {
|
if (publicChatAPI != null) {
|
||||||
|
application.createDefaultPublicChatsIfNeeded()
|
||||||
|
application.createRSSFeedsIfNeeded()
|
||||||
|
application.lokiPublicChatManager.startPollersIfNeeded()
|
||||||
|
application.startRSSFeedPollersIfNeeded()
|
||||||
val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers()
|
val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers()
|
||||||
servers.forEach { publicChatAPI.setDisplayName(name, it) }
|
servers.forEach { publicChatAPI.setDisplayName(name, it) }
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
|||||||
public val publicChat = "public_chat"
|
public val publicChat = "public_chat"
|
||||||
@JvmStatic val createFriendRequestTableCommand = "CREATE TABLE $friendRequestTableName ($threadID INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
|
@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 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 {
|
override fun getThreadID(hexEncodedPublicKey: String): Long {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user