Fix group name clearing after avatar change.
This commit is contained in:
parent
8dbcb255ad
commit
d8f3e032c7
5 changed files with 35 additions and 11 deletions
|
@ -68,12 +68,13 @@ public final class GroupManager {
|
|||
@NonNull GroupId groupId,
|
||||
@Nullable byte[] avatar,
|
||||
boolean avatarChanged,
|
||||
@Nullable String name)
|
||||
@NonNull String name,
|
||||
boolean nameChanged)
|
||||
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException, GroupChangeBusyException
|
||||
{
|
||||
if (groupId.isV2()) {
|
||||
try (GroupManagerV2.GroupEditor edit = new GroupManagerV2(context).edit(groupId.requireV2())) {
|
||||
return edit.updateGroupTitleAndAvatar(name, avatar, avatarChanged);
|
||||
return edit.updateGroupTitleAndAvatar(nameChanged ? name : null, avatar, avatarChanged);
|
||||
}
|
||||
} else {
|
||||
List<Recipient> members = DatabaseFactory.getGroupDatabase(context)
|
||||
|
|
|
@ -15,7 +15,14 @@ interface EditProfileRepository {
|
|||
|
||||
void getCurrentDisplayName(@NonNull Consumer<String> displayNameConsumer);
|
||||
|
||||
void uploadProfile(@NonNull ProfileName profileName, @Nullable String displayName, @Nullable byte[] avatar, boolean avatarChanged, @NonNull Consumer<UploadResult> uploadResultConsumer);
|
||||
void getCurrentName(@NonNull Consumer<String> nameConsumer);
|
||||
|
||||
void uploadProfile(@NonNull ProfileName profileName,
|
||||
@NonNull String displayName,
|
||||
boolean displayNameChanged,
|
||||
@Nullable byte[] avatar,
|
||||
boolean avatarChanged,
|
||||
@NonNull Consumer<UploadResult> uploadResultConsumer);
|
||||
|
||||
void getCurrentUsername(@NonNull Consumer<Optional<String>> callback);
|
||||
|
||||
|
|
|
@ -39,10 +39,8 @@ class EditProfileViewModel extends ViewModel {
|
|||
|
||||
if (!hasInstanceState) {
|
||||
if (groupId != null) {
|
||||
repository.getCurrentDisplayName(value -> {
|
||||
givenName.setValue(value);
|
||||
originalDisplayName.setValue(value);
|
||||
});
|
||||
repository.getCurrentDisplayName(originalDisplayName::setValue);
|
||||
repository.getCurrentName(givenName::setValue);
|
||||
} else {
|
||||
repository.getCurrentProfileName(name -> {
|
||||
givenName.setValue(name.getGivenName());
|
||||
|
@ -123,7 +121,8 @@ class EditProfileViewModel extends ViewModel {
|
|||
String oldDisplayName = isGroup() ? originalDisplayName.getValue() : null;
|
||||
|
||||
repository.uploadProfile(profileName,
|
||||
Objects.equals(oldDisplayName, displayName) ? null : displayName,
|
||||
displayName,
|
||||
!Objects.equals(oldDisplayName, displayName),
|
||||
newAvatar,
|
||||
oldAvatar != newAvatar,
|
||||
uploadResultConsumer);
|
||||
|
|
|
@ -65,16 +65,22 @@ class EditPushGroupProfileRepository implements EditProfileRepository {
|
|||
SimpleTask.run(() -> Recipient.resolved(getRecipientId()).getDisplayName(context), displayNameConsumer::accept);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCurrentName(@NonNull Consumer<String> nameConsumer) {
|
||||
SimpleTask.run(() -> Recipient.resolved(getRecipientId()).getName(context), nameConsumer::accept);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadProfile(@NonNull ProfileName profileName,
|
||||
@Nullable String displayName,
|
||||
@NonNull String displayName,
|
||||
boolean displayNameChanged,
|
||||
@Nullable byte[] avatar,
|
||||
boolean avatarChanged,
|
||||
@NonNull Consumer<UploadResult> uploadResultConsumer)
|
||||
{
|
||||
SimpleTask.run(() -> {
|
||||
try {
|
||||
GroupManager.updateGroup(context, groupId, avatar, avatarChanged, displayName);
|
||||
GroupManager.updateGroup(context, groupId, avatar, avatarChanged, displayName, displayNameChanged);
|
||||
|
||||
return UploadResult.SUCCESS;
|
||||
} catch (GroupChangeFailedException | GroupInsufficientRightsException | IOException | GroupNotAMemberException | GroupChangeBusyException e) {
|
||||
|
|
|
@ -108,7 +108,18 @@ class EditSelfProfileRepository implements EditProfileRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void uploadProfile(@NonNull ProfileName profileName, @Nullable String displayName, @Nullable byte[] avatar, boolean avatarChanged, @NonNull Consumer<UploadResult> uploadResultConsumer) {
|
||||
public void getCurrentName(@NonNull Consumer<String> nameConsumer) {
|
||||
nameConsumer.accept("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadProfile(@NonNull ProfileName profileName,
|
||||
@NonNull String displayName,
|
||||
boolean displayNameChanged,
|
||||
@Nullable byte[] avatar,
|
||||
boolean avatarChanged,
|
||||
@NonNull Consumer<UploadResult> uploadResultConsumer)
|
||||
{
|
||||
SimpleTask.run(() -> {
|
||||
DatabaseFactory.getRecipientDatabase(context).setProfileName(Recipient.self().getId(), profileName);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue