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

@ -26,7 +26,6 @@ import org.asamk.signal.util.SendMessageResultUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.stream.Stream;
@ -131,9 +130,7 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
SendGroupMessageResults groupMessageResults = null;
if (groupId == null) {
isNewGroup = true;
var results = m.createGroup(groupName,
groupMembers,
groupAvatar == null ? null : new File(groupAvatar));
var results = m.createGroup(groupName, groupMembers, groupAvatar);
groupMessageResults = results.second();
groupId = results.first();
groupName = null;
@ -155,7 +152,7 @@ public class UpdateGroupCommand implements JsonRpcLocalCommand {
.withGroupLinkState(groupLinkState)
.withAddMemberPermission(groupAddMemberPermission)
.withEditDetailsPermission(groupEditDetailsPermission)
.withAvatarFile(groupAvatar == null ? null : new File(groupAvatar))
.withAvatarFile(groupAvatar)
.withExpirationTimer(groupExpiration)
.withIsAnnouncementGroup(groupSendMessagesPermission == 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.output.OutputWriter;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
@ -50,7 +49,7 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
var avatarPath = ns.getString("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 {
m.updateProfile(UpdateProfile.newBuilder()

View file

@ -147,7 +147,7 @@ public class DbusManagerImpl implements Manager {
emptyIfNull(updateProfile.getFamilyName()),
emptyIfNull(updateProfile.getAbout()),
emptyIfNull(updateProfile.getAboutEmoji()),
updateProfile.getAvatar() == null ? "" : updateProfile.getAvatar().getPath(),
updateProfile.getAvatar() == null ? "" : updateProfile.getAvatar(),
updateProfile.isDeleteAvatar());
}
@ -231,11 +231,11 @@ public class DbusManagerImpl implements Manager {
@Override
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 {
final var newGroupId = signal.createGroup(emptyIfNull(name),
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()));
}
@ -253,7 +253,7 @@ public class DbusManagerImpl implements Manager {
if (updateGroup.getAvatarFile() != null) {
group.Set("org.asamk.Signal.Group",
"Avatar",
updateGroup.getAvatarFile() == null ? "" : updateGroup.getAvatarFile().getPath());
updateGroup.getAvatarFile() == null ? "" : updateGroup.getAvatarFile());
}
if (updateGroup.getExpirationTimer() != null) {
group.Set("org.asamk.Signal.Group", "MessageExpirationTimer", updateGroup.getExpirationTimer());

View file

@ -618,7 +618,7 @@ public class DbusSignalImpl implements Signal {
avatar = nullIfEmpty(avatar);
final var memberIdentifiers = getSingleRecipientIdentifiers(members, m.getSelfNumber());
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();
checkGroupSendMessageResults(results.second().timestamp(), results.second().results());
return results.first().serialize();
@ -627,7 +627,7 @@ public class DbusSignalImpl implements Signal {
UpdateGroup.newBuilder()
.withName(name)
.withMembers(memberIdentifiers)
.withAvatarFile(avatar == null ? null : new File(avatar))
.withAvatarFile(avatar)
.build());
if (results != null) {
checkGroupSendMessageResults(results.timestamp(), results.results());
@ -687,7 +687,7 @@ public class DbusSignalImpl implements Signal {
about = nullIfEmpty(about);
aboutEmoji = nullIfEmpty(aboutEmoji);
avatarPath = nullIfEmpty(avatarPath);
File avatarFile = removeAvatar || avatarPath == null ? null : new File(avatarPath);
final var avatarFile = removeAvatar || avatarPath == null ? null : avatarPath;
m.updateProfile(UpdateProfile.newBuilder()
.withGivenName(givenName)
.withFamilyName(familyName)
@ -1270,7 +1270,7 @@ public class DbusSignalImpl implements Signal {
}
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) {