import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
-import org.asamk.signal.manager.storage.protocol.IdentityInfo;
-import org.asamk.signal.manager.util.Utils;
import org.asamk.signal.util.ErrorUtils;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.whispersystems.libsignal.util.guava.Optional;
}
}
+ @Override
+ public long sendMessageReaction(
+ final String emoji, final boolean remove, final String targetAuthor, final long targetSentTimestamp, final String recipient
+ ) {
+ var recipients = new ArrayList<String>(1);
+ recipients.add(recipient);
+ return sendMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, recipients);
+ }
+
+ @Override
+ public long sendMessageReaction(
+ final String emoji, final boolean remove, final String targetAuthor, final long targetSentTimestamp, final List<String> recipients
+ ) {
+ try {
+ final var results = m.sendMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, recipients);
+ checkSendMessageResults(results.first(), results.second());
+ return results.first();
+ } catch (InvalidNumberException e) {
+ throw new Error.InvalidNumber(e.getMessage());
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
+ }
+ }
+
@Override
public long sendNoteToSelfMessage(
final String message, final List<String> attachments
}
}
+ @Override
+ public long sendGroupMessageReaction(
+ final String emoji, final boolean remove, final String targetAuthor, final long targetSentTimestamp, final byte[] groupId
+ ) {
+ try {
+ final var results = m.sendGroupMessageReaction(emoji, remove, targetAuthor, targetSentTimestamp, GroupId.unknownVersion(groupId));
+ checkSendMessageResults(results.first(), results.second());
+ return results.first();
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
+ } catch (InvalidNumberException e) {
+ throw new Error.InvalidNumber(e.getMessage());
+ } catch (GroupNotFoundException | NotAGroupMemberException e) {
+ throw new Error.GroupNotFound(e.getMessage());
+ }
+ }
+
// Since contact names might be empty if not defined, also potentially return
// the profile name
@Override
public String getContactName(final String number) {
- String name = "";
try {
- name = m.getContactOrProfileName(number);
+ return m.getContactOrProfileName(number);
} catch (Exception e) {
throw new Error.InvalidNumber(e.getMessage());
}
- return name;
}
@Override
@Override
public List<String> getContactNumber(final String name) {
- // Contact names have precendence.
- List<String> numbers = new ArrayList<>();
+ // Contact names have precedence.
+ var numbers = new ArrayList<String>();
var contacts = m.getContacts();
for (var c : contacts) {
if (c.name != null && c.name.equals(name)) {
}
}
// Try profiles if no contact name was found
- for (IdentityInfo identity : m.getIdentities()) {
- String number = identity.getAddress().getNumber().orNull();
+ for (var identity : m.getIdentities()) {
+ final var address = identity.getAddress();
+ var number = address.getNumber().orNull();
if (number != null) {
- var address = Utils.getSignalServiceAddressFromIdentifier(number);
var profile = m.getRecipientProfile(address);
- String profileName = profile.getDisplayName();
- if (profileName.equals(name)) {
+ if (profile != null && profile.getDisplayName().equals(name)) {
numbers.add(number);
}
}
}
- if (numbers.size() == 0) {
- throw new Error.Failure("Contact name not found");
- }
return numbers;
}
@Override
public void joinGroup(final String groupLink) {
- final GroupInviteLinkUrl linkUrl;
try {
- linkUrl = GroupInviteLinkUrl.fromUri(groupLink);
+ final var linkUrl = GroupInviteLinkUrl.fromUri(groupLink);
+ if (linkUrl == null) {
+ throw new Error.Failure("Group link is invalid:");
+ }
m.joinGroup(linkUrl);
} catch (GroupInviteLinkUrl.InvalidGroupLinkException | GroupLinkNotActiveException e) {
throw new Error.Failure("Group link is invalid: " + e.getMessage());
return group.isMember(m.getSelfAddress());
}
}
-
}