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
.RateLimitException
;
25 import org
.asamk
.signal
.manager
.api
.RecipientAddress
;
26 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
27 import org
.asamk
.signal
.manager
.api
.SendMessageResult
;
28 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
29 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
30 import org
.asamk
.signal
.manager
.api
.TypingAction
;
31 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
32 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
33 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
34 import org
.asamk
.signal
.manager
.api
.UserStatus
;
35 import org
.asamk
.signal
.util
.DateUtils
;
36 import org
.asamk
.signal
.util
.SendMessageResultUtils
;
37 import org
.freedesktop
.dbus
.DBusPath
;
38 import org
.freedesktop
.dbus
.connections
.impl
.DBusConnection
;
39 import org
.freedesktop
.dbus
.exceptions
.DBusException
;
40 import org
.freedesktop
.dbus
.exceptions
.DBusExecutionException
;
41 import org
.freedesktop
.dbus
.interfaces
.DBusInterface
;
42 import org
.freedesktop
.dbus
.types
.Variant
;
43 import org
.slf4j
.Logger
;
44 import org
.slf4j
.LoggerFactory
;
47 import java
.io
.IOException
;
49 import java
.net
.URISyntaxException
;
50 import java
.util
.ArrayList
;
51 import java
.util
.Arrays
;
52 import java
.util
.Base64
;
53 import java
.util
.Collection
;
54 import java
.util
.HashSet
;
55 import java
.util
.List
;
57 import java
.util
.Objects
;
58 import java
.util
.Optional
;
60 import java
.util
.UUID
;
61 import java
.util
.stream
.Collectors
;
63 import static org
.asamk
.signal
.dbus
.DbusUtils
.makeValidObjectPathElement
;
65 public class DbusSignalImpl
implements Signal
, AutoCloseable
{
67 private final Manager m
;
68 private final DBusConnection connection
;
69 private final String objectPath
;
70 private final boolean noReceiveOnStart
;
72 private DBusPath thisDevice
;
73 private final List
<StructDevice
> devices
= new ArrayList
<>();
74 private final List
<StructGroup
> groups
= new ArrayList
<>();
75 private final List
<StructIdentity
> identities
= new ArrayList
<>();
76 private DbusReceiveMessageHandler dbusMessageHandler
;
77 private int subscriberCount
;
79 private static final Logger logger
= LoggerFactory
.getLogger(DbusSignalImpl
.class);
81 public DbusSignalImpl(
82 final Manager m
, DBusConnection connection
, final String objectPath
, final boolean noReceiveOnStart
85 this.connection
= connection
;
86 this.objectPath
= objectPath
;
87 this.noReceiveOnStart
= noReceiveOnStart
;
89 m
.addAddressChangedListener(() -> {
95 public void initObjects() {
97 if (!noReceiveOnStart
) {
102 private void exportObjects() {
107 updateConfiguration();
112 public void close() {
113 if (dbusMessageHandler
!= null) {
114 m
.removeReceiveHandler(dbusMessageHandler
);
115 dbusMessageHandler
= null;
120 private void unExportObjects() {
123 unExportConfiguration();
124 unExportIdentities();
125 connection
.unExportObject(this.objectPath
);
129 public String
getObjectPath() {
134 public String
getSelfNumber() {
135 return m
.getSelfNumber();
139 public void subscribeReceive() {
140 if (dbusMessageHandler
== null) {
141 dbusMessageHandler
= new DbusReceiveMessageHandler(connection
, objectPath
);
142 m
.addReceiveHandler(dbusMessageHandler
);
148 public void unsubscribeReceive() {
149 subscriberCount
= Math
.max(0, subscriberCount
- 1);
150 if (subscriberCount
== 0 && dbusMessageHandler
!= null) {
151 m
.removeReceiveHandler(dbusMessageHandler
);
152 dbusMessageHandler
= null;
157 public void submitRateLimitChallenge(String challenge
, String captcha
) {
159 m
.submitRateLimitRecaptchaChallenge(challenge
, captcha
);
160 } catch (IOException e
) {
161 throw new Error
.Failure("Submit challenge error: " + e
.getMessage());
167 public void unregister() throws Error
.Failure
{
170 } catch (IOException e
) {
171 throw new Error
.Failure("Failed to unregister: " + e
.getMessage());
176 public void deleteAccount() throws Error
.Failure
{
179 } catch (IOException e
) {
180 throw new Error
.Failure("Failed to delete account: " + e
.getMessage());
185 public void addDevice(String uri
) {
187 var deviceLinkUrl
= DeviceLinkUrl
.parseDeviceLinkUri(new URI(uri
));
188 m
.addDeviceLink(deviceLinkUrl
);
189 } catch (IOException
| InvalidDeviceLinkException e
) {
190 throw new Error
.Failure(e
.getClass().getSimpleName() + " Add device link failed. " + e
.getMessage());
191 } catch (NotPrimaryDeviceException e
) {
192 throw new Error
.Failure("This command doesn't work on linked devices.");
193 } catch (URISyntaxException e
) {
194 throw new Error
.InvalidUri(e
.getClass().getSimpleName()
195 + " Device link uri has invalid format: "
201 public DBusPath
getDevice(long deviceId
) {
203 final var deviceOptional
= devices
.stream().filter(g
-> g
.getId().equals(deviceId
)).findFirst();
204 if (deviceOptional
.isEmpty()) {
205 throw new Error
.DeviceNotFound("Device not found");
207 return deviceOptional
.get().getObjectPath();
211 public List
<StructDevice
> listDevices() {
217 public DBusPath
getThisDevice() {
223 public long sendMessage(final String message
, final List
<String
> attachments
, final String recipient
) {
224 return sendMessage(message
, attachments
, List
.of(recipient
));
228 public long sendMessage(final String message
, final List
<String
> attachments
, final List
<String
> recipients
) {
230 final var results
= m
.sendMessage(new Message(message
,
238 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
239 .map(RecipientIdentifier
.class::cast
)
240 .collect(Collectors
.toSet()));
242 checkSendMessageResults(results
);
243 return results
.timestamp();
244 } catch (AttachmentInvalidException e
) {
245 throw new Error
.AttachmentInvalid(e
.getMessage());
246 } catch (IOException
| InvalidStickerException e
) {
247 throw new Error
.Failure(e
);
248 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
249 throw new Error
.GroupNotFound(e
.getMessage());
250 } catch (UnregisteredRecipientException e
) {
251 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
256 public long sendRemoteDeleteMessage(
257 final long targetSentTimestamp
, final String recipient
259 return sendRemoteDeleteMessage(targetSentTimestamp
, List
.of(recipient
));
263 public long sendRemoteDeleteMessage(
264 final long targetSentTimestamp
, final List
<String
> recipients
267 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
268 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
269 .map(RecipientIdentifier
.class::cast
)
270 .collect(Collectors
.toSet()));
271 checkSendMessageResults(results
);
272 return results
.timestamp();
273 } catch (IOException e
) {
274 throw new Error
.Failure(e
.getMessage());
275 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
276 throw new Error
.GroupNotFound(e
.getMessage());
281 public long sendMessageReaction(
283 final boolean remove
,
284 final String targetAuthor
,
285 final long targetSentTimestamp
,
286 final String recipient
288 return sendMessageReaction(emoji
, remove
, targetAuthor
, targetSentTimestamp
, List
.of(recipient
));
292 public long sendMessageReaction(
294 final boolean remove
,
295 final String targetAuthor
,
296 final long targetSentTimestamp
,
297 final List
<String
> recipients
300 final var results
= m
.sendMessageReaction(emoji
,
302 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
304 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
305 .map(RecipientIdentifier
.class::cast
)
306 .collect(Collectors
.toSet()),
308 checkSendMessageResults(results
);
309 return results
.timestamp();
310 } catch (IOException e
) {
311 throw new Error
.Failure(e
.getMessage());
312 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
313 throw new Error
.GroupNotFound(e
.getMessage());
314 } catch (UnregisteredRecipientException e
) {
315 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
320 public long sendPaymentNotification(
321 final byte[] receipt
, final String note
, final String recipient
322 ) throws Error
.Failure
{
324 final var results
= m
.sendPaymentNotificationMessage(receipt
,
326 getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
327 checkSendMessageResults(results
);
328 return results
.timestamp();
329 } catch (IOException e
) {
330 throw new Error
.Failure(e
.getMessage());
335 public void sendTyping(
336 final String recipient
, final boolean stop
337 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
339 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
340 getSingleRecipientIdentifiers(List
.of(recipient
), m
.getSelfNumber()).stream()
341 .map(RecipientIdentifier
.class::cast
)
342 .collect(Collectors
.toSet()));
343 checkSendMessageResults(results
);
344 } catch (IOException e
) {
345 throw new Error
.Failure(e
.getMessage());
346 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
347 throw new Error
.GroupNotFound(e
.getMessage());
352 public void sendReadReceipt(
353 final String recipient
, final List
<Long
> messageIds
354 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
355 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
356 checkSendMessageResults(results
);
360 public void sendViewedReceipt(
361 final String recipient
, final List
<Long
> messageIds
362 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
363 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
364 checkSendMessageResults(results
);
368 public void sendContacts() {
371 } catch (IOException e
) {
372 throw new Error
.Failure("SendContacts error: " + e
.getMessage());
377 public void sendSyncRequest() {
379 m
.requestAllSyncData();
380 } catch (IOException e
) {
381 throw new Error
.Failure("Request sync data error: " + e
.getMessage());
386 public long sendNoteToSelfMessage(
387 final String message
, final List
<String
> attachments
388 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
390 final var results
= m
.sendMessage(new Message(message
,
397 List
.of()), Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
));
398 checkSendMessageResults(results
);
399 return results
.timestamp();
400 } catch (AttachmentInvalidException e
) {
401 throw new Error
.AttachmentInvalid(e
.getMessage());
402 } catch (IOException
| InvalidStickerException e
) {
403 throw new Error
.Failure(e
.getMessage());
404 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
405 throw new Error
.GroupNotFound(e
.getMessage());
406 } catch (UnregisteredRecipientException e
) {
407 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
412 public void sendEndSessionMessage(final List
<String
> recipients
) {
414 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
415 checkSendMessageResults(results
);
416 } catch (IOException e
) {
417 throw new Error
.Failure(e
.getMessage());
422 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
423 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
427 public void deleteContact(final String recipient
) throws Error
.Failure
{
428 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
432 public long sendGroupMessage(final String message
, final List
<String
> attachments
, final byte[] groupId
) {
434 var results
= m
.sendMessage(new Message(message
,
441 List
.of()), Set
.of(getGroupRecipientIdentifier(groupId
)));
442 checkSendMessageResults(results
);
443 return results
.timestamp();
444 } catch (IOException
| InvalidStickerException e
) {
445 throw new Error
.Failure(e
.getMessage());
446 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
447 throw new Error
.GroupNotFound(e
.getMessage());
448 } catch (AttachmentInvalidException e
) {
449 throw new Error
.AttachmentInvalid(e
.getMessage());
450 } catch (UnregisteredRecipientException e
) {
451 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
456 public void sendGroupTyping(
457 final byte[] groupId
, final boolean stop
458 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
460 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
461 Set
.of(getGroupRecipientIdentifier(groupId
)));
462 checkSendMessageResults(results
);
463 } catch (IOException e
) {
464 throw new Error
.Failure(e
.getMessage());
465 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
466 throw new Error
.GroupNotFound(e
.getMessage());
471 public long sendGroupRemoteDeleteMessage(
472 final long targetSentTimestamp
, final byte[] groupId
475 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
476 Set
.of(getGroupRecipientIdentifier(groupId
)));
477 checkSendMessageResults(results
);
478 return results
.timestamp();
479 } catch (IOException e
) {
480 throw new Error
.Failure(e
.getMessage());
481 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
482 throw new Error
.GroupNotFound(e
.getMessage());
487 public long sendGroupMessageReaction(
489 final boolean remove
,
490 final String targetAuthor
,
491 final long targetSentTimestamp
,
495 final var results
= m
.sendMessageReaction(emoji
,
497 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
499 Set
.of(getGroupRecipientIdentifier(groupId
)),
501 checkSendMessageResults(results
);
502 return results
.timestamp();
503 } catch (IOException e
) {
504 throw new Error
.Failure(e
.getMessage());
505 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
506 throw new Error
.GroupNotFound(e
.getMessage());
507 } catch (UnregisteredRecipientException e
) {
508 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
512 // Since contact names might be empty if not defined, also potentially return
515 public String
getContactName(final String number
) {
516 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
517 return name
== null ?
"" : name
;
521 public void setContactName(final String number
, final String name
) {
523 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "");
524 } catch (NotPrimaryDeviceException e
) {
525 throw new Error
.Failure("This command doesn't work on linked devices.");
526 } catch (UnregisteredRecipientException e
) {
527 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
532 public void setExpirationTimer(final String number
, final int expiration
) {
534 m
.setExpirationTimer(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), expiration
);
535 } catch (IOException e
) {
536 throw new Error
.Failure(e
.getMessage());
537 } catch (UnregisteredRecipientException e
) {
538 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
543 public void setContactBlocked(final String number
, final boolean blocked
) {
545 m
.setContactsBlocked(List
.of(getSingleRecipientIdentifier(number
, m
.getSelfNumber())), blocked
);
546 } catch (NotPrimaryDeviceException e
) {
547 throw new Error
.Failure("This command doesn't work on linked devices.");
548 } catch (IOException e
) {
549 throw new Error
.Failure(e
.getMessage());
550 } catch (UnregisteredRecipientException e
) {
551 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
557 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
559 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
560 } catch (NotPrimaryDeviceException e
) {
561 throw new Error
.Failure("This command doesn't work on linked devices.");
562 } catch (GroupNotFoundException e
) {
563 throw new Error
.GroupNotFound(e
.getMessage());
564 } catch (IOException e
) {
565 throw new Error
.Failure(e
.getMessage());
571 public List
<byte[]> getGroupIds() {
572 var groups
= m
.getGroups();
573 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
577 public DBusPath
getGroup(final byte[] groupId
) {
579 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
580 if (groupOptional
.isEmpty()) {
581 throw new Error
.GroupNotFound("Group not found");
583 return groupOptional
.get().getObjectPath();
587 public List
<StructGroup
> listGroups() {
594 public String
getGroupName(final byte[] groupId
) {
595 var group
= m
.getGroup(getGroupId(groupId
));
596 if (group
== null || group
.title() == null) {
599 return group
.title();
605 public List
<String
> getGroupMembers(final byte[] groupId
) {
606 var group
= m
.getGroup(getGroupId(groupId
));
610 final var members
= group
.members();
611 return getRecipientStrings(members
);
616 public byte[] createGroup(
617 final String name
, final List
<String
> members
, final String avatar
618 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
619 return updateGroupInternal(new byte[0], name
, members
, avatar
);
624 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
625 return updateGroupInternal(groupId
, name
, members
, avatar
);
628 public byte[] updateGroupInternal(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.");
664 public boolean isRegistered() {
669 public boolean isRegistered(String number
) {
670 var result
= isRegistered(List
.of(number
));
671 return result
.get(0);
675 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
676 if (numbers
.isEmpty()) {
680 Map
<String
, UserStatus
> registered
;
682 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
683 } catch (IOException e
) {
684 throw new Error
.Failure(e
.getMessage());
685 } catch (RateLimitException e
) {
686 throw new Error
.Failure(e
.getMessage()
688 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
691 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
695 public void updateProfile(
701 final boolean removeAvatar
704 givenName
= nullIfEmpty(givenName
);
705 familyName
= nullIfEmpty(familyName
);
706 about
= nullIfEmpty(about
);
707 aboutEmoji
= nullIfEmpty(aboutEmoji
);
708 avatarPath
= nullIfEmpty(avatarPath
);
709 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
710 m
.updateProfile(UpdateProfile
.newBuilder()
711 .withGivenName(givenName
)
712 .withFamilyName(familyName
)
714 .withAboutEmoji(aboutEmoji
)
715 .withAvatar(avatarFile
)
716 .withDeleteAvatar(removeAvatar
)
718 } catch (IOException e
) {
719 throw new Error
.Failure(e
.getMessage());
724 public void updateProfile(
727 final String aboutEmoji
,
729 final boolean removeAvatar
731 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
735 public void removePin() {
737 m
.setRegistrationLockPin(Optional
.empty());
738 } catch (IOException e
) {
739 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
740 } catch (NotPrimaryDeviceException e
) {
741 throw new Error
.Failure("This command doesn't work on linked devices.");
746 public void setPin(String registrationLockPin
) {
748 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
749 } catch (IOException e
) {
750 throw new Error
.Failure("Set pin error: " + e
.getMessage());
751 } catch (NotPrimaryDeviceException e
) {
752 throw new Error
.Failure("This command doesn't work on linked devices.");
756 // Provide option to query a version string in order to react on potential
757 // future interface changes
759 public String
version() {
760 return BaseConfig
.PROJECT_VERSION
;
763 // Create a unique list of Numbers from Identities and Contacts to really get
764 // all numbers the system knows
766 public List
<String
> listNumbers() {
767 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
769 .map(r
-> r
.getAddress().number().orElse(null))
770 .filter(Objects
::nonNull
)
776 public List
<String
> getContactNumber(final String name
) {
777 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
779 .map(r
-> r
.getAddress().getLegacyIdentifier())
785 public void quitGroup(final byte[] groupId
) {
786 var group
= getGroupId(groupId
);
788 m
.quitGroup(group
, Set
.of());
789 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
790 throw new Error
.GroupNotFound(e
.getMessage());
791 } catch (IOException
| LastGroupAdminException e
) {
792 throw new Error
.Failure(e
.getMessage());
793 } catch (UnregisteredRecipientException e
) {
794 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
799 public byte[] joinGroup(final String groupLink
) {
801 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
802 if (linkUrl
== null) {
803 throw new Error
.Failure("Group link is invalid:");
805 final var result
= m
.joinGroup(linkUrl
);
806 return result
.first().serialize();
807 } catch (PendingAdminApprovalException e
) {
808 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
809 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
810 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
811 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
812 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
813 } catch (IOException e
) {
814 throw new Error
.Failure(e
.getMessage());
819 public boolean isContactBlocked(final String number
) {
820 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
825 public boolean isGroupBlocked(final byte[] groupId
) {
826 var group
= m
.getGroup(getGroupId(groupId
));
830 return group
.isBlocked();
836 public boolean isMember(final byte[] groupId
) {
837 var group
= m
.getGroup(getGroupId(groupId
));
841 return group
.isMember();
846 public String
uploadStickerPack(String stickerPackPath
) {
847 File path
= new File(stickerPackPath
);
849 return m
.uploadStickerPack(path
).toString();
850 } catch (IOException e
) {
851 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
852 } catch (StickerPackInvalidException e
) {
853 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
857 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
858 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
864 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
866 if (result
.isIdentityFailure()) {
867 throw new Error
.UntrustedIdentity(message
);
869 throw new Error
.Failure(message
);
873 private void checkSendMessageResults(final SendMessageResults results
) {
874 final var sendMessageResults
= results
.results().values().stream().findFirst();
875 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
876 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
880 if (results
.hasSuccess()) {
884 var message
= new StringBuilder();
885 message
.append("Failed to send messages:\n");
886 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
887 for (var error
: errors
) {
888 message
.append(error
).append('\n');
890 message
.append(results
.timestamp());
892 throw new Error
.Failure(message
.toString());
895 private static void checkGroupSendMessageResults(
896 long timestamp
, Collection
<SendMessageResult
> results
897 ) throws DBusExecutionException
{
898 if (results
.size() == 1) {
899 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
903 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
904 if (errors
.isEmpty() || errors
.size() < results
.size()) {
908 var message
= new StringBuilder();
909 message
.append("Failed to send message:\n");
910 for (var error
: errors
) {
911 message
.append(error
).append('\n');
913 message
.append(timestamp
);
915 throw new Error
.Failure(message
.toString());
918 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
919 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
922 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
923 final Collection
<String
> recipientStrings
, final String localNumber
924 ) throws DBusExecutionException
{
925 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
926 for (var recipientString
: recipientStrings
) {
927 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
932 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
933 final String recipientString
, final String localNumber
934 ) throws DBusExecutionException
{
936 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
937 } catch (InvalidNumberException e
) {
938 throw new Error
.InvalidNumber(e
.getMessage());
942 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
943 return new RecipientIdentifier
.Group(getGroupId(groupId
));
946 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
948 return GroupId
.unknownVersion(groupId
);
949 } catch (Throwable e
) {
950 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
954 private byte[] nullIfEmpty(final byte[] array
) {
955 return array
.length
== 0 ?
null : array
;
958 private String
nullIfEmpty(final String name
) {
959 return name
.isEmpty() ?
null : name
;
962 private String
emptyIfNull(final String string
) {
963 return string
== null ?
"" : string
;
966 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
967 return basePath
+ "/Devices/" + deviceId
;
970 private void updateDevices() {
971 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
973 linkedDevices
= m
.getLinkedDevices();
974 } catch (IOException e
) {
975 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
980 linkedDevices
.forEach(d
-> {
981 final var object
= new DbusSignalDeviceImpl(d
);
982 final var deviceObjectPath
= object
.getObjectPath();
983 exportObject(object
);
984 if (d
.isThisDevice()) {
985 thisDevice
= new DBusPath(deviceObjectPath
);
987 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
991 private void unExportDevices() {
992 this.devices
.stream()
993 .map(StructDevice
::getObjectPath
)
994 .map(DBusPath
::getPath
)
995 .forEach(connection
::unExportObject
);
996 this.devices
.clear();
999 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
1000 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
1003 private void updateGroups() {
1004 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
1005 groups
= m
.getGroups();
1009 groups
.forEach(g
-> {
1010 final var object
= new DbusSignalGroupImpl(g
.groupId());
1011 exportObject(object
);
1012 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1013 g
.groupId().serialize(),
1014 emptyIfNull(g
.title())));
1018 private void unExportGroups() {
1019 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1020 this.groups
.clear();
1023 private static String
getConfigurationObjectPath(String basePath
) {
1024 return basePath
+ "/Configuration";
1027 private void updateConfiguration() {
1028 unExportConfiguration();
1029 final var object
= new DbusSignalConfigurationImpl();
1030 exportObject(object
);
1033 private void unExportConfiguration() {
1034 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1035 connection
.unExportObject(objectPath
);
1038 private void exportObject(final DBusInterface object
) {
1040 connection
.exportObject(object
);
1041 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1042 } catch (DBusException e
) {
1043 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1047 private void updateIdentities() {
1048 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1049 identities
= m
.getIdentities();
1051 unExportIdentities();
1053 identities
.forEach(i
-> {
1054 final var object
= new DbusSignalIdentityImpl(i
);
1055 exportObject(object
);
1056 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1057 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1058 i
.recipient().number().orElse("")));
1062 private static String
getIdentityObjectPath(String basePath
, String id
) {
1063 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1066 private void unExportIdentities() {
1067 this.identities
.stream()
1068 .map(StructIdentity
::getObjectPath
)
1069 .map(DBusPath
::getPath
)
1070 .forEach(connection
::unExportObject
);
1071 this.identities
.clear();
1075 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1076 final var found
= identities
.stream()
1077 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1080 if (found
.isEmpty()) {
1081 throw new Error
.Failure("Identity for " + number
+ " unknown");
1083 return found
.get().getObjectPath();
1087 public List
<StructIdentity
> listIdentities() {
1089 return this.identities
;
1092 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1094 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1096 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1097 this.identity
= identity
;
1098 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1099 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1100 new DbusProperty
<>("Uuid",
1101 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1102 new DbusProperty
<>("Fingerprint", identity
::getFingerprint
),
1103 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1104 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1105 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1106 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1110 public String
getObjectPath() {
1111 return getIdentityObjectPath(objectPath
,
1112 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1116 public void trust() throws Error
.Failure
{
1117 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1119 m
.trustIdentityAllKeys(recipient
);
1120 } catch (UnregisteredRecipientException e
) {
1121 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1127 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1128 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1130 if (safetyNumber
== null) {
1131 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1133 final IdentityVerificationCode verificationCode
;
1135 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1136 } catch (Exception e
) {
1137 throw new Error
.Failure(
1138 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1142 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1144 throw new Error
.Failure(
1145 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1147 } catch (UnregisteredRecipientException e
) {
1148 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1154 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1156 private final org
.asamk
.signal
.manager
.api
.Device device
;
1158 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1159 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1160 List
.of(new DbusProperty
<>("Id", device
::id
),
1161 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1162 new DbusProperty
<>("Created", device
::created
),
1163 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1164 this.device
= device
;
1168 public String
getObjectPath() {
1169 return getDeviceObjectPath(objectPath
, device
.id());
1173 public void removeDevice() throws Error
.Failure
{
1175 m
.removeLinkedDevices(device
.id());
1177 } catch (IOException e
) {
1178 throw new Error
.Failure(e
.getMessage());
1182 private void setDeviceName(String name
) {
1183 if (!device
.isThisDevice()) {
1184 throw new Error
.Failure("Only the name of this device can be changed");
1187 m
.updateAccountAttributes(name
);
1188 // update device list
1190 } catch (IOException e
) {
1191 throw new Error
.Failure(e
.getMessage());
1196 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1198 public DbusSignalConfigurationImpl() {
1199 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1200 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1201 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1202 this::getUnidentifiedDeliveryIndicators
,
1203 this::setUnidentifiedDeliveryIndicators
),
1204 new DbusProperty
<>("TypingIndicators",
1205 this::getTypingIndicators
,
1206 this::setTypingIndicators
),
1207 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1212 public String
getObjectPath() {
1213 return getConfigurationObjectPath(objectPath
);
1216 public void setReadReceipts(Boolean readReceipts
) {
1217 setConfiguration(readReceipts
, null, null, null);
1220 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1221 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1224 public void setTypingIndicators(Boolean typingIndicators
) {
1225 setConfiguration(null, null, typingIndicators
, null);
1228 public void setLinkPreviews(Boolean linkPreviews
) {
1229 setConfiguration(null, null, null, linkPreviews
);
1232 private void setConfiguration(
1233 Boolean readReceipts
,
1234 Boolean unidentifiedDeliveryIndicators
,
1235 Boolean typingIndicators
,
1236 Boolean linkPreviews
1239 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1240 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1241 Optional
.ofNullable(typingIndicators
),
1242 Optional
.ofNullable(linkPreviews
)));
1243 } catch (NotPrimaryDeviceException e
) {
1244 throw new Error
.Failure("This command doesn't work on linked devices.");
1248 private boolean getReadReceipts() {
1249 return m
.getConfiguration().readReceipts().orElse(false);
1252 private boolean getUnidentifiedDeliveryIndicators() {
1253 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1256 private boolean getTypingIndicators() {
1257 return m
.getConfiguration().typingIndicators().orElse(false);
1260 private boolean getLinkPreviews() {
1261 return m
.getConfiguration().linkPreviews().orElse(false);
1265 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1267 private final GroupId groupId
;
1269 public DbusSignalGroupImpl(final GroupId groupId
) {
1270 this.groupId
= groupId
;
1271 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1272 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1273 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1274 new DbusProperty
<>("Description",
1275 () -> emptyIfNull(getGroup().description()),
1276 this::setGroupDescription
),
1277 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1278 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1279 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1280 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1281 new DbusProperty
<>("MessageExpirationTimer",
1282 () -> getGroup().messageExpirationTimer(),
1283 this::setMessageExpirationTime
),
1284 new DbusProperty
<>("Members",
1285 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1286 new DbusProperty
<>("PendingMembers",
1287 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1288 new DbusProperty
<>("RequestingMembers",
1289 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1290 new DbusProperty
<>("Admins",
1291 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1292 new DbusProperty
<>("Banned",
1293 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1294 new DbusProperty
<>("PermissionAddMember",
1295 () -> getGroup().permissionAddMember().name(),
1296 this::setGroupPermissionAddMember
),
1297 new DbusProperty
<>("PermissionEditDetails",
1298 () -> getGroup().permissionEditDetails().name(),
1299 this::setGroupPermissionEditDetails
),
1300 new DbusProperty
<>("PermissionSendMessage",
1301 () -> getGroup().permissionSendMessage().name(),
1302 this::setGroupPermissionSendMessage
),
1303 new DbusProperty
<>("GroupInviteLink", () -> {
1304 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1305 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1310 public String
getObjectPath() {
1311 return getGroupObjectPath(objectPath
, groupId
.serialize());
1315 public void quitGroup() throws Error
.Failure
{
1317 m
.quitGroup(groupId
, Set
.of());
1318 } catch (GroupNotFoundException e
) {
1319 throw new Error
.GroupNotFound(e
.getMessage());
1320 } catch (NotAGroupMemberException e
) {
1321 throw new Error
.NotAGroupMember(e
.getMessage());
1322 } catch (IOException e
) {
1323 throw new Error
.Failure(e
.getMessage());
1324 } catch (LastGroupAdminException e
) {
1325 throw new Error
.LastGroupAdmin(e
.getMessage());
1326 } catch (UnregisteredRecipientException e
) {
1327 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1332 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1334 m
.deleteGroup(groupId
);
1335 } catch (IOException e
) {
1336 throw new Error
.Failure(e
.getMessage());
1342 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1343 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1344 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1348 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1349 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1350 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1354 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1355 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1356 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1360 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1361 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1362 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1366 public void resetLink() throws Error
.Failure
{
1367 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1371 public void disableLink() throws Error
.Failure
{
1372 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1376 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1377 updateGroup(UpdateGroup
.newBuilder()
1378 .withGroupLinkState(requiresApproval
1379 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1380 : GroupLinkState
.ENABLED
)
1384 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1385 return m
.getGroup(groupId
);
1388 private void setGroupName(final String name
) {
1389 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1392 private void setGroupDescription(final String description
) {
1393 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1396 private void setGroupAvatar(final String avatar
) {
1397 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1400 private void setMessageExpirationTime(final int expirationTime
) {
1401 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1404 private void setGroupPermissionAddMember(final String permission
) {
1405 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1408 private void setGroupPermissionEditDetails(final String permission
) {
1409 updateGroup(UpdateGroup
.newBuilder()
1410 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1414 private void setGroupPermissionSendMessage(final String permission
) {
1415 updateGroup(UpdateGroup
.newBuilder()
1416 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1420 private void setIsBlocked(final boolean isBlocked
) {
1422 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1423 } catch (NotPrimaryDeviceException e
) {
1424 throw new Error
.Failure("This command doesn't work on linked devices.");
1425 } catch (GroupNotFoundException e
) {
1426 throw new Error
.GroupNotFound(e
.getMessage());
1427 } catch (IOException e
) {
1428 throw new Error
.Failure(e
.getMessage());
1432 private void updateGroup(final UpdateGroup updateGroup
) {
1434 m
.updateGroup(groupId
, updateGroup
);
1435 } catch (IOException e
) {
1436 throw new Error
.Failure(e
.getMessage());
1437 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1438 throw new Error
.GroupNotFound(e
.getMessage());
1439 } catch (AttachmentInvalidException e
) {
1440 throw new Error
.AttachmentInvalid(e
.getMessage());
1441 } catch (UnregisteredRecipientException e
) {
1442 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");