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.");
555 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
557 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
558 } catch (NotPrimaryDeviceException e
) {
559 throw new Error
.Failure("This command doesn't work on linked devices.");
560 } catch (GroupNotFoundException e
) {
561 throw new Error
.GroupNotFound(e
.getMessage());
562 } catch (IOException e
) {
563 throw new Error
.Failure(e
.getMessage());
568 public List
<byte[]> getGroupIds() {
569 var groups
= m
.getGroups();
570 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
574 public DBusPath
getGroup(final byte[] groupId
) {
576 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
577 if (groupOptional
.isEmpty()) {
578 throw new Error
.GroupNotFound("Group not found");
580 return groupOptional
.get().getObjectPath();
584 public List
<StructGroup
> listGroups() {
590 public String
getGroupName(final byte[] groupId
) {
591 var group
= m
.getGroup(getGroupId(groupId
));
592 if (group
== null || group
.title() == null) {
595 return group
.title();
600 public List
<String
> getGroupMembers(final byte[] groupId
) {
601 var group
= m
.getGroup(getGroupId(groupId
));
605 final var members
= group
.members();
606 return getRecipientStrings(members
);
611 public byte[] createGroup(
612 final String name
, final List
<String
> members
, final String avatar
613 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
614 return updateGroup(new byte[0], name
, members
, avatar
);
618 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
620 groupId
= nullIfEmpty(groupId
);
621 name
= nullIfEmpty(name
);
622 avatar
= nullIfEmpty(avatar
);
623 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
624 if (groupId
== null) {
625 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
627 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
628 return results
.first().serialize();
630 final var results
= m
.updateGroup(getGroupId(groupId
),
631 UpdateGroup
.newBuilder()
633 .withMembers(memberIdentifiers
)
634 .withAvatarFile(avatar
)
636 if (results
!= null) {
637 checkGroupSendMessageResults(results
.timestamp(), results
.results());
641 } catch (IOException e
) {
642 throw new Error
.Failure(e
.getMessage());
643 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
644 throw new Error
.GroupNotFound(e
.getMessage());
645 } catch (AttachmentInvalidException e
) {
646 throw new Error
.AttachmentInvalid(e
.getMessage());
647 } catch (UnregisteredRecipientException e
) {
648 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
653 public boolean isRegistered() {
658 public boolean isRegistered(String number
) {
659 var result
= isRegistered(List
.of(number
));
660 return result
.get(0);
664 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
665 if (numbers
.isEmpty()) {
669 Map
<String
, UserStatus
> registered
;
671 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
672 } catch (IOException e
) {
673 throw new Error
.Failure(e
.getMessage());
674 } catch (RateLimitException e
) {
675 throw new Error
.Failure(e
.getMessage()
677 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
680 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
684 public void updateProfile(
690 final boolean removeAvatar
693 givenName
= nullIfEmpty(givenName
);
694 familyName
= nullIfEmpty(familyName
);
695 about
= nullIfEmpty(about
);
696 aboutEmoji
= nullIfEmpty(aboutEmoji
);
697 avatarPath
= nullIfEmpty(avatarPath
);
698 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
699 m
.updateProfile(UpdateProfile
.newBuilder()
700 .withGivenName(givenName
)
701 .withFamilyName(familyName
)
703 .withAboutEmoji(aboutEmoji
)
704 .withAvatar(avatarFile
)
705 .withDeleteAvatar(removeAvatar
)
707 } catch (IOException e
) {
708 throw new Error
.Failure(e
.getMessage());
713 public void updateProfile(
716 final String aboutEmoji
,
718 final boolean removeAvatar
720 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
724 public void removePin() {
726 m
.setRegistrationLockPin(Optional
.empty());
727 } catch (IOException e
) {
728 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
729 } catch (NotPrimaryDeviceException e
) {
730 throw new Error
.Failure("This command doesn't work on linked devices.");
735 public void setPin(String registrationLockPin
) {
737 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
738 } catch (IOException e
) {
739 throw new Error
.Failure("Set pin error: " + e
.getMessage());
740 } catch (NotPrimaryDeviceException e
) {
741 throw new Error
.Failure("This command doesn't work on linked devices.");
745 // Provide option to query a version string in order to react on potential
746 // future interface changes
748 public String
version() {
749 return BaseConfig
.PROJECT_VERSION
;
752 // Create a unique list of Numbers from Identities and Contacts to really get
753 // all numbers the system knows
755 public List
<String
> listNumbers() {
756 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
758 .map(r
-> r
.getAddress().number().orElse(null))
759 .filter(Objects
::nonNull
)
765 public List
<String
> getContactNumber(final String name
) {
766 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
768 .map(r
-> r
.getAddress().getLegacyIdentifier())
773 public void quitGroup(final byte[] groupId
) {
774 var group
= getGroupId(groupId
);
776 m
.quitGroup(group
, Set
.of());
777 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
778 throw new Error
.GroupNotFound(e
.getMessage());
779 } catch (IOException
| LastGroupAdminException e
) {
780 throw new Error
.Failure(e
.getMessage());
781 } catch (UnregisteredRecipientException e
) {
782 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
787 public byte[] joinGroup(final String groupLink
) {
789 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
790 if (linkUrl
== null) {
791 throw new Error
.Failure("Group link is invalid:");
793 final var result
= m
.joinGroup(linkUrl
);
794 return result
.first().serialize();
795 } catch (PendingAdminApprovalException e
) {
796 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
797 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
798 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
799 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
800 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
801 } catch (IOException e
) {
802 throw new Error
.Failure(e
.getMessage());
807 public boolean isContactBlocked(final String number
) {
808 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
812 public boolean isGroupBlocked(final byte[] groupId
) {
813 var group
= m
.getGroup(getGroupId(groupId
));
817 return group
.isBlocked();
822 public boolean isMember(final byte[] groupId
) {
823 var group
= m
.getGroup(getGroupId(groupId
));
827 return group
.isMember();
832 public String
uploadStickerPack(String stickerPackPath
) {
833 File path
= new File(stickerPackPath
);
835 return m
.uploadStickerPack(path
).toString();
836 } catch (IOException e
) {
837 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
838 } catch (StickerPackInvalidException e
) {
839 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
843 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
844 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
850 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
852 if (result
.isIdentityFailure()) {
853 throw new Error
.UntrustedIdentity(message
);
855 throw new Error
.Failure(message
);
859 private void checkSendMessageResults(final SendMessageResults results
) {
860 final var sendMessageResults
= results
.results().values().stream().findFirst();
861 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
862 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
866 if (results
.hasSuccess()) {
870 var message
= new StringBuilder();
871 message
.append("Failed to send messages:\n");
872 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
873 for (var error
: errors
) {
874 message
.append(error
).append('\n');
876 message
.append(results
.timestamp());
878 throw new Error
.Failure(message
.toString());
881 private static void checkGroupSendMessageResults(
882 long timestamp
, Collection
<SendMessageResult
> results
883 ) throws DBusExecutionException
{
884 if (results
.size() == 1) {
885 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
889 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
890 if (errors
.isEmpty() || errors
.size() < results
.size()) {
894 var message
= new StringBuilder();
895 message
.append("Failed to send message:\n");
896 for (var error
: errors
) {
897 message
.append(error
).append('\n');
899 message
.append(timestamp
);
901 throw new Error
.Failure(message
.toString());
904 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
905 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
908 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
909 final Collection
<String
> recipientStrings
, final String localNumber
910 ) throws DBusExecutionException
{
911 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
912 for (var recipientString
: recipientStrings
) {
913 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
918 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
919 final String recipientString
, final String localNumber
920 ) throws DBusExecutionException
{
922 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
923 } catch (InvalidNumberException e
) {
924 throw new Error
.InvalidNumber(e
.getMessage());
928 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
929 return new RecipientIdentifier
.Group(getGroupId(groupId
));
932 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
934 return GroupId
.unknownVersion(groupId
);
935 } catch (Throwable e
) {
936 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
940 private byte[] nullIfEmpty(final byte[] array
) {
941 return array
.length
== 0 ?
null : array
;
944 private String
nullIfEmpty(final String name
) {
945 return name
.isEmpty() ?
null : name
;
948 private String
emptyIfNull(final String string
) {
949 return string
== null ?
"" : string
;
952 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
953 return basePath
+ "/Devices/" + deviceId
;
956 private void updateDevices() {
957 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
959 linkedDevices
= m
.getLinkedDevices();
960 } catch (IOException e
) {
961 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
966 linkedDevices
.forEach(d
-> {
967 final var object
= new DbusSignalDeviceImpl(d
);
968 final var deviceObjectPath
= object
.getObjectPath();
969 exportObject(object
);
970 if (d
.isThisDevice()) {
971 thisDevice
= new DBusPath(deviceObjectPath
);
973 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
977 private void unExportDevices() {
978 this.devices
.stream()
979 .map(StructDevice
::getObjectPath
)
980 .map(DBusPath
::getPath
)
981 .forEach(connection
::unExportObject
);
982 this.devices
.clear();
985 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
986 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
989 private void updateGroups() {
990 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
991 groups
= m
.getGroups();
995 groups
.forEach(g
-> {
996 final var object
= new DbusSignalGroupImpl(g
.groupId());
997 exportObject(object
);
998 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
999 g
.groupId().serialize(),
1000 emptyIfNull(g
.title())));
1004 private void unExportGroups() {
1005 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1006 this.groups
.clear();
1009 private static String
getConfigurationObjectPath(String basePath
) {
1010 return basePath
+ "/Configuration";
1013 private void updateConfiguration() {
1014 unExportConfiguration();
1015 final var object
= new DbusSignalConfigurationImpl();
1016 exportObject(object
);
1019 private void unExportConfiguration() {
1020 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1021 connection
.unExportObject(objectPath
);
1024 private void exportObject(final DBusInterface object
) {
1026 connection
.exportObject(object
);
1027 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1028 } catch (DBusException e
) {
1029 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1033 private void updateIdentities() {
1034 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1035 identities
= m
.getIdentities();
1037 unExportIdentities();
1039 identities
.forEach(i
-> {
1040 final var object
= new DbusSignalIdentityImpl(i
);
1041 exportObject(object
);
1042 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1043 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1044 i
.recipient().number().orElse("")));
1048 private static String
getIdentityObjectPath(String basePath
, String id
) {
1049 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1052 private void unExportIdentities() {
1053 this.identities
.stream()
1054 .map(StructIdentity
::getObjectPath
)
1055 .map(DBusPath
::getPath
)
1056 .forEach(connection
::unExportObject
);
1057 this.identities
.clear();
1061 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1062 final var found
= identities
.stream()
1063 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1066 if (found
.isEmpty()) {
1067 throw new Error
.Failure("Identity for " + number
+ " unknown");
1069 return found
.get().getObjectPath();
1073 public List
<StructIdentity
> listIdentities() {
1075 return this.identities
;
1078 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1080 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1082 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1083 this.identity
= identity
;
1084 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1085 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1086 new DbusProperty
<>("Uuid",
1087 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1088 new DbusProperty
<>("Fingerprint", identity
::getFingerprint
),
1089 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1090 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1091 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1092 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1096 public String
getObjectPath() {
1097 return getIdentityObjectPath(objectPath
,
1098 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1102 public void trust() throws Error
.Failure
{
1103 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1105 m
.trustIdentityAllKeys(recipient
);
1106 } catch (UnregisteredRecipientException e
) {
1107 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1113 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1114 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1116 if (safetyNumber
== null) {
1117 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1119 final IdentityVerificationCode verificationCode
;
1121 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1122 } catch (Exception e
) {
1123 throw new Error
.Failure(
1124 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1128 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1130 throw new Error
.Failure(
1131 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1133 } catch (UnregisteredRecipientException e
) {
1134 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1140 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1142 private final org
.asamk
.signal
.manager
.api
.Device device
;
1144 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1145 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1146 List
.of(new DbusProperty
<>("Id", device
::id
),
1147 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1148 new DbusProperty
<>("Created", device
::created
),
1149 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1150 this.device
= device
;
1154 public String
getObjectPath() {
1155 return getDeviceObjectPath(objectPath
, device
.id());
1159 public void removeDevice() throws Error
.Failure
{
1161 m
.removeLinkedDevices(device
.id());
1163 } catch (IOException e
) {
1164 throw new Error
.Failure(e
.getMessage());
1168 private void setDeviceName(String name
) {
1169 if (!device
.isThisDevice()) {
1170 throw new Error
.Failure("Only the name of this device can be changed");
1173 m
.updateAccountAttributes(name
);
1174 // update device list
1176 } catch (IOException e
) {
1177 throw new Error
.Failure(e
.getMessage());
1182 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1184 public DbusSignalConfigurationImpl() {
1185 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1186 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1187 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1188 this::getUnidentifiedDeliveryIndicators
,
1189 this::setUnidentifiedDeliveryIndicators
),
1190 new DbusProperty
<>("TypingIndicators",
1191 this::getTypingIndicators
,
1192 this::setTypingIndicators
),
1193 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1198 public String
getObjectPath() {
1199 return getConfigurationObjectPath(objectPath
);
1202 public void setReadReceipts(Boolean readReceipts
) {
1203 setConfiguration(readReceipts
, null, null, null);
1206 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1207 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1210 public void setTypingIndicators(Boolean typingIndicators
) {
1211 setConfiguration(null, null, typingIndicators
, null);
1214 public void setLinkPreviews(Boolean linkPreviews
) {
1215 setConfiguration(null, null, null, linkPreviews
);
1218 private void setConfiguration(
1219 Boolean readReceipts
,
1220 Boolean unidentifiedDeliveryIndicators
,
1221 Boolean typingIndicators
,
1222 Boolean linkPreviews
1225 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1226 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1227 Optional
.ofNullable(typingIndicators
),
1228 Optional
.ofNullable(linkPreviews
)));
1229 } catch (NotPrimaryDeviceException e
) {
1230 throw new Error
.Failure("This command doesn't work on linked devices.");
1234 private boolean getReadReceipts() {
1235 return m
.getConfiguration().readReceipts().orElse(false);
1238 private boolean getUnidentifiedDeliveryIndicators() {
1239 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1242 private boolean getTypingIndicators() {
1243 return m
.getConfiguration().typingIndicators().orElse(false);
1246 private boolean getLinkPreviews() {
1247 return m
.getConfiguration().linkPreviews().orElse(false);
1251 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1253 private final GroupId groupId
;
1255 public DbusSignalGroupImpl(final GroupId groupId
) {
1256 this.groupId
= groupId
;
1257 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1258 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1259 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1260 new DbusProperty
<>("Description",
1261 () -> emptyIfNull(getGroup().description()),
1262 this::setGroupDescription
),
1263 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1264 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1265 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1266 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1267 new DbusProperty
<>("MessageExpirationTimer",
1268 () -> getGroup().messageExpirationTimer(),
1269 this::setMessageExpirationTime
),
1270 new DbusProperty
<>("Members",
1271 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1272 new DbusProperty
<>("PendingMembers",
1273 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1274 new DbusProperty
<>("RequestingMembers",
1275 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1276 new DbusProperty
<>("Admins",
1277 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1278 new DbusProperty
<>("Banned",
1279 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1280 new DbusProperty
<>("PermissionAddMember",
1281 () -> getGroup().permissionAddMember().name(),
1282 this::setGroupPermissionAddMember
),
1283 new DbusProperty
<>("PermissionEditDetails",
1284 () -> getGroup().permissionEditDetails().name(),
1285 this::setGroupPermissionEditDetails
),
1286 new DbusProperty
<>("PermissionSendMessage",
1287 () -> getGroup().permissionSendMessage().name(),
1288 this::setGroupPermissionSendMessage
),
1289 new DbusProperty
<>("GroupInviteLink", () -> {
1290 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1291 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1296 public String
getObjectPath() {
1297 return getGroupObjectPath(objectPath
, groupId
.serialize());
1301 public void quitGroup() throws Error
.Failure
{
1303 m
.quitGroup(groupId
, Set
.of());
1304 } catch (GroupNotFoundException e
) {
1305 throw new Error
.GroupNotFound(e
.getMessage());
1306 } catch (NotAGroupMemberException e
) {
1307 throw new Error
.NotAGroupMember(e
.getMessage());
1308 } catch (IOException e
) {
1309 throw new Error
.Failure(e
.getMessage());
1310 } catch (LastGroupAdminException e
) {
1311 throw new Error
.LastGroupAdmin(e
.getMessage());
1312 } catch (UnregisteredRecipientException e
) {
1313 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1318 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1320 m
.deleteGroup(groupId
);
1321 } catch (IOException e
) {
1322 throw new Error
.Failure(e
.getMessage());
1328 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1329 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1330 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1334 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1335 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1336 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1340 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1341 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1342 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1346 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1347 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1348 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1352 public void resetLink() throws Error
.Failure
{
1353 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1357 public void disableLink() throws Error
.Failure
{
1358 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1362 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1363 updateGroup(UpdateGroup
.newBuilder()
1364 .withGroupLinkState(requiresApproval
1365 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1366 : GroupLinkState
.ENABLED
)
1370 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1371 return m
.getGroup(groupId
);
1374 private void setGroupName(final String name
) {
1375 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1378 private void setGroupDescription(final String description
) {
1379 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1382 private void setGroupAvatar(final String avatar
) {
1383 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1386 private void setMessageExpirationTime(final int expirationTime
) {
1387 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1390 private void setGroupPermissionAddMember(final String permission
) {
1391 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1394 private void setGroupPermissionEditDetails(final String permission
) {
1395 updateGroup(UpdateGroup
.newBuilder()
1396 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1400 private void setGroupPermissionSendMessage(final String permission
) {
1401 updateGroup(UpdateGroup
.newBuilder()
1402 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1406 private void setIsBlocked(final boolean isBlocked
) {
1408 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1409 } catch (NotPrimaryDeviceException e
) {
1410 throw new Error
.Failure("This command doesn't work on linked devices.");
1411 } catch (GroupNotFoundException e
) {
1412 throw new Error
.GroupNotFound(e
.getMessage());
1413 } catch (IOException e
) {
1414 throw new Error
.Failure(e
.getMessage());
1418 private void updateGroup(final UpdateGroup updateGroup
) {
1420 m
.updateGroup(groupId
, updateGroup
);
1421 } catch (IOException e
) {
1422 throw new Error
.Failure(e
.getMessage());
1423 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1424 throw new Error
.GroupNotFound(e
.getMessage());
1425 } catch (AttachmentInvalidException e
) {
1426 throw new Error
.AttachmentInvalid(e
.getMessage());
1427 } catch (UnregisteredRecipientException e
) {
1428 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");