From 06f75859fa3287f1221d4911e20524badebba795 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 26 Nov 2019 09:55:08 +1100 Subject: [PATCH] Removed custom profile avatar url table since signal already has an existing one. Clean --- .../securesms/CreateProfileActivity.java | 36 +++++++------------ .../database/helpers/SQLCipherOpenHelper.java | 1 - .../securesms/loki/LokiUserDatabase.kt | 24 ++----------- 3 files changed, 15 insertions(+), 46 deletions(-) diff --git a/src/org/thoughtcrime/securesms/CreateProfileActivity.java b/src/org/thoughtcrime/securesms/CreateProfileActivity.java index a597f44a89..feaf664cd1 100644 --- a/src/org/thoughtcrime/securesms/CreateProfileActivity.java +++ b/src/org/thoughtcrime/securesms/CreateProfileActivity.java @@ -39,7 +39,6 @@ import org.thoughtcrime.securesms.crypto.ProfileKeyUtil; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.dependencies.InjectableType; -import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.permissions.Permissions; @@ -58,7 +57,9 @@ import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.crypto.ProfileCipher; import org.whispersystems.signalservice.api.util.StreamDetails; +import org.whispersystems.signalservice.loki.api.LokiDotNetAPI; import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; +import org.whispersystems.signalservice.loki.api.LokiStorageAPI; import org.whispersystems.signalservice.loki.utilities.Analytics; import java.io.ByteArrayInputStream; @@ -72,6 +73,7 @@ import java.util.regex.Pattern; import javax.inject.Inject; +import kotlin.Triple; import network.loki.messenger.R; @SuppressLint("StaticFieldLeak") @@ -393,19 +395,8 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje } } - // Loki - Original code - // ======== -// try { -// accountManager.setProfileName(profileKey, name); -// TextSecurePreferences.setProfileName(context, name); -// } catch (IOException e) { -// Log.w(TAG, e); -// return false; -// } - // ======== - try { - // Loki - Original code + // Loki - Original profile photo code // ======== // accountManager.setProfileAvatar(profileKey, avatar); // ======== @@ -413,26 +404,23 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje //TODO: there is no need to upload the avatar again if there is no change AvatarHelper.setAvatar(CreateProfileActivity.this, Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)), avatarBytes); TextSecurePreferences.setProfileAvatarId(CreateProfileActivity.this, new SecureRandom().nextInt()); - + //Loki - Upload the profile photo here if (avatar != null) { Log.d("Loki", "Start uploading profile photo"); LokiStorageAPI storageAPI = LokiStorageAPI.shared; - Triple result = storageAPI.uploadProfilePhoto(storageAPI.getServer(), avatarBytes); - String url = result.component2(); - Log.d("Loki", "Upload profile photo success, the url is " + url); - TextSecurePreferences.setProfileAvatarUrl(CreateProfileActivity.this, url); - } - else { + LokiDotNetAPI.UploadResult result = storageAPI.uploadProfilePhoto(storageAPI.getServer(), avatarBytes); + Log.d("Loki", "Profile photo uploaded, the url is " + result.getUrl()); + TextSecurePreferences.setProfileAvatarUrl(CreateProfileActivity.this, result.getUrl()); + } else { TextSecurePreferences.setProfileAvatarUrl(CreateProfileActivity.this, null); } - } catch (IOException e) { - Log.w(TAG, e); + } catch (Exception e) { + Log.d("Loki", "Failed to upload profile photo: " + e); return false; } - ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceProfileKeyUpdateJob()); - + // ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceProfileKeyUpdateJob()); return true; } diff --git a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 9d63491677..6715feb5ee 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -136,7 +136,6 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { db.execSQL(LokiThreadDatabase.getCreatePublicChatTableCommand()); db.execSQL(LokiUserDatabase.getCreateDisplayNameTableCommand()); db.execSQL(LokiUserDatabase.getCreateServerDisplayNameTableCommand()); - db.execSQL(LokiUserDatabase.getCreateProfileAvatarUrlTableCommand()); executeStatements(db, SmsDatabase.CREATE_INDEXS); executeStatements(db, MmsDatabase.CREATE_INDEXS); diff --git a/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt b/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt index 859d1d93a4..e72d898ce3 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiUserDatabase.kt @@ -25,9 +25,6 @@ class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database private val serverDisplayNameTable = "loki_user_server_display_name_database" private val serverID = "server_id" @JvmStatic val createServerDisplayNameTableCommand = "CREATE TABLE $serverDisplayNameTable ($hexEncodedPublicKey TEXT, $serverID TEXT, $displayName TEXT, PRIMARY KEY ($hexEncodedPublicKey, $serverID));" - // Profile Avatar URL cache - private val profileAvatarUrlTable = "loki_user_profile_avatar_url_database" - @JvmStatic val createProfileAvatarUrlTableCommand = "CREATE TABLE $profileAvatarUrlTable ($hexEncodedPublicKey TEXT PRIMARY KEY, $profileAvatarUrl TEXT);" } override fun getDisplayName(hexEncodedPublicKey: String): String? { @@ -72,25 +69,10 @@ class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database } override fun getProfileAvatarUrl(hexEncodedPublicKey: String): String? { - if (hexEncodedPublicKey == TextSecurePreferences.getLocalNumber(context)) { - return TextSecurePreferences.getProfileAvatarUrl(context) + return if (hexEncodedPublicKey == TextSecurePreferences.getLocalNumber(context)) { + TextSecurePreferences.getProfileAvatarUrl(context) } else { - val database = databaseHelper.readableDatabase - return database.get(profileAvatarUrlTable, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { cursor -> - cursor.getString(cursor.getColumnIndexOrThrow(profileAvatarUrl)) - } + Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).resolve().profileAvatar } } - - //TODO figure out what to do with Recipient - /* - fun setProfileAvatarUrl(hexEncodedPublicKey: String, profileAvatarUrl: String) { - val database = databaseHelper.writableDatabase - val row = ContentValues(2) - row.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey) - row.put(Companion.profileAvatarUrl, profileAvatarUrl) - database.insertOrUpdate(profileAvatarUrlTable, row, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) - Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).notifyListeners() - } - */ } \ No newline at end of file