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