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
.DeviceLinkUrl
;
9 import org
.asamk
.signal
.manager
.api
.GroupId
;
10 import org
.asamk
.signal
.manager
.api
.GroupInviteLinkUrl
;
11 import org
.asamk
.signal
.manager
.api
.GroupLinkState
;
12 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
13 import org
.asamk
.signal
.manager
.api
.GroupPermission
;
14 import org
.asamk
.signal
.manager
.api
.GroupSendingNotAllowedException
;
15 import org
.asamk
.signal
.manager
.api
.IdentityVerificationCode
;
16 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
17 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
18 import org
.asamk
.signal
.manager
.api
.InvalidNumberException
;
19 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
20 import org
.asamk
.signal
.manager
.api
.LastGroupAdminException
;
21 import org
.asamk
.signal
.manager
.api
.Message
;
22 import org
.asamk
.signal
.manager
.api
.NotAGroupMemberException
;
23 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
24 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
25 import org
.asamk
.signal
.manager
.api
.RateLimitException
;
26 import org
.asamk
.signal
.manager
.api
.RecipientAddress
;
27 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
28 import org
.asamk
.signal
.manager
.api
.SendMessageResult
;
29 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
30 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
31 import org
.asamk
.signal
.manager
.api
.TypingAction
;
32 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
33 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
34 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
35 import org
.asamk
.signal
.manager
.api
.UserStatus
;
36 import org
.asamk
.signal
.util
.DateUtils
;
37 import org
.asamk
.signal
.util
.SendMessageResultUtils
;
38 import org
.freedesktop
.dbus
.DBusPath
;
39 import org
.freedesktop
.dbus
.connections
.impl
.DBusConnection
;
40 import org
.freedesktop
.dbus
.exceptions
.DBusException
;
41 import org
.freedesktop
.dbus
.exceptions
.DBusExecutionException
;
42 import org
.freedesktop
.dbus
.interfaces
.DBusInterface
;
43 import org
.freedesktop
.dbus
.types
.Variant
;
44 import org
.slf4j
.Logger
;
45 import org
.slf4j
.LoggerFactory
;
48 import java
.io
.IOException
;
50 import java
.net
.URISyntaxException
;
51 import java
.util
.ArrayList
;
52 import java
.util
.Arrays
;
53 import java
.util
.Base64
;
54 import java
.util
.Collection
;
55 import java
.util
.HashSet
;
56 import java
.util
.List
;
58 import java
.util
.Objects
;
59 import java
.util
.Optional
;
61 import java
.util
.UUID
;
62 import java
.util
.stream
.Collectors
;
64 import static org
.asamk
.signal
.dbus
.DbusUtils
.makeValidObjectPathElement
;
66 public class DbusSignalImpl
implements Signal
, AutoCloseable
{
68 private final Manager m
;
69 private final DBusConnection connection
;
70 private final String objectPath
;
71 private final boolean noReceiveOnStart
;
73 private DBusPath thisDevice
;
74 private final List
<StructDevice
> devices
= new ArrayList
<>();
75 private final List
<StructGroup
> groups
= new ArrayList
<>();
76 private final List
<StructIdentity
> identities
= new ArrayList
<>();
77 private DbusReceiveMessageHandler dbusMessageHandler
;
78 private int subscriberCount
;
80 private static final Logger logger
= LoggerFactory
.getLogger(DbusSignalImpl
.class);
82 public DbusSignalImpl(
83 final Manager m
, DBusConnection connection
, final String objectPath
, final boolean noReceiveOnStart
86 this.connection
= connection
;
87 this.objectPath
= objectPath
;
88 this.noReceiveOnStart
= noReceiveOnStart
;
90 m
.addAddressChangedListener(() -> {
96 public void initObjects() {
98 if (!noReceiveOnStart
) {
103 private void exportObjects() {
108 updateConfiguration();
113 public void close() {
114 if (dbusMessageHandler
!= null) {
115 m
.removeReceiveHandler(dbusMessageHandler
);
116 dbusMessageHandler
= null;
121 private void unExportObjects() {
124 unExportConfiguration();
125 unExportIdentities();
126 connection
.unExportObject(this.objectPath
);
130 public String
getObjectPath() {
135 public String
getSelfNumber() {
136 return m
.getSelfNumber();
140 public void subscribeReceive() {
141 if (dbusMessageHandler
== null) {
142 dbusMessageHandler
= new DbusReceiveMessageHandler(connection
, objectPath
);
143 m
.addReceiveHandler(dbusMessageHandler
);
149 public void unsubscribeReceive() {
150 subscriberCount
= Math
.max(0, subscriberCount
- 1);
151 if (subscriberCount
== 0 && dbusMessageHandler
!= null) {
152 m
.removeReceiveHandler(dbusMessageHandler
);
153 dbusMessageHandler
= null;
158 public void submitRateLimitChallenge(String challenge
, String captcha
) {
160 m
.submitRateLimitRecaptchaChallenge(challenge
, captcha
);
161 } catch (IOException e
) {
162 throw new Error
.Failure("Submit challenge error: " + e
.getMessage());
163 } catch (CaptchaRejectedException e
) {
164 throw new Error
.Failure(
165 "Captcha rejected, it may be outdated, already used or solved from a different IP address.");
170 public void unregister() throws Error
.Failure
{
173 } catch (IOException e
) {
174 throw new Error
.Failure("Failed to unregister: " + e
.getMessage());
179 public void deleteAccount() throws Error
.Failure
{
182 } catch (IOException e
) {
183 throw new Error
.Failure("Failed to delete account: " + e
.getMessage());
188 public void addDevice(String uri
) {
190 var deviceLinkUrl
= DeviceLinkUrl
.parseDeviceLinkUri(new URI(uri
));
191 m
.addDeviceLink(deviceLinkUrl
);
192 } catch (IOException
| InvalidDeviceLinkException e
) {
193 throw new Error
.Failure(e
.getClass().getSimpleName() + " Add device link failed. " + e
.getMessage());
194 } catch (NotPrimaryDeviceException e
) {
195 throw new Error
.Failure("This command doesn't work on linked devices.");
196 } catch (URISyntaxException e
) {
197 throw new Error
.InvalidUri(e
.getClass().getSimpleName()
198 + " Device link uri has invalid format: "
204 public DBusPath
getDevice(long deviceId
) {
206 final var deviceOptional
= devices
.stream().filter(g
-> g
.getId().equals(deviceId
)).findFirst();
207 if (deviceOptional
.isEmpty()) {
208 throw new Error
.DeviceNotFound("Device not found");
210 return deviceOptional
.get().getObjectPath();
214 public List
<StructDevice
> listDevices() {
220 public DBusPath
getThisDevice() {
226 public long sendMessage(final String message
, final List
<String
> attachments
, final String recipient
) {
227 return sendMessage(message
, attachments
, List
.of(recipient
));
231 public long sendMessage(final String messageText
, final List
<String
> attachments
, final List
<String
> recipients
) {
233 final var message
= new Message(messageText
,
241 final var recipientIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
242 .map(RecipientIdentifier
.class::cast
)
243 .collect(Collectors
.toSet());
244 final var results
= m
.sendMessage(message
, recipientIdentifiers
, false);
246 checkSendMessageResults(results
);
247 return results
.timestamp();
248 } catch (AttachmentInvalidException e
) {
249 throw new Error
.AttachmentInvalid(e
.getMessage());
250 } catch (IOException
| InvalidStickerException e
) {
251 throw new Error
.Failure(e
);
252 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
253 throw new Error
.GroupNotFound(e
.getMessage());
254 } catch (UnregisteredRecipientException e
) {
255 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
260 public long sendRemoteDeleteMessage(
261 final long targetSentTimestamp
, final String recipient
263 return sendRemoteDeleteMessage(targetSentTimestamp
, List
.of(recipient
));
267 public long sendRemoteDeleteMessage(
268 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
, final String note
, final String recipient
326 ) throws Error
.Failure
{
328 final var results
= m
.sendPaymentNotificationMessage(receipt
,
330 getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
331 checkSendMessageResults(results
);
332 return results
.timestamp();
333 } catch (IOException e
) {
334 throw new Error
.Failure(e
.getMessage());
339 public void sendTyping(
340 final String recipient
, final boolean stop
341 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
343 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
344 getSingleRecipientIdentifiers(List
.of(recipient
), m
.getSelfNumber()).stream()
345 .map(RecipientIdentifier
.class::cast
)
346 .collect(Collectors
.toSet()));
347 checkSendMessageResults(results
);
348 } catch (IOException e
) {
349 throw new Error
.Failure(e
.getMessage());
350 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
351 throw new Error
.GroupNotFound(e
.getMessage());
356 public void sendReadReceipt(
357 final String recipient
, final List
<Long
> messageIds
358 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
359 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
360 checkSendMessageResults(results
);
364 public void sendViewedReceipt(
365 final String recipient
, final List
<Long
> messageIds
366 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
367 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
368 checkSendMessageResults(results
);
372 public void sendContacts() {
375 } catch (IOException e
) {
376 throw new Error
.Failure("SendContacts error: " + e
.getMessage());
381 public void sendSyncRequest() {
383 m
.requestAllSyncData();
384 } catch (IOException e
) {
385 throw new Error
.Failure("Request sync data error: " + e
.getMessage());
390 public long sendNoteToSelfMessage(
391 final String messageText
, final List
<String
> attachments
392 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
394 final var message
= new Message(messageText
,
402 final var results
= m
.sendMessage(message
, Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
), false);
403 checkSendMessageResults(results
);
404 return results
.timestamp();
405 } catch (AttachmentInvalidException e
) {
406 throw new Error
.AttachmentInvalid(e
.getMessage());
407 } catch (IOException
| InvalidStickerException e
) {
408 throw new Error
.Failure(e
.getMessage());
409 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
410 throw new Error
.GroupNotFound(e
.getMessage());
411 } catch (UnregisteredRecipientException e
) {
412 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
417 public void sendEndSessionMessage(final List
<String
> recipients
) {
419 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
420 checkSendMessageResults(results
);
421 } catch (IOException e
) {
422 throw new Error
.Failure(e
.getMessage());
427 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
428 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
432 public void deleteContact(final String recipient
) throws Error
.Failure
{
433 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
437 public long sendGroupMessage(final String messageText
, final List
<String
> attachments
, final byte[] groupId
) {
439 final var message
= new Message(messageText
,
447 var results
= m
.sendMessage(message
, Set
.of(getGroupRecipientIdentifier(groupId
)), false);
448 checkSendMessageResults(results
);
449 return results
.timestamp();
450 } catch (IOException
| InvalidStickerException e
) {
451 throw new Error
.Failure(e
.getMessage());
452 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
453 throw new Error
.GroupNotFound(e
.getMessage());
454 } catch (AttachmentInvalidException e
) {
455 throw new Error
.AttachmentInvalid(e
.getMessage());
456 } catch (UnregisteredRecipientException e
) {
457 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
462 public void sendGroupTyping(
463 final byte[] groupId
, final boolean stop
464 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
466 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
467 Set
.of(getGroupRecipientIdentifier(groupId
)));
468 checkSendMessageResults(results
);
469 } catch (IOException e
) {
470 throw new Error
.Failure(e
.getMessage());
471 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
472 throw new Error
.GroupNotFound(e
.getMessage());
477 public long sendGroupRemoteDeleteMessage(
478 final long targetSentTimestamp
, final byte[] groupId
481 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
482 Set
.of(getGroupRecipientIdentifier(groupId
)));
483 checkSendMessageResults(results
);
484 return results
.timestamp();
485 } catch (IOException e
) {
486 throw new Error
.Failure(e
.getMessage());
487 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
488 throw new Error
.GroupNotFound(e
.getMessage());
493 public long sendGroupMessageReaction(
495 final boolean remove
,
496 final String targetAuthor
,
497 final long targetSentTimestamp
,
501 final var results
= m
.sendMessageReaction(emoji
,
503 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
505 Set
.of(getGroupRecipientIdentifier(groupId
)),
507 checkSendMessageResults(results
);
508 return results
.timestamp();
509 } catch (IOException e
) {
510 throw new Error
.Failure(e
.getMessage());
511 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
512 throw new Error
.GroupNotFound(e
.getMessage());
513 } catch (UnregisteredRecipientException e
) {
514 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
518 // Since contact names might be empty if not defined, also potentially return
521 public String
getContactName(final String number
) {
522 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
523 return name
== null ?
"" : name
;
527 public void setContactName(final String number
, final String name
) {
529 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "");
530 } catch (NotPrimaryDeviceException e
) {
531 throw new Error
.Failure("This command doesn't work on linked devices.");
532 } catch (UnregisteredRecipientException e
) {
533 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
538 public void setExpirationTimer(final String number
, final int expiration
) {
540 m
.setExpirationTimer(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), expiration
);
541 } catch (IOException e
) {
542 throw new Error
.Failure(e
.getMessage());
543 } catch (UnregisteredRecipientException e
) {
544 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
549 public void setContactBlocked(final String number
, final boolean blocked
) {
551 m
.setContactsBlocked(List
.of(getSingleRecipientIdentifier(number
, m
.getSelfNumber())), blocked
);
552 } catch (NotPrimaryDeviceException e
) {
553 throw new Error
.Failure("This command doesn't work on linked devices.");
554 } catch (IOException e
) {
555 throw new Error
.Failure(e
.getMessage());
556 } catch (UnregisteredRecipientException e
) {
557 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
563 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
565 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
566 } catch (NotPrimaryDeviceException e
) {
567 throw new Error
.Failure("This command doesn't work on linked devices.");
568 } catch (GroupNotFoundException e
) {
569 throw new Error
.GroupNotFound(e
.getMessage());
570 } catch (IOException e
) {
571 throw new Error
.Failure(e
.getMessage());
577 public List
<byte[]> getGroupIds() {
578 var groups
= m
.getGroups();
579 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
583 public DBusPath
getGroup(final byte[] groupId
) {
585 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
586 if (groupOptional
.isEmpty()) {
587 throw new Error
.GroupNotFound("Group not found");
589 return groupOptional
.get().getObjectPath();
593 public List
<StructGroup
> listGroups() {
600 public String
getGroupName(final byte[] groupId
) {
601 var group
= m
.getGroup(getGroupId(groupId
));
602 if (group
== null || group
.title() == null) {
605 return group
.title();
611 public List
<String
> getGroupMembers(final byte[] groupId
) {
612 var group
= m
.getGroup(getGroupId(groupId
));
616 final var members
= group
.members();
617 return getRecipientStrings(members
);
622 public byte[] createGroup(
623 final String name
, final List
<String
> members
, final String avatar
624 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
625 return updateGroupInternal(new byte[0], name
, members
, avatar
);
630 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
631 return updateGroupInternal(groupId
, name
, members
, avatar
);
634 public byte[] updateGroupInternal(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
636 groupId
= nullIfEmpty(groupId
);
637 name
= nullIfEmpty(name
);
638 avatar
= nullIfEmpty(avatar
);
639 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
640 if (groupId
== null) {
641 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
643 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
644 return results
.first().serialize();
646 final var results
= m
.updateGroup(getGroupId(groupId
),
647 UpdateGroup
.newBuilder()
649 .withMembers(memberIdentifiers
)
650 .withAvatarFile(avatar
)
652 if (results
!= null) {
653 checkGroupSendMessageResults(results
.timestamp(), results
.results());
657 } catch (IOException e
) {
658 throw new Error
.Failure(e
.getMessage());
659 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
660 throw new Error
.GroupNotFound(e
.getMessage());
661 } catch (AttachmentInvalidException e
) {
662 throw new Error
.AttachmentInvalid(e
.getMessage());
663 } catch (UnregisteredRecipientException e
) {
664 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
670 public boolean isRegistered() {
675 public boolean isRegistered(String number
) {
676 var result
= isRegistered(List
.of(number
));
677 return result
.getFirst();
681 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
682 if (numbers
.isEmpty()) {
686 Map
<String
, UserStatus
> registered
;
688 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
689 } catch (IOException e
) {
690 throw new Error
.Failure(e
.getMessage());
691 } catch (RateLimitException e
) {
692 throw new Error
.Failure(e
.getMessage()
694 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
697 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
701 public void updateProfile(
707 final boolean removeAvatar
710 givenName
= nullIfEmpty(givenName
);
711 familyName
= nullIfEmpty(familyName
);
712 about
= nullIfEmpty(about
);
713 aboutEmoji
= nullIfEmpty(aboutEmoji
);
714 avatarPath
= nullIfEmpty(avatarPath
);
715 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
716 m
.updateProfile(UpdateProfile
.newBuilder()
717 .withGivenName(givenName
)
718 .withFamilyName(familyName
)
720 .withAboutEmoji(aboutEmoji
)
721 .withAvatar(avatarFile
)
722 .withDeleteAvatar(removeAvatar
)
724 } catch (IOException e
) {
725 throw new Error
.Failure(e
.getMessage());
730 public void updateProfile(
733 final String aboutEmoji
,
735 final boolean removeAvatar
737 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
741 public void removePin() {
743 m
.setRegistrationLockPin(Optional
.empty());
744 } catch (IOException e
) {
745 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
746 } catch (NotPrimaryDeviceException e
) {
747 throw new Error
.Failure("This command doesn't work on linked devices.");
752 public void setPin(String registrationLockPin
) {
754 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
755 } catch (IOException e
) {
756 throw new Error
.Failure("Set pin error: " + e
.getMessage());
757 } catch (NotPrimaryDeviceException e
) {
758 throw new Error
.Failure("This command doesn't work on linked devices.");
762 // Provide option to query a version string in order to react on potential
763 // future interface changes
765 public String
version() {
766 return BaseConfig
.PROJECT_VERSION
;
769 // Create a unique list of Numbers from Identities and Contacts to really get
770 // all numbers the system knows
772 public List
<String
> listNumbers() {
773 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
775 .map(r
-> r
.getAddress().number().orElse(null))
776 .filter(Objects
::nonNull
)
782 public List
<String
> getContactNumber(final String name
) {
783 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
785 .map(r
-> r
.getAddress().getLegacyIdentifier())
791 public void quitGroup(final byte[] groupId
) {
792 var group
= getGroupId(groupId
);
794 m
.quitGroup(group
, Set
.of());
795 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
796 throw new Error
.GroupNotFound(e
.getMessage());
797 } catch (IOException
| LastGroupAdminException e
) {
798 throw new Error
.Failure(e
.getMessage());
799 } catch (UnregisteredRecipientException e
) {
800 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
805 public byte[] joinGroup(final String groupLink
) {
807 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
808 if (linkUrl
== null) {
809 throw new Error
.Failure("Group link is invalid:");
811 final var result
= m
.joinGroup(linkUrl
);
812 return result
.first().serialize();
813 } catch (PendingAdminApprovalException e
) {
814 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
815 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
816 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
817 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
818 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
819 } catch (IOException e
) {
820 throw new Error
.Failure(e
.getMessage());
825 public boolean isContactBlocked(final String number
) {
826 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
831 public boolean isGroupBlocked(final byte[] groupId
) {
832 var group
= m
.getGroup(getGroupId(groupId
));
836 return group
.isBlocked();
842 public boolean isMember(final byte[] groupId
) {
843 var group
= m
.getGroup(getGroupId(groupId
));
847 return group
.isMember();
852 public String
uploadStickerPack(String stickerPackPath
) {
853 File path
= new File(stickerPackPath
);
855 return m
.uploadStickerPack(path
).toString();
856 } catch (IOException e
) {
857 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
858 } catch (StickerPackInvalidException e
) {
859 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
863 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
864 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
870 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
872 if (result
.isIdentityFailure()) {
873 throw new Error
.UntrustedIdentity(message
);
875 throw new Error
.Failure(message
);
879 private void checkSendMessageResults(final SendMessageResults results
) {
880 final var sendMessageResults
= results
.results().values().stream().findFirst();
881 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
882 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
886 if (results
.hasSuccess()) {
890 var message
= new StringBuilder();
891 message
.append("Failed to send messages:\n");
892 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
893 for (var error
: errors
) {
894 message
.append(error
).append('\n');
896 message
.append(results
.timestamp());
898 throw new Error
.Failure(message
.toString());
901 private static void checkGroupSendMessageResults(
902 long timestamp
, Collection
<SendMessageResult
> results
903 ) throws DBusExecutionException
{
904 if (results
.size() == 1) {
905 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
909 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
910 if (errors
.isEmpty() || errors
.size() < results
.size()) {
914 var message
= new StringBuilder();
915 message
.append("Failed to send message:\n");
916 for (var error
: errors
) {
917 message
.append(error
).append('\n');
919 message
.append(timestamp
);
921 throw new Error
.Failure(message
.toString());
924 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
925 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
928 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
929 final Collection
<String
> recipientStrings
, final String localNumber
930 ) throws DBusExecutionException
{
931 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
932 for (var recipientString
: recipientStrings
) {
933 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
938 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
939 final String recipientString
, final String localNumber
940 ) throws DBusExecutionException
{
942 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
943 } catch (InvalidNumberException e
) {
944 throw new Error
.InvalidNumber(e
.getMessage());
948 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
949 return new RecipientIdentifier
.Group(getGroupId(groupId
));
952 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
954 return GroupId
.unknownVersion(groupId
);
955 } catch (Throwable e
) {
956 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
960 private byte[] nullIfEmpty(final byte[] array
) {
961 return array
.length
== 0 ?
null : array
;
964 private String
nullIfEmpty(final String name
) {
965 return name
.isEmpty() ?
null : name
;
968 private String
emptyIfNull(final String string
) {
969 return string
== null ?
"" : string
;
972 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
973 return basePath
+ "/Devices/" + deviceId
;
976 private void updateDevices() {
977 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
979 linkedDevices
= m
.getLinkedDevices();
980 } catch (IOException e
) {
981 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
986 linkedDevices
.forEach(d
-> {
987 final var object
= new DbusSignalDeviceImpl(d
);
988 final var deviceObjectPath
= object
.getObjectPath();
989 exportObject(object
);
990 if (d
.isThisDevice()) {
991 thisDevice
= new DBusPath(deviceObjectPath
);
993 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
997 private void unExportDevices() {
998 this.devices
.stream()
999 .map(StructDevice
::getObjectPath
)
1000 .map(DBusPath
::getPath
)
1001 .forEach(connection
::unExportObject
);
1002 this.devices
.clear();
1005 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
1006 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
1009 private void updateGroups() {
1010 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
1011 groups
= m
.getGroups();
1015 groups
.forEach(g
-> {
1016 final var object
= new DbusSignalGroupImpl(g
.groupId());
1017 exportObject(object
);
1018 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1019 g
.groupId().serialize(),
1020 emptyIfNull(g
.title())));
1024 private void unExportGroups() {
1025 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1026 this.groups
.clear();
1029 private static String
getConfigurationObjectPath(String basePath
) {
1030 return basePath
+ "/Configuration";
1033 private void updateConfiguration() {
1034 unExportConfiguration();
1035 final var object
= new DbusSignalConfigurationImpl();
1036 exportObject(object
);
1039 private void unExportConfiguration() {
1040 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1041 connection
.unExportObject(objectPath
);
1044 private void exportObject(final DBusInterface object
) {
1046 connection
.exportObject(object
);
1047 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1048 } catch (DBusException e
) {
1049 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1053 private void updateIdentities() {
1054 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1055 identities
= m
.getIdentities();
1057 unExportIdentities();
1059 identities
.forEach(i
-> {
1060 final var object
= new DbusSignalIdentityImpl(i
);
1061 exportObject(object
);
1062 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1063 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1064 i
.recipient().number().orElse("")));
1068 private static String
getIdentityObjectPath(String basePath
, String id
) {
1069 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1072 private void unExportIdentities() {
1073 this.identities
.stream()
1074 .map(StructIdentity
::getObjectPath
)
1075 .map(DBusPath
::getPath
)
1076 .forEach(connection
::unExportObject
);
1077 this.identities
.clear();
1081 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1082 final var found
= identities
.stream()
1083 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1086 if (found
.isEmpty()) {
1087 throw new Error
.Failure("Identity for " + number
+ " unknown");
1089 return found
.get().getObjectPath();
1093 public List
<StructIdentity
> listIdentities() {
1095 return this.identities
;
1098 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1100 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1102 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1103 this.identity
= identity
;
1104 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1105 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1106 new DbusProperty
<>("Uuid",
1107 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1108 new DbusProperty
<>("Fingerprint", identity
::fingerprint
),
1109 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1110 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1111 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1112 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1116 public String
getObjectPath() {
1117 return getIdentityObjectPath(objectPath
,
1118 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1122 public void trust() throws Error
.Failure
{
1123 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1125 m
.trustIdentityAllKeys(recipient
);
1126 } catch (UnregisteredRecipientException e
) {
1127 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1133 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1134 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1136 if (safetyNumber
== null) {
1137 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1139 final IdentityVerificationCode verificationCode
;
1141 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1142 } catch (Exception e
) {
1143 throw new Error
.Failure(
1144 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1148 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1150 throw new Error
.Failure(
1151 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1153 } catch (UnregisteredRecipientException e
) {
1154 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1160 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1162 private final org
.asamk
.signal
.manager
.api
.Device device
;
1164 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1165 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1166 List
.of(new DbusProperty
<>("Id", device
::id
),
1167 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1168 new DbusProperty
<>("Created", device
::created
),
1169 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1170 this.device
= device
;
1174 public String
getObjectPath() {
1175 return getDeviceObjectPath(objectPath
, device
.id());
1179 public void removeDevice() throws Error
.Failure
{
1181 m
.removeLinkedDevices(device
.id());
1183 } catch (NotPrimaryDeviceException e
) {
1184 throw new Error
.Failure("This command doesn't work on linked devices.");
1185 } catch (IOException e
) {
1186 throw new Error
.Failure(e
.getMessage());
1190 private void setDeviceName(String name
) {
1191 if (!device
.isThisDevice()) {
1192 throw new Error
.Failure("Only the name of this device can be changed");
1195 m
.updateAccountAttributes(name
, null, null, null);
1196 // update device list
1198 } catch (IOException e
) {
1199 throw new Error
.Failure(e
.getMessage());
1204 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1206 public DbusSignalConfigurationImpl() {
1207 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1208 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1209 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1210 this::getUnidentifiedDeliveryIndicators
,
1211 this::setUnidentifiedDeliveryIndicators
),
1212 new DbusProperty
<>("TypingIndicators",
1213 this::getTypingIndicators
,
1214 this::setTypingIndicators
),
1215 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1220 public String
getObjectPath() {
1221 return getConfigurationObjectPath(objectPath
);
1224 public void setReadReceipts(Boolean readReceipts
) {
1225 setConfiguration(readReceipts
, null, null, null);
1228 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1229 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1232 public void setTypingIndicators(Boolean typingIndicators
) {
1233 setConfiguration(null, null, typingIndicators
, null);
1236 public void setLinkPreviews(Boolean linkPreviews
) {
1237 setConfiguration(null, null, null, linkPreviews
);
1240 private void setConfiguration(
1241 Boolean readReceipts
,
1242 Boolean unidentifiedDeliveryIndicators
,
1243 Boolean typingIndicators
,
1244 Boolean linkPreviews
1247 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1248 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1249 Optional
.ofNullable(typingIndicators
),
1250 Optional
.ofNullable(linkPreviews
)));
1251 } catch (NotPrimaryDeviceException e
) {
1252 throw new Error
.Failure("This command doesn't work on linked devices.");
1256 private boolean getReadReceipts() {
1257 return m
.getConfiguration().readReceipts().orElse(false);
1260 private boolean getUnidentifiedDeliveryIndicators() {
1261 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1264 private boolean getTypingIndicators() {
1265 return m
.getConfiguration().typingIndicators().orElse(false);
1268 private boolean getLinkPreviews() {
1269 return m
.getConfiguration().linkPreviews().orElse(false);
1273 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1275 private final GroupId groupId
;
1277 public DbusSignalGroupImpl(final GroupId groupId
) {
1278 this.groupId
= groupId
;
1279 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1280 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1281 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1282 new DbusProperty
<>("Description",
1283 () -> emptyIfNull(getGroup().description()),
1284 this::setGroupDescription
),
1285 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1286 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1287 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1288 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1289 new DbusProperty
<>("MessageExpirationTimer",
1290 () -> getGroup().messageExpirationTimer(),
1291 this::setMessageExpirationTime
),
1292 new DbusProperty
<>("Members",
1293 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1294 new DbusProperty
<>("PendingMembers",
1295 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1296 new DbusProperty
<>("RequestingMembers",
1297 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1298 new DbusProperty
<>("Admins",
1299 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1300 new DbusProperty
<>("Banned",
1301 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1302 new DbusProperty
<>("PermissionAddMember",
1303 () -> getGroup().permissionAddMember().name(),
1304 this::setGroupPermissionAddMember
),
1305 new DbusProperty
<>("PermissionEditDetails",
1306 () -> getGroup().permissionEditDetails().name(),
1307 this::setGroupPermissionEditDetails
),
1308 new DbusProperty
<>("PermissionSendMessage",
1309 () -> getGroup().permissionSendMessage().name(),
1310 this::setGroupPermissionSendMessage
),
1311 new DbusProperty
<>("GroupInviteLink", () -> {
1312 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1313 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1318 public String
getObjectPath() {
1319 return getGroupObjectPath(objectPath
, groupId
.serialize());
1323 public void quitGroup() throws Error
.Failure
{
1325 m
.quitGroup(groupId
, Set
.of());
1326 } catch (GroupNotFoundException e
) {
1327 throw new Error
.GroupNotFound(e
.getMessage());
1328 } catch (NotAGroupMemberException e
) {
1329 throw new Error
.NotAGroupMember(e
.getMessage());
1330 } catch (IOException e
) {
1331 throw new Error
.Failure(e
.getMessage());
1332 } catch (LastGroupAdminException e
) {
1333 throw new Error
.LastGroupAdmin(e
.getMessage());
1334 } catch (UnregisteredRecipientException e
) {
1335 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1340 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1342 m
.deleteGroup(groupId
);
1343 } catch (IOException e
) {
1344 throw new Error
.Failure(e
.getMessage());
1350 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1351 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1352 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1356 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1357 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1358 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1362 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1363 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1364 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1368 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1369 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1370 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1374 public void resetLink() throws Error
.Failure
{
1375 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1379 public void disableLink() throws Error
.Failure
{
1380 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1384 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1385 updateGroup(UpdateGroup
.newBuilder()
1386 .withGroupLinkState(requiresApproval
1387 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1388 : GroupLinkState
.ENABLED
)
1392 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1393 return m
.getGroup(groupId
);
1396 private void setGroupName(final String name
) {
1397 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1400 private void setGroupDescription(final String description
) {
1401 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1404 private void setGroupAvatar(final String avatar
) {
1405 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1408 private void setMessageExpirationTime(final int expirationTime
) {
1409 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1412 private void setGroupPermissionAddMember(final String permission
) {
1413 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1416 private void setGroupPermissionEditDetails(final String permission
) {
1417 updateGroup(UpdateGroup
.newBuilder()
1418 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1422 private void setGroupPermissionSendMessage(final String permission
) {
1423 updateGroup(UpdateGroup
.newBuilder()
1424 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1428 private void setIsBlocked(final boolean isBlocked
) {
1430 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1431 } catch (NotPrimaryDeviceException e
) {
1432 throw new Error
.Failure("This command doesn't work on linked devices.");
1433 } catch (GroupNotFoundException e
) {
1434 throw new Error
.GroupNotFound(e
.getMessage());
1435 } catch (IOException e
) {
1436 throw new Error
.Failure(e
.getMessage());
1440 private void updateGroup(final UpdateGroup updateGroup
) {
1442 m
.updateGroup(groupId
, updateGroup
);
1443 } catch (IOException e
) {
1444 throw new Error
.Failure(e
.getMessage());
1445 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1446 throw new Error
.GroupNotFound(e
.getMessage());
1447 } catch (AttachmentInvalidException e
) {
1448 throw new Error
.AttachmentInvalid(e
.getMessage());
1449 } catch (UnregisteredRecipientException e
) {
1450 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");