mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 11:18:35 +00:00
Support gv2 avatar removal.
This commit is contained in:
parent
d726da822c
commit
3b673c07a0
@ -73,7 +73,7 @@ public final class GroupManager {
|
|||||||
{
|
{
|
||||||
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, avatarChanged ? avatar : null);
|
return edit.updateGroupTitleAndAvatar(name, avatar, avatarChanged);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<Recipient> members = DatabaseFactory.getGroupDatabase(context)
|
List<Recipient> members = DatabaseFactory.getGroupDatabase(context)
|
||||||
|
@ -209,23 +209,24 @@ final class GroupManagerV2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
@NonNull GroupManager.GroupActionResult updateGroupTitleAndAvatar(@Nullable String title, @Nullable byte[] avatarBytes)
|
@NonNull GroupManager.GroupActionResult updateGroupTitleAndAvatar(@Nullable String title, @Nullable byte[] avatarBytes, boolean avatarChanged)
|
||||||
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
|
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
GroupChange.Actions.Builder change = groupOperations.createModifyGroupTitleAndMembershipChange(Optional.fromNullable(title), Collections.emptySet(), Collections.emptySet());
|
GroupChange.Actions.Builder change = groupOperations.createModifyGroupTitleAndMembershipChange(Optional.fromNullable(title), Collections.emptySet(), Collections.emptySet());
|
||||||
|
|
||||||
if (avatarBytes != null) {
|
if (avatarChanged) {
|
||||||
String cdnKey = groupsV2Api.uploadAvatar(avatarBytes, groupSecretParams, authorization.getAuthorizationForToday(selfUuid, groupSecretParams));
|
String cdnKey = avatarBytes != null ? groupsV2Api.uploadAvatar(avatarBytes, groupSecretParams, authorization.getAuthorizationForToday(selfUuid, groupSecretParams))
|
||||||
|
: "";
|
||||||
change.setModifyAvatar(GroupChange.Actions.ModifyAvatarAction.newBuilder()
|
change.setModifyAvatar(GroupChange.Actions.ModifyAvatarAction.newBuilder()
|
||||||
.setAvatar(cdnKey));
|
.setAvatar(cdnKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupManager.GroupActionResult groupActionResult = commitChangeWithConflictResolution(change);
|
GroupManager.GroupActionResult groupActionResult = commitChangeWithConflictResolution(change);
|
||||||
|
|
||||||
if (avatarBytes != null) {
|
if (avatarChanged) {
|
||||||
AvatarHelper.setAvatar(context, Recipient.externalGroup(context, groupId).getId(), new ByteArrayInputStream(avatarBytes));
|
AvatarHelper.setAvatar(context, Recipient.externalGroup(context, groupId).getId(), avatarBytes != null ? new ByteArrayInputStream(avatarBytes) : null);
|
||||||
groupDatabase.onAvatarUpdated(groupId, true);
|
groupDatabase.onAvatarUpdated(groupId, avatarBytes != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupActionResult;
|
return groupActionResult;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.groups.v2.processing;
|
package org.thoughtcrime.securesms.groups.v2.processing;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -11,7 +12,6 @@ import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
|
|||||||
import org.signal.zkgroup.VerificationFailedException;
|
import org.signal.zkgroup.VerificationFailedException;
|
||||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
import org.signal.zkgroup.groups.GroupSecretParams;
|
import org.signal.zkgroup.groups.GroupSecretParams;
|
||||||
import org.signal.zkgroup.util.UUIDUtil;
|
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||||
@ -223,15 +223,18 @@ public final class GroupsV2StateProcessor {
|
|||||||
private void updateLocalDatabaseGroupState(@NonNull GlobalGroupState inputGroupState,
|
private void updateLocalDatabaseGroupState(@NonNull GlobalGroupState inputGroupState,
|
||||||
@NonNull DecryptedGroup newLocalState)
|
@NonNull DecryptedGroup newLocalState)
|
||||||
{
|
{
|
||||||
|
boolean needsAvatarFetch;
|
||||||
|
|
||||||
if (inputGroupState.getLocalState() == null) {
|
if (inputGroupState.getLocalState() == null) {
|
||||||
groupDatabase.create(masterKey, newLocalState);
|
groupDatabase.create(masterKey, newLocalState);
|
||||||
|
needsAvatarFetch = !TextUtils.isEmpty(newLocalState.getAvatar());
|
||||||
} else {
|
} else {
|
||||||
groupDatabase.update(masterKey, newLocalState);
|
groupDatabase.update(masterKey, newLocalState);
|
||||||
|
needsAvatarFetch = !newLocalState.getAvatar().equals(inputGroupState.getLocalState().getAvatar());
|
||||||
}
|
}
|
||||||
|
|
||||||
String avatar = newLocalState.getAvatar();
|
if (needsAvatarFetch) {
|
||||||
if (!avatar.isEmpty()) {
|
jobManager.add(new AvatarGroupsV2DownloadJob(groupId, newLocalState.getAvatar()));
|
||||||
jobManager.add(new AvatarGroupsV2DownloadJob(groupId, avatar));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean fullMemberPostUpdate = GroupProtoUtil.isMember(Recipient.self().getUuid().get(), newLocalState.getMembersList());
|
final boolean fullMemberPostUpdate = GroupProtoUtil.isMember(Recipient.self().getUuid().get(), newLocalState.getMembersList());
|
||||||
|
@ -46,14 +46,7 @@ public final class AvatarGroupsV2DownloadJob extends BaseJob {
|
|||||||
.setMaxAttempts(10)
|
.setMaxAttempts(10)
|
||||||
.build(),
|
.build(),
|
||||||
groupId,
|
groupId,
|
||||||
requireNonEmpty(cdnKey));
|
cdnKey);
|
||||||
}
|
|
||||||
|
|
||||||
private static String requireNonEmpty(@NonNull String string) {
|
|
||||||
if (string.isEmpty()) {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AvatarGroupsV2DownloadJob(@NonNull Parameters parameters, @NonNull GroupId.V2 groupId, @NonNull String cdnKey) {
|
private AvatarGroupsV2DownloadJob(@NonNull Parameters parameters, @NonNull GroupId.V2 groupId, @NonNull String cdnKey) {
|
||||||
@ -87,6 +80,15 @@ public final class AvatarGroupsV2DownloadJob extends BaseJob {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cdnKey.length() == 0) {
|
||||||
|
Log.w(TAG, "Removing avatar for group " + groupId);
|
||||||
|
AvatarHelper.setAvatar(context, record.get().getRecipientId(), null);
|
||||||
|
database.onAvatarUpdated(groupId, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "Downloading new avatar for group " + groupId);
|
||||||
|
|
||||||
attachment = File.createTempFile("avatar", "gv2", context.getCacheDir());
|
attachment = File.createTempFile("avatar", "gv2", context.getCacheDir());
|
||||||
attachment.deleteOnExit();
|
attachment.deleteOnExit();
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class EditProfileViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRemoveProfilePhoto() {
|
public boolean canRemoveProfilePhoto() {
|
||||||
return (!isGroup() || groupId.isV1()) && hasAvatar();
|
return hasAvatar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
|
Loading…
x
Reference in New Issue
Block a user