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
{
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 final static 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();
111 public void close() {
112 if (dbusMessageHandler
!= null) {
113 m
.removeReceiveHandler(dbusMessageHandler
);
114 dbusMessageHandler
= null;
119 private void unExportObjects() {
122 unExportConfiguration();
123 unExportIdentities();
124 connection
.unExportObject(this.objectPath
);
128 public String
getObjectPath() {
133 public String
getSelfNumber() {
134 return m
.getSelfNumber();
138 public void subscribeReceive() {
139 if (dbusMessageHandler
== null) {
140 dbusMessageHandler
= new DbusReceiveMessageHandler(connection
, objectPath
);
141 m
.addReceiveHandler(dbusMessageHandler
);
147 public void unsubscribeReceive() {
148 subscriberCount
= Math
.max(0, subscriberCount
- 1);
149 if (subscriberCount
== 0 && dbusMessageHandler
!= null) {
150 m
.removeReceiveHandler(dbusMessageHandler
);
151 dbusMessageHandler
= null;
156 public void submitRateLimitChallenge(String challenge
, String captcha
) {
158 m
.submitRateLimitRecaptchaChallenge(challenge
, captcha
);
159 } catch (IOException e
) {
160 throw new Error
.Failure("Submit challenge error: " + e
.getMessage());
166 public void unregister() throws Error
.Failure
{
169 } catch (IOException e
) {
170 throw new Error
.Failure("Failed to unregister: " + e
.getMessage());
175 public void deleteAccount() throws Error
.Failure
{
178 } catch (IOException e
) {
179 throw new Error
.Failure("Failed to delete account: " + e
.getMessage());
184 public void addDevice(String uri
) {
186 var deviceLinkUrl
= DeviceLinkUrl
.parseDeviceLinkUri(new URI(uri
));
187 m
.addDeviceLink(deviceLinkUrl
);
188 } catch (IOException
| InvalidDeviceLinkException e
) {
189 throw new Error
.Failure(e
.getClass().getSimpleName() + " Add device link failed. " + e
.getMessage());
190 } catch (NotPrimaryDeviceException e
) {
191 throw new Error
.Failure("This command doesn't work on linked devices.");
192 } catch (URISyntaxException e
) {
193 throw new Error
.InvalidUri(e
.getClass().getSimpleName()
194 + " Device link uri has invalid format: "
200 public DBusPath
getDevice(long deviceId
) {
202 final var deviceOptional
= devices
.stream().filter(g
-> g
.getId().equals(deviceId
)).findFirst();
203 if (deviceOptional
.isEmpty()) {
204 throw new Error
.DeviceNotFound("Device not found");
206 return deviceOptional
.get().getObjectPath();
210 public List
<StructDevice
> listDevices() {
216 public DBusPath
getThisDevice() {
222 public long sendMessage(final String message
, final List
<String
> attachments
, final String recipient
) {
223 return sendMessage(message
, attachments
, List
.of(recipient
));
227 public long sendMessage(final String message
, final List
<String
> attachments
, final List
<String
> recipients
) {
229 final var results
= m
.sendMessage(new Message(message
,
237 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
238 .map(RecipientIdentifier
.class::cast
)
239 .collect(Collectors
.toSet()));
241 checkSendMessageResults(results
);
242 return results
.timestamp();
243 } catch (AttachmentInvalidException e
) {
244 throw new Error
.AttachmentInvalid(e
.getMessage());
245 } catch (IOException
| InvalidStickerException e
) {
246 throw new Error
.Failure(e
);
247 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
248 throw new Error
.GroupNotFound(e
.getMessage());
249 } catch (UnregisteredRecipientException e
) {
250 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
255 public long sendRemoteDeleteMessage(
256 final long targetSentTimestamp
, final String recipient
258 return sendRemoteDeleteMessage(targetSentTimestamp
, List
.of(recipient
));
262 public long sendRemoteDeleteMessage(
263 final long targetSentTimestamp
, final List
<String
> recipients
266 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
267 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
268 .map(RecipientIdentifier
.class::cast
)
269 .collect(Collectors
.toSet()));
270 checkSendMessageResults(results
);
271 return results
.timestamp();
272 } catch (IOException e
) {
273 throw new Error
.Failure(e
.getMessage());
274 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
275 throw new Error
.GroupNotFound(e
.getMessage());
280 public long sendMessageReaction(
282 final boolean remove
,
283 final String targetAuthor
,
284 final long targetSentTimestamp
,
285 final String recipient
287 return sendMessageReaction(emoji
, remove
, targetAuthor
, targetSentTimestamp
, List
.of(recipient
));
291 public long sendMessageReaction(
293 final boolean remove
,
294 final String targetAuthor
,
295 final long targetSentTimestamp
,
296 final List
<String
> recipients
299 final var results
= m
.sendMessageReaction(emoji
,
301 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
303 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
304 .map(RecipientIdentifier
.class::cast
)
305 .collect(Collectors
.toSet()),
307 checkSendMessageResults(results
);
308 return results
.timestamp();
309 } catch (IOException e
) {
310 throw new Error
.Failure(e
.getMessage());
311 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
312 throw new Error
.GroupNotFound(e
.getMessage());
313 } catch (UnregisteredRecipientException e
) {
314 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
319 public long sendPaymentNotification(
320 final byte[] receipt
, final String note
, final String recipient
321 ) throws Error
.Failure
{
323 final var results
= m
.sendPaymentNotificationMessage(receipt
,
325 getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
326 checkSendMessageResults(results
);
327 return results
.timestamp();
328 } catch (IOException e
) {
329 throw new Error
.Failure(e
.getMessage());
334 public void sendTyping(
335 final String recipient
, final boolean stop
336 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
338 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
339 getSingleRecipientIdentifiers(List
.of(recipient
), m
.getSelfNumber()).stream()
340 .map(RecipientIdentifier
.class::cast
)
341 .collect(Collectors
.toSet()));
342 checkSendMessageResults(results
);
343 } catch (IOException e
) {
344 throw new Error
.Failure(e
.getMessage());
345 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
346 throw new Error
.GroupNotFound(e
.getMessage());
351 public void sendReadReceipt(
352 final String recipient
, final List
<Long
> messageIds
353 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
354 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
355 checkSendMessageResults(results
);
359 public void sendViewedReceipt(
360 final String recipient
, final List
<Long
> messageIds
361 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
362 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
363 checkSendMessageResults(results
);
367 public void sendContacts() {
370 } catch (IOException e
) {
371 throw new Error
.Failure("SendContacts error: " + e
.getMessage());
376 public void sendSyncRequest() {
378 m
.requestAllSyncData();
379 } catch (IOException e
) {
380 throw new Error
.Failure("Request sync data error: " + e
.getMessage());
385 public long sendNoteToSelfMessage(
386 final String message
, final List
<String
> attachments
387 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
389 final var results
= m
.sendMessage(new Message(message
,
396 List
.of()), Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
));
397 checkSendMessageResults(results
);
398 return results
.timestamp();
399 } catch (AttachmentInvalidException e
) {
400 throw new Error
.AttachmentInvalid(e
.getMessage());
401 } catch (IOException
| InvalidStickerException e
) {
402 throw new Error
.Failure(e
.getMessage());
403 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
404 throw new Error
.GroupNotFound(e
.getMessage());
405 } catch (UnregisteredRecipientException e
) {
406 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
411 public void sendEndSessionMessage(final List
<String
> recipients
) {
413 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
414 checkSendMessageResults(results
);
415 } catch (IOException e
) {
416 throw new Error
.Failure(e
.getMessage());
421 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
422 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
426 public void deleteContact(final String recipient
) throws Error
.Failure
{
427 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
431 public long sendGroupMessage(final String message
, final List
<String
> attachments
, final byte[] groupId
) {
433 var results
= m
.sendMessage(new Message(message
,
440 List
.of()), Set
.of(getGroupRecipientIdentifier(groupId
)));
441 checkSendMessageResults(results
);
442 return results
.timestamp();
443 } catch (IOException
| InvalidStickerException e
) {
444 throw new Error
.Failure(e
.getMessage());
445 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
446 throw new Error
.GroupNotFound(e
.getMessage());
447 } catch (AttachmentInvalidException e
) {
448 throw new Error
.AttachmentInvalid(e
.getMessage());
449 } catch (UnregisteredRecipientException e
) {
450 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
455 public void sendGroupTyping(
456 final byte[] groupId
, final boolean stop
457 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
459 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
460 Set
.of(getGroupRecipientIdentifier(groupId
)));
461 checkSendMessageResults(results
);
462 } catch (IOException e
) {
463 throw new Error
.Failure(e
.getMessage());
464 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
465 throw new Error
.GroupNotFound(e
.getMessage());
470 public long sendGroupRemoteDeleteMessage(
471 final long targetSentTimestamp
, final byte[] groupId
474 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
475 Set
.of(getGroupRecipientIdentifier(groupId
)));
476 checkSendMessageResults(results
);
477 return results
.timestamp();
478 } catch (IOException e
) {
479 throw new Error
.Failure(e
.getMessage());
480 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
481 throw new Error
.GroupNotFound(e
.getMessage());
486 public long sendGroupMessageReaction(
488 final boolean remove
,
489 final String targetAuthor
,
490 final long targetSentTimestamp
,
494 final var results
= m
.sendMessageReaction(emoji
,
496 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
498 Set
.of(getGroupRecipientIdentifier(groupId
)),
500 checkSendMessageResults(results
);
501 return results
.timestamp();
502 } catch (IOException e
) {
503 throw new Error
.Failure(e
.getMessage());
504 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
505 throw new Error
.GroupNotFound(e
.getMessage());
506 } catch (UnregisteredRecipientException e
) {
507 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
511 // Since contact names might be empty if not defined, also potentially return
514 public String
getContactName(final String number
) {
515 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
516 return name
== null ?
"" : name
;
520 public void setContactName(final String number
, final String name
) {
522 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "");
523 } catch (NotPrimaryDeviceException e
) {
524 throw new Error
.Failure("This command doesn't work on linked devices.");
525 } catch (UnregisteredRecipientException e
) {
526 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
531 public void setExpirationTimer(final String number
, final int expiration
) {
533 m
.setExpirationTimer(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), expiration
);
534 } catch (IOException e
) {
535 throw new Error
.Failure(e
.getMessage());
536 } catch (UnregisteredRecipientException e
) {
537 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
542 public void setContactBlocked(final String number
, final boolean blocked
) {
544 m
.setContactsBlocked(List
.of(getSingleRecipientIdentifier(number
, m
.getSelfNumber())), blocked
);
545 } catch (NotPrimaryDeviceException e
) {
546 throw new Error
.Failure("This command doesn't work on linked devices.");
547 } catch (IOException e
) {
548 throw new Error
.Failure(e
.getMessage());
549 } catch (UnregisteredRecipientException e
) {
550 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
556 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
558 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
559 } catch (NotPrimaryDeviceException e
) {
560 throw new Error
.Failure("This command doesn't work on linked devices.");
561 } catch (GroupNotFoundException e
) {
562 throw new Error
.GroupNotFound(e
.getMessage());
563 } catch (IOException e
) {
564 throw new Error
.Failure(e
.getMessage());
570 public List
<byte[]> getGroupIds() {
571 var groups
= m
.getGroups();
572 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
576 public DBusPath
getGroup(final byte[] groupId
) {
578 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
579 if (groupOptional
.isEmpty()) {
580 throw new Error
.GroupNotFound("Group not found");
582 return groupOptional
.get().getObjectPath();
586 public List
<StructGroup
> listGroups() {
593 public String
getGroupName(final byte[] groupId
) {
594 var group
= m
.getGroup(getGroupId(groupId
));
595 if (group
== null || group
.title() == null) {
598 return group
.title();
604 public List
<String
> getGroupMembers(final byte[] groupId
) {
605 var group
= m
.getGroup(getGroupId(groupId
));
609 final var members
= group
.members();
610 return getRecipientStrings(members
);
615 public byte[] createGroup(
616 final String name
, final List
<String
> members
, final String avatar
617 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
618 return updateGroupInternal(new byte[0], name
, members
, avatar
);
623 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
624 return updateGroupInternal(groupId
, name
, members
, avatar
);
627 public byte[] updateGroupInternal(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
629 groupId
= nullIfEmpty(groupId
);
630 name
= nullIfEmpty(name
);
631 avatar
= nullIfEmpty(avatar
);
632 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
633 if (groupId
== null) {
634 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
636 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
637 return results
.first().serialize();
639 final var results
= m
.updateGroup(getGroupId(groupId
),
640 UpdateGroup
.newBuilder()
642 .withMembers(memberIdentifiers
)
643 .withAvatarFile(avatar
)
645 if (results
!= null) {
646 checkGroupSendMessageResults(results
.timestamp(), results
.results());
650 } catch (IOException e
) {
651 throw new Error
.Failure(e
.getMessage());
652 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
653 throw new Error
.GroupNotFound(e
.getMessage());
654 } catch (AttachmentInvalidException e
) {
655 throw new Error
.AttachmentInvalid(e
.getMessage());
656 } catch (UnregisteredRecipientException e
) {
657 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());
684 } catch (RateLimitException e
) {
685 throw new Error
.Failure(e
.getMessage()
687 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
690 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
694 public void updateProfile(
700 final boolean removeAvatar
703 givenName
= nullIfEmpty(givenName
);
704 familyName
= nullIfEmpty(familyName
);
705 about
= nullIfEmpty(about
);
706 aboutEmoji
= nullIfEmpty(aboutEmoji
);
707 avatarPath
= nullIfEmpty(avatarPath
);
708 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
709 m
.updateProfile(UpdateProfile
.newBuilder()
710 .withGivenName(givenName
)
711 .withFamilyName(familyName
)
713 .withAboutEmoji(aboutEmoji
)
714 .withAvatar(avatarFile
)
715 .withDeleteAvatar(removeAvatar
)
717 } catch (IOException e
) {
718 throw new Error
.Failure(e
.getMessage());
723 public void updateProfile(
726 final String aboutEmoji
,
728 final boolean removeAvatar
730 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
734 public void removePin() {
736 m
.setRegistrationLockPin(Optional
.empty());
737 } catch (IOException e
) {
738 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
739 } catch (NotPrimaryDeviceException e
) {
740 throw new Error
.Failure("This command doesn't work on linked devices.");
745 public void setPin(String registrationLockPin
) {
747 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
748 } catch (IOException e
) {
749 throw new Error
.Failure("Set pin error: " + e
.getMessage());
750 } catch (NotPrimaryDeviceException e
) {
751 throw new Error
.Failure("This command doesn't work on linked devices.");
755 // Provide option to query a version string in order to react on potential
756 // future interface changes
758 public String
version() {
759 return BaseConfig
.PROJECT_VERSION
;
762 // Create a unique list of Numbers from Identities and Contacts to really get
763 // all numbers the system knows
765 public List
<String
> listNumbers() {
766 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
768 .map(r
-> r
.getAddress().number().orElse(null))
769 .filter(Objects
::nonNull
)
775 public List
<String
> getContactNumber(final String name
) {
776 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
778 .map(r
-> r
.getAddress().getLegacyIdentifier())
784 public void quitGroup(final byte[] groupId
) {
785 var group
= getGroupId(groupId
);
787 m
.quitGroup(group
, Set
.of());
788 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
789 throw new Error
.GroupNotFound(e
.getMessage());
790 } catch (IOException
| LastGroupAdminException e
) {
791 throw new Error
.Failure(e
.getMessage());
792 } catch (UnregisteredRecipientException e
) {
793 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
798 public byte[] joinGroup(final String groupLink
) {
800 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
801 if (linkUrl
== null) {
802 throw new Error
.Failure("Group link is invalid:");
804 final var result
= m
.joinGroup(linkUrl
);
805 return result
.first().serialize();
806 } catch (PendingAdminApprovalException e
) {
807 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
808 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
809 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
810 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
811 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
812 } catch (IOException e
) {
813 throw new Error
.Failure(e
.getMessage());
818 public boolean isContactBlocked(final String number
) {
819 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
824 public boolean isGroupBlocked(final byte[] groupId
) {
825 var group
= m
.getGroup(getGroupId(groupId
));
829 return group
.isBlocked();
835 public boolean isMember(final byte[] groupId
) {
836 var group
= m
.getGroup(getGroupId(groupId
));
840 return group
.isMember();
845 public String
uploadStickerPack(String stickerPackPath
) {
846 File path
= new File(stickerPackPath
);
848 return m
.uploadStickerPack(path
).toString();
849 } catch (IOException e
) {
850 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
851 } catch (StickerPackInvalidException e
) {
852 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
856 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
857 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
863 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
865 if (result
.isIdentityFailure()) {
866 throw new Error
.UntrustedIdentity(message
);
868 throw new Error
.Failure(message
);
872 private void checkSendMessageResults(final SendMessageResults results
) {
873 final var sendMessageResults
= results
.results().values().stream().findFirst();
874 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
875 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
879 if (results
.hasSuccess()) {
883 var message
= new StringBuilder();
884 message
.append("Failed to send messages:\n");
885 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
886 for (var error
: errors
) {
887 message
.append(error
).append('\n');
889 message
.append(results
.timestamp());
891 throw new Error
.Failure(message
.toString());
894 private static void checkGroupSendMessageResults(
895 long timestamp
, Collection
<SendMessageResult
> results
896 ) throws DBusExecutionException
{
897 if (results
.size() == 1) {
898 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
902 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
903 if (errors
.isEmpty() || errors
.size() < results
.size()) {
907 var message
= new StringBuilder();
908 message
.append("Failed to send message:\n");
909 for (var error
: errors
) {
910 message
.append(error
).append('\n');
912 message
.append(timestamp
);
914 throw new Error
.Failure(message
.toString());
917 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
918 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
921 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
922 final Collection
<String
> recipientStrings
, final String localNumber
923 ) throws DBusExecutionException
{
924 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
925 for (var recipientString
: recipientStrings
) {
926 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
931 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
932 final String recipientString
, final String localNumber
933 ) throws DBusExecutionException
{
935 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
936 } catch (InvalidNumberException e
) {
937 throw new Error
.InvalidNumber(e
.getMessage());
941 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
942 return new RecipientIdentifier
.Group(getGroupId(groupId
));
945 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
947 return GroupId
.unknownVersion(groupId
);
948 } catch (Throwable e
) {
949 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
953 private byte[] nullIfEmpty(final byte[] array
) {
954 return array
.length
== 0 ?
null : array
;
957 private String
nullIfEmpty(final String name
) {
958 return name
.isEmpty() ?
null : name
;
961 private String
emptyIfNull(final String string
) {
962 return string
== null ?
"" : string
;
965 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
966 return basePath
+ "/Devices/" + deviceId
;
969 private void updateDevices() {
970 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
972 linkedDevices
= m
.getLinkedDevices();
973 } catch (IOException e
) {
974 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
979 linkedDevices
.forEach(d
-> {
980 final var object
= new DbusSignalDeviceImpl(d
);
981 final var deviceObjectPath
= object
.getObjectPath();
982 exportObject(object
);
983 if (d
.isThisDevice()) {
984 thisDevice
= new DBusPath(deviceObjectPath
);
986 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
990 private void unExportDevices() {
991 this.devices
.stream()
992 .map(StructDevice
::getObjectPath
)
993 .map(DBusPath
::getPath
)
994 .forEach(connection
::unExportObject
);
995 this.devices
.clear();
998 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
999 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
1002 private void updateGroups() {
1003 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
1004 groups
= m
.getGroups();
1008 groups
.forEach(g
-> {
1009 final var object
= new DbusSignalGroupImpl(g
.groupId());
1010 exportObject(object
);
1011 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1012 g
.groupId().serialize(),
1013 emptyIfNull(g
.title())));
1017 private void unExportGroups() {
1018 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1019 this.groups
.clear();
1022 private static String
getConfigurationObjectPath(String basePath
) {
1023 return basePath
+ "/Configuration";
1026 private void updateConfiguration() {
1027 unExportConfiguration();
1028 final var object
= new DbusSignalConfigurationImpl();
1029 exportObject(object
);
1032 private void unExportConfiguration() {
1033 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1034 connection
.unExportObject(objectPath
);
1037 private void exportObject(final DBusInterface object
) {
1039 connection
.exportObject(object
);
1040 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1041 } catch (DBusException e
) {
1042 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1046 private void updateIdentities() {
1047 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1048 identities
= m
.getIdentities();
1050 unExportIdentities();
1052 identities
.forEach(i
-> {
1053 final var object
= new DbusSignalIdentityImpl(i
);
1054 exportObject(object
);
1055 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1056 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1057 i
.recipient().number().orElse("")));
1061 private static String
getIdentityObjectPath(String basePath
, String id
) {
1062 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1065 private void unExportIdentities() {
1066 this.identities
.stream()
1067 .map(StructIdentity
::getObjectPath
)
1068 .map(DBusPath
::getPath
)
1069 .forEach(connection
::unExportObject
);
1070 this.identities
.clear();
1074 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1075 final var found
= identities
.stream()
1076 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1079 if (found
.isEmpty()) {
1080 throw new Error
.Failure("Identity for " + number
+ " unknown");
1082 return found
.get().getObjectPath();
1086 public List
<StructIdentity
> listIdentities() {
1088 return this.identities
;
1091 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1093 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1095 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1096 this.identity
= identity
;
1097 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1098 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1099 new DbusProperty
<>("Uuid",
1100 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1101 new DbusProperty
<>("Fingerprint", identity
::getFingerprint
),
1102 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1103 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1104 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1105 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1109 public String
getObjectPath() {
1110 return getIdentityObjectPath(objectPath
,
1111 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1115 public void trust() throws Error
.Failure
{
1116 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1118 m
.trustIdentityAllKeys(recipient
);
1119 } catch (UnregisteredRecipientException e
) {
1120 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1126 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1127 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1129 if (safetyNumber
== null) {
1130 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1132 final IdentityVerificationCode verificationCode
;
1134 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1135 } catch (Exception e
) {
1136 throw new Error
.Failure(
1137 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1141 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1143 throw new Error
.Failure(
1144 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1146 } catch (UnregisteredRecipientException e
) {
1147 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1153 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1155 private final org
.asamk
.signal
.manager
.api
.Device device
;
1157 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1158 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1159 List
.of(new DbusProperty
<>("Id", device
::id
),
1160 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1161 new DbusProperty
<>("Created", device
::created
),
1162 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1163 this.device
= device
;
1167 public String
getObjectPath() {
1168 return getDeviceObjectPath(objectPath
, device
.id());
1172 public void removeDevice() throws Error
.Failure
{
1174 m
.removeLinkedDevices(device
.id());
1176 } catch (IOException e
) {
1177 throw new Error
.Failure(e
.getMessage());
1181 private void setDeviceName(String name
) {
1182 if (!device
.isThisDevice()) {
1183 throw new Error
.Failure("Only the name of this device can be changed");
1186 m
.updateAccountAttributes(name
);
1187 // update device list
1189 } catch (IOException e
) {
1190 throw new Error
.Failure(e
.getMessage());
1195 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1197 public DbusSignalConfigurationImpl() {
1198 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1199 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1200 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1201 this::getUnidentifiedDeliveryIndicators
,
1202 this::setUnidentifiedDeliveryIndicators
),
1203 new DbusProperty
<>("TypingIndicators",
1204 this::getTypingIndicators
,
1205 this::setTypingIndicators
),
1206 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1211 public String
getObjectPath() {
1212 return getConfigurationObjectPath(objectPath
);
1215 public void setReadReceipts(Boolean readReceipts
) {
1216 setConfiguration(readReceipts
, null, null, null);
1219 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1220 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1223 public void setTypingIndicators(Boolean typingIndicators
) {
1224 setConfiguration(null, null, typingIndicators
, null);
1227 public void setLinkPreviews(Boolean linkPreviews
) {
1228 setConfiguration(null, null, null, linkPreviews
);
1231 private void setConfiguration(
1232 Boolean readReceipts
,
1233 Boolean unidentifiedDeliveryIndicators
,
1234 Boolean typingIndicators
,
1235 Boolean linkPreviews
1238 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1239 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1240 Optional
.ofNullable(typingIndicators
),
1241 Optional
.ofNullable(linkPreviews
)));
1242 } catch (NotPrimaryDeviceException e
) {
1243 throw new Error
.Failure("This command doesn't work on linked devices.");
1247 private boolean getReadReceipts() {
1248 return m
.getConfiguration().readReceipts().orElse(false);
1251 private boolean getUnidentifiedDeliveryIndicators() {
1252 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1255 private boolean getTypingIndicators() {
1256 return m
.getConfiguration().typingIndicators().orElse(false);
1259 private boolean getLinkPreviews() {
1260 return m
.getConfiguration().linkPreviews().orElse(false);
1264 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1266 private final GroupId groupId
;
1268 public DbusSignalGroupImpl(final GroupId groupId
) {
1269 this.groupId
= groupId
;
1270 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1271 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1272 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1273 new DbusProperty
<>("Description",
1274 () -> emptyIfNull(getGroup().description()),
1275 this::setGroupDescription
),
1276 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1277 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1278 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1279 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1280 new DbusProperty
<>("MessageExpirationTimer",
1281 () -> getGroup().messageExpirationTimer(),
1282 this::setMessageExpirationTime
),
1283 new DbusProperty
<>("Members",
1284 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1285 new DbusProperty
<>("PendingMembers",
1286 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1287 new DbusProperty
<>("RequestingMembers",
1288 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1289 new DbusProperty
<>("Admins",
1290 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1291 new DbusProperty
<>("Banned",
1292 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1293 new DbusProperty
<>("PermissionAddMember",
1294 () -> getGroup().permissionAddMember().name(),
1295 this::setGroupPermissionAddMember
),
1296 new DbusProperty
<>("PermissionEditDetails",
1297 () -> getGroup().permissionEditDetails().name(),
1298 this::setGroupPermissionEditDetails
),
1299 new DbusProperty
<>("PermissionSendMessage",
1300 () -> getGroup().permissionSendMessage().name(),
1301 this::setGroupPermissionSendMessage
),
1302 new DbusProperty
<>("GroupInviteLink", () -> {
1303 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1304 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1309 public String
getObjectPath() {
1310 return getGroupObjectPath(objectPath
, groupId
.serialize());
1314 public void quitGroup() throws Error
.Failure
{
1316 m
.quitGroup(groupId
, Set
.of());
1317 } catch (GroupNotFoundException e
) {
1318 throw new Error
.GroupNotFound(e
.getMessage());
1319 } catch (NotAGroupMemberException e
) {
1320 throw new Error
.NotAGroupMember(e
.getMessage());
1321 } catch (IOException e
) {
1322 throw new Error
.Failure(e
.getMessage());
1323 } catch (LastGroupAdminException e
) {
1324 throw new Error
.LastGroupAdmin(e
.getMessage());
1325 } catch (UnregisteredRecipientException e
) {
1326 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1331 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1333 m
.deleteGroup(groupId
);
1334 } catch (IOException e
) {
1335 throw new Error
.Failure(e
.getMessage());
1341 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1342 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1343 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1347 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1348 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1349 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1353 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1354 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1355 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1359 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1360 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1361 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1365 public void resetLink() throws Error
.Failure
{
1366 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1370 public void disableLink() throws Error
.Failure
{
1371 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1375 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1376 updateGroup(UpdateGroup
.newBuilder()
1377 .withGroupLinkState(requiresApproval
1378 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1379 : GroupLinkState
.ENABLED
)
1383 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1384 return m
.getGroup(groupId
);
1387 private void setGroupName(final String name
) {
1388 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1391 private void setGroupDescription(final String description
) {
1392 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1395 private void setGroupAvatar(final String avatar
) {
1396 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1399 private void setMessageExpirationTime(final int expirationTime
) {
1400 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1403 private void setGroupPermissionAddMember(final String permission
) {
1404 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1407 private void setGroupPermissionEditDetails(final String permission
) {
1408 updateGroup(UpdateGroup
.newBuilder()
1409 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1413 private void setGroupPermissionSendMessage(final String permission
) {
1414 updateGroup(UpdateGroup
.newBuilder()
1415 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1419 private void setIsBlocked(final boolean isBlocked
) {
1421 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1422 } catch (NotPrimaryDeviceException e
) {
1423 throw new Error
.Failure("This command doesn't work on linked devices.");
1424 } catch (GroupNotFoundException e
) {
1425 throw new Error
.GroupNotFound(e
.getMessage());
1426 } catch (IOException e
) {
1427 throw new Error
.Failure(e
.getMessage());
1431 private void updateGroup(final UpdateGroup updateGroup
) {
1433 m
.updateGroup(groupId
, updateGroup
);
1434 } catch (IOException e
) {
1435 throw new Error
.Failure(e
.getMessage());
1436 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1437 throw new Error
.GroupNotFound(e
.getMessage());
1438 } catch (AttachmentInvalidException e
) {
1439 throw new Error
.AttachmentInvalid(e
.getMessage());
1440 } catch (UnregisteredRecipientException e
) {
1441 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");