mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Allow setting local group names and avatars for MMS groups.
This commit is contained in:
@@ -73,13 +73,15 @@ public final class GroupManager {
|
||||
try (GroupManagerV2.GroupEditor edit = new GroupManagerV2(context).edit(groupId.requireV2())) {
|
||||
return edit.updateGroupTitleAndAvatar(nameChanged ? name : null, avatar, avatarChanged);
|
||||
}
|
||||
} else {
|
||||
} else if (groupId.isV1()) {
|
||||
List<Recipient> members = DatabaseFactory.getGroupDatabase(context)
|
||||
.getGroupMembers(groupId, GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
|
||||
|
||||
Set<RecipientId> recipientIds = getMemberIds(new HashSet<>(members));
|
||||
|
||||
return GroupManagerV1.updateGroup(context, groupId.requireV1(), recipientIds, avatar, name, 0);
|
||||
} else {
|
||||
return GroupManagerV1.updateGroup(context, groupId.requireMms(), avatar, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,15 @@ final class GroupManagerV1 {
|
||||
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(groupRecipient.getId(), true);
|
||||
return sendGroupUpdate(context, groupIdV1, memberIds, name, avatarBytes, memberIds.size() - 1);
|
||||
} else {
|
||||
groupDatabase.create(groupId.requireMms(), memberIds);
|
||||
groupDatabase.create(groupId.requireMms(), name, memberIds);
|
||||
|
||||
try {
|
||||
AvatarHelper.setAvatar(context, groupRecipientId, avatarBytes != null ? new ByteArrayInputStream(avatarBytes) : null);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to save avatar!", e);
|
||||
}
|
||||
groupDatabase.onAvatarUpdated(groupId, avatarBytes != null);
|
||||
|
||||
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
|
||||
return new GroupActionResult(groupRecipient, threadId, memberIds.size() - 1, Collections.emptyList());
|
||||
}
|
||||
@@ -112,6 +120,28 @@ final class GroupManagerV1 {
|
||||
}
|
||||
}
|
||||
|
||||
static GroupActionResult updateGroup(@NonNull Context context,
|
||||
@NonNull GroupId.Mms groupId,
|
||||
@Nullable byte[] avatarBytes,
|
||||
@Nullable String name)
|
||||
{
|
||||
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
|
||||
RecipientId groupRecipientId = DatabaseFactory.getRecipientDatabase(context).getOrInsertFromGroupId(groupId);
|
||||
Recipient groupRecipient = Recipient.resolved(groupRecipientId);
|
||||
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient);
|
||||
|
||||
groupDatabase.updateTitle(groupId, name);
|
||||
groupDatabase.onAvatarUpdated(groupId, avatarBytes != null);
|
||||
|
||||
try {
|
||||
AvatarHelper.setAvatar(context, groupRecipientId, avatarBytes != null ? new ByteArrayInputStream(avatarBytes) : null);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to save avatar!", e);
|
||||
}
|
||||
|
||||
return new GroupActionResult(groupRecipient, threadId, 0, Collections.emptyList());
|
||||
}
|
||||
|
||||
private static GroupActionResult sendGroupUpdate(@NonNull Context context,
|
||||
@NonNull GroupId.V1 groupId,
|
||||
@NonNull Set<RecipientId> members,
|
||||
|
||||
@@ -116,8 +116,7 @@ public class AddGroupDetailsFragment extends LoggingFragment {
|
||||
viewModel.getCanSubmitForm().observe(getViewLifecycleOwner(), isFormValid -> setCreateEnabled(isFormValid, true));
|
||||
viewModel.getIsMms().observe(getViewLifecycleOwner(), isMms -> {
|
||||
mmsWarning.setVisibility(isMms ? View.VISIBLE : View.GONE);
|
||||
name.setVisibility(isMms ? View.GONE : View.VISIBLE);
|
||||
avatar.setVisibility(isMms ? View.GONE : View.VISIBLE);
|
||||
name.setHint(isMms ? R.string.AddGroupDetailsFragment__group_name_optional : R.string.AddGroupDetailsFragment__group_name_required);
|
||||
toolbar.setTitle(isMms ? R.string.AddGroupDetailsFragment__create_group : R.string.AddGroupDetailsFragment__name_this_group);
|
||||
});
|
||||
viewModel.getNonGv2CapableMembers().observe(getViewLifecycleOwner(), nonGv2CapableMembers -> {
|
||||
|
||||
@@ -48,11 +48,11 @@ final class AddGroupDetailsRepository {
|
||||
});
|
||||
}
|
||||
|
||||
void createPushGroup(@NonNull Set<RecipientId> members,
|
||||
@Nullable byte[] avatar,
|
||||
@Nullable String name,
|
||||
boolean mms,
|
||||
Consumer<GroupCreateResult> resultConsumer)
|
||||
void createGroup(@NonNull Set<RecipientId> members,
|
||||
@Nullable byte[] avatar,
|
||||
@Nullable String name,
|
||||
boolean mms,
|
||||
Consumer<GroupCreateResult> resultConsumer)
|
||||
{
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
Set<Recipient> recipients = new HashSet<>(Stream.of(members).map(Recipient::resolved).toList());
|
||||
|
||||
@@ -117,7 +117,7 @@ public final class AddGroupDetailsViewModel extends ViewModel {
|
||||
Set<RecipientId> memberIds = Stream.of(members).map(member -> member.getMember().getId()).collect(Collectors.toSet());
|
||||
byte[] avatarBytes = avatar.getValue();
|
||||
boolean isGroupMms = isMms.getValue() == Boolean.TRUE;
|
||||
String groupName = isGroupMms ? "" : name.getValue();
|
||||
String groupName = name.getValue();
|
||||
|
||||
if (!isGroupMms && TextUtils.isEmpty(groupName)) {
|
||||
groupCreateResult.postValue(GroupCreateResult.error(GroupCreateResult.Error.Type.ERROR_INVALID_NAME));
|
||||
@@ -129,11 +129,11 @@ public final class AddGroupDetailsViewModel extends ViewModel {
|
||||
return;
|
||||
}
|
||||
|
||||
repository.createPushGroup(memberIds,
|
||||
avatarBytes,
|
||||
groupName,
|
||||
isGroupMms,
|
||||
groupCreateResult::postValue);
|
||||
repository.createGroup(memberIds,
|
||||
avatarBytes,
|
||||
groupName,
|
||||
isGroupMms,
|
||||
groupCreateResult::postValue);
|
||||
}
|
||||
|
||||
private static @NonNull List<GroupMemberEntry.NewGroupCandidate> filterDeletedMembers(@NonNull List<GroupMemberEntry.NewGroupCandidate> members, @NonNull Set<RecipientId> deleted) {
|
||||
|
||||
@@ -416,7 +416,7 @@ public class ManageGroupFragment extends LoggingFragment {
|
||||
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_edit) {
|
||||
startActivity(EditProfileActivity.getIntentForGroupProfile(requireActivity(), getGroupId().requirePush()));
|
||||
startActivity(EditProfileActivity.getIntentForGroupProfile(requireActivity(), getGroupId()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user