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
.CaptchaRejectedException
;
8 import org
.asamk
.signal
.manager
.api
.DeviceLimitExceededException
;
9 import org
.asamk
.signal
.manager
.api
.DeviceLinkUrl
;
10 import org
.asamk
.signal
.manager
.api
.GroupId
;
11 import org
.asamk
.signal
.manager
.api
.GroupInviteLinkUrl
;
12 import org
.asamk
.signal
.manager
.api
.GroupLinkState
;
13 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
14 import org
.asamk
.signal
.manager
.api
.GroupPermission
;
15 import org
.asamk
.signal
.manager
.api
.GroupSendingNotAllowedException
;
16 import org
.asamk
.signal
.manager
.api
.IdentityVerificationCode
;
17 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
18 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
19 import org
.asamk
.signal
.manager
.api
.InvalidNumberException
;
20 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
21 import org
.asamk
.signal
.manager
.api
.LastGroupAdminException
;
22 import org
.asamk
.signal
.manager
.api
.Message
;
23 import org
.asamk
.signal
.manager
.api
.NotAGroupMemberException
;
24 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
25 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
26 import org
.asamk
.signal
.manager
.api
.RateLimitException
;
27 import org
.asamk
.signal
.manager
.api
.RecipientAddress
;
28 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
29 import org
.asamk
.signal
.manager
.api
.SendMessageResult
;
30 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
31 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
32 import org
.asamk
.signal
.manager
.api
.TypingAction
;
33 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
34 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
35 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
36 import org
.asamk
.signal
.manager
.api
.UserStatus
;
37 import org
.asamk
.signal
.util
.DateUtils
;
38 import org
.asamk
.signal
.util
.SendMessageResultUtils
;
39 import org
.freedesktop
.dbus
.DBusPath
;
40 import org
.freedesktop
.dbus
.connections
.impl
.DBusConnection
;
41 import org
.freedesktop
.dbus
.exceptions
.DBusException
;
42 import org
.freedesktop
.dbus
.exceptions
.DBusExecutionException
;
43 import org
.freedesktop
.dbus
.interfaces
.DBusInterface
;
44 import org
.freedesktop
.dbus
.types
.Variant
;
45 import org
.slf4j
.Logger
;
46 import org
.slf4j
.LoggerFactory
;
49 import java
.io
.IOException
;
51 import java
.net
.URISyntaxException
;
52 import java
.util
.ArrayList
;
53 import java
.util
.Arrays
;
54 import java
.util
.Base64
;
55 import java
.util
.Collection
;
56 import java
.util
.HashSet
;
57 import java
.util
.List
;
59 import java
.util
.Objects
;
60 import java
.util
.Optional
;
62 import java
.util
.UUID
;
63 import java
.util
.stream
.Collectors
;
65 import static org
.asamk
.signal
.dbus
.DbusUtils
.makeValidObjectPathElement
;
67 public class DbusSignalImpl
implements Signal
, AutoCloseable
{
69 private final Manager m
;
70 private final DBusConnection connection
;
71 private final String objectPath
;
72 private final boolean noReceiveOnStart
;
74 private DBusPath thisDevice
;
75 private final List
<StructDevice
> devices
= new ArrayList
<>();
76 private final List
<StructGroup
> groups
= new ArrayList
<>();
77 private final List
<StructIdentity
> identities
= new ArrayList
<>();
78 private DbusReceiveMessageHandler dbusMessageHandler
;
79 private int subscriberCount
;
81 private static final Logger logger
= LoggerFactory
.getLogger(DbusSignalImpl
.class);
83 public DbusSignalImpl(
85 DBusConnection connection
,
86 final String objectPath
,
87 final boolean noReceiveOnStart
90 this.connection
= connection
;
91 this.objectPath
= objectPath
;
92 this.noReceiveOnStart
= noReceiveOnStart
;
94 m
.addAddressChangedListener(() -> {
100 public void initObjects() {
102 if (!noReceiveOnStart
) {
107 private void exportObjects() {
112 updateConfiguration();
117 public void close() {
118 if (dbusMessageHandler
!= null) {
119 m
.removeReceiveHandler(dbusMessageHandler
);
120 dbusMessageHandler
= null;
125 private void unExportObjects() {
128 unExportConfiguration();
129 unExportIdentities();
130 connection
.unExportObject(this.objectPath
);
134 public String
getObjectPath() {
139 public String
getSelfNumber() {
140 return m
.getSelfNumber();
144 public void subscribeReceive() {
145 if (dbusMessageHandler
== null) {
146 dbusMessageHandler
= new DbusReceiveMessageHandler(connection
, objectPath
);
147 m
.addReceiveHandler(dbusMessageHandler
);
153 public void unsubscribeReceive() {
154 subscriberCount
= Math
.max(0, subscriberCount
- 1);
155 if (subscriberCount
== 0 && dbusMessageHandler
!= null) {
156 m
.removeReceiveHandler(dbusMessageHandler
);
157 dbusMessageHandler
= null;
162 public void submitRateLimitChallenge(String challenge
, String captcha
) {
164 m
.submitRateLimitRecaptchaChallenge(challenge
, captcha
);
165 } catch (IOException e
) {
166 throw new Error
.Failure("Submit challenge error: " + e
.getMessage());
167 } catch (CaptchaRejectedException e
) {
168 throw new Error
.Failure(
169 "Captcha rejected, it may be outdated, already used or solved from a different IP address.");
174 public void unregister() throws Error
.Failure
{
177 } catch (IOException e
) {
178 throw new Error
.Failure("Failed to unregister: " + e
.getMessage());
183 public void deleteAccount() throws Error
.Failure
{
186 } catch (IOException e
) {
187 throw new Error
.Failure("Failed to delete account: " + e
.getMessage());
192 public void addDevice(String uri
) {
194 var deviceLinkUrl
= DeviceLinkUrl
.parseDeviceLinkUri(new URI(uri
));
195 m
.addDeviceLink(deviceLinkUrl
);
196 } catch (IOException
| InvalidDeviceLinkException
| DeviceLimitExceededException e
) {
197 throw new Error
.Failure(e
.getClass().getSimpleName() + " Add device link failed. " + e
.getMessage());
198 } catch (NotPrimaryDeviceException e
) {
199 throw new Error
.Failure("This command doesn't work on linked devices.");
200 } catch (URISyntaxException e
) {
201 throw new Error
.InvalidUri(e
.getClass().getSimpleName()
202 + " Device link uri has invalid format: "
208 public DBusPath
getDevice(long deviceId
) {
210 final var deviceOptional
= devices
.stream().filter(g
-> g
.getId().equals(deviceId
)).findFirst();
211 if (deviceOptional
.isEmpty()) {
212 throw new Error
.DeviceNotFound("Device not found");
214 return deviceOptional
.get().getObjectPath();
218 public List
<StructDevice
> listDevices() {
224 public DBusPath
getThisDevice() {
230 public long sendMessage(final String message
, final List
<String
> attachments
, final String recipient
) {
231 return sendMessage(message
, attachments
, List
.of(recipient
));
235 public long sendMessage(final String messageText
, final List
<String
> attachments
, final List
<String
> recipients
) {
237 final var message
= new Message(messageText
,
245 final var recipientIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
246 .map(RecipientIdentifier
.class::cast
)
247 .collect(Collectors
.toSet());
248 final var results
= m
.sendMessage(message
, recipientIdentifiers
, false);
250 checkSendMessageResults(results
);
251 return results
.timestamp();
252 } catch (AttachmentInvalidException e
) {
253 throw new Error
.AttachmentInvalid(e
.getMessage());
254 } catch (IOException
| InvalidStickerException e
) {
255 throw new Error
.Failure(e
);
256 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
257 throw new Error
.GroupNotFound(e
.getMessage());
258 } catch (UnregisteredRecipientException e
) {
259 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
264 public long sendRemoteDeleteMessage(final long targetSentTimestamp
, final String recipient
) {
265 return sendRemoteDeleteMessage(targetSentTimestamp
, List
.of(recipient
));
269 public long sendRemoteDeleteMessage(final long targetSentTimestamp
, final List
<String
> recipients
) {
271 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
272 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
273 .map(RecipientIdentifier
.class::cast
)
274 .collect(Collectors
.toSet()));
275 checkSendMessageResults(results
);
276 return results
.timestamp();
277 } catch (IOException e
) {
278 throw new Error
.Failure(e
.getMessage());
279 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
280 throw new Error
.GroupNotFound(e
.getMessage());
285 public long sendMessageReaction(
287 final boolean remove
,
288 final String targetAuthor
,
289 final long targetSentTimestamp
,
290 final String recipient
292 return sendMessageReaction(emoji
, remove
, targetAuthor
, targetSentTimestamp
, List
.of(recipient
));
296 public long sendMessageReaction(
298 final boolean remove
,
299 final String targetAuthor
,
300 final long targetSentTimestamp
,
301 final List
<String
> recipients
304 final var results
= m
.sendMessageReaction(emoji
,
306 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
308 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
309 .map(RecipientIdentifier
.class::cast
)
310 .collect(Collectors
.toSet()),
312 checkSendMessageResults(results
);
313 return results
.timestamp();
314 } catch (IOException e
) {
315 throw new Error
.Failure(e
.getMessage());
316 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
317 throw new Error
.GroupNotFound(e
.getMessage());
318 } catch (UnregisteredRecipientException e
) {
319 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
324 public long sendPaymentNotification(
325 final byte[] receipt
,
327 final String recipient
328 ) throws Error
.Failure
{
330 final var results
= m
.sendPaymentNotificationMessage(receipt
,
332 getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
333 checkSendMessageResults(results
);
334 return results
.timestamp();
335 } catch (IOException e
) {
336 throw new Error
.Failure(e
.getMessage());
341 public void sendTyping(
342 final String recipient
,
344 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
346 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
347 getSingleRecipientIdentifiers(List
.of(recipient
), m
.getSelfNumber()).stream()
348 .map(RecipientIdentifier
.class::cast
)
349 .collect(Collectors
.toSet()));
350 checkSendMessageResults(results
);
351 } catch (IOException e
) {
352 throw new Error
.Failure(e
.getMessage());
353 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
354 throw new Error
.GroupNotFound(e
.getMessage());
359 public void sendReadReceipt(
360 final String recipient
,
361 final List
<Long
> messageIds
362 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
363 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
364 checkSendMessageResults(results
);
368 public void sendViewedReceipt(
369 final String recipient
,
370 final List
<Long
> messageIds
371 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
372 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
373 checkSendMessageResults(results
);
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 messageText
,
397 final List
<String
> attachments
398 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
400 final var message
= new Message(messageText
,
408 final var results
= m
.sendMessage(message
, Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
), false);
409 checkSendMessageResults(results
);
410 return results
.timestamp();
411 } catch (AttachmentInvalidException e
) {
412 throw new Error
.AttachmentInvalid(e
.getMessage());
413 } catch (IOException
| InvalidStickerException e
) {
414 throw new Error
.Failure(e
.getMessage());
415 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
416 throw new Error
.GroupNotFound(e
.getMessage());
417 } catch (UnregisteredRecipientException e
) {
418 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
423 public void sendEndSessionMessage(final List
<String
> recipients
) {
425 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
426 checkSendMessageResults(results
);
427 } catch (IOException e
) {
428 throw new Error
.Failure(e
.getMessage());
433 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
434 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
438 public void deleteContact(final String recipient
) throws Error
.Failure
{
439 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
443 public long sendGroupMessage(final String messageText
, final List
<String
> attachments
, final byte[] groupId
) {
445 final var message
= new Message(messageText
,
453 var results
= m
.sendMessage(message
, Set
.of(getGroupRecipientIdentifier(groupId
)), false);
454 checkSendMessageResults(results
);
455 return results
.timestamp();
456 } catch (IOException
| InvalidStickerException e
) {
457 throw new Error
.Failure(e
.getMessage());
458 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
459 throw new Error
.GroupNotFound(e
.getMessage());
460 } catch (AttachmentInvalidException e
) {
461 throw new Error
.AttachmentInvalid(e
.getMessage());
462 } catch (UnregisteredRecipientException e
) {
463 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
468 public void sendGroupTyping(
469 final byte[] groupId
,
471 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
473 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
474 Set
.of(getGroupRecipientIdentifier(groupId
)));
475 checkSendMessageResults(results
);
476 } catch (IOException e
) {
477 throw new Error
.Failure(e
.getMessage());
478 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
479 throw new Error
.GroupNotFound(e
.getMessage());
484 public long sendGroupRemoteDeleteMessage(final long targetSentTimestamp
, final byte[] groupId
) {
486 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
487 Set
.of(getGroupRecipientIdentifier(groupId
)));
488 checkSendMessageResults(results
);
489 return results
.timestamp();
490 } catch (IOException e
) {
491 throw new Error
.Failure(e
.getMessage());
492 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
493 throw new Error
.GroupNotFound(e
.getMessage());
498 public long sendGroupMessageReaction(
500 final boolean remove
,
501 final String targetAuthor
,
502 final long targetSentTimestamp
,
506 final var results
= m
.sendMessageReaction(emoji
,
508 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
510 Set
.of(getGroupRecipientIdentifier(groupId
)),
512 checkSendMessageResults(results
);
513 return results
.timestamp();
514 } catch (IOException e
) {
515 throw new Error
.Failure(e
.getMessage());
516 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
517 throw new Error
.GroupNotFound(e
.getMessage());
518 } catch (UnregisteredRecipientException e
) {
519 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
523 // Since contact names might be empty if not defined, also potentially return
526 public String
getContactName(final String number
) {
527 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
528 return name
== null ?
"" : name
;
532 public void setContactName(final String number
, final String name
) {
534 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "");
535 } catch (NotPrimaryDeviceException e
) {
536 throw new Error
.Failure("This command doesn't work on linked devices.");
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.");
568 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
570 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
571 } catch (NotPrimaryDeviceException e
) {
572 throw new Error
.Failure("This command doesn't work on linked devices.");
573 } catch (GroupNotFoundException e
) {
574 throw new Error
.GroupNotFound(e
.getMessage());
575 } catch (IOException e
) {
576 throw new Error
.Failure(e
.getMessage());
582 public List
<byte[]> getGroupIds() {
583 var groups
= m
.getGroups();
584 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
588 public DBusPath
getGroup(final byte[] groupId
) {
590 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
591 if (groupOptional
.isEmpty()) {
592 throw new Error
.GroupNotFound("Group not found");
594 return groupOptional
.get().getObjectPath();
598 public List
<StructGroup
> listGroups() {
605 public String
getGroupName(final byte[] groupId
) {
606 var group
= m
.getGroup(getGroupId(groupId
));
607 if (group
== null || group
.title() == null) {
610 return group
.title();
616 public List
<String
> getGroupMembers(final byte[] groupId
) {
617 var group
= m
.getGroup(getGroupId(groupId
));
621 final var members
= group
.members();
622 return getRecipientStrings(members
);
627 public byte[] createGroup(
629 final List
<String
> members
,
631 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
632 return updateGroupInternal(new byte[0], name
, members
, avatar
);
637 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
638 return updateGroupInternal(groupId
, name
, members
, avatar
);
641 public byte[] updateGroupInternal(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
643 groupId
= nullIfEmpty(groupId
);
644 name
= nullIfEmpty(name
);
645 avatar
= nullIfEmpty(avatar
);
646 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
647 if (groupId
== null) {
648 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
650 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
651 return results
.first().serialize();
653 final var results
= m
.updateGroup(getGroupId(groupId
),
654 UpdateGroup
.newBuilder()
656 .withMembers(memberIdentifiers
)
657 .withAvatarFile(avatar
)
659 if (results
!= null) {
660 checkGroupSendMessageResults(results
.timestamp(), results
.results());
664 } catch (IOException e
) {
665 throw new Error
.Failure(e
.getMessage());
666 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
667 throw new Error
.GroupNotFound(e
.getMessage());
668 } catch (AttachmentInvalidException e
) {
669 throw new Error
.AttachmentInvalid(e
.getMessage());
670 } catch (UnregisteredRecipientException e
) {
671 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
677 public boolean isRegistered() {
682 public boolean isRegistered(String number
) {
683 var result
= isRegistered(List
.of(number
));
684 return result
.getFirst();
688 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
689 if (numbers
.isEmpty()) {
693 Map
<String
, UserStatus
> registered
;
695 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
696 } catch (IOException e
) {
697 throw new Error
.Failure(e
.getMessage());
698 } catch (RateLimitException e
) {
699 throw new Error
.Failure(e
.getMessage()
701 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
704 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
708 public void updateProfile(
714 final boolean removeAvatar
717 givenName
= nullIfEmpty(givenName
);
718 familyName
= nullIfEmpty(familyName
);
719 about
= nullIfEmpty(about
);
720 aboutEmoji
= nullIfEmpty(aboutEmoji
);
721 avatarPath
= nullIfEmpty(avatarPath
);
722 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
723 m
.updateProfile(UpdateProfile
.newBuilder()
724 .withGivenName(givenName
)
725 .withFamilyName(familyName
)
727 .withAboutEmoji(aboutEmoji
)
728 .withAvatar(avatarFile
)
729 .withDeleteAvatar(removeAvatar
)
731 } catch (IOException e
) {
732 throw new Error
.Failure(e
.getMessage());
737 public void updateProfile(
740 final String aboutEmoji
,
742 final boolean removeAvatar
744 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
748 public void removePin() {
750 m
.setRegistrationLockPin(Optional
.empty());
751 } catch (IOException e
) {
752 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
753 } catch (NotPrimaryDeviceException e
) {
754 throw new Error
.Failure("This command doesn't work on linked devices.");
759 public void setPin(String registrationLockPin
) {
761 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
762 } catch (IOException e
) {
763 throw new Error
.Failure("Set pin error: " + e
.getMessage());
764 } catch (NotPrimaryDeviceException e
) {
765 throw new Error
.Failure("This command doesn't work on linked devices.");
769 // Provide option to query a version string in order to react on potential
770 // future interface changes
772 public String
version() {
773 return BaseConfig
.PROJECT_VERSION
;
776 // Create a unique list of Numbers from Identities and Contacts to really get
777 // all numbers the system knows
779 public List
<String
> listNumbers() {
780 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
782 .map(r
-> r
.getAddress().number().orElse(null))
783 .filter(Objects
::nonNull
)
789 public List
<String
> getContactNumber(final String name
) {
790 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
792 .map(r
-> r
.getAddress().getLegacyIdentifier())
798 public void quitGroup(final byte[] groupId
) {
799 var group
= getGroupId(groupId
);
801 m
.quitGroup(group
, Set
.of());
802 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
803 throw new Error
.GroupNotFound(e
.getMessage());
804 } catch (IOException
| LastGroupAdminException e
) {
805 throw new Error
.Failure(e
.getMessage());
806 } catch (UnregisteredRecipientException e
) {
807 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
812 public byte[] joinGroup(final String groupLink
) {
814 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
815 if (linkUrl
== null) {
816 throw new Error
.Failure("Group link is invalid:");
818 final var result
= m
.joinGroup(linkUrl
);
819 return result
.first().serialize();
820 } catch (PendingAdminApprovalException e
) {
821 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
822 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
823 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
824 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
825 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
826 } catch (IOException e
) {
827 throw new Error
.Failure(e
.getMessage());
832 public boolean isContactBlocked(final String number
) {
833 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
838 public boolean isGroupBlocked(final byte[] groupId
) {
839 var group
= m
.getGroup(getGroupId(groupId
));
843 return group
.isBlocked();
849 public boolean isMember(final byte[] groupId
) {
850 var group
= m
.getGroup(getGroupId(groupId
));
854 return group
.isMember();
859 public String
uploadStickerPack(String stickerPackPath
) {
860 File path
= new File(stickerPackPath
);
862 return m
.uploadStickerPack(path
).toString();
863 } catch (IOException e
) {
864 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
865 } catch (StickerPackInvalidException e
) {
866 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
870 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
871 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
877 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
879 if (result
.isIdentityFailure()) {
880 throw new Error
.UntrustedIdentity(message
);
882 throw new Error
.Failure(message
);
886 private void checkSendMessageResults(final SendMessageResults results
) {
887 final var sendMessageResults
= results
.results().values().stream().findFirst();
888 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
889 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
893 if (results
.hasSuccess()) {
897 var message
= new StringBuilder();
898 message
.append("Failed to send messages:\n");
899 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
900 for (var error
: errors
) {
901 message
.append(error
).append('\n');
903 message
.append(results
.timestamp());
905 throw new Error
.Failure(message
.toString());
908 private static void checkGroupSendMessageResults(
910 Collection
<SendMessageResult
> results
911 ) throws DBusExecutionException
{
912 if (results
.size() == 1) {
913 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
917 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
918 if (errors
.isEmpty() || errors
.size() < results
.size()) {
922 var message
= new StringBuilder();
923 message
.append("Failed to send message:\n");
924 for (var error
: errors
) {
925 message
.append(error
).append('\n');
927 message
.append(timestamp
);
929 throw new Error
.Failure(message
.toString());
932 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
933 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
936 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
937 final Collection
<String
> recipientStrings
,
938 final String localNumber
939 ) throws DBusExecutionException
{
940 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
941 for (var recipientString
: recipientStrings
) {
942 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
947 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
948 final String recipientString
,
949 final String localNumber
950 ) throws DBusExecutionException
{
952 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
953 } catch (InvalidNumberException e
) {
954 throw new Error
.InvalidNumber(e
.getMessage());
958 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
959 return new RecipientIdentifier
.Group(getGroupId(groupId
));
962 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
964 return GroupId
.unknownVersion(groupId
);
965 } catch (Throwable e
) {
966 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
970 private byte[] nullIfEmpty(final byte[] array
) {
971 return array
.length
== 0 ?
null : array
;
974 private String
nullIfEmpty(final String name
) {
975 return name
.isEmpty() ?
null : name
;
978 private String
emptyIfNull(final String string
) {
979 return string
== null ?
"" : string
;
982 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
983 return basePath
+ "/Devices/" + deviceId
;
986 private void updateDevices() {
987 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
989 linkedDevices
= m
.getLinkedDevices();
990 } catch (IOException e
) {
991 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
996 linkedDevices
.forEach(d
-> {
997 final var object
= new DbusSignalDeviceImpl(d
);
998 final var deviceObjectPath
= object
.getObjectPath();
999 exportObject(object
);
1000 if (d
.isThisDevice()) {
1001 thisDevice
= new DBusPath(deviceObjectPath
);
1003 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
1007 private void unExportDevices() {
1008 this.devices
.stream()
1009 .map(StructDevice
::getObjectPath
)
1010 .map(DBusPath
::getPath
)
1011 .forEach(connection
::unExportObject
);
1012 this.devices
.clear();
1015 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
1016 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
1019 private void updateGroups() {
1020 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
1021 groups
= m
.getGroups();
1025 groups
.forEach(g
-> {
1026 final var object
= new DbusSignalGroupImpl(g
.groupId());
1027 exportObject(object
);
1028 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1029 g
.groupId().serialize(),
1030 emptyIfNull(g
.title())));
1034 private void unExportGroups() {
1035 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1036 this.groups
.clear();
1039 private static String
getConfigurationObjectPath(String basePath
) {
1040 return basePath
+ "/Configuration";
1043 private void updateConfiguration() {
1044 unExportConfiguration();
1045 final var object
= new DbusSignalConfigurationImpl();
1046 exportObject(object
);
1049 private void unExportConfiguration() {
1050 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1051 connection
.unExportObject(objectPath
);
1054 private void exportObject(final DBusInterface object
) {
1056 connection
.exportObject(object
);
1057 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1058 } catch (DBusException e
) {
1059 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1063 private void updateIdentities() {
1064 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1065 identities
= m
.getIdentities();
1067 unExportIdentities();
1069 identities
.forEach(i
-> {
1070 final var object
= new DbusSignalIdentityImpl(i
);
1071 exportObject(object
);
1072 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1073 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1074 i
.recipient().number().orElse("")));
1078 private static String
getIdentityObjectPath(String basePath
, String id
) {
1079 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1082 private void unExportIdentities() {
1083 this.identities
.stream()
1084 .map(StructIdentity
::getObjectPath
)
1085 .map(DBusPath
::getPath
)
1086 .forEach(connection
::unExportObject
);
1087 this.identities
.clear();
1091 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1092 final var found
= identities
.stream()
1093 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1096 if (found
.isEmpty()) {
1097 throw new Error
.Failure("Identity for " + number
+ " unknown");
1099 return found
.get().getObjectPath();
1103 public List
<StructIdentity
> listIdentities() {
1105 return this.identities
;
1108 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1110 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1112 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1113 this.identity
= identity
;
1114 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1115 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1116 new DbusProperty
<>("Uuid",
1117 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1118 new DbusProperty
<>("Fingerprint", identity
::fingerprint
),
1119 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1120 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1121 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1122 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1126 public String
getObjectPath() {
1127 return getIdentityObjectPath(objectPath
,
1128 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1132 public void trust() throws Error
.Failure
{
1133 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1135 m
.trustIdentityAllKeys(recipient
);
1136 } catch (UnregisteredRecipientException e
) {
1137 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1143 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1144 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1146 if (safetyNumber
== null) {
1147 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1149 final IdentityVerificationCode verificationCode
;
1151 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1152 } catch (Exception e
) {
1153 throw new Error
.Failure(
1154 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1158 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1160 throw new Error
.Failure(
1161 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1163 } catch (UnregisteredRecipientException e
) {
1164 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1170 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1172 private final org
.asamk
.signal
.manager
.api
.Device device
;
1174 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1175 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1176 List
.of(new DbusProperty
<>("Id", device
::id
),
1177 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1178 new DbusProperty
<>("Created", device
::created
),
1179 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1180 this.device
= device
;
1184 public String
getObjectPath() {
1185 return getDeviceObjectPath(objectPath
, device
.id());
1189 public void removeDevice() throws Error
.Failure
{
1191 m
.removeLinkedDevices(device
.id());
1193 } catch (NotPrimaryDeviceException e
) {
1194 throw new Error
.Failure("This command doesn't work on linked devices.");
1195 } catch (IOException e
) {
1196 throw new Error
.Failure(e
.getMessage());
1200 private void setDeviceName(String name
) {
1201 if (!device
.isThisDevice()) {
1202 throw new Error
.Failure("Only the name of this device can be changed");
1205 m
.updateAccountAttributes(name
, null, null, null);
1206 // update device list
1208 } catch (IOException e
) {
1209 throw new Error
.Failure(e
.getMessage());
1214 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1216 public DbusSignalConfigurationImpl() {
1217 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1218 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1219 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1220 this::getUnidentifiedDeliveryIndicators
,
1221 this::setUnidentifiedDeliveryIndicators
),
1222 new DbusProperty
<>("TypingIndicators",
1223 this::getTypingIndicators
,
1224 this::setTypingIndicators
),
1225 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1230 public String
getObjectPath() {
1231 return getConfigurationObjectPath(objectPath
);
1234 public void setReadReceipts(Boolean readReceipts
) {
1235 setConfiguration(readReceipts
, null, null, null);
1238 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1239 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1242 public void setTypingIndicators(Boolean typingIndicators
) {
1243 setConfiguration(null, null, typingIndicators
, null);
1246 public void setLinkPreviews(Boolean linkPreviews
) {
1247 setConfiguration(null, null, null, linkPreviews
);
1250 private void setConfiguration(
1251 Boolean readReceipts
,
1252 Boolean unidentifiedDeliveryIndicators
,
1253 Boolean typingIndicators
,
1254 Boolean linkPreviews
1257 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1258 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1259 Optional
.ofNullable(typingIndicators
),
1260 Optional
.ofNullable(linkPreviews
)));
1261 } catch (NotPrimaryDeviceException e
) {
1262 throw new Error
.Failure("This command doesn't work on linked devices.");
1266 private boolean getReadReceipts() {
1267 return m
.getConfiguration().readReceipts().orElse(false);
1270 private boolean getUnidentifiedDeliveryIndicators() {
1271 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1274 private boolean getTypingIndicators() {
1275 return m
.getConfiguration().typingIndicators().orElse(false);
1278 private boolean getLinkPreviews() {
1279 return m
.getConfiguration().linkPreviews().orElse(false);
1283 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1285 private final GroupId groupId
;
1287 public DbusSignalGroupImpl(final GroupId groupId
) {
1288 this.groupId
= groupId
;
1289 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1290 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1291 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1292 new DbusProperty
<>("Description",
1293 () -> emptyIfNull(getGroup().description()),
1294 this::setGroupDescription
),
1295 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1296 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1297 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1298 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1299 new DbusProperty
<>("MessageExpirationTimer",
1300 () -> getGroup().messageExpirationTimer(),
1301 this::setMessageExpirationTime
),
1302 new DbusProperty
<>("Members",
1303 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1304 new DbusProperty
<>("PendingMembers",
1305 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1306 new DbusProperty
<>("RequestingMembers",
1307 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1308 new DbusProperty
<>("Admins",
1309 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1310 new DbusProperty
<>("Banned",
1311 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1312 new DbusProperty
<>("PermissionAddMember",
1313 () -> getGroup().permissionAddMember().name(),
1314 this::setGroupPermissionAddMember
),
1315 new DbusProperty
<>("PermissionEditDetails",
1316 () -> getGroup().permissionEditDetails().name(),
1317 this::setGroupPermissionEditDetails
),
1318 new DbusProperty
<>("PermissionSendMessage",
1319 () -> getGroup().permissionSendMessage().name(),
1320 this::setGroupPermissionSendMessage
),
1321 new DbusProperty
<>("GroupInviteLink", () -> {
1322 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1323 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1328 public String
getObjectPath() {
1329 return getGroupObjectPath(objectPath
, groupId
.serialize());
1333 public void quitGroup() throws Error
.Failure
{
1335 m
.quitGroup(groupId
, Set
.of());
1336 } catch (GroupNotFoundException e
) {
1337 throw new Error
.GroupNotFound(e
.getMessage());
1338 } catch (NotAGroupMemberException e
) {
1339 throw new Error
.NotAGroupMember(e
.getMessage());
1340 } catch (IOException e
) {
1341 throw new Error
.Failure(e
.getMessage());
1342 } catch (LastGroupAdminException e
) {
1343 throw new Error
.LastGroupAdmin(e
.getMessage());
1344 } catch (UnregisteredRecipientException e
) {
1345 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1350 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1352 m
.deleteGroup(groupId
);
1353 } catch (IOException e
) {
1354 throw new Error
.Failure(e
.getMessage());
1360 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1361 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1362 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1366 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1367 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1368 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1372 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1373 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1374 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1378 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1379 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1380 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1384 public void resetLink() throws Error
.Failure
{
1385 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1389 public void disableLink() throws Error
.Failure
{
1390 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1394 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1395 updateGroup(UpdateGroup
.newBuilder()
1396 .withGroupLinkState(requiresApproval
1397 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1398 : GroupLinkState
.ENABLED
)
1402 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1403 return m
.getGroup(groupId
);
1406 private void setGroupName(final String name
) {
1407 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1410 private void setGroupDescription(final String description
) {
1411 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1414 private void setGroupAvatar(final String avatar
) {
1415 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1418 private void setMessageExpirationTime(final int expirationTime
) {
1419 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1422 private void setGroupPermissionAddMember(final String permission
) {
1423 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1426 private void setGroupPermissionEditDetails(final String permission
) {
1427 updateGroup(UpdateGroup
.newBuilder()
1428 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1432 private void setGroupPermissionSendMessage(final String permission
) {
1433 updateGroup(UpdateGroup
.newBuilder()
1434 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1438 private void setIsBlocked(final boolean isBlocked
) {
1440 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1441 } catch (NotPrimaryDeviceException e
) {
1442 throw new Error
.Failure("This command doesn't work on linked devices.");
1443 } catch (GroupNotFoundException e
) {
1444 throw new Error
.GroupNotFound(e
.getMessage());
1445 } catch (IOException e
) {
1446 throw new Error
.Failure(e
.getMessage());
1450 private void updateGroup(final UpdateGroup updateGroup
) {
1452 m
.updateGroup(groupId
, updateGroup
);
1453 } catch (IOException e
) {
1454 throw new Error
.Failure(e
.getMessage());
1455 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1456 throw new Error
.GroupNotFound(e
.getMessage());
1457 } catch (AttachmentInvalidException e
) {
1458 throw new Error
.AttachmentInvalid(e
.getMessage());
1459 } catch (UnregisteredRecipientException e
) {
1460 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");