X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/b738f5740c94fe7a5df9e322e1345a99ef0c5ce5..9f3276d7e359cf681a42c675ad376977d5957395:/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index d19116a4..4af7156d 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -10,13 +10,14 @@ import org.asamk.signal.manager.storage.groups.GroupInfo; import org.asamk.signal.util.ErrorUtils; import org.freedesktop.dbus.exceptions.DBusExecutionException; import org.whispersystems.libsignal.util.Pair; +import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.messages.SendMessageResult; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.util.InvalidNumberException; +import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -45,9 +46,30 @@ public class DbusSignalImpl implements Signal { return sendMessage(message, attachments, recipients); } + private static void checkSendMessageResult(long timestamp, SendMessageResult result) throws DBusExecutionException { + String error = ErrorUtils.getErrorMessageFromSendMessageResult(result); + + if (error == null) { + return; + } + + final String message = timestamp + "\nFailed to send message:\n" + error + '\n'; + + if (result.getIdentityFailure() != null) { + throw new Error.UntrustedIdentity(message); + } else { + throw new Error.Failure(message); + } + } + private static void checkSendMessageResults( long timestamp, List results ) throws DBusExecutionException { + if (results.size() == 1) { + checkSendMessageResult(timestamp, results.get(0)); + return; + } + List errors = ErrorUtils.getErrorMessagesFromSendMessageResults(results); if (errors.size() == 0) { return; @@ -78,6 +100,21 @@ public class DbusSignalImpl implements Signal { } } + @Override + public long sendNoteToSelfMessage( + final String message, final List attachments + ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity { + try { + final Pair results = m.sendSelfMessage(message, attachments); + checkSendMessageResult(results.first(), results.second()); + return results.first(); + } catch (AttachmentInvalidException e) { + throw new Error.AttachmentInvalid(e.getMessage()); + } catch (IOException e) { + throw new Error.Failure(e.getMessage()); + } + } + @Override public void sendEndSessionMessage(final List recipients) { try { @@ -167,7 +204,7 @@ public class DbusSignalImpl implements Signal { public List getGroupMembers(final byte[] groupId) { GroupInfo group = m.getGroup(GroupId.unknownVersion(groupId)); if (group == null) { - return Collections.emptyList(); + return List.of(); } else { return group.getMembers() .stream() @@ -194,7 +231,7 @@ public class DbusSignalImpl implements Signal { } final Pair> results = m.updateGroup(groupId == null ? null - : GroupId.unknownVersion(groupId), name, members, avatar); + : GroupId.unknownVersion(groupId), name, members, avatar == null ? null : new File(avatar)); checkSendMessageResults(0, results.second()); return results.first().serialize(); } catch (IOException e) { @@ -212,4 +249,26 @@ public class DbusSignalImpl implements Signal { public boolean isRegistered() { return true; } + + @Override + public void updateProfile( + final String name, + final String about, + final String aboutEmoji, + String avatarPath, + final boolean removeAvatar + ) { + try { + if (avatarPath.isEmpty()) { + avatarPath = null; + } + Optional avatarFile = removeAvatar + ? Optional.absent() + : avatarPath == null ? null : Optional.of(new File(avatarPath)); + m.setProfile(name, about, aboutEmoji, avatarFile); + } catch (IOException e) { + throw new Error.Failure(e.getMessage()); + } + } + }