mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Use display name
This commit is contained in:
parent
acae76161d
commit
956f20fc0e
@ -36,6 +36,7 @@ import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDisplayNameDatabase;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
public class DatabaseFactory {
|
||||
@ -70,6 +71,7 @@ public class DatabaseFactory {
|
||||
private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase;
|
||||
private final LokiMessageFriendRequestDatabase lokiMessageFriendRequestDatabase;
|
||||
private final LokiThreadFriendRequestDatabase lokiThreadFriendRequestDatabase;
|
||||
private final LokiUserDisplayNameDatabase lokiUserDisplayNameDatabase;
|
||||
|
||||
public static DatabaseFactory getInstance(Context context) {
|
||||
synchronized (lock) {
|
||||
@ -176,6 +178,10 @@ public class DatabaseFactory {
|
||||
public static LokiThreadFriendRequestDatabase getLokiThreadFriendRequestDatabase(Context context) {
|
||||
return getInstance(context).lokiThreadFriendRequestDatabase;
|
||||
}
|
||||
|
||||
public static LokiUserDisplayNameDatabase getLokiUserDisplayNameDatabase(Context context) {
|
||||
return getInstance(context).lokiUserDisplayNameDatabase;
|
||||
}
|
||||
// endregion
|
||||
|
||||
public static void upgradeRestored(Context context, SQLiteDatabase database){
|
||||
@ -214,6 +220,7 @@ public class DatabaseFactory {
|
||||
this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper);
|
||||
this.lokiMessageFriendRequestDatabase = new LokiMessageFriendRequestDatabase(context, databaseHelper);
|
||||
this.lokiThreadFriendRequestDatabase = new LokiThreadFriendRequestDatabase(context, databaseHelper);
|
||||
this.lokiUserDisplayNameDatabase = new LokiUserDisplayNameDatabase(context, databaseHelper);
|
||||
}
|
||||
|
||||
public void onApplicationLevelUpgrade(@NonNull Context context, @NonNull MasterSecret masterSecret,
|
||||
|
@ -39,6 +39,7 @@ import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDisplayNameDatabase;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
@ -123,6 +124,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiMessageFriendRequestDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiThreadFriendRequestDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiUserDisplayNameDatabase.getCreateTableCommand());
|
||||
|
||||
executeStatements(db, SmsDatabase.CREATE_INDEXS);
|
||||
executeStatements(db, MmsDatabase.CREATE_INDEXS);
|
||||
|
@ -271,7 +271,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
|
||||
Optional<String> senderDisplayName = content.senderDisplayName;
|
||||
if (senderDisplayName.isPresent()) {
|
||||
// TODO: Use display name
|
||||
DatabaseFactory.getLokiUserDisplayNameDatabase(context).setDisplayName(envelope.getSource(), senderDisplayName.get());
|
||||
}
|
||||
|
||||
if (content.getDataMessage().isPresent()) {
|
||||
|
@ -0,0 +1,31 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
|
||||
class LokiUserDisplayNameDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_user_display_name_database"
|
||||
private val hexEncodedPublicKey = "hex_encoded_public_key"
|
||||
private val displayName = "display_name"
|
||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($hexEncodedPublicKey TEXT PRIMARY KEY, $displayName TEXT);"
|
||||
}
|
||||
|
||||
fun getDisplayName(hexEncodedPublicKey: String): String? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { cursor ->
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(displayName))
|
||||
}
|
||||
}
|
||||
|
||||
fun setDisplayName(hexEncodedPublicKey: String, displayName: String) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val row = ContentValues(2)
|
||||
row.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
||||
row.put(Companion.displayName, displayName)
|
||||
database.insertOrUpdate(tableName, row, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey ))
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.SystemContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.TransparentContactPhoto;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
|
||||
@ -48,7 +49,6 @@ import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientProvider.RecipientDetails;
|
||||
import org.thoughtcrime.securesms.util.FutureTaskListener;
|
||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
@ -70,6 +70,7 @@ public class Recipient implements RecipientModifiedListener {
|
||||
private final @NonNull Address address;
|
||||
private final @NonNull List<Recipient> participants = new LinkedList<>();
|
||||
|
||||
private Context context;
|
||||
private @Nullable String name;
|
||||
private @Nullable String customLabel;
|
||||
private boolean resolving;
|
||||
@ -116,11 +117,13 @@ public class Recipient implements RecipientModifiedListener {
|
||||
if (recipient.isPresent()) consumer.accept(recipient.get());
|
||||
}
|
||||
|
||||
Recipient(@NonNull Address address,
|
||||
Recipient(@NonNull Context context,
|
||||
@NonNull Address address,
|
||||
@Nullable Recipient stale,
|
||||
@NonNull Optional<RecipientDetails> details,
|
||||
@NonNull ListenableFutureTask<RecipientDetails> future)
|
||||
{
|
||||
this.context = context;
|
||||
this.address = address;
|
||||
this.color = null;
|
||||
this.resolving = true;
|
||||
@ -235,7 +238,8 @@ public class Recipient implements RecipientModifiedListener {
|
||||
});
|
||||
}
|
||||
|
||||
Recipient(@NonNull Address address, @NonNull RecipientDetails details) {
|
||||
Recipient(@NonNull Context context, @NonNull Address address, @NonNull RecipientDetails details) {
|
||||
this.context = context;
|
||||
this.address = address;
|
||||
this.contactUri = details.contactUri;
|
||||
this.name = details.name;
|
||||
@ -288,6 +292,9 @@ public class Recipient implements RecipientModifiedListener {
|
||||
}
|
||||
|
||||
public synchronized @Nullable String getName() {
|
||||
String displayName = DatabaseFactory.getLokiUserDisplayNameDatabase(context).getDisplayName(this.address.toString());
|
||||
if (displayName != null) { return displayName; }
|
||||
|
||||
if (this.name == null && isMmsGroupRecipient()) {
|
||||
List<String> names = new LinkedList<>();
|
||||
|
||||
|
@ -66,9 +66,9 @@ class RecipientProvider {
|
||||
Optional<RecipientDetails> prefetchedRecipientDetails = createPrefetchedRecipientDetails(context, address, settings, groupRecord);
|
||||
|
||||
if (asynchronous) {
|
||||
cachedRecipient = new Recipient(address, cachedRecipient, prefetchedRecipientDetails, getRecipientDetailsAsync(context, address, settings, groupRecord));
|
||||
cachedRecipient = new Recipient(context, address, cachedRecipient, prefetchedRecipientDetails, getRecipientDetailsAsync(context, address, settings, groupRecord));
|
||||
} else {
|
||||
cachedRecipient = new Recipient(address, getRecipientDetailsSync(context, address, settings, groupRecord, false));
|
||||
cachedRecipient = new Recipient(context, address, getRecipientDetailsSync(context, address, settings, groupRecord, false));
|
||||
}
|
||||
|
||||
recipientCache.set(address, cachedRecipient);
|
||||
|
Loading…
Reference in New Issue
Block a user