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
{
355 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()),
357 checkSendMessageResults(results
);
358 } catch (IOException e
) {
359 throw new Error
.Failure(e
.getMessage());
364 public void sendViewedReceipt(
365 final String recipient
, final List
<Long
> messageIds
366 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
368 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()),
370 checkSendMessageResults(results
);
371 } catch (IOException e
) {
372 throw new Error
.Failure(e
.getMessage());
377 public void sendContacts() {
380 } catch (IOException e
) {
381 throw new Error
.Failure("SendContacts error: " + e
.getMessage());
386 public void sendSyncRequest() {
388 m
.requestAllSyncData();
389 } catch (IOException e
) {
390 throw new Error
.Failure("Request sync data error: " + e
.getMessage());
395 public long sendNoteToSelfMessage(
396 final String message
, final List
<String
> attachments
397 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
399 final var results
= m
.sendMessage(new Message(message
,
406 List
.of()), Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
));
407 checkSendMessageResults(results
);
408 return results
.timestamp();
409 } catch (AttachmentInvalidException e
) {
410 throw new Error
.AttachmentInvalid(e
.getMessage());
411 } catch (IOException
| InvalidStickerException e
) {
412 throw new Error
.Failure(e
.getMessage());
413 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
414 throw new Error
.GroupNotFound(e
.getMessage());
415 } catch (UnregisteredRecipientException e
) {
416 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
421 public void sendEndSessionMessage(final List
<String
> recipients
) {
423 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
424 checkSendMessageResults(results
);
425 } catch (IOException e
) {
426 throw new Error
.Failure(e
.getMessage());
431 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
432 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
436 public void deleteContact(final String recipient
) throws Error
.Failure
{
437 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
441 public long sendGroupMessage(final String message
, final List
<String
> attachments
, final byte[] groupId
) {
443 var results
= m
.sendMessage(new Message(message
,
450 List
.of()), Set
.of(getGroupRecipientIdentifier(groupId
)));
451 checkSendMessageResults(results
);
452 return results
.timestamp();
453 } catch (IOException
| InvalidStickerException e
) {
454 throw new Error
.Failure(e
.getMessage());
455 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
456 throw new Error
.GroupNotFound(e
.getMessage());
457 } catch (AttachmentInvalidException e
) {
458 throw new Error
.AttachmentInvalid(e
.getMessage());
459 } catch (UnregisteredRecipientException e
) {
460 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
465 public void sendGroupTyping(
466 final byte[] groupId
, final boolean stop
467 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
469 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
470 Set
.of(getGroupRecipientIdentifier(groupId
)));
471 checkSendMessageResults(results
);
472 } catch (IOException e
) {
473 throw new Error
.Failure(e
.getMessage());
474 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
475 throw new Error
.GroupNotFound(e
.getMessage());
480 public long sendGroupRemoteDeleteMessage(
481 final long targetSentTimestamp
, final byte[] groupId
484 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
485 Set
.of(getGroupRecipientIdentifier(groupId
)));
486 checkSendMessageResults(results
);
487 return results
.timestamp();
488 } catch (IOException e
) {
489 throw new Error
.Failure(e
.getMessage());
490 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
491 throw new Error
.GroupNotFound(e
.getMessage());
496 public long sendGroupMessageReaction(
498 final boolean remove
,
499 final String targetAuthor
,
500 final long targetSentTimestamp
,
504 final var results
= m
.sendMessageReaction(emoji
,
506 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
508 Set
.of(getGroupRecipientIdentifier(groupId
)),
510 checkSendMessageResults(results
);
511 return results
.timestamp();
512 } catch (IOException e
) {
513 throw new Error
.Failure(e
.getMessage());
514 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
515 throw new Error
.GroupNotFound(e
.getMessage());
516 } catch (UnregisteredRecipientException e
) {
517 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
521 // Since contact names might be empty if not defined, also potentially return
524 public String
getContactName(final String number
) {
525 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
526 return name
== null ?
"" : name
;
530 public void setContactName(final String number
, final String name
) {
532 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "");
533 } catch (NotPrimaryDeviceException e
) {
534 throw new Error
.Failure("This command doesn't work on linked devices.");
535 } catch (IOException e
) {
536 throw new Error
.Failure("Contact is not registered.");
537 } catch (UnregisteredRecipientException e
) {
538 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
543 public void setExpirationTimer(final String number
, final int expiration
) {
545 m
.setExpirationTimer(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), expiration
);
546 } catch (IOException e
) {
547 throw new Error
.Failure(e
.getMessage());
548 } catch (UnregisteredRecipientException e
) {
549 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
554 public void setContactBlocked(final String number
, final boolean blocked
) {
556 m
.setContactsBlocked(List
.of(getSingleRecipientIdentifier(number
, m
.getSelfNumber())), blocked
);
557 } catch (NotPrimaryDeviceException e
) {
558 throw new Error
.Failure("This command doesn't work on linked devices.");
559 } catch (IOException e
) {
560 throw new Error
.Failure(e
.getMessage());
561 } catch (UnregisteredRecipientException e
) {
562 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
567 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
569 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
570 } catch (NotPrimaryDeviceException e
) {
571 throw new Error
.Failure("This command doesn't work on linked devices.");
572 } catch (GroupNotFoundException e
) {
573 throw new Error
.GroupNotFound(e
.getMessage());
574 } catch (IOException e
) {
575 throw new Error
.Failure(e
.getMessage());
580 public List
<byte[]> getGroupIds() {
581 var groups
= m
.getGroups();
582 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
586 public DBusPath
getGroup(final byte[] groupId
) {
588 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
589 if (groupOptional
.isEmpty()) {
590 throw new Error
.GroupNotFound("Group not found");
592 return groupOptional
.get().getObjectPath();
596 public List
<StructGroup
> listGroups() {
602 public String
getGroupName(final byte[] groupId
) {
603 var group
= m
.getGroup(getGroupId(groupId
));
604 if (group
== null || group
.title() == null) {
607 return group
.title();
612 public List
<String
> getGroupMembers(final byte[] groupId
) {
613 var group
= m
.getGroup(getGroupId(groupId
));
617 final var members
= group
.members();
618 return getRecipientStrings(members
);
623 public byte[] createGroup(
624 final String name
, final List
<String
> members
, final String avatar
625 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
626 return updateGroup(new byte[0], name
, members
, avatar
);
630 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
632 groupId
= nullIfEmpty(groupId
);
633 name
= nullIfEmpty(name
);
634 avatar
= nullIfEmpty(avatar
);
635 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
636 if (groupId
== null) {
637 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
639 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
640 return results
.first().serialize();
642 final var results
= m
.updateGroup(getGroupId(groupId
),
643 UpdateGroup
.newBuilder()
645 .withMembers(memberIdentifiers
)
646 .withAvatarFile(avatar
)
648 if (results
!= null) {
649 checkGroupSendMessageResults(results
.timestamp(), results
.results());
653 } catch (IOException e
) {
654 throw new Error
.Failure(e
.getMessage());
655 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
656 throw new Error
.GroupNotFound(e
.getMessage());
657 } catch (AttachmentInvalidException e
) {
658 throw new Error
.AttachmentInvalid(e
.getMessage());
659 } catch (UnregisteredRecipientException e
) {
660 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
665 public boolean isRegistered() {
670 public boolean isRegistered(String number
) {
671 var result
= isRegistered(List
.of(number
));
672 return result
.get(0);
676 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
677 if (numbers
.isEmpty()) {
681 Map
<String
, UserStatus
> registered
;
683 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
684 } catch (IOException e
) {
685 throw new Error
.Failure(e
.getMessage());
686 } catch (RateLimitException e
) {
687 throw new Error
.Failure(e
.getMessage()
689 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
692 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
696 public void updateProfile(
702 final boolean removeAvatar
705 givenName
= nullIfEmpty(givenName
);
706 familyName
= nullIfEmpty(familyName
);
707 about
= nullIfEmpty(about
);
708 aboutEmoji
= nullIfEmpty(aboutEmoji
);
709 avatarPath
= nullIfEmpty(avatarPath
);
710 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
711 m
.updateProfile(UpdateProfile
.newBuilder()
712 .withGivenName(givenName
)
713 .withFamilyName(familyName
)
715 .withAboutEmoji(aboutEmoji
)
716 .withAvatar(avatarFile
)
717 .withDeleteAvatar(removeAvatar
)
719 } catch (IOException e
) {
720 throw new Error
.Failure(e
.getMessage());
725 public void updateProfile(
728 final String aboutEmoji
,
730 final boolean removeAvatar
732 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
736 public void removePin() {
738 m
.setRegistrationLockPin(Optional
.empty());
739 } catch (IOException e
) {
740 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
741 } catch (NotPrimaryDeviceException e
) {
742 throw new Error
.Failure("This command doesn't work on linked devices.");
747 public void setPin(String registrationLockPin
) {
749 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
750 } catch (IOException e
) {
751 throw new Error
.Failure("Set pin error: " + e
.getMessage());
752 } catch (NotPrimaryDeviceException e
) {
753 throw new Error
.Failure("This command doesn't work on linked devices.");
757 // Provide option to query a version string in order to react on potential
758 // future interface changes
760 public String
version() {
761 return BaseConfig
.PROJECT_VERSION
;
764 // Create a unique list of Numbers from Identities and Contacts to really get
765 // all numbers the system knows
767 public List
<String
> listNumbers() {
768 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
770 .map(r
-> r
.getAddress().number().orElse(null))
771 .filter(Objects
::nonNull
)
777 public List
<String
> getContactNumber(final String name
) {
778 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
780 .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()));
824 public boolean isGroupBlocked(final byte[] groupId
) {
825 var group
= m
.getGroup(getGroupId(groupId
));
829 return group
.isBlocked();
834 public boolean isMember(final byte[] groupId
) {
835 var group
= m
.getGroup(getGroupId(groupId
));
839 return group
.isMember();
844 public String
uploadStickerPack(String stickerPackPath
) {
845 File path
= new File(stickerPackPath
);
847 return m
.uploadStickerPack(path
).toString();
848 } catch (IOException e
) {
849 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
850 } catch (StickerPackInvalidException e
) {
851 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
855 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
856 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
862 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
864 if (result
.isIdentityFailure()) {
865 throw new Error
.UntrustedIdentity(message
);
867 throw new Error
.Failure(message
);
871 private void checkSendMessageResults(final SendMessageResults results
) {
872 final var sendMessageResults
= results
.results().values().stream().findFirst();
873 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
874 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
878 if (results
.hasSuccess()) {
882 var message
= new StringBuilder();
883 message
.append("Failed to send messages:\n");
884 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
885 for (var error
: errors
) {
886 message
.append(error
).append('\n');
888 message
.append(results
.timestamp());
890 throw new Error
.Failure(message
.toString());
893 private static void checkGroupSendMessageResults(
894 long timestamp
, Collection
<SendMessageResult
> results
895 ) throws DBusExecutionException
{
896 if (results
.size() == 1) {
897 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
901 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
902 if (errors
.isEmpty() || errors
.size() < results
.size()) {
906 var message
= new StringBuilder();
907 message
.append("Failed to send message:\n");
908 for (var error
: errors
) {
909 message
.append(error
).append('\n');
911 message
.append(timestamp
);
913 throw new Error
.Failure(message
.toString());
916 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
917 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
920 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
921 final Collection
<String
> recipientStrings
, final String localNumber
922 ) throws DBusExecutionException
{
923 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
924 for (var recipientString
: recipientStrings
) {
925 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
930 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
931 final String recipientString
, final String localNumber
932 ) throws DBusExecutionException
{
934 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
935 } catch (InvalidNumberException e
) {
936 throw new Error
.InvalidNumber(e
.getMessage());
940 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
941 return new RecipientIdentifier
.Group(getGroupId(groupId
));
944 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
946 return GroupId
.unknownVersion(groupId
);
947 } catch (Throwable e
) {
948 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
952 private byte[] nullIfEmpty(final byte[] array
) {
953 return array
.length
== 0 ?
null : array
;
956 private String
nullIfEmpty(final String name
) {
957 return name
.isEmpty() ?
null : name
;
960 private String
emptyIfNull(final String string
) {
961 return string
== null ?
"" : string
;
964 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
965 return basePath
+ "/Devices/" + deviceId
;
968 private void updateDevices() {
969 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
971 linkedDevices
= m
.getLinkedDevices();
972 } catch (IOException e
) {
973 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
978 linkedDevices
.forEach(d
-> {
979 final var object
= new DbusSignalDeviceImpl(d
);
980 final var deviceObjectPath
= object
.getObjectPath();
981 exportObject(object
);
982 if (d
.isThisDevice()) {
983 thisDevice
= new DBusPath(deviceObjectPath
);
985 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
989 private void unExportDevices() {
990 this.devices
.stream()
991 .map(StructDevice
::getObjectPath
)
992 .map(DBusPath
::getPath
)
993 .forEach(connection
::unExportObject
);
994 this.devices
.clear();
997 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
998 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
1001 private void updateGroups() {
1002 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
1003 groups
= m
.getGroups();
1007 groups
.forEach(g
-> {
1008 final var object
= new DbusSignalGroupImpl(g
.groupId());
1009 exportObject(object
);
1010 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1011 g
.groupId().serialize(),
1012 emptyIfNull(g
.title())));
1016 private void unExportGroups() {
1017 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1018 this.groups
.clear();
1021 private static String
getConfigurationObjectPath(String basePath
) {
1022 return basePath
+ "/Configuration";
1025 private void updateConfiguration() {
1026 unExportConfiguration();
1027 final var object
= new DbusSignalConfigurationImpl();
1028 exportObject(object
);
1031 private void unExportConfiguration() {
1032 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1033 connection
.unExportObject(objectPath
);
1036 private void exportObject(final DBusInterface object
) {
1038 connection
.exportObject(object
);
1039 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1040 } catch (DBusException e
) {
1041 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1045 private void updateIdentities() {
1046 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1047 identities
= m
.getIdentities();
1049 unExportIdentities();
1051 identities
.forEach(i
-> {
1052 final var object
= new DbusSignalIdentityImpl(i
);
1053 exportObject(object
);
1054 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1055 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1056 i
.recipient().number().orElse("")));
1060 private static String
getIdentityObjectPath(String basePath
, String id
) {
1061 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1064 private void unExportIdentities() {
1065 this.identities
.stream()
1066 .map(StructIdentity
::getObjectPath
)
1067 .map(DBusPath
::getPath
)
1068 .forEach(connection
::unExportObject
);
1069 this.identities
.clear();
1073 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1074 final var found
= identities
.stream()
1075 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1078 if (found
.isEmpty()) {
1079 throw new Error
.Failure("Identity for " + number
+ " unknown");
1081 return found
.get().getObjectPath();
1085 public List
<StructIdentity
> listIdentities() {
1087 return this.identities
;
1090 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1092 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1094 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1095 this.identity
= identity
;
1096 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1097 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1098 new DbusProperty
<>("Uuid",
1099 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1100 new DbusProperty
<>("Fingerprint", identity
::getFingerprint
),
1101 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1102 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1103 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1104 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1108 public String
getObjectPath() {
1109 return getIdentityObjectPath(objectPath
,
1110 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1114 public void trust() throws Error
.Failure
{
1115 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1117 m
.trustIdentityAllKeys(recipient
);
1118 } catch (UnregisteredRecipientException e
) {
1119 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1125 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1126 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1128 if (safetyNumber
== null) {
1129 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1131 final IdentityVerificationCode verificationCode
;
1133 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1134 } catch (Exception e
) {
1135 throw new Error
.Failure(
1136 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1140 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1142 throw new Error
.Failure(
1143 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1145 } catch (UnregisteredRecipientException e
) {
1146 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1152 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1154 private final org
.asamk
.signal
.manager
.api
.Device device
;
1156 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1157 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1158 List
.of(new DbusProperty
<>("Id", device
::id
),
1159 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1160 new DbusProperty
<>("Created", device
::created
),
1161 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1162 this.device
= device
;
1166 public String
getObjectPath() {
1167 return getDeviceObjectPath(objectPath
, device
.id());
1171 public void removeDevice() throws Error
.Failure
{
1173 m
.removeLinkedDevices(device
.id());
1175 } catch (IOException e
) {
1176 throw new Error
.Failure(e
.getMessage());
1180 private void setDeviceName(String name
) {
1181 if (!device
.isThisDevice()) {
1182 throw new Error
.Failure("Only the name of this device can be changed");
1185 m
.updateAccountAttributes(name
);
1186 // update device list
1188 } catch (IOException e
) {
1189 throw new Error
.Failure(e
.getMessage());
1194 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1196 public DbusSignalConfigurationImpl() {
1197 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1198 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1199 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1200 this::getUnidentifiedDeliveryIndicators
,
1201 this::setUnidentifiedDeliveryIndicators
),
1202 new DbusProperty
<>("TypingIndicators",
1203 this::getTypingIndicators
,
1204 this::setTypingIndicators
),
1205 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1210 public String
getObjectPath() {
1211 return getConfigurationObjectPath(objectPath
);
1214 public void setReadReceipts(Boolean readReceipts
) {
1215 setConfiguration(readReceipts
, null, null, null);
1218 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1219 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1222 public void setTypingIndicators(Boolean typingIndicators
) {
1223 setConfiguration(null, null, typingIndicators
, null);
1226 public void setLinkPreviews(Boolean linkPreviews
) {
1227 setConfiguration(null, null, null, linkPreviews
);
1230 private void setConfiguration(
1231 Boolean readReceipts
,
1232 Boolean unidentifiedDeliveryIndicators
,
1233 Boolean typingIndicators
,
1234 Boolean linkPreviews
1237 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1238 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1239 Optional
.ofNullable(typingIndicators
),
1240 Optional
.ofNullable(linkPreviews
)));
1241 } catch (IOException e
) {
1242 throw new Error
.Failure("UpdateAccount error: " + e
.getMessage());
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.");