1 package org
.asamk
.signal
.dbus
;
3 import org
.asamk
.Signal
;
4 import org
.asamk
.signal
.BaseConfig
;
5 import org
.asamk
.signal
.manager
.Manager
;
6 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
7 import org
.asamk
.signal
.manager
.api
.DeviceLinkUrl
;
8 import org
.asamk
.signal
.manager
.api
.GroupId
;
9 import org
.asamk
.signal
.manager
.api
.GroupInviteLinkUrl
;
10 import org
.asamk
.signal
.manager
.api
.GroupLinkState
;
11 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
12 import org
.asamk
.signal
.manager
.api
.GroupPermission
;
13 import org
.asamk
.signal
.manager
.api
.GroupSendingNotAllowedException
;
14 import org
.asamk
.signal
.manager
.api
.IdentityVerificationCode
;
15 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
16 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
17 import org
.asamk
.signal
.manager
.api
.InvalidNumberException
;
18 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
19 import org
.asamk
.signal
.manager
.api
.LastGroupAdminException
;
20 import org
.asamk
.signal
.manager
.api
.Message
;
21 import org
.asamk
.signal
.manager
.api
.NotAGroupMemberException
;
22 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
23 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
24 import org
.asamk
.signal
.manager
.api
.RecipientAddress
;
25 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
26 import org
.asamk
.signal
.manager
.api
.SendMessageResult
;
27 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
28 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
29 import org
.asamk
.signal
.manager
.api
.TypingAction
;
30 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
31 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
32 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
33 import org
.asamk
.signal
.manager
.api
.UserStatus
;
34 import org
.asamk
.signal
.util
.SendMessageResultUtils
;
35 import org
.freedesktop
.dbus
.DBusPath
;
36 import org
.freedesktop
.dbus
.connections
.impl
.DBusConnection
;
37 import org
.freedesktop
.dbus
.exceptions
.DBusException
;
38 import org
.freedesktop
.dbus
.exceptions
.DBusExecutionException
;
39 import org
.freedesktop
.dbus
.interfaces
.DBusInterface
;
40 import org
.freedesktop
.dbus
.types
.Variant
;
41 import org
.slf4j
.Logger
;
42 import org
.slf4j
.LoggerFactory
;
45 import java
.io
.IOException
;
47 import java
.net
.URISyntaxException
;
48 import java
.util
.ArrayList
;
49 import java
.util
.Arrays
;
50 import java
.util
.Base64
;
51 import java
.util
.Collection
;
52 import java
.util
.HashSet
;
53 import java
.util
.List
;
55 import java
.util
.Objects
;
56 import java
.util
.Optional
;
58 import java
.util
.UUID
;
59 import java
.util
.stream
.Collectors
;
61 import static org
.asamk
.signal
.dbus
.DbusUtils
.makeValidObjectPathElement
;
63 public class DbusSignalImpl
implements Signal
{
65 private final Manager m
;
66 private final DBusConnection connection
;
67 private final String objectPath
;
68 private final boolean noReceiveOnStart
;
70 private DBusPath thisDevice
;
71 private final List
<StructDevice
> devices
= new ArrayList
<>();
72 private final List
<StructGroup
> groups
= new ArrayList
<>();
73 private final List
<StructIdentity
> identities
= new ArrayList
<>();
74 private DbusReceiveMessageHandler dbusMessageHandler
;
75 private int subscriberCount
;
77 private final static Logger logger
= LoggerFactory
.getLogger(DbusSignalImpl
.class);
79 public DbusSignalImpl(
80 final Manager m
, DBusConnection connection
, final String objectPath
, final boolean noReceiveOnStart
83 this.connection
= connection
;
84 this.objectPath
= objectPath
;
85 this.noReceiveOnStart
= noReceiveOnStart
;
87 m
.addAddressChangedListener(() -> {
93 public void initObjects() {
95 if (!noReceiveOnStart
) {
100 private void exportObjects() {
105 updateConfiguration();
109 public void close() {
110 if (dbusMessageHandler
!= null) {
111 m
.removeReceiveHandler(dbusMessageHandler
);
112 dbusMessageHandler
= null;
117 private void unExportObjects() {
120 unExportConfiguration();
121 unExportIdentities();
122 connection
.unExportObject(this.objectPath
);
126 public String
getObjectPath() {
131 public String
getSelfNumber() {
132 return m
.getSelfNumber();
136 public void subscribeReceive() {
137 if (dbusMessageHandler
== null) {
138 dbusMessageHandler
= new DbusReceiveMessageHandler(connection
, objectPath
);
139 m
.addReceiveHandler(dbusMessageHandler
);
145 public void unsubscribeReceive() {
146 subscriberCount
= Math
.max(0, subscriberCount
- 1);
147 if (subscriberCount
== 0 && dbusMessageHandler
!= null) {
148 m
.removeReceiveHandler(dbusMessageHandler
);
149 dbusMessageHandler
= null;
154 public void submitRateLimitChallenge(String challenge
, String captcha
) {
156 m
.submitRateLimitRecaptchaChallenge(challenge
, captcha
);
157 } catch (IOException e
) {
158 throw new Error
.Failure("Submit challenge error: " + e
.getMessage());
164 public void unregister() throws Error
.Failure
{
167 } catch (IOException e
) {
168 throw new Error
.Failure("Failed to unregister: " + e
.getMessage());
173 public void deleteAccount() throws Error
.Failure
{
176 } catch (IOException e
) {
177 throw new Error
.Failure("Failed to delete account: " + e
.getMessage());
182 public void addDevice(String uri
) {
184 var deviceLinkUrl
= DeviceLinkUrl
.parseDeviceLinkUri(new URI(uri
));
185 m
.addDeviceLink(deviceLinkUrl
);
186 } catch (IOException
| InvalidDeviceLinkException e
) {
187 throw new Error
.Failure(e
.getClass().getSimpleName() + " Add device link failed. " + e
.getMessage());
188 } catch (NotPrimaryDeviceException e
) {
189 throw new Error
.Failure("This command doesn't work on linked devices.");
190 } catch (URISyntaxException e
) {
191 throw new Error
.InvalidUri(e
.getClass().getSimpleName()
192 + " Device link uri has invalid format: "
198 public DBusPath
getDevice(long deviceId
) {
200 final var deviceOptional
= devices
.stream().filter(g
-> g
.getId().equals(deviceId
)).findFirst();
201 if (deviceOptional
.isEmpty()) {
202 throw new Error
.DeviceNotFound("Device not found");
204 return deviceOptional
.get().getObjectPath();
208 public List
<StructDevice
> listDevices() {
214 public DBusPath
getThisDevice() {
220 public long sendMessage(final String message
, final List
<String
> attachments
, final String recipient
) {
221 return sendMessage(message
, attachments
, List
.of(recipient
));
225 public long sendMessage(final String message
, final List
<String
> attachments
, final List
<String
> recipients
) {
227 final var results
= m
.sendMessage(new Message(message
,
235 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
236 .map(RecipientIdentifier
.class::cast
)
237 .collect(Collectors
.toSet()));
239 checkSendMessageResults(results
);
240 return results
.timestamp();
241 } catch (AttachmentInvalidException e
) {
242 throw new Error
.AttachmentInvalid(e
.getMessage());
243 } catch (IOException
| InvalidStickerException e
) {
244 throw new Error
.Failure(e
);
245 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
246 throw new Error
.GroupNotFound(e
.getMessage());
247 } catch (UnregisteredRecipientException e
) {
248 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
253 public long sendRemoteDeleteMessage(
254 final long targetSentTimestamp
, final String recipient
256 return sendRemoteDeleteMessage(targetSentTimestamp
, List
.of(recipient
));
260 public long sendRemoteDeleteMessage(
261 final long targetSentTimestamp
, final List
<String
> recipients
264 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
265 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
266 .map(RecipientIdentifier
.class::cast
)
267 .collect(Collectors
.toSet()));
268 checkSendMessageResults(results
);
269 return results
.timestamp();
270 } catch (IOException e
) {
271 throw new Error
.Failure(e
.getMessage());
272 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
273 throw new Error
.GroupNotFound(e
.getMessage());
278 public long sendMessageReaction(
280 final boolean remove
,
281 final String targetAuthor
,
282 final long targetSentTimestamp
,
283 final String recipient
285 return sendMessageReaction(emoji
, remove
, targetAuthor
, targetSentTimestamp
, List
.of(recipient
));
289 public long sendMessageReaction(
291 final boolean remove
,
292 final String targetAuthor
,
293 final long targetSentTimestamp
,
294 final List
<String
> recipients
297 final var results
= m
.sendMessageReaction(emoji
,
299 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
301 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
302 .map(RecipientIdentifier
.class::cast
)
303 .collect(Collectors
.toSet()),
305 checkSendMessageResults(results
);
306 return results
.timestamp();
307 } catch (IOException e
) {
308 throw new Error
.Failure(e
.getMessage());
309 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
310 throw new Error
.GroupNotFound(e
.getMessage());
311 } catch (UnregisteredRecipientException e
) {
312 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
317 public long sendPaymentNotification(
318 final byte[] receipt
, final String note
, final String recipient
319 ) throws Error
.Failure
{
321 final var results
= m
.sendPaymentNotificationMessage(receipt
,
323 getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
324 checkSendMessageResults(results
);
325 return results
.timestamp();
326 } catch (IOException e
) {
327 throw new Error
.Failure(e
.getMessage());
332 public void sendTyping(
333 final String recipient
, final boolean stop
334 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
336 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
337 getSingleRecipientIdentifiers(List
.of(recipient
), m
.getSelfNumber()).stream()
338 .map(RecipientIdentifier
.class::cast
)
339 .collect(Collectors
.toSet()));
340 checkSendMessageResults(results
);
341 } catch (IOException e
) {
342 throw new Error
.Failure(e
.getMessage());
343 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
344 throw new Error
.GroupNotFound(e
.getMessage());
349 public void sendReadReceipt(
350 final String recipient
, final List
<Long
> messageIds
351 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
353 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()),
355 checkSendMessageResults(results
);
356 } catch (IOException e
) {
357 throw new Error
.Failure(e
.getMessage());
362 public void sendViewedReceipt(
363 final String recipient
, final List
<Long
> messageIds
364 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
366 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()),
368 checkSendMessageResults(results
);
369 } catch (IOException e
) {
370 throw new Error
.Failure(e
.getMessage());
375 public void sendContacts() {
378 } catch (IOException e
) {
379 throw new Error
.Failure("SendContacts error: " + e
.getMessage());
384 public void sendSyncRequest() {
386 m
.requestAllSyncData();
387 } catch (IOException e
) {
388 throw new Error
.Failure("Request sync data error: " + e
.getMessage());
393 public long sendNoteToSelfMessage(
394 final String message
, final List
<String
> attachments
395 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
397 final var results
= m
.sendMessage(new Message(message
,
404 List
.of()), Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
));
405 checkSendMessageResults(results
);
406 return results
.timestamp();
407 } catch (AttachmentInvalidException e
) {
408 throw new Error
.AttachmentInvalid(e
.getMessage());
409 } catch (IOException
| InvalidStickerException e
) {
410 throw new Error
.Failure(e
.getMessage());
411 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
412 throw new Error
.GroupNotFound(e
.getMessage());
413 } catch (UnregisteredRecipientException e
) {
414 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
419 public void sendEndSessionMessage(final List
<String
> recipients
) {
421 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
422 checkSendMessageResults(results
);
423 } catch (IOException e
) {
424 throw new Error
.Failure(e
.getMessage());
429 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
430 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
434 public void deleteContact(final String recipient
) throws Error
.Failure
{
435 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
439 public long sendGroupMessage(final String message
, final List
<String
> attachments
, final byte[] groupId
) {
441 var results
= m
.sendMessage(new Message(message
,
448 List
.of()), Set
.of(getGroupRecipientIdentifier(groupId
)));
449 checkSendMessageResults(results
);
450 return results
.timestamp();
451 } catch (IOException
| InvalidStickerException e
) {
452 throw new Error
.Failure(e
.getMessage());
453 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
454 throw new Error
.GroupNotFound(e
.getMessage());
455 } catch (AttachmentInvalidException e
) {
456 throw new Error
.AttachmentInvalid(e
.getMessage());
457 } catch (UnregisteredRecipientException e
) {
458 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
463 public void sendGroupTyping(
464 final byte[] groupId
, final boolean stop
465 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
467 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
468 Set
.of(getGroupRecipientIdentifier(groupId
)));
469 checkSendMessageResults(results
);
470 } catch (IOException e
) {
471 throw new Error
.Failure(e
.getMessage());
472 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
473 throw new Error
.GroupNotFound(e
.getMessage());
478 public long sendGroupRemoteDeleteMessage(
479 final long targetSentTimestamp
, final byte[] groupId
482 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
483 Set
.of(getGroupRecipientIdentifier(groupId
)));
484 checkSendMessageResults(results
);
485 return results
.timestamp();
486 } catch (IOException e
) {
487 throw new Error
.Failure(e
.getMessage());
488 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
489 throw new Error
.GroupNotFound(e
.getMessage());
494 public long sendGroupMessageReaction(
496 final boolean remove
,
497 final String targetAuthor
,
498 final long targetSentTimestamp
,
502 final var results
= m
.sendMessageReaction(emoji
,
504 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
506 Set
.of(getGroupRecipientIdentifier(groupId
)),
508 checkSendMessageResults(results
);
509 return results
.timestamp();
510 } catch (IOException e
) {
511 throw new Error
.Failure(e
.getMessage());
512 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
513 throw new Error
.GroupNotFound(e
.getMessage());
514 } catch (UnregisteredRecipientException e
) {
515 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
519 // Since contact names might be empty if not defined, also potentially return
522 public String
getContactName(final String number
) {
523 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
524 return name
== null ?
"" : name
;
528 public void setContactName(final String number
, final String name
) {
530 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "");
531 } catch (NotPrimaryDeviceException e
) {
532 throw new Error
.Failure("This command doesn't work on linked devices.");
533 } catch (IOException e
) {
534 throw new Error
.Failure("Contact is not registered.");
535 } catch (UnregisteredRecipientException e
) {
536 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
541 public void setExpirationTimer(final String number
, final int expiration
) {
543 m
.setExpirationTimer(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), expiration
);
544 } catch (IOException e
) {
545 throw new Error
.Failure(e
.getMessage());
546 } catch (UnregisteredRecipientException e
) {
547 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
552 public void setContactBlocked(final String number
, final boolean blocked
) {
554 m
.setContactsBlocked(List
.of(getSingleRecipientIdentifier(number
, m
.getSelfNumber())), blocked
);
555 } catch (NotPrimaryDeviceException e
) {
556 throw new Error
.Failure("This command doesn't work on linked devices.");
557 } catch (IOException e
) {
558 throw new Error
.Failure(e
.getMessage());
559 } catch (UnregisteredRecipientException e
) {
560 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
565 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
567 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
568 } catch (NotPrimaryDeviceException e
) {
569 throw new Error
.Failure("This command doesn't work on linked devices.");
570 } catch (GroupNotFoundException e
) {
571 throw new Error
.GroupNotFound(e
.getMessage());
572 } catch (IOException e
) {
573 throw new Error
.Failure(e
.getMessage());
578 public List
<byte[]> getGroupIds() {
579 var groups
= m
.getGroups();
580 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
584 public DBusPath
getGroup(final byte[] groupId
) {
586 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
587 if (groupOptional
.isEmpty()) {
588 throw new Error
.GroupNotFound("Group not found");
590 return groupOptional
.get().getObjectPath();
594 public List
<StructGroup
> listGroups() {
600 public String
getGroupName(final byte[] groupId
) {
601 var group
= m
.getGroup(getGroupId(groupId
));
602 if (group
== null || group
.title() == null) {
605 return group
.title();
610 public List
<String
> getGroupMembers(final byte[] groupId
) {
611 var group
= m
.getGroup(getGroupId(groupId
));
615 final var members
= group
.members();
616 return getRecipientStrings(members
);
621 public byte[] createGroup(
622 final String name
, final List
<String
> members
, final String avatar
623 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
624 return updateGroup(new byte[0], name
, members
, avatar
);
628 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
630 groupId
= nullIfEmpty(groupId
);
631 name
= nullIfEmpty(name
);
632 avatar
= nullIfEmpty(avatar
);
633 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
634 if (groupId
== null) {
635 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
637 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
638 return results
.first().serialize();
640 final var results
= m
.updateGroup(getGroupId(groupId
),
641 UpdateGroup
.newBuilder()
643 .withMembers(memberIdentifiers
)
644 .withAvatarFile(avatar
)
646 if (results
!= null) {
647 checkGroupSendMessageResults(results
.timestamp(), results
.results());
651 } catch (IOException e
) {
652 throw new Error
.Failure(e
.getMessage());
653 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
654 throw new Error
.GroupNotFound(e
.getMessage());
655 } catch (AttachmentInvalidException e
) {
656 throw new Error
.AttachmentInvalid(e
.getMessage());
657 } catch (UnregisteredRecipientException e
) {
658 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
663 public boolean isRegistered() {
668 public boolean isRegistered(String number
) {
669 var result
= isRegistered(List
.of(number
));
670 return result
.get(0);
674 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
675 if (numbers
.isEmpty()) {
679 Map
<String
, UserStatus
> registered
;
681 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
682 } catch (IOException e
) {
683 throw new Error
.Failure(e
.getMessage());
686 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
690 public void updateProfile(
696 final boolean removeAvatar
699 givenName
= nullIfEmpty(givenName
);
700 familyName
= nullIfEmpty(familyName
);
701 about
= nullIfEmpty(about
);
702 aboutEmoji
= nullIfEmpty(aboutEmoji
);
703 avatarPath
= nullIfEmpty(avatarPath
);
704 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
705 m
.updateProfile(UpdateProfile
.newBuilder()
706 .withGivenName(givenName
)
707 .withFamilyName(familyName
)
709 .withAboutEmoji(aboutEmoji
)
710 .withAvatar(avatarFile
)
711 .withDeleteAvatar(removeAvatar
)
713 } catch (IOException e
) {
714 throw new Error
.Failure(e
.getMessage());
719 public void updateProfile(
722 final String aboutEmoji
,
724 final boolean removeAvatar
726 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
730 public void removePin() {
732 m
.setRegistrationLockPin(Optional
.empty());
733 } catch (IOException e
) {
734 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
735 } catch (NotPrimaryDeviceException e
) {
736 throw new Error
.Failure("This command doesn't work on linked devices.");
741 public void setPin(String registrationLockPin
) {
743 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
744 } catch (IOException e
) {
745 throw new Error
.Failure("Set pin error: " + e
.getMessage());
746 } catch (NotPrimaryDeviceException e
) {
747 throw new Error
.Failure("This command doesn't work on linked devices.");
751 // Provide option to query a version string in order to react on potential
752 // future interface changes
754 public String
version() {
755 return BaseConfig
.PROJECT_VERSION
;
758 // Create a unique list of Numbers from Identities and Contacts to really get
759 // all numbers the system knows
761 public List
<String
> listNumbers() {
762 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
764 .map(r
-> r
.getAddress().number().orElse(null))
765 .filter(Objects
::nonNull
)
771 public List
<String
> getContactNumber(final String name
) {
772 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
774 .map(r
-> r
.getAddress().getLegacyIdentifier())
779 public void quitGroup(final byte[] groupId
) {
780 var group
= getGroupId(groupId
);
782 m
.quitGroup(group
, Set
.of());
783 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
784 throw new Error
.GroupNotFound(e
.getMessage());
785 } catch (IOException
| LastGroupAdminException e
) {
786 throw new Error
.Failure(e
.getMessage());
787 } catch (UnregisteredRecipientException e
) {
788 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
793 public byte[] joinGroup(final String groupLink
) {
795 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
796 if (linkUrl
== null) {
797 throw new Error
.Failure("Group link is invalid:");
799 final var result
= m
.joinGroup(linkUrl
);
800 return result
.first().serialize();
801 } catch (PendingAdminApprovalException e
) {
802 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
803 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
804 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
805 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
806 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
807 } catch (IOException e
) {
808 throw new Error
.Failure(e
.getMessage());
813 public boolean isContactBlocked(final String number
) {
814 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
818 public boolean isGroupBlocked(final byte[] groupId
) {
819 var group
= m
.getGroup(getGroupId(groupId
));
823 return group
.isBlocked();
828 public boolean isMember(final byte[] groupId
) {
829 var group
= m
.getGroup(getGroupId(groupId
));
833 return group
.isMember();
838 public String
uploadStickerPack(String stickerPackPath
) {
839 File path
= new File(stickerPackPath
);
841 return m
.uploadStickerPack(path
).toString();
842 } catch (IOException e
) {
843 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
844 } catch (StickerPackInvalidException e
) {
845 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
849 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
850 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
856 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
858 if (result
.isIdentityFailure()) {
859 throw new Error
.UntrustedIdentity(message
);
861 throw new Error
.Failure(message
);
865 private void checkSendMessageResults(final SendMessageResults results
) {
866 final var sendMessageResults
= results
.results().values().stream().findFirst();
867 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
868 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
872 if (results
.hasSuccess()) {
876 var message
= new StringBuilder();
877 message
.append("Failed to send messages:\n");
878 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
879 for (var error
: errors
) {
880 message
.append(error
).append('\n');
882 message
.append(results
.timestamp());
884 throw new Error
.Failure(message
.toString());
887 private static void checkGroupSendMessageResults(
888 long timestamp
, Collection
<SendMessageResult
> results
889 ) throws DBusExecutionException
{
890 if (results
.size() == 1) {
891 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
895 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
896 if (errors
.size() == 0 || errors
.size() < results
.size()) {
900 var message
= new StringBuilder();
901 message
.append("Failed to send message:\n");
902 for (var error
: errors
) {
903 message
.append(error
).append('\n');
905 message
.append(timestamp
);
907 throw new Error
.Failure(message
.toString());
910 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
911 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
914 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
915 final Collection
<String
> recipientStrings
, final String localNumber
916 ) throws DBusExecutionException
{
917 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
918 for (var recipientString
: recipientStrings
) {
919 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
924 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
925 final String recipientString
, final String localNumber
926 ) throws DBusExecutionException
{
928 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
929 } catch (InvalidNumberException e
) {
930 throw new Error
.InvalidNumber(e
.getMessage());
934 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
935 return new RecipientIdentifier
.Group(getGroupId(groupId
));
938 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
940 return GroupId
.unknownVersion(groupId
);
941 } catch (Throwable e
) {
942 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
946 private byte[] nullIfEmpty(final byte[] array
) {
947 return array
.length
== 0 ?
null : array
;
950 private String
nullIfEmpty(final String name
) {
951 return name
.isEmpty() ?
null : name
;
954 private String
emptyIfNull(final String string
) {
955 return string
== null ?
"" : string
;
958 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
959 return basePath
+ "/Devices/" + deviceId
;
962 private void updateDevices() {
963 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
965 linkedDevices
= m
.getLinkedDevices();
966 } catch (IOException e
) {
967 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
972 linkedDevices
.forEach(d
-> {
973 final var object
= new DbusSignalDeviceImpl(d
);
974 final var deviceObjectPath
= object
.getObjectPath();
975 exportObject(object
);
976 if (d
.isThisDevice()) {
977 thisDevice
= new DBusPath(deviceObjectPath
);
979 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
983 private void unExportDevices() {
984 this.devices
.stream()
985 .map(StructDevice
::getObjectPath
)
986 .map(DBusPath
::getPath
)
987 .forEach(connection
::unExportObject
);
988 this.devices
.clear();
991 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
992 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
995 private void updateGroups() {
996 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
997 groups
= m
.getGroups();
1001 groups
.forEach(g
-> {
1002 final var object
= new DbusSignalGroupImpl(g
.groupId());
1003 exportObject(object
);
1004 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1005 g
.groupId().serialize(),
1006 emptyIfNull(g
.title())));
1010 private void unExportGroups() {
1011 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1012 this.groups
.clear();
1015 private static String
getConfigurationObjectPath(String basePath
) {
1016 return basePath
+ "/Configuration";
1019 private void updateConfiguration() {
1020 unExportConfiguration();
1021 final var object
= new DbusSignalConfigurationImpl();
1022 exportObject(object
);
1025 private void unExportConfiguration() {
1026 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1027 connection
.unExportObject(objectPath
);
1030 private void exportObject(final DBusInterface object
) {
1032 connection
.exportObject(object
);
1033 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1034 } catch (DBusException e
) {
1035 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1039 private void updateIdentities() {
1040 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1041 identities
= m
.getIdentities();
1043 unExportIdentities();
1045 identities
.forEach(i
-> {
1046 final var object
= new DbusSignalIdentityImpl(i
);
1047 exportObject(object
);
1048 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1049 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1050 i
.recipient().number().orElse("")));
1054 private static String
getIdentityObjectPath(String basePath
, String id
) {
1055 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1058 private void unExportIdentities() {
1059 this.identities
.stream()
1060 .map(StructIdentity
::getObjectPath
)
1061 .map(DBusPath
::getPath
)
1062 .forEach(connection
::unExportObject
);
1063 this.identities
.clear();
1067 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1068 final var found
= identities
.stream()
1069 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1072 if (found
.isEmpty()) {
1073 throw new Error
.Failure("Identity for " + number
+ " unknown");
1075 return found
.get().getObjectPath();
1079 public List
<StructIdentity
> listIdentities() {
1081 return this.identities
;
1084 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1086 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1088 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1089 this.identity
= identity
;
1090 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1091 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1092 new DbusProperty
<>("Uuid",
1093 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1094 new DbusProperty
<>("Fingerprint", identity
::getFingerprint
),
1095 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1096 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1097 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1098 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1102 public String
getObjectPath() {
1103 return getIdentityObjectPath(objectPath
,
1104 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1108 public void trust() throws Error
.Failure
{
1109 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1111 m
.trustIdentityAllKeys(recipient
);
1112 } catch (UnregisteredRecipientException e
) {
1113 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1119 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1120 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1122 if (safetyNumber
== null) {
1123 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1125 final IdentityVerificationCode verificationCode
;
1127 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1128 } catch (Exception e
) {
1129 throw new Error
.Failure(
1130 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1134 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1136 throw new Error
.Failure(
1137 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1139 } catch (UnregisteredRecipientException e
) {
1140 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1146 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1148 private final org
.asamk
.signal
.manager
.api
.Device device
;
1150 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1151 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1152 List
.of(new DbusProperty
<>("Id", device
::id
),
1153 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1154 new DbusProperty
<>("Created", device
::created
),
1155 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1156 this.device
= device
;
1160 public String
getObjectPath() {
1161 return getDeviceObjectPath(objectPath
, device
.id());
1165 public void removeDevice() throws Error
.Failure
{
1167 m
.removeLinkedDevices(device
.id());
1169 } catch (IOException e
) {
1170 throw new Error
.Failure(e
.getMessage());
1174 private void setDeviceName(String name
) {
1175 if (!device
.isThisDevice()) {
1176 throw new Error
.Failure("Only the name of this device can be changed");
1179 m
.updateAccountAttributes(name
);
1180 // update device list
1182 } catch (IOException e
) {
1183 throw new Error
.Failure(e
.getMessage());
1188 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1190 public DbusSignalConfigurationImpl() {
1191 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1192 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1193 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1194 this::getUnidentifiedDeliveryIndicators
,
1195 this::setUnidentifiedDeliveryIndicators
),
1196 new DbusProperty
<>("TypingIndicators",
1197 this::getTypingIndicators
,
1198 this::setTypingIndicators
),
1199 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1204 public String
getObjectPath() {
1205 return getConfigurationObjectPath(objectPath
);
1208 public void setReadReceipts(Boolean readReceipts
) {
1209 setConfiguration(readReceipts
, null, null, null);
1212 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1213 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1216 public void setTypingIndicators(Boolean typingIndicators
) {
1217 setConfiguration(null, null, typingIndicators
, null);
1220 public void setLinkPreviews(Boolean linkPreviews
) {
1221 setConfiguration(null, null, null, linkPreviews
);
1224 private void setConfiguration(
1225 Boolean readReceipts
,
1226 Boolean unidentifiedDeliveryIndicators
,
1227 Boolean typingIndicators
,
1228 Boolean linkPreviews
1231 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1232 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1233 Optional
.ofNullable(typingIndicators
),
1234 Optional
.ofNullable(linkPreviews
)));
1235 } catch (IOException e
) {
1236 throw new Error
.Failure("UpdateAccount error: " + e
.getMessage());
1237 } catch (NotPrimaryDeviceException e
) {
1238 throw new Error
.Failure("This command doesn't work on linked devices.");
1242 private boolean getReadReceipts() {
1243 return m
.getConfiguration().readReceipts().orElse(false);
1246 private boolean getUnidentifiedDeliveryIndicators() {
1247 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1250 private boolean getTypingIndicators() {
1251 return m
.getConfiguration().typingIndicators().orElse(false);
1254 private boolean getLinkPreviews() {
1255 return m
.getConfiguration().linkPreviews().orElse(false);
1259 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1261 private final GroupId groupId
;
1263 public DbusSignalGroupImpl(final GroupId groupId
) {
1264 this.groupId
= groupId
;
1265 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1266 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1267 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1268 new DbusProperty
<>("Description",
1269 () -> emptyIfNull(getGroup().description()),
1270 this::setGroupDescription
),
1271 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1272 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1273 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1274 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1275 new DbusProperty
<>("MessageExpirationTimer",
1276 () -> getGroup().messageExpirationTimer(),
1277 this::setMessageExpirationTime
),
1278 new DbusProperty
<>("Members",
1279 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1280 new DbusProperty
<>("PendingMembers",
1281 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1282 new DbusProperty
<>("RequestingMembers",
1283 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1284 new DbusProperty
<>("Admins",
1285 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1286 new DbusProperty
<>("Banned",
1287 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1288 new DbusProperty
<>("PermissionAddMember",
1289 () -> getGroup().permissionAddMember().name(),
1290 this::setGroupPermissionAddMember
),
1291 new DbusProperty
<>("PermissionEditDetails",
1292 () -> getGroup().permissionEditDetails().name(),
1293 this::setGroupPermissionEditDetails
),
1294 new DbusProperty
<>("PermissionSendMessage",
1295 () -> getGroup().permissionSendMessage().name(),
1296 this::setGroupPermissionSendMessage
),
1297 new DbusProperty
<>("GroupInviteLink", () -> {
1298 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1299 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1304 public String
getObjectPath() {
1305 return getGroupObjectPath(objectPath
, groupId
.serialize());
1309 public void quitGroup() throws Error
.Failure
{
1311 m
.quitGroup(groupId
, Set
.of());
1312 } catch (GroupNotFoundException e
) {
1313 throw new Error
.GroupNotFound(e
.getMessage());
1314 } catch (NotAGroupMemberException e
) {
1315 throw new Error
.NotAGroupMember(e
.getMessage());
1316 } catch (IOException e
) {
1317 throw new Error
.Failure(e
.getMessage());
1318 } catch (LastGroupAdminException e
) {
1319 throw new Error
.LastGroupAdmin(e
.getMessage());
1320 } catch (UnregisteredRecipientException e
) {
1321 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1326 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1328 m
.deleteGroup(groupId
);
1329 } catch (IOException e
) {
1330 throw new Error
.Failure(e
.getMessage());
1336 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1337 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1338 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1342 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1343 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1344 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1348 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1349 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1350 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1354 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1355 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1356 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1360 public void resetLink() throws Error
.Failure
{
1361 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1365 public void disableLink() throws Error
.Failure
{
1366 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1370 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1371 updateGroup(UpdateGroup
.newBuilder()
1372 .withGroupLinkState(requiresApproval
1373 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1374 : GroupLinkState
.ENABLED
)
1378 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1379 return m
.getGroup(groupId
);
1382 private void setGroupName(final String name
) {
1383 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1386 private void setGroupDescription(final String description
) {
1387 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1390 private void setGroupAvatar(final String avatar
) {
1391 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1394 private void setMessageExpirationTime(final int expirationTime
) {
1395 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1398 private void setGroupPermissionAddMember(final String permission
) {
1399 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1402 private void setGroupPermissionEditDetails(final String permission
) {
1403 updateGroup(UpdateGroup
.newBuilder()
1404 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1408 private void setGroupPermissionSendMessage(final String permission
) {
1409 updateGroup(UpdateGroup
.newBuilder()
1410 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1414 private void setIsBlocked(final boolean isBlocked
) {
1416 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1417 } catch (NotPrimaryDeviceException e
) {
1418 throw new Error
.Failure("This command doesn't work on linked devices.");
1419 } catch (GroupNotFoundException e
) {
1420 throw new Error
.GroupNotFound(e
.getMessage());
1421 } catch (IOException e
) {
1422 throw new Error
.Failure(e
.getMessage());
1426 private void updateGroup(final UpdateGroup updateGroup
) {
1428 m
.updateGroup(groupId
, updateGroup
);
1429 } catch (IOException e
) {
1430 throw new Error
.Failure(e
.getMessage());
1431 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1432 throw new Error
.GroupNotFound(e
.getMessage());
1433 } catch (AttachmentInvalidException e
) {
1434 throw new Error
.AttachmentInvalid(e
.getMessage());
1435 } catch (UnregisteredRecipientException e
) {
1436 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");