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
,
246 final var recipientIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
247 .map(RecipientIdentifier
.class::cast
)
248 .collect(Collectors
.toSet());
249 final var results
= m
.sendMessage(message
, recipientIdentifiers
, false);
251 checkSendMessageResults(results
);
252 return results
.timestamp();
253 } catch (AttachmentInvalidException e
) {
254 throw new Error
.AttachmentInvalid(e
.getMessage());
255 } catch (IOException
| InvalidStickerException e
) {
256 throw new Error
.Failure(e
);
257 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
258 throw new Error
.GroupNotFound(e
.getMessage());
259 } catch (UnregisteredRecipientException e
) {
260 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
265 public long sendRemoteDeleteMessage(final long targetSentTimestamp
, final String recipient
) {
266 return sendRemoteDeleteMessage(targetSentTimestamp
, List
.of(recipient
));
270 public long sendRemoteDeleteMessage(final long targetSentTimestamp
, final List
<String
> recipients
) {
272 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
273 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
274 .map(RecipientIdentifier
.class::cast
)
275 .collect(Collectors
.toSet()));
276 checkSendMessageResults(results
);
277 return results
.timestamp();
278 } catch (IOException e
) {
279 throw new Error
.Failure(e
.getMessage());
280 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
281 throw new Error
.GroupNotFound(e
.getMessage());
286 public long sendMessageReaction(
288 final boolean remove
,
289 final String targetAuthor
,
290 final long targetSentTimestamp
,
291 final String recipient
293 return sendMessageReaction(emoji
, remove
, targetAuthor
, targetSentTimestamp
, List
.of(recipient
));
297 public long sendMessageReaction(
299 final boolean remove
,
300 final String targetAuthor
,
301 final long targetSentTimestamp
,
302 final List
<String
> recipients
305 final var results
= m
.sendMessageReaction(emoji
,
307 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
309 getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
310 .map(RecipientIdentifier
.class::cast
)
311 .collect(Collectors
.toSet()),
313 checkSendMessageResults(results
);
314 return results
.timestamp();
315 } catch (IOException e
) {
316 throw new Error
.Failure(e
.getMessage());
317 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
318 throw new Error
.GroupNotFound(e
.getMessage());
319 } catch (UnregisteredRecipientException e
) {
320 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
325 public long sendPaymentNotification(
326 final byte[] receipt
,
328 final String recipient
329 ) throws Error
.Failure
{
331 final var results
= m
.sendPaymentNotificationMessage(receipt
,
333 getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
334 checkSendMessageResults(results
);
335 return results
.timestamp();
336 } catch (IOException e
) {
337 throw new Error
.Failure(e
.getMessage());
342 public void sendTyping(
343 final String recipient
,
345 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
347 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
348 getSingleRecipientIdentifiers(List
.of(recipient
), m
.getSelfNumber()).stream()
349 .map(RecipientIdentifier
.class::cast
)
350 .collect(Collectors
.toSet()));
351 checkSendMessageResults(results
);
352 } catch (IOException e
) {
353 throw new Error
.Failure(e
.getMessage());
354 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
355 throw new Error
.GroupNotFound(e
.getMessage());
360 public void sendReadReceipt(
361 final String recipient
,
362 final List
<Long
> messageIds
363 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
364 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
365 checkSendMessageResults(results
);
369 public void sendViewedReceipt(
370 final String recipient
,
371 final List
<Long
> messageIds
372 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
373 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
374 checkSendMessageResults(results
);
378 public void sendContacts() {
381 } catch (IOException e
) {
382 throw new Error
.Failure("SendContacts error: " + e
.getMessage());
387 public void sendSyncRequest() {
389 m
.requestAllSyncData();
390 } catch (IOException e
) {
391 throw new Error
.Failure("Request sync data error: " + e
.getMessage());
396 public long sendNoteToSelfMessage(
397 final String messageText
,
398 final List
<String
> attachments
399 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
401 final var message
= new Message(messageText
,
410 final var results
= m
.sendMessage(message
, Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
), false);
411 checkSendMessageResults(results
);
412 return results
.timestamp();
413 } catch (AttachmentInvalidException e
) {
414 throw new Error
.AttachmentInvalid(e
.getMessage());
415 } catch (IOException
| InvalidStickerException e
) {
416 throw new Error
.Failure(e
.getMessage());
417 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
418 throw new Error
.GroupNotFound(e
.getMessage());
419 } catch (UnregisteredRecipientException e
) {
420 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
425 public void sendEndSessionMessage(final List
<String
> recipients
) {
427 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
428 checkSendMessageResults(results
);
429 } catch (IOException e
) {
430 throw new Error
.Failure(e
.getMessage());
435 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
436 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
440 public void deleteContact(final String recipient
) throws Error
.Failure
{
441 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
445 public long sendGroupMessage(final String messageText
, final List
<String
> attachments
, final byte[] groupId
) {
447 final var message
= new Message(messageText
,
456 var results
= m
.sendMessage(message
, Set
.of(getGroupRecipientIdentifier(groupId
)), false);
457 checkSendMessageResults(results
);
458 return results
.timestamp();
459 } catch (IOException
| InvalidStickerException e
) {
460 throw new Error
.Failure(e
.getMessage());
461 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
462 throw new Error
.GroupNotFound(e
.getMessage());
463 } catch (AttachmentInvalidException e
) {
464 throw new Error
.AttachmentInvalid(e
.getMessage());
465 } catch (UnregisteredRecipientException e
) {
466 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
471 public void sendGroupTyping(
472 final byte[] groupId
,
474 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
476 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
477 Set
.of(getGroupRecipientIdentifier(groupId
)));
478 checkSendMessageResults(results
);
479 } catch (IOException e
) {
480 throw new Error
.Failure(e
.getMessage());
481 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
482 throw new Error
.GroupNotFound(e
.getMessage());
487 public long sendGroupRemoteDeleteMessage(final long targetSentTimestamp
, final byte[] groupId
) {
489 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
490 Set
.of(getGroupRecipientIdentifier(groupId
)));
491 checkSendMessageResults(results
);
492 return results
.timestamp();
493 } catch (IOException e
) {
494 throw new Error
.Failure(e
.getMessage());
495 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
496 throw new Error
.GroupNotFound(e
.getMessage());
501 public long sendGroupMessageReaction(
503 final boolean remove
,
504 final String targetAuthor
,
505 final long targetSentTimestamp
,
509 final var results
= m
.sendMessageReaction(emoji
,
511 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
513 Set
.of(getGroupRecipientIdentifier(groupId
)),
515 checkSendMessageResults(results
);
516 return results
.timestamp();
517 } catch (IOException e
) {
518 throw new Error
.Failure(e
.getMessage());
519 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
520 throw new Error
.GroupNotFound(e
.getMessage());
521 } catch (UnregisteredRecipientException e
) {
522 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
526 // Since contact names might be empty if not defined, also potentially return
529 public String
getContactName(final String number
) {
530 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
531 return name
== null ?
"" : name
;
535 public void setContactName(final String number
, final String name
) {
537 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "", null, null, null);
538 } catch (NotPrimaryDeviceException e
) {
539 throw new Error
.Failure("This command doesn't work on linked devices.");
540 } catch (UnregisteredRecipientException e
) {
541 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
546 public void setExpirationTimer(final String number
, final int expiration
) {
548 m
.setExpirationTimer(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), expiration
);
549 } catch (IOException e
) {
550 throw new Error
.Failure(e
.getMessage());
551 } catch (UnregisteredRecipientException e
) {
552 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
557 public void setContactBlocked(final String number
, final boolean blocked
) {
559 m
.setContactsBlocked(List
.of(getSingleRecipientIdentifier(number
, m
.getSelfNumber())), blocked
);
560 } catch (NotPrimaryDeviceException e
) {
561 throw new Error
.Failure("This command doesn't work on linked devices.");
562 } catch (IOException e
) {
563 throw new Error
.Failure(e
.getMessage());
564 } catch (UnregisteredRecipientException e
) {
565 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
571 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
573 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
574 } catch (NotPrimaryDeviceException e
) {
575 throw new Error
.Failure("This command doesn't work on linked devices.");
576 } catch (GroupNotFoundException e
) {
577 throw new Error
.GroupNotFound(e
.getMessage());
578 } catch (IOException e
) {
579 throw new Error
.Failure(e
.getMessage());
585 public List
<byte[]> getGroupIds() {
586 var groups
= m
.getGroups();
587 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
591 public DBusPath
getGroup(final byte[] groupId
) {
593 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
594 if (groupOptional
.isEmpty()) {
595 throw new Error
.GroupNotFound("Group not found");
597 return groupOptional
.get().getObjectPath();
601 public List
<StructGroup
> listGroups() {
608 public String
getGroupName(final byte[] groupId
) {
609 var group
= m
.getGroup(getGroupId(groupId
));
610 if (group
== null || group
.title() == null) {
613 return group
.title();
619 public List
<String
> getGroupMembers(final byte[] groupId
) {
620 var group
= m
.getGroup(getGroupId(groupId
));
624 final var members
= group
.members();
625 return getRecipientStrings(members
);
630 public byte[] createGroup(
632 final List
<String
> members
,
634 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
635 return updateGroupInternal(new byte[0], name
, members
, avatar
);
640 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
641 return updateGroupInternal(groupId
, name
, members
, avatar
);
644 public byte[] updateGroupInternal(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
646 groupId
= nullIfEmpty(groupId
);
647 name
= nullIfEmpty(name
);
648 avatar
= nullIfEmpty(avatar
);
649 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
650 if (groupId
== null) {
651 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
653 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
654 return results
.first().serialize();
656 final var results
= m
.updateGroup(getGroupId(groupId
),
657 UpdateGroup
.newBuilder()
659 .withMembers(memberIdentifiers
)
660 .withAvatarFile(avatar
)
662 if (results
!= null) {
663 checkGroupSendMessageResults(results
.timestamp(), results
.results());
667 } catch (IOException e
) {
668 throw new Error
.Failure(e
.getMessage());
669 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
670 throw new Error
.GroupNotFound(e
.getMessage());
671 } catch (AttachmentInvalidException e
) {
672 throw new Error
.AttachmentInvalid(e
.getMessage());
673 } catch (UnregisteredRecipientException e
) {
674 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
680 public boolean isRegistered() {
685 public boolean isRegistered(String number
) {
686 var result
= isRegistered(List
.of(number
));
687 return result
.getFirst();
691 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
692 if (numbers
.isEmpty()) {
696 Map
<String
, UserStatus
> registered
;
698 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
699 } catch (IOException e
) {
700 throw new Error
.Failure(e
.getMessage());
701 } catch (RateLimitException e
) {
702 throw new Error
.Failure(e
.getMessage()
704 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
707 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
711 public void updateProfile(
717 final boolean removeAvatar
720 givenName
= nullIfEmpty(givenName
);
721 familyName
= nullIfEmpty(familyName
);
722 about
= nullIfEmpty(about
);
723 aboutEmoji
= nullIfEmpty(aboutEmoji
);
724 avatarPath
= nullIfEmpty(avatarPath
);
725 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
726 m
.updateProfile(UpdateProfile
.newBuilder()
727 .withGivenName(givenName
)
728 .withFamilyName(familyName
)
730 .withAboutEmoji(aboutEmoji
)
731 .withAvatar(avatarFile
)
732 .withDeleteAvatar(removeAvatar
)
734 } catch (IOException e
) {
735 throw new Error
.Failure(e
.getMessage());
740 public void updateProfile(
743 final String aboutEmoji
,
745 final boolean removeAvatar
747 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
751 public void removePin() {
753 m
.setRegistrationLockPin(Optional
.empty());
754 } catch (IOException e
) {
755 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
756 } catch (NotPrimaryDeviceException e
) {
757 throw new Error
.Failure("This command doesn't work on linked devices.");
762 public void setPin(String registrationLockPin
) {
764 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
765 } catch (IOException e
) {
766 throw new Error
.Failure("Set pin error: " + e
.getMessage());
767 } catch (NotPrimaryDeviceException e
) {
768 throw new Error
.Failure("This command doesn't work on linked devices.");
772 // Provide option to query a version string in order to react on potential
773 // future interface changes
775 public String
version() {
776 return BaseConfig
.PROJECT_VERSION
;
779 // Create a unique list of Numbers from Identities and Contacts to really get
780 // all numbers the system knows
782 public List
<String
> listNumbers() {
783 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
785 .map(r
-> r
.getAddress().number().orElse(null))
786 .filter(Objects
::nonNull
)
792 public List
<String
> getContactNumber(final String name
) {
793 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
795 .map(r
-> r
.getAddress().getLegacyIdentifier())
801 public void quitGroup(final byte[] groupId
) {
802 var group
= getGroupId(groupId
);
804 m
.quitGroup(group
, Set
.of());
805 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
806 throw new Error
.GroupNotFound(e
.getMessage());
807 } catch (IOException
| LastGroupAdminException e
) {
808 throw new Error
.Failure(e
.getMessage());
809 } catch (UnregisteredRecipientException e
) {
810 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
815 public byte[] joinGroup(final String groupLink
) {
817 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
818 if (linkUrl
== null) {
819 throw new Error
.Failure("Group link is invalid:");
821 final var result
= m
.joinGroup(linkUrl
);
822 return result
.first().serialize();
823 } catch (PendingAdminApprovalException e
) {
824 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
825 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
826 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
827 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
828 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
829 } catch (IOException e
) {
830 throw new Error
.Failure(e
.getMessage());
835 public boolean isContactBlocked(final String number
) {
836 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
841 public boolean isGroupBlocked(final byte[] groupId
) {
842 var group
= m
.getGroup(getGroupId(groupId
));
846 return group
.isBlocked();
852 public boolean isMember(final byte[] groupId
) {
853 var group
= m
.getGroup(getGroupId(groupId
));
857 return group
.isMember();
862 public String
uploadStickerPack(String stickerPackPath
) {
863 File path
= new File(stickerPackPath
);
865 return m
.uploadStickerPack(path
).toString();
866 } catch (IOException e
) {
867 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
868 } catch (StickerPackInvalidException e
) {
869 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
873 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
874 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
880 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
882 if (result
.isIdentityFailure()) {
883 throw new Error
.UntrustedIdentity(message
);
885 throw new Error
.Failure(message
);
889 private void checkSendMessageResults(final SendMessageResults results
) {
890 final var sendMessageResults
= results
.results().values().stream().findFirst();
891 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
892 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
896 if (results
.hasSuccess()) {
900 var message
= new StringBuilder();
901 message
.append("Failed to send messages:\n");
902 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
903 for (var error
: errors
) {
904 message
.append(error
).append('\n');
906 message
.append(results
.timestamp());
908 throw new Error
.Failure(message
.toString());
911 private static void checkGroupSendMessageResults(
913 Collection
<SendMessageResult
> results
914 ) throws DBusExecutionException
{
915 if (results
.size() == 1) {
916 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
920 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
921 if (errors
.isEmpty() || errors
.size() < results
.size()) {
925 var message
= new StringBuilder();
926 message
.append("Failed to send message:\n");
927 for (var error
: errors
) {
928 message
.append(error
).append('\n');
930 message
.append(timestamp
);
932 throw new Error
.Failure(message
.toString());
935 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
936 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
939 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
940 final Collection
<String
> recipientStrings
,
941 final String localNumber
942 ) throws DBusExecutionException
{
943 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
944 for (var recipientString
: recipientStrings
) {
945 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
950 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
951 final String recipientString
,
952 final String localNumber
953 ) throws DBusExecutionException
{
955 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
956 } catch (InvalidNumberException e
) {
957 throw new Error
.InvalidNumber(e
.getMessage());
961 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
962 return new RecipientIdentifier
.Group(getGroupId(groupId
));
965 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
967 return GroupId
.unknownVersion(groupId
);
968 } catch (Throwable e
) {
969 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
973 private byte[] nullIfEmpty(final byte[] array
) {
974 return array
.length
== 0 ?
null : array
;
977 private String
nullIfEmpty(final String name
) {
978 return name
.isEmpty() ?
null : name
;
981 private String
emptyIfNull(final String string
) {
982 return string
== null ?
"" : string
;
985 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
986 return basePath
+ "/Devices/" + deviceId
;
989 private void updateDevices() {
990 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
992 linkedDevices
= m
.getLinkedDevices();
993 } catch (IOException e
) {
994 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
999 linkedDevices
.forEach(d
-> {
1000 final var object
= new DbusSignalDeviceImpl(d
);
1001 final var deviceObjectPath
= object
.getObjectPath();
1002 exportObject(object
);
1003 if (d
.isThisDevice()) {
1004 thisDevice
= new DBusPath(deviceObjectPath
);
1006 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
1010 private void unExportDevices() {
1011 this.devices
.stream()
1012 .map(StructDevice
::getObjectPath
)
1013 .map(DBusPath
::getPath
)
1014 .forEach(connection
::unExportObject
);
1015 this.devices
.clear();
1018 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
1019 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
1022 private void updateGroups() {
1023 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
1024 groups
= m
.getGroups();
1028 groups
.forEach(g
-> {
1029 final var object
= new DbusSignalGroupImpl(g
.groupId());
1030 exportObject(object
);
1031 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1032 g
.groupId().serialize(),
1033 emptyIfNull(g
.title())));
1037 private void unExportGroups() {
1038 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1039 this.groups
.clear();
1042 private static String
getConfigurationObjectPath(String basePath
) {
1043 return basePath
+ "/Configuration";
1046 private void updateConfiguration() {
1047 unExportConfiguration();
1048 final var object
= new DbusSignalConfigurationImpl();
1049 exportObject(object
);
1052 private void unExportConfiguration() {
1053 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1054 connection
.unExportObject(objectPath
);
1057 private void exportObject(final DBusInterface object
) {
1059 connection
.exportObject(object
);
1060 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1061 } catch (DBusException e
) {
1062 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1066 private void updateIdentities() {
1067 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1068 identities
= m
.getIdentities();
1070 unExportIdentities();
1072 identities
.forEach(i
-> {
1073 final var object
= new DbusSignalIdentityImpl(i
);
1074 exportObject(object
);
1075 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1076 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1077 i
.recipient().number().orElse("")));
1081 private static String
getIdentityObjectPath(String basePath
, String id
) {
1082 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1085 private void unExportIdentities() {
1086 this.identities
.stream()
1087 .map(StructIdentity
::getObjectPath
)
1088 .map(DBusPath
::getPath
)
1089 .forEach(connection
::unExportObject
);
1090 this.identities
.clear();
1094 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1095 final var found
= identities
.stream()
1096 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1099 if (found
.isEmpty()) {
1100 throw new Error
.Failure("Identity for " + number
+ " unknown");
1102 return found
.get().getObjectPath();
1106 public List
<StructIdentity
> listIdentities() {
1108 return this.identities
;
1111 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1113 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1115 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1116 this.identity
= identity
;
1117 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1118 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1119 new DbusProperty
<>("Uuid",
1120 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1121 new DbusProperty
<>("Fingerprint", identity
::fingerprint
),
1122 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1123 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1124 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1125 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1129 public String
getObjectPath() {
1130 return getIdentityObjectPath(objectPath
,
1131 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1135 public void trust() throws Error
.Failure
{
1136 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1138 m
.trustIdentityAllKeys(recipient
);
1139 } catch (UnregisteredRecipientException e
) {
1140 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1146 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1147 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1149 if (safetyNumber
== null) {
1150 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1152 final IdentityVerificationCode verificationCode
;
1154 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1155 } catch (Exception e
) {
1156 throw new Error
.Failure(
1157 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1161 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1163 throw new Error
.Failure(
1164 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1166 } catch (UnregisteredRecipientException e
) {
1167 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1173 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1175 private final org
.asamk
.signal
.manager
.api
.Device device
;
1177 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1178 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1179 List
.of(new DbusProperty
<>("Id", device
::id
),
1180 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1181 new DbusProperty
<>("Created", device
::created
),
1182 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1183 this.device
= device
;
1187 public String
getObjectPath() {
1188 return getDeviceObjectPath(objectPath
, device
.id());
1192 public void removeDevice() throws Error
.Failure
{
1194 m
.removeLinkedDevices(device
.id());
1196 } catch (NotPrimaryDeviceException e
) {
1197 throw new Error
.Failure("This command doesn't work on linked devices.");
1198 } catch (IOException e
) {
1199 throw new Error
.Failure(e
.getMessage());
1203 private void setDeviceName(String name
) {
1204 if (!device
.isThisDevice()) {
1205 throw new Error
.Failure("Only the name of this device can be changed");
1208 m
.updateAccountAttributes(name
, null, null, null);
1209 // update device list
1211 } catch (IOException e
) {
1212 throw new Error
.Failure(e
.getMessage());
1217 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1219 public DbusSignalConfigurationImpl() {
1220 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1221 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1222 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1223 this::getUnidentifiedDeliveryIndicators
,
1224 this::setUnidentifiedDeliveryIndicators
),
1225 new DbusProperty
<>("TypingIndicators",
1226 this::getTypingIndicators
,
1227 this::setTypingIndicators
),
1228 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1233 public String
getObjectPath() {
1234 return getConfigurationObjectPath(objectPath
);
1237 public void setReadReceipts(Boolean readReceipts
) {
1238 setConfiguration(readReceipts
, null, null, null);
1241 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1242 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1245 public void setTypingIndicators(Boolean typingIndicators
) {
1246 setConfiguration(null, null, typingIndicators
, null);
1249 public void setLinkPreviews(Boolean linkPreviews
) {
1250 setConfiguration(null, null, null, linkPreviews
);
1253 private void setConfiguration(
1254 Boolean readReceipts
,
1255 Boolean unidentifiedDeliveryIndicators
,
1256 Boolean typingIndicators
,
1257 Boolean linkPreviews
1260 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1261 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1262 Optional
.ofNullable(typingIndicators
),
1263 Optional
.ofNullable(linkPreviews
)));
1264 } catch (NotPrimaryDeviceException e
) {
1265 throw new Error
.Failure("This command doesn't work on linked devices.");
1269 private boolean getReadReceipts() {
1270 return m
.getConfiguration().readReceipts().orElse(false);
1273 private boolean getUnidentifiedDeliveryIndicators() {
1274 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1277 private boolean getTypingIndicators() {
1278 return m
.getConfiguration().typingIndicators().orElse(false);
1281 private boolean getLinkPreviews() {
1282 return m
.getConfiguration().linkPreviews().orElse(false);
1286 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1288 private final GroupId groupId
;
1290 public DbusSignalGroupImpl(final GroupId groupId
) {
1291 this.groupId
= groupId
;
1292 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1293 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1294 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1295 new DbusProperty
<>("Description",
1296 () -> emptyIfNull(getGroup().description()),
1297 this::setGroupDescription
),
1298 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1299 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1300 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1301 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1302 new DbusProperty
<>("MessageExpirationTimer",
1303 () -> getGroup().messageExpirationTimer(),
1304 this::setMessageExpirationTime
),
1305 new DbusProperty
<>("Members",
1306 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1307 new DbusProperty
<>("PendingMembers",
1308 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1309 new DbusProperty
<>("RequestingMembers",
1310 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1311 new DbusProperty
<>("Admins",
1312 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1313 new DbusProperty
<>("Banned",
1314 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1315 new DbusProperty
<>("PermissionAddMember",
1316 () -> getGroup().permissionAddMember().name(),
1317 this::setGroupPermissionAddMember
),
1318 new DbusProperty
<>("PermissionEditDetails",
1319 () -> getGroup().permissionEditDetails().name(),
1320 this::setGroupPermissionEditDetails
),
1321 new DbusProperty
<>("PermissionSendMessage",
1322 () -> getGroup().permissionSendMessage().name(),
1323 this::setGroupPermissionSendMessage
),
1324 new DbusProperty
<>("GroupInviteLink", () -> {
1325 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1326 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1331 public String
getObjectPath() {
1332 return getGroupObjectPath(objectPath
, groupId
.serialize());
1336 public void quitGroup() throws Error
.Failure
{
1338 m
.quitGroup(groupId
, Set
.of());
1339 } catch (GroupNotFoundException e
) {
1340 throw new Error
.GroupNotFound(e
.getMessage());
1341 } catch (NotAGroupMemberException e
) {
1342 throw new Error
.NotAGroupMember(e
.getMessage());
1343 } catch (IOException e
) {
1344 throw new Error
.Failure(e
.getMessage());
1345 } catch (LastGroupAdminException e
) {
1346 throw new Error
.LastGroupAdmin(e
.getMessage());
1347 } catch (UnregisteredRecipientException e
) {
1348 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1353 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1355 m
.deleteGroup(groupId
);
1356 } catch (IOException e
) {
1357 throw new Error
.Failure(e
.getMessage());
1363 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1364 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1365 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1369 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1370 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1371 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1375 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1376 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1377 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1381 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1382 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1383 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1387 public void resetLink() throws Error
.Failure
{
1388 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1392 public void disableLink() throws Error
.Failure
{
1393 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1397 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1398 updateGroup(UpdateGroup
.newBuilder()
1399 .withGroupLinkState(requiresApproval
1400 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1401 : GroupLinkState
.ENABLED
)
1405 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1406 return m
.getGroup(groupId
);
1409 private void setGroupName(final String name
) {
1410 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1413 private void setGroupDescription(final String description
) {
1414 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1417 private void setGroupAvatar(final String avatar
) {
1418 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1421 private void setMessageExpirationTime(final int expirationTime
) {
1422 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1425 private void setGroupPermissionAddMember(final String permission
) {
1426 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1429 private void setGroupPermissionEditDetails(final String permission
) {
1430 updateGroup(UpdateGroup
.newBuilder()
1431 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1435 private void setGroupPermissionSendMessage(final String permission
) {
1436 updateGroup(UpdateGroup
.newBuilder()
1437 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1441 private void setIsBlocked(final boolean isBlocked
) {
1443 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1444 } catch (NotPrimaryDeviceException e
) {
1445 throw new Error
.Failure("This command doesn't work on linked devices.");
1446 } catch (GroupNotFoundException e
) {
1447 throw new Error
.GroupNotFound(e
.getMessage());
1448 } catch (IOException e
) {
1449 throw new Error
.Failure(e
.getMessage());
1453 private void updateGroup(final UpdateGroup updateGroup
) {
1455 m
.updateGroup(groupId
, updateGroup
);
1456 } catch (IOException e
) {
1457 throw new Error
.Failure(e
.getMessage());
1458 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1459 throw new Error
.GroupNotFound(e
.getMessage());
1460 } catch (AttachmentInvalidException e
) {
1461 throw new Error
.AttachmentInvalid(e
.getMessage());
1462 } catch (UnregisteredRecipientException e
) {
1463 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");