mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Fetch own username from the whoami endpoint.
This commit is contained in:
committed by
Cody Henthorne
parent
53883ee3d3
commit
8c915572fb
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user