diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java index 8e272dc274..7cecd86e2b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java @@ -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 members = DatabaseFactory.getGroupDatabase(context) diff --git a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileRepository.java b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileRepository.java index 4bf247dabc..eb8743aa80 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileRepository.java @@ -15,7 +15,14 @@ interface EditProfileRepository { void getCurrentDisplayName(@NonNull Consumer displayNameConsumer); - void uploadProfile(@NonNull ProfileName profileName, @Nullable String displayName, @Nullable byte[] avatar, boolean avatarChanged, @NonNull Consumer uploadResultConsumer); + void getCurrentName(@NonNull Consumer nameConsumer); + + void uploadProfile(@NonNull ProfileName profileName, + @NonNull String displayName, + boolean displayNameChanged, + @Nullable byte[] avatar, + boolean avatarChanged, + @NonNull Consumer uploadResultConsumer); void getCurrentUsername(@NonNull Consumer> callback); diff --git a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileViewModel.java index 46fb34892d..b9da8c6d2a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileViewModel.java @@ -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); diff --git a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditPushGroupProfileRepository.java b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditPushGroupProfileRepository.java index c3ee820d73..d02b1f4a97 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditPushGroupProfileRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditPushGroupProfileRepository.java @@ -65,16 +65,22 @@ class EditPushGroupProfileRepository implements EditProfileRepository { SimpleTask.run(() -> Recipient.resolved(getRecipientId()).getDisplayName(context), displayNameConsumer::accept); } + @Override + public void getCurrentName(@NonNull Consumer 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 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) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditSelfProfileRepository.java b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditSelfProfileRepository.java index 1c52f46a1c..be264b3558 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditSelfProfileRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditSelfProfileRepository.java @@ -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 uploadResultConsumer) { + public void getCurrentName(@NonNull Consumer nameConsumer) { + nameConsumer.accept(""); + } + + @Override + public void uploadProfile(@NonNull ProfileName profileName, + @NonNull String displayName, + boolean displayNameChanged, + @Nullable byte[] avatar, + boolean avatarChanged, + @NonNull Consumer uploadResultConsumer) + { SimpleTask.run(() -> { DatabaseFactory.getRecipientDatabase(context).setProfileName(Recipient.self().getId(), profileName);