Allow using data URIs for updateGroup/updateProfile avatars

Fixes #1082
This commit is contained in:
AsamK 2022-11-14 19:31:40 +01:00
parent dcaf1cc189
commit 5771bb858f
11 changed files with 60 additions and 73 deletions

View file

@ -102,7 +102,7 @@ public interface Manager extends Closeable {
void deleteGroup(GroupId groupId) throws IOException; void deleteGroup(GroupId groupId) throws IOException;
Pair<GroupId, SendGroupMessageResults> createGroup( Pair<GroupId, SendGroupMessageResults> createGroup(
String name, Set<RecipientIdentifier.Single> members, File avatarFile String name, Set<RecipientIdentifier.Single> members, String avatarFile
) throws IOException, AttachmentInvalidException, UnregisteredRecipientException; ) throws IOException, AttachmentInvalidException, UnregisteredRecipientException;
SendGroupMessageResults updateGroup( SendGroupMessageResults updateGroup(

View file

@ -394,7 +394,7 @@ class ManagerImpl implements Manager {
@Override @Override
public Pair<GroupId, SendGroupMessageResults> createGroup( public Pair<GroupId, SendGroupMessageResults> createGroup(
String name, Set<RecipientIdentifier.Single> members, File avatarFile String name, Set<RecipientIdentifier.Single> members, String avatarFile
) throws IOException, AttachmentInvalidException, UnregisteredRecipientException { ) throws IOException, AttachmentInvalidException, UnregisteredRecipientException {
return context.getGroupHelper() return context.getGroupHelper()
.createGroup(name, .createGroup(name,

View file

@ -3,7 +3,6 @@ package org.asamk.signal.manager.api;
import org.asamk.signal.manager.groups.GroupLinkState; import org.asamk.signal.manager.groups.GroupLinkState;
import org.asamk.signal.manager.groups.GroupPermission; import org.asamk.signal.manager.groups.GroupPermission;
import java.io.File;
import java.util.Set; import java.util.Set;
public class UpdateGroup { public class UpdateGroup {
@ -20,7 +19,7 @@ public class UpdateGroup {
private final GroupLinkState groupLinkState; private final GroupLinkState groupLinkState;
private final GroupPermission addMemberPermission; private final GroupPermission addMemberPermission;
private final GroupPermission editDetailsPermission; private final GroupPermission editDetailsPermission;
private final File avatarFile; private final String avatarFile;
private final Integer expirationTimer; private final Integer expirationTimer;
private final Boolean isAnnouncementGroup; private final Boolean isAnnouncementGroup;
@ -77,7 +76,7 @@ public class UpdateGroup {
final GroupLinkState groupLinkState, final GroupLinkState groupLinkState,
final GroupPermission addMemberPermission, final GroupPermission addMemberPermission,
final GroupPermission editDetailsPermission, final GroupPermission editDetailsPermission,
final File avatarFile, final String avatarFile,
final Integer expirationTimer, final Integer expirationTimer,
final Boolean isAnnouncementGroup final Boolean isAnnouncementGroup
) { ) {
@ -146,7 +145,7 @@ public class UpdateGroup {
return editDetailsPermission; return editDetailsPermission;
} }
public File getAvatarFile() { public String getAvatarFile() {
return avatarFile; return avatarFile;
} }
@ -172,7 +171,7 @@ public class UpdateGroup {
private GroupLinkState groupLinkState; private GroupLinkState groupLinkState;
private GroupPermission addMemberPermission; private GroupPermission addMemberPermission;
private GroupPermission editDetailsPermission; private GroupPermission editDetailsPermission;
private File avatarFile; private String avatarFile;
private Integer expirationTimer; private Integer expirationTimer;
private Boolean isAnnouncementGroup; private Boolean isAnnouncementGroup;
@ -192,7 +191,7 @@ public class UpdateGroup {
final GroupLinkState groupLinkState, final GroupLinkState groupLinkState,
final GroupPermission addMemberPermission, final GroupPermission addMemberPermission,
final GroupPermission editDetailsPermission, final GroupPermission editDetailsPermission,
final File avatarFile, final String avatarFile,
final Integer expirationTimer, final Integer expirationTimer,
final Boolean isAnnouncementGroup final Boolean isAnnouncementGroup
) { ) {
@ -273,7 +272,7 @@ public class UpdateGroup {
return this; return this;
} }
public Builder withAvatarFile(final File val) { public Builder withAvatarFile(final String val) {
avatarFile = val; avatarFile = val;
return this; return this;
} }

View file

@ -1,14 +1,12 @@
package org.asamk.signal.manager.api; package org.asamk.signal.manager.api;
import java.io.File;
public class UpdateProfile { public class UpdateProfile {
private final String givenName; private final String givenName;
private final String familyName; private final String familyName;
private final String about; private final String about;
private final String aboutEmoji; private final String aboutEmoji;
private final File avatar; private final String avatar;
private final boolean deleteAvatar; private final boolean deleteAvatar;
private final byte[] mobileCoinAddress; private final byte[] mobileCoinAddress;
@ -54,7 +52,7 @@ public class UpdateProfile {
return aboutEmoji; return aboutEmoji;
} }
public File getAvatar() { public String getAvatar() {
return avatar; return avatar;
} }
@ -72,7 +70,7 @@ public class UpdateProfile {
private String familyName; private String familyName;
private String about; private String about;
private String aboutEmoji; private String aboutEmoji;
private File avatar; private String avatar;
private boolean deleteAvatar; private boolean deleteAvatar;
private byte[] mobileCoinAddress; private byte[] mobileCoinAddress;
@ -99,7 +97,7 @@ public class UpdateProfile {
return this; return this;
} }
public Builder withAvatar(final File val) { public Builder withAvatar(final String val) {
avatar = val; avatar = val;
return this; return this;
} }

View file

@ -26,6 +26,7 @@ import org.asamk.signal.manager.storage.groups.GroupInfoV2;
import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.asamk.signal.manager.util.AttachmentUtils; import org.asamk.signal.manager.util.AttachmentUtils;
import org.asamk.signal.manager.util.IOUtils; import org.asamk.signal.manager.util.IOUtils;
import org.asamk.signal.manager.util.Utils;
import org.signal.libsignal.zkgroup.InvalidInputException; import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.groups.GroupMasterKey; import org.signal.libsignal.zkgroup.groups.GroupMasterKey;
import org.signal.libsignal.zkgroup.groups.GroupSecretParams; import org.signal.libsignal.zkgroup.groups.GroupSecretParams;
@ -47,7 +48,6 @@ import org.whispersystems.signalservice.api.push.DistributionId;
import org.whispersystems.signalservice.api.push.ServiceId; import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.exceptions.ConflictException; import org.whispersystems.signalservice.api.push.exceptions.ConflictException;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -164,7 +164,7 @@ public class GroupHelper {
} }
public Pair<GroupId, SendGroupMessageResults> createGroup( public Pair<GroupId, SendGroupMessageResults> createGroup(
String name, Set<RecipientId> members, File avatarFile String name, Set<RecipientId> members, String avatarFile
) throws IOException, AttachmentInvalidException { ) throws IOException, AttachmentInvalidException {
final var selfRecipientId = account.getSelfRecipientId(); final var selfRecipientId = account.getSelfRecipientId();
if (members != null && members.contains(selfRecipientId)) { if (members != null && members.contains(selfRecipientId)) {
@ -172,14 +172,15 @@ public class GroupHelper {
members.remove(selfRecipientId); members.remove(selfRecipientId);
} }
final var avatarBytes = readAvatarBytes(avatarFile);
var gv2Pair = context.getGroupV2Helper() var gv2Pair = context.getGroupV2Helper()
.createGroup(name == null ? "" : name, members == null ? Set.of() : members, avatarFile); .createGroup(name == null ? "" : name, members == null ? Set.of() : members, avatarBytes);
if (gv2Pair == null) { if (gv2Pair == null) {
// Failed to create v2 group, creating v1 group instead // Failed to create v2 group, creating v1 group instead
var gv1 = new GroupInfoV1(GroupIdV1.createRandom()); var gv1 = new GroupInfoV1(GroupIdV1.createRandom());
gv1.addMembers(List.of(selfRecipientId)); gv1.addMembers(List.of(selfRecipientId));
final var result = updateGroupV1(gv1, name, members, avatarFile); final var result = updateGroupV1(gv1, name, members, avatarBytes);
return new Pair<>(gv1.getGroupId(), result); return new Pair<>(gv1.getGroupId(), result);
} }
@ -187,10 +188,9 @@ public class GroupHelper {
final var decryptedGroup = gv2Pair.second(); final var decryptedGroup = gv2Pair.second();
gv2.setGroup(decryptedGroup); gv2.setGroup(decryptedGroup);
if (avatarFile != null) { if (avatarBytes != null) {
context.getAvatarStore() context.getAvatarStore()
.storeGroupAvatar(gv2.getGroupId(), .storeGroupAvatar(gv2.getGroupId(), outputStream -> outputStream.write(avatarBytes));
outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream));
} }
account.getGroupStore().updateGroup(gv2); account.getGroupStore().updateGroup(gv2);
@ -217,11 +217,12 @@ public class GroupHelper {
final GroupLinkState groupLinkState, final GroupLinkState groupLinkState,
final GroupPermission addMemberPermission, final GroupPermission addMemberPermission,
final GroupPermission editDetailsPermission, final GroupPermission editDetailsPermission,
final File avatarFile, final String avatarFile,
final Integer expirationTimer, final Integer expirationTimer,
final Boolean isAnnouncementGroup final Boolean isAnnouncementGroup
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException { ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException {
var group = getGroupForUpdating(groupId); var group = getGroupForUpdating(groupId);
final var avatarBytes = readAvatarBytes(avatarFile);
if (group instanceof GroupInfoV2) { if (group instanceof GroupInfoV2) {
try { try {
@ -238,7 +239,7 @@ public class GroupHelper {
groupLinkState, groupLinkState,
addMemberPermission, addMemberPermission,
editDetailsPermission, editDetailsPermission,
avatarFile, avatarBytes,
expirationTimer, expirationTimer,
isAnnouncementGroup); isAnnouncementGroup);
} catch (ConflictException e) { } catch (ConflictException e) {
@ -257,14 +258,14 @@ public class GroupHelper {
groupLinkState, groupLinkState,
addMemberPermission, addMemberPermission,
editDetailsPermission, editDetailsPermission,
avatarFile, avatarBytes,
expirationTimer, expirationTimer,
isAnnouncementGroup); isAnnouncementGroup);
} }
} }
final var gv1 = (GroupInfoV1) group; final var gv1 = (GroupInfoV1) group;
final var result = updateGroupV1(gv1, name, members, avatarFile); final var result = updateGroupV1(gv1, name, members, avatarBytes);
if (expirationTimer != null) { if (expirationTimer != null) {
setExpirationTimer(gv1, expirationTimer); setExpirationTimer(gv1, expirationTimer);
} }
@ -521,7 +522,7 @@ public class GroupHelper {
} }
private SendGroupMessageResults updateGroupV1( private SendGroupMessageResults updateGroupV1(
final GroupInfoV1 gv1, final String name, final Set<RecipientId> members, final File avatarFile final GroupInfoV1 gv1, final String name, final Set<RecipientId> members, final byte[] avatarFile
) throws IOException, AttachmentInvalidException { ) throws IOException, AttachmentInvalidException {
updateGroupV1Details(gv1, name, members, avatarFile); updateGroupV1Details(gv1, name, members, avatarFile);
@ -534,7 +535,7 @@ public class GroupHelper {
} }
private void updateGroupV1Details( private void updateGroupV1Details(
final GroupInfoV1 g, final String name, final Collection<RecipientId> members, final File avatarFile final GroupInfoV1 g, final String name, final Collection<RecipientId> members, final byte[] avatarFile
) throws IOException { ) throws IOException {
if (name != null) { if (name != null) {
g.name = name; g.name = name;
@ -545,9 +546,7 @@ public class GroupHelper {
} }
if (avatarFile != null) { if (avatarFile != null) {
context.getAvatarStore() context.getAvatarStore().storeGroupAvatar(g.getGroupId(), outputStream -> outputStream.write(avatarFile));
.storeGroupAvatar(g.getGroupId(),
outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream));
} }
} }
@ -581,7 +580,7 @@ public class GroupHelper {
final GroupLinkState groupLinkState, final GroupLinkState groupLinkState,
final GroupPermission addMemberPermission, final GroupPermission addMemberPermission,
final GroupPermission editDetailsPermission, final GroupPermission editDetailsPermission,
final File avatarFile, final byte[] avatarFile,
final Integer expirationTimer, final Integer expirationTimer,
final Boolean isAnnouncementGroup final Boolean isAnnouncementGroup
) throws IOException { ) throws IOException {
@ -716,8 +715,7 @@ public class GroupHelper {
var groupGroupChangePair = groupV2Helper.updateGroup(group, name, description, avatarFile); var groupGroupChangePair = groupV2Helper.updateGroup(group, name, description, avatarFile);
if (avatarFile != null) { if (avatarFile != null) {
context.getAvatarStore() context.getAvatarStore()
.storeGroupAvatar(group.getGroupId(), .storeGroupAvatar(group.getGroupId(), outputStream -> outputStream.write(avatarFile));
outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream));
} }
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
} }
@ -819,4 +817,13 @@ public class GroupHelper {
account.getRecipientAddressResolver())) account.getRecipientAddressResolver()))
.toList()); .toList());
} }
private byte[] readAvatarBytes(final String avatarFile) throws IOException {
if (avatarFile == null) {
return null;
}
try (final var avatar = Utils.createStreamDetails(avatarFile).first().getStream()) {
return IOUtils.readFully(avatar);
}
}
} }

View file

@ -12,7 +12,6 @@ import org.asamk.signal.manager.groups.GroupUtils;
import org.asamk.signal.manager.groups.NotAGroupMemberException; import org.asamk.signal.manager.groups.NotAGroupMemberException;
import org.asamk.signal.manager.storage.groups.GroupInfoV2; import org.asamk.signal.manager.storage.groups.GroupInfoV2;
import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.asamk.signal.manager.util.IOUtils;
import org.asamk.signal.manager.util.Utils; import org.asamk.signal.manager.util.Utils;
import org.signal.libsignal.zkgroup.InvalidInputException; import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.VerificationFailedException; import org.signal.libsignal.zkgroup.VerificationFailedException;
@ -47,10 +46,7 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException; import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
import org.whispersystems.signalservice.api.util.UuidUtil; import org.whispersystems.signalservice.api.util.UuidUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -138,10 +134,9 @@ class GroupV2Helper {
} }
Pair<GroupInfoV2, DecryptedGroup> createGroup( Pair<GroupInfoV2, DecryptedGroup> createGroup(
String name, Set<RecipientId> members, File avatarFile String name, Set<RecipientId> members, byte[] avatarFile
) throws IOException { ) {
final var avatarBytes = readAvatarBytes(avatarFile); final var newGroup = buildNewGroup(name, members, avatarFile);
final var newGroup = buildNewGroup(name, members, avatarBytes);
if (newGroup == null) { if (newGroup == null) {
return null; return null;
} }
@ -170,14 +165,6 @@ class GroupV2Helper {
return new Pair<>(g, decryptedGroup); return new Pair<>(g, decryptedGroup);
} }
private byte[] readAvatarBytes(final File avatarFile) throws IOException {
final byte[] avatarBytes;
try (InputStream avatar = avatarFile == null ? null : new FileInputStream(avatarFile)) {
avatarBytes = avatar == null ? null : IOUtils.readFully(avatar);
}
return avatarBytes;
}
private GroupsV2Operations.NewGroup buildNewGroup( private GroupsV2Operations.NewGroup buildNewGroup(
String name, Set<RecipientId> members, byte[] avatar String name, Set<RecipientId> members, byte[] avatar
) { ) {
@ -210,7 +197,7 @@ class GroupV2Helper {
} }
Pair<DecryptedGroup, GroupChange> updateGroup( Pair<DecryptedGroup, GroupChange> updateGroup(
GroupInfoV2 groupInfoV2, String name, String description, File avatarFile GroupInfoV2 groupInfoV2, String name, String description, byte[] avatarFile
) throws IOException { ) throws IOException {
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey()); final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
var groupOperations = dependencies.getGroupsV2Operations().forGroup(groupSecretParams); var groupOperations = dependencies.getGroupsV2Operations().forGroup(groupSecretParams);
@ -222,9 +209,8 @@ class GroupV2Helper {
} }
if (avatarFile != null) { if (avatarFile != null) {
final var avatarBytes = readAvatarBytes(avatarFile);
var avatarCdnKey = dependencies.getGroupsV2Api() var avatarCdnKey = dependencies.getGroupsV2Api()
.uploadAvatar(avatarBytes, groupSecretParams, getGroupAuthForToday(groupSecretParams)); .uploadAvatar(avatarFile, groupSecretParams, getGroupAuthForToday(groupSecretParams));
change.setModifyAvatar(GroupChange.Actions.ModifyAvatarAction.newBuilder().setAvatar(avatarCdnKey)); change.setModifyAvatar(GroupChange.Actions.ModifyAvatarAction.newBuilder().setAvatar(avatarCdnKey));
} }

View file

@ -30,7 +30,6 @@ import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException
import org.whispersystems.signalservice.api.services.ProfileService; import org.whispersystems.signalservice.api.services.ProfileService;
import org.whispersystems.signalservice.api.util.ExpiringProfileCredentialUtil; import org.whispersystems.signalservice.api.util.ExpiringProfileCredentialUtil;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
@ -146,7 +145,7 @@ public final class ProfileHelper {
final String familyName, final String familyName,
String about, String about,
String aboutEmoji, String aboutEmoji,
Optional<File> avatar, Optional<String> avatar,
byte[] mobileCoinAddress byte[] mobileCoinAddress
) throws IOException { ) throws IOException {
setProfile(true, false, givenName, familyName, about, aboutEmoji, avatar, mobileCoinAddress); setProfile(true, false, givenName, familyName, about, aboutEmoji, avatar, mobileCoinAddress);
@ -159,7 +158,7 @@ public final class ProfileHelper {
final String familyName, final String familyName,
String about, String about,
String aboutEmoji, String aboutEmoji,
Optional<File> avatar, Optional<String> avatar,
byte[] mobileCoinAddress byte[] mobileCoinAddress
) throws IOException { ) throws IOException {
var profile = getSelfProfile(); var profile = getSelfProfile();
@ -183,7 +182,8 @@ public final class ProfileHelper {
if (uploadProfile) { if (uploadProfile) {
final var streamDetails = avatar != null && avatar.isPresent() final var streamDetails = avatar != null && avatar.isPresent()
? Utils.createStreamDetailsFromFile(avatar.get()) ? Utils.createStreamDetails(avatar.get())
.first()
: forceUploadAvatar && avatar == null ? context.getAvatarStore() : forceUploadAvatar && avatar == null ? context.getAvatarStore()
.retrieveProfileAvatar(account.getSelfRecipientAddress()) : null; .retrieveProfileAvatar(account.getSelfRecipientAddress()) : null;
try (streamDetails) { try (streamDetails) {
@ -212,9 +212,10 @@ public final class ProfileHelper {
if (avatar != null) { if (avatar != null) {
if (avatar.isPresent()) { if (avatar.isPresent()) {
final var streamDetails = Utils.createStreamDetails(avatar.get()).first();
context.getAvatarStore() context.getAvatarStore()
.storeProfileAvatar(account.getSelfRecipientAddress(), .storeProfileAvatar(account.getSelfRecipientAddress(),
outputStream -> IOUtils.copyFileToStream(avatar.get(), outputStream)); outputStream -> IOUtils.copyStream(streamDetails.getStream(), outputStream));
} else { } else {
context.getAvatarStore().deleteProfileAvatar(account.getSelfRecipientAddress()); context.getAvatarStore().deleteProfileAvatar(account.getSelfRecipientAddress());
} }

View file

@ -26,7 +26,6 @@ import org.asamk.signal.util.SendMessageResultUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -131,9 +130,7 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
SendGroupMessageResults groupMessageResults = null; SendGroupMessageResults groupMessageResults = null;
if (groupId == null) { if (groupId == null) {
isNewGroup = true; isNewGroup = true;
var results = m.createGroup(groupName, var results = m.createGroup(groupName, groupMembers, groupAvatar);
groupMembers,
groupAvatar == null ? null : new File(groupAvatar));
groupMessageResults = results.second(); groupMessageResults = results.second();
groupId = results.first(); groupId = results.first();
groupName = null; groupName = null;
@ -155,7 +152,7 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
.withGroupLinkState(groupLinkState) .withGroupLinkState(groupLinkState)
.withAddMemberPermission(groupAddMemberPermission) .withAddMemberPermission(groupAddMemberPermission)
.withEditDetailsPermission(groupEditDetailsPermission) .withEditDetailsPermission(groupEditDetailsPermission)
.withAvatarFile(groupAvatar == null ? null : new File(groupAvatar)) .withAvatarFile(groupAvatar)
.withExpirationTimer(groupExpiration) .withExpirationTimer(groupExpiration)
.withIsAnnouncementGroup(groupSendMessagesPermission == null .withIsAnnouncementGroup(groupSendMessagesPermission == null
? null ? null

View file

@ -10,7 +10,6 @@ import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.UpdateProfile; import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.output.OutputWriter; import org.asamk.signal.output.OutputWriter;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Base64; import java.util.Base64;
@ -50,7 +49,7 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
var avatarPath = ns.getString("avatar"); var avatarPath = ns.getString("avatar");
boolean removeAvatar = Boolean.TRUE.equals(ns.getBoolean("remove-avatar")); boolean removeAvatar = Boolean.TRUE.equals(ns.getBoolean("remove-avatar"));
File avatarFile = removeAvatar || avatarPath == null ? null : new File(avatarPath); String avatarFile = removeAvatar || avatarPath == null ? null : avatarPath;
try { try {
m.updateProfile(UpdateProfile.newBuilder() m.updateProfile(UpdateProfile.newBuilder()

View file

@ -147,7 +147,7 @@ public class DbusManagerImpl implements Manager {
emptyIfNull(updateProfile.getFamilyName()), emptyIfNull(updateProfile.getFamilyName()),
emptyIfNull(updateProfile.getAbout()), emptyIfNull(updateProfile.getAbout()),
emptyIfNull(updateProfile.getAboutEmoji()), emptyIfNull(updateProfile.getAboutEmoji()),
updateProfile.getAvatar() == null ? "" : updateProfile.getAvatar().getPath(), updateProfile.getAvatar() == null ? "" : updateProfile.getAvatar(),
updateProfile.isDeleteAvatar()); updateProfile.isDeleteAvatar());
} }
@ -231,11 +231,11 @@ public class DbusManagerImpl implements Manager {
@Override @Override
public Pair<GroupId, SendGroupMessageResults> createGroup( public Pair<GroupId, SendGroupMessageResults> createGroup(
final String name, final Set<RecipientIdentifier.Single> members, final File avatarFile final String name, final Set<RecipientIdentifier.Single> members, final String avatarFile
) throws IOException, AttachmentInvalidException { ) throws IOException, AttachmentInvalidException {
final var newGroupId = signal.createGroup(emptyIfNull(name), final var newGroupId = signal.createGroup(emptyIfNull(name),
members.stream().map(RecipientIdentifier.Single::getIdentifier).toList(), members.stream().map(RecipientIdentifier.Single::getIdentifier).toList(),
avatarFile == null ? "" : avatarFile.getPath()); avatarFile == null ? "" : avatarFile);
return new Pair<>(GroupId.unknownVersion(newGroupId), new SendGroupMessageResults(0, List.of())); return new Pair<>(GroupId.unknownVersion(newGroupId), new SendGroupMessageResults(0, List.of()));
} }
@ -253,7 +253,7 @@ public class DbusManagerImpl implements Manager {
if (updateGroup.getAvatarFile() != null) { if (updateGroup.getAvatarFile() != null) {
group.Set("org.asamk.Signal.Group", group.Set("org.asamk.Signal.Group",
"Avatar", "Avatar",
updateGroup.getAvatarFile() == null ? "" : updateGroup.getAvatarFile().getPath()); updateGroup.getAvatarFile() == null ? "" : updateGroup.getAvatarFile());
} }
if (updateGroup.getExpirationTimer() != null) { if (updateGroup.getExpirationTimer() != null) {
group.Set("org.asamk.Signal.Group", "MessageExpirationTimer", updateGroup.getExpirationTimer()); group.Set("org.asamk.Signal.Group", "MessageExpirationTimer", updateGroup.getExpirationTimer());

View file

@ -618,7 +618,7 @@ public class DbusSignalImpl implements Signal {
avatar = nullIfEmpty(avatar); avatar = nullIfEmpty(avatar);
final var memberIdentifiers = getSingleRecipientIdentifiers(members, m.getSelfNumber()); final var memberIdentifiers = getSingleRecipientIdentifiers(members, m.getSelfNumber());
if (groupId == null) { if (groupId == null) {
final var results = m.createGroup(name, memberIdentifiers, avatar == null ? null : new File(avatar)); final var results = m.createGroup(name, memberIdentifiers, avatar);
updateGroups(); updateGroups();
checkGroupSendMessageResults(results.second().timestamp(), results.second().results()); checkGroupSendMessageResults(results.second().timestamp(), results.second().results());
return results.first().serialize(); return results.first().serialize();
@ -627,7 +627,7 @@ public class DbusSignalImpl implements Signal {
UpdateGroup.newBuilder() UpdateGroup.newBuilder()
.withName(name) .withName(name)
.withMembers(memberIdentifiers) .withMembers(memberIdentifiers)
.withAvatarFile(avatar == null ? null : new File(avatar)) .withAvatarFile(avatar)
.build()); .build());
if (results != null) { if (results != null) {
checkGroupSendMessageResults(results.timestamp(), results.results()); checkGroupSendMessageResults(results.timestamp(), results.results());
@ -687,7 +687,7 @@ public class DbusSignalImpl implements Signal {
about = nullIfEmpty(about); about = nullIfEmpty(about);
aboutEmoji = nullIfEmpty(aboutEmoji); aboutEmoji = nullIfEmpty(aboutEmoji);
avatarPath = nullIfEmpty(avatarPath); avatarPath = nullIfEmpty(avatarPath);
File avatarFile = removeAvatar || avatarPath == null ? null : new File(avatarPath); final var avatarFile = removeAvatar || avatarPath == null ? null : avatarPath;
m.updateProfile(UpdateProfile.newBuilder() m.updateProfile(UpdateProfile.newBuilder()
.withGivenName(givenName) .withGivenName(givenName)
.withFamilyName(familyName) .withFamilyName(familyName)
@ -1270,7 +1270,7 @@ public class DbusSignalImpl implements Signal {
} }
private void setGroupAvatar(final String avatar) { private void setGroupAvatar(final String avatar) {
updateGroup(UpdateGroup.newBuilder().withAvatarFile(new File(avatar)).build()); updateGroup(UpdateGroup.newBuilder().withAvatarFile(avatar).build());
} }
private void setMessageExpirationTime(final int expirationTime) { private void setMessageExpirationTime(final int expirationTime) {