mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 23:13:38 +00:00
Removed custom profile avatar url table since signal already has an existing one.
Clean
This commit is contained in:
parent
5a4b619c9d
commit
06f75859fa
@ -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<Long, String, byte[]> 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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user