kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fetch own username from the whoami endpoint.
rodzic
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,9 @@ public class RefreshOwnProfileJob extends BaseJob {
|
|||
profileAndCredential.getExpiringProfileKeyCredential()
|
||||
.ifPresent(expiringProfileKeyCredential -> setExpiringProfileKeyCredential(self, ProfileKeyUtil.getSelfProfileKey(), expiringProfileKeyCredential));
|
||||
|
||||
String username = ApplicationDependencies.getSignalServiceAccountManager().getWhoAmI().getUsername();
|
||||
SignalDatabase.recipients().setUsername(Recipient.self().getId(), username);
|
||||
|
||||
StoryOnboardingDownloadJob.Companion.enqueueIfNeeded();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.signal.core.util.concurrent.SignalExecutors;
|
|||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.UsernameIsNotReservedException;
|
||||
|
@ -66,6 +67,7 @@ class UsernameEditRepository {
|
|||
try {
|
||||
accountManager.confirmUsername(reserveUsernameResponse);
|
||||
SignalDatabase.recipients().setUsername(Recipient.self().getId(), reserveUsernameResponse.getUsername());
|
||||
ApplicationDependencies.getJobManager().add(new MultiDeviceProfileContentUpdateJob());
|
||||
Log.i(TAG, "[confirmUsername] Successfully reserved username.");
|
||||
return UsernameSetResult.SUCCESS;
|
||||
} catch (UsernameTakenException e) {
|
||||
|
|
|
@ -12,6 +12,9 @@ public class WhoAmIResponse {
|
|||
@JsonProperty
|
||||
public String number;
|
||||
|
||||
@JsonProperty
|
||||
public String username;
|
||||
|
||||
public String getAci() {
|
||||
return uuid;
|
||||
}
|
||||
|
@ -23,4 +26,8 @@ public class WhoAmIResponse {
|
|||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue