Fetch own username from the whoami endpoint.

This commit is contained in:
Greyson Parrelli
2022-11-01 10:26:50 -04:00
committed by Cody Henthorne
parent 53883ee3d3
commit 8c915572fb
4 changed files with 23 additions and 12 deletions

View File

@@ -2068,20 +2068,19 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
}
fun setUsername(id: RecipientId, username: String?) {
if (username != null) {
val existingUsername = getByUsername(username)
if (existingUsername.isPresent && id != existingUsername.get()) {
Log.i(TAG, "Username was previously thought to be owned by " + existingUsername.get() + ". Clearing their username.")
setUsername(existingUsername.get(), null)
writableDatabase.withinTransaction {
if (username != null) {
val existingUsername = getByUsername(username)
if (existingUsername.isPresent && id != existingUsername.get()) {
Log.i(TAG, "Username was previously thought to be owned by " + existingUsername.get() + ". Clearing their username.")
setUsername(existingUsername.get(), null)
}
}
}
val contentValues = ContentValues(1).apply {
put(USERNAME, username)
}
if (update(id, contentValues)) {
ApplicationDependencies.getDatabaseObserver().notifyRecipientChanged(id)
StorageSyncHelper.scheduleSyncForDataChange()
if (update(id, contentValuesOf(USERNAME to username))) {
ApplicationDependencies.getDatabaseObserver().notifyRecipientChanged(id)
StorageSyncHelper.scheduleSyncForDataChange()
}
}
}