import org.asamk.signal.BaseConfig;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.AttachmentInvalidException;
+import org.asamk.signal.manager.api.GroupId;
+import org.asamk.signal.manager.api.GroupInviteLinkUrl;
+import org.asamk.signal.manager.api.GroupLinkState;
+import org.asamk.signal.manager.api.GroupNotFoundException;
+import org.asamk.signal.manager.api.GroupPermission;
+import org.asamk.signal.manager.api.GroupSendingNotAllowedException;
import org.asamk.signal.manager.api.InactiveGroupLinkException;
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
import org.asamk.signal.manager.api.InvalidNumberException;
import org.asamk.signal.manager.api.InvalidStickerException;
+import org.asamk.signal.manager.api.LastGroupAdminException;
import org.asamk.signal.manager.api.Message;
-import org.asamk.signal.manager.api.NotMasterDeviceException;
+import org.asamk.signal.manager.api.NotAGroupMemberException;
+import org.asamk.signal.manager.api.NotPrimaryDeviceException;
+import org.asamk.signal.manager.api.PendingAdminApprovalException;
+import org.asamk.signal.manager.api.RecipientAddress;
import org.asamk.signal.manager.api.RecipientIdentifier;
import org.asamk.signal.manager.api.SendMessageResult;
import org.asamk.signal.manager.api.SendMessageResults;
import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
+import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.api.UserStatus;
-import org.asamk.signal.manager.groups.GroupId;
-import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
-import org.asamk.signal.manager.groups.GroupLinkState;
-import org.asamk.signal.manager.groups.GroupNotFoundException;
-import org.asamk.signal.manager.groups.GroupPermission;
-import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
-import org.asamk.signal.manager.groups.LastGroupAdminException;
-import org.asamk.signal.manager.groups.NotAGroupMemberException;
-import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.asamk.signal.util.SendMessageResultUtils;
import org.freedesktop.dbus.DBusPath;
import org.freedesktop.dbus.connections.impl.DBusConnection;
attachments,
List.of(),
Optional.empty(),
- Optional.empty()),
+ Optional.empty(),
+ List.of(),
+ Optional.empty(),
+ List.of()),
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
.map(RecipientIdentifier.class::cast)
.collect(Collectors.toSet()));
targetSentTimestamp,
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
.map(RecipientIdentifier.class::cast)
- .collect(Collectors.toSet()));
+ .collect(Collectors.toSet()),
+ false);
checkSendMessageResults(results);
return results.timestamp();
} catch (IOException e) {
}
}
+ @Override
+ public long sendPaymentNotification(
+ final byte[] receipt, final String note, final String recipient
+ ) throws Error.Failure {
+ try {
+ final var results = m.sendPaymentNotificationMessage(receipt,
+ note,
+ getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
+ checkSendMessageResults(results);
+ return results.timestamp();
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
+ }
+ }
+
@Override
public void sendTyping(
final String recipient, final boolean stop
attachments,
List.of(),
Optional.empty(),
- Optional.empty()), Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
+ Optional.empty(),
+ List.of(),
+ Optional.empty(),
+ List.of()), Set.of(RecipientIdentifier.NoteToSelf.INSTANCE));
checkSendMessageResults(results);
return results.timestamp();
} catch (AttachmentInvalidException e) {
attachments,
List.of(),
Optional.empty(),
- Optional.empty()), Set.of(getGroupRecipientIdentifier(groupId)));
+ Optional.empty(),
+ List.of(),
+ Optional.empty(),
+ List.of()), Set.of(getGroupRecipientIdentifier(groupId)));
checkSendMessageResults(results);
return results.timestamp();
} catch (IOException | InvalidStickerException e) {
remove,
getSingleRecipientIdentifier(targetAuthor, m.getSelfNumber()),
targetSentTimestamp,
- Set.of(getGroupRecipientIdentifier(groupId)));
+ Set.of(getGroupRecipientIdentifier(groupId)),
+ false);
checkSendMessageResults(results);
return results.timestamp();
} catch (IOException e) {
@Override
public void setContactName(final String number, final String name) {
try {
- m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name);
- } catch (NotMasterDeviceException e) {
+ m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name, "");
+ } catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new Error.Failure("Contact is not registered.");
public void setContactBlocked(final String number, final boolean blocked) {
try {
m.setContactsBlocked(List.of(getSingleRecipientIdentifier(number, m.getSelfNumber())), blocked);
- } catch (NotMasterDeviceException e) {
+ } catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
public void setGroupBlocked(final byte[] groupId, final boolean blocked) {
try {
m.setGroupsBlocked(List.of(getGroupId(groupId)), blocked);
- } catch (NotMasterDeviceException e) {
+ } catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (GroupNotFoundException e) {
throw new Error.GroupNotFound(e.getMessage());
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();
UpdateGroup.newBuilder()
.withName(name)
.withMembers(memberIdentifiers)
- .withAvatarFile(avatar == null ? null : new File(avatar))
+ .withAvatarFile(avatar)
.build());
if (results != null) {
checkGroupSendMessageResults(results.timestamp(), results.results());
about = nullIfEmpty(about);
aboutEmoji = nullIfEmpty(aboutEmoji);
avatarPath = nullIfEmpty(avatarPath);
- Optional<File> avatarFile = removeAvatar
- ? Optional.empty()
- : avatarPath == null ? null : Optional.of(new File(avatarPath));
- m.setProfile(givenName, familyName, about, aboutEmoji, avatarFile);
+ final var avatarFile = removeAvatar || avatarPath == null ? null : avatarPath;
+ m.updateProfile(UpdateProfile.newBuilder()
+ .withGivenName(givenName)
+ .withFamilyName(familyName)
+ .withAbout(about)
+ .withAboutEmoji(aboutEmoji)
+ .withAvatar(avatarFile)
+ .withDeleteAvatar(removeAvatar)
+ .build());
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
m.setRegistrationLockPin(Optional.empty());
} catch (IOException e) {
throw new Error.Failure("Remove pin error: " + e.getMessage());
- } catch (NotMasterDeviceException e) {
+ } catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
}
}
m.setRegistrationLockPin(Optional.of(registrationLockPin));
} catch (IOException e) {
throw new Error.Failure("Set pin error: " + e.getMessage());
- } catch (NotMasterDeviceException e) {
+ } catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
}
}
}
final var result = m.joinGroup(linkUrl);
return result.first().serialize();
+ } catch (PendingAdminApprovalException e) {
+ throw new Error.Failure("Pending admin approval: " + e.getMessage());
} catch (GroupInviteLinkUrl.InvalidGroupLinkException | InactiveGroupLinkException e) {
throw new Error.Failure("Group link is invalid: " + e.getMessage());
} catch (GroupInviteLinkUrl.UnknownGroupLinkVersionException e) {
Optional.ofNullable(linkPreviews)));
} catch (IOException e) {
throw new Error.Failure("UpdateAccount error: " + e.getMessage());
- } catch (NotMasterDeviceException e) {
+ } catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
}
}
public void quitGroup() throws Error.Failure {
try {
m.quitGroup(groupId, Set.of());
- } catch (GroupNotFoundException | NotAGroupMemberException e) {
+ } catch (GroupNotFoundException e) {
throw new Error.GroupNotFound(e.getMessage());
+ } catch (NotAGroupMemberException e) {
+ throw new Error.NotAGroupMember(e.getMessage());
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
} catch (LastGroupAdminException e) {
}
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 setIsBlocked(final boolean isBlocked) {
try {
m.setGroupsBlocked(List.of(groupId), isBlocked);
- } catch (NotMasterDeviceException e) {
+ } catch (NotPrimaryDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (GroupNotFoundException e) {
throw new Error.GroupNotFound(e.getMessage());