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(
84 final Manager m
, DBusConnection connection
, final String objectPath
, final boolean noReceiveOnStart
87 this.connection
= connection
;
88 this.objectPath
= objectPath
;
89 this.noReceiveOnStart
= noReceiveOnStart
;
91 m
.addAddressChangedListener(() -> {
97 public void initObjects() {
99 if (!noReceiveOnStart
) {
104 private void exportObjects() {
109 updateConfiguration();
114 public void close() {
115 if (dbusMessageHandler
!= null) {
116 m
.removeReceiveHandler(dbusMessageHandler
);
117 dbusMessageHandler
= null;
122 private void unExportObjects() {
125 unExportConfiguration();
126 unExportIdentities();
127 connection
.unExportObject(this.objectPath
);
131 public String
getObjectPath() {
136 public String
getSelfNumber() {
137 return m
.getSelfNumber();
141 public void subscribeReceive() {
142 if (dbusMessageHandler
== null) {
143 dbusMessageHandler
= new DbusReceiveMessageHandler(connection
, objectPath
);
144 m
.addReceiveHandler(dbusMessageHandler
);
150 public void unsubscribeReceive() {
151 subscriberCount
= Math
.max(0, subscriberCount
- 1);
152 if (subscriberCount
== 0 && dbusMessageHandler
!= null) {
153 m
.removeReceiveHandler(dbusMessageHandler
);
154 dbusMessageHandler
= null;
159 public void submitRateLimitChallenge(String challenge
, String captcha
) {
161 m
.submitRateLimitRecaptchaChallenge(challenge
, captcha
);
162 } catch (IOException e
) {
163 throw new Error
.Failure("Submit challenge error: " + e
.getMessage());
164 } catch (CaptchaRejectedException e
) {
165 throw new Error
.Failure(
166 "Captcha rejected, it may be outdated, already used or solved from a different IP address.");
171 public void unregister() throws Error
.Failure
{
174 } catch (IOException e
) {
175 throw new Error
.Failure("Failed to unregister: " + e
.getMessage());
180 public void deleteAccount() throws Error
.Failure
{
183 } catch (IOException e
) {
184 throw new Error
.Failure("Failed to delete account: " + e
.getMessage());
189 public void addDevice(String uri
) {
191 var deviceLinkUrl
= DeviceLinkUrl
.parseDeviceLinkUri(new URI(uri
));
192 m
.addDeviceLink(deviceLinkUrl
);
193 } catch (IOException
| InvalidDeviceLinkException
| DeviceLimitExceededException e
) {
194 throw new Error
.Failure(e
.getClass().getSimpleName() + " Add device link failed. " + e
.getMessage());
195 } catch (NotPrimaryDeviceException e
) {
196 throw new Error
.Failure("This command doesn't work on linked devices.");
197 } catch (URISyntaxException e
) {
198 throw new Error
.InvalidUri(e
.getClass().getSimpleName()
199 + " Device link uri has invalid format: "
205 public DBusPath
getDevice(long deviceId
) {
207 final var deviceOptional
= devices
.stream().filter(g
-> g
.getId().equals(deviceId
)).findFirst();
208 if (deviceOptional
.isEmpty()) {
209 throw new Error
.DeviceNotFound("Device not found");
211 return deviceOptional
.get().getObjectPath();
215 public List
<StructDevice
> listDevices() {
221 public DBusPath
getThisDevice() {
227 public long sendMessage(final String message
, final List
<String
> attachments
, final String recipient
) {
228 return sendMessage(message
, attachments
, List
.of(recipient
));
232 public long sendMessage(final String messageText
, final List
<String
> attachments
, final List
<String
> recipients
) {
234 final var message
= new Message(messageText
,
242 final var recipientIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()).stream()
243 .map(RecipientIdentifier
.class::cast
)
244 .collect(Collectors
.toSet());
245 final var results
= m
.sendMessage(message
, recipientIdentifiers
, false);
247 checkSendMessageResults(results
);
248 return results
.timestamp();
249 } catch (AttachmentInvalidException e
) {
250 throw new Error
.AttachmentInvalid(e
.getMessage());
251 } catch (IOException
| InvalidStickerException e
) {
252 throw new Error
.Failure(e
);
253 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
254 throw new Error
.GroupNotFound(e
.getMessage());
255 } catch (UnregisteredRecipientException e
) {
256 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
261 public long sendRemoteDeleteMessage(
262 final long targetSentTimestamp
, final String recipient
264 return sendRemoteDeleteMessage(targetSentTimestamp
, List
.of(recipient
));
268 public long sendRemoteDeleteMessage(
269 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
, final String note
, final String recipient
327 ) throws Error
.Failure
{
329 final var results
= m
.sendPaymentNotificationMessage(receipt
,
331 getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
332 checkSendMessageResults(results
);
333 return results
.timestamp();
334 } catch (IOException e
) {
335 throw new Error
.Failure(e
.getMessage());
340 public void sendTyping(
341 final String recipient
, final boolean stop
342 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
344 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
345 getSingleRecipientIdentifiers(List
.of(recipient
), m
.getSelfNumber()).stream()
346 .map(RecipientIdentifier
.class::cast
)
347 .collect(Collectors
.toSet()));
348 checkSendMessageResults(results
);
349 } catch (IOException e
) {
350 throw new Error
.Failure(e
.getMessage());
351 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
352 throw new Error
.GroupNotFound(e
.getMessage());
357 public void sendReadReceipt(
358 final String recipient
, final List
<Long
> messageIds
359 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
360 final var results
= m
.sendReadReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
361 checkSendMessageResults(results
);
365 public void sendViewedReceipt(
366 final String recipient
, final List
<Long
> messageIds
367 ) throws Error
.Failure
, Error
.UntrustedIdentity
{
368 final var results
= m
.sendViewedReceipt(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()), messageIds
);
369 checkSendMessageResults(results
);
373 public void sendContacts() {
376 } catch (IOException e
) {
377 throw new Error
.Failure("SendContacts error: " + e
.getMessage());
382 public void sendSyncRequest() {
384 m
.requestAllSyncData();
385 } catch (IOException e
) {
386 throw new Error
.Failure("Request sync data error: " + e
.getMessage());
391 public long sendNoteToSelfMessage(
392 final String messageText
, final List
<String
> attachments
393 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.UntrustedIdentity
{
395 final var message
= new Message(messageText
,
403 final var results
= m
.sendMessage(message
, Set
.of(RecipientIdentifier
.NoteToSelf
.INSTANCE
), false);
404 checkSendMessageResults(results
);
405 return results
.timestamp();
406 } catch (AttachmentInvalidException e
) {
407 throw new Error
.AttachmentInvalid(e
.getMessage());
408 } catch (IOException
| InvalidStickerException e
) {
409 throw new Error
.Failure(e
.getMessage());
410 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
411 throw new Error
.GroupNotFound(e
.getMessage());
412 } catch (UnregisteredRecipientException e
) {
413 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
418 public void sendEndSessionMessage(final List
<String
> recipients
) {
420 final var results
= m
.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber()));
421 checkSendMessageResults(results
);
422 } catch (IOException e
) {
423 throw new Error
.Failure(e
.getMessage());
428 public void deleteRecipient(final String recipient
) throws Error
.Failure
{
429 m
.deleteRecipient(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
433 public void deleteContact(final String recipient
) throws Error
.Failure
{
434 m
.deleteContact(getSingleRecipientIdentifier(recipient
, m
.getSelfNumber()));
438 public long sendGroupMessage(final String messageText
, final List
<String
> attachments
, final byte[] groupId
) {
440 final var message
= new Message(messageText
,
448 var results
= m
.sendMessage(message
, Set
.of(getGroupRecipientIdentifier(groupId
)), false);
449 checkSendMessageResults(results
);
450 return results
.timestamp();
451 } catch (IOException
| InvalidStickerException e
) {
452 throw new Error
.Failure(e
.getMessage());
453 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
454 throw new Error
.GroupNotFound(e
.getMessage());
455 } catch (AttachmentInvalidException e
) {
456 throw new Error
.AttachmentInvalid(e
.getMessage());
457 } catch (UnregisteredRecipientException e
) {
458 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
463 public void sendGroupTyping(
464 final byte[] groupId
, final boolean stop
465 ) throws Error
.Failure
, Error
.GroupNotFound
, Error
.UntrustedIdentity
{
467 final var results
= m
.sendTypingMessage(stop ? TypingAction
.STOP
: TypingAction
.START
,
468 Set
.of(getGroupRecipientIdentifier(groupId
)));
469 checkSendMessageResults(results
);
470 } catch (IOException e
) {
471 throw new Error
.Failure(e
.getMessage());
472 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
473 throw new Error
.GroupNotFound(e
.getMessage());
478 public long sendGroupRemoteDeleteMessage(
479 final long targetSentTimestamp
, final byte[] groupId
482 final var results
= m
.sendRemoteDeleteMessage(targetSentTimestamp
,
483 Set
.of(getGroupRecipientIdentifier(groupId
)));
484 checkSendMessageResults(results
);
485 return results
.timestamp();
486 } catch (IOException e
) {
487 throw new Error
.Failure(e
.getMessage());
488 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
489 throw new Error
.GroupNotFound(e
.getMessage());
494 public long sendGroupMessageReaction(
496 final boolean remove
,
497 final String targetAuthor
,
498 final long targetSentTimestamp
,
502 final var results
= m
.sendMessageReaction(emoji
,
504 getSingleRecipientIdentifier(targetAuthor
, m
.getSelfNumber()),
506 Set
.of(getGroupRecipientIdentifier(groupId
)),
508 checkSendMessageResults(results
);
509 return results
.timestamp();
510 } catch (IOException e
) {
511 throw new Error
.Failure(e
.getMessage());
512 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
513 throw new Error
.GroupNotFound(e
.getMessage());
514 } catch (UnregisteredRecipientException e
) {
515 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
519 // Since contact names might be empty if not defined, also potentially return
522 public String
getContactName(final String number
) {
523 final var name
= m
.getContactOrProfileName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
524 return name
== null ?
"" : name
;
528 public void setContactName(final String number
, final String name
) {
530 m
.setContactName(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), name
, "");
531 } catch (NotPrimaryDeviceException e
) {
532 throw new Error
.Failure("This command doesn't work on linked devices.");
533 } catch (UnregisteredRecipientException e
) {
534 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
539 public void setExpirationTimer(final String number
, final int expiration
) {
541 m
.setExpirationTimer(getSingleRecipientIdentifier(number
, m
.getSelfNumber()), expiration
);
542 } catch (IOException e
) {
543 throw new Error
.Failure(e
.getMessage());
544 } catch (UnregisteredRecipientException e
) {
545 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
550 public void setContactBlocked(final String number
, final boolean blocked
) {
552 m
.setContactsBlocked(List
.of(getSingleRecipientIdentifier(number
, m
.getSelfNumber())), blocked
);
553 } catch (NotPrimaryDeviceException e
) {
554 throw new Error
.Failure("This command doesn't work on linked devices.");
555 } catch (IOException e
) {
556 throw new Error
.Failure(e
.getMessage());
557 } catch (UnregisteredRecipientException e
) {
558 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
564 public void setGroupBlocked(final byte[] groupId
, final boolean blocked
) {
566 m
.setGroupsBlocked(List
.of(getGroupId(groupId
)), blocked
);
567 } catch (NotPrimaryDeviceException e
) {
568 throw new Error
.Failure("This command doesn't work on linked devices.");
569 } catch (GroupNotFoundException e
) {
570 throw new Error
.GroupNotFound(e
.getMessage());
571 } catch (IOException e
) {
572 throw new Error
.Failure(e
.getMessage());
578 public List
<byte[]> getGroupIds() {
579 var groups
= m
.getGroups();
580 return groups
.stream().map(g
-> g
.groupId().serialize()).toList();
584 public DBusPath
getGroup(final byte[] groupId
) {
586 final var groupOptional
= groups
.stream().filter(g
-> Arrays
.equals(g
.getId(), groupId
)).findFirst();
587 if (groupOptional
.isEmpty()) {
588 throw new Error
.GroupNotFound("Group not found");
590 return groupOptional
.get().getObjectPath();
594 public List
<StructGroup
> listGroups() {
601 public String
getGroupName(final byte[] groupId
) {
602 var group
= m
.getGroup(getGroupId(groupId
));
603 if (group
== null || group
.title() == null) {
606 return group
.title();
612 public List
<String
> getGroupMembers(final byte[] groupId
) {
613 var group
= m
.getGroup(getGroupId(groupId
));
617 final var members
= group
.members();
618 return getRecipientStrings(members
);
623 public byte[] createGroup(
624 final String name
, final List
<String
> members
, final String avatar
625 ) throws Error
.AttachmentInvalid
, Error
.Failure
, Error
.InvalidNumber
{
626 return updateGroupInternal(new byte[0], name
, members
, avatar
);
631 public byte[] updateGroup(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
632 return updateGroupInternal(groupId
, name
, members
, avatar
);
635 public byte[] updateGroupInternal(byte[] groupId
, String name
, List
<String
> members
, String avatar
) {
637 groupId
= nullIfEmpty(groupId
);
638 name
= nullIfEmpty(name
);
639 avatar
= nullIfEmpty(avatar
);
640 final var memberIdentifiers
= getSingleRecipientIdentifiers(members
, m
.getSelfNumber());
641 if (groupId
== null) {
642 final var results
= m
.createGroup(name
, memberIdentifiers
, avatar
);
644 checkGroupSendMessageResults(results
.second().timestamp(), results
.second().results());
645 return results
.first().serialize();
647 final var results
= m
.updateGroup(getGroupId(groupId
),
648 UpdateGroup
.newBuilder()
650 .withMembers(memberIdentifiers
)
651 .withAvatarFile(avatar
)
653 if (results
!= null) {
654 checkGroupSendMessageResults(results
.timestamp(), results
.results());
658 } catch (IOException e
) {
659 throw new Error
.Failure(e
.getMessage());
660 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
661 throw new Error
.GroupNotFound(e
.getMessage());
662 } catch (AttachmentInvalidException e
) {
663 throw new Error
.AttachmentInvalid(e
.getMessage());
664 } catch (UnregisteredRecipientException e
) {
665 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
671 public boolean isRegistered() {
676 public boolean isRegistered(String number
) {
677 var result
= isRegistered(List
.of(number
));
678 return result
.getFirst();
682 public List
<Boolean
> isRegistered(List
<String
> numbers
) {
683 if (numbers
.isEmpty()) {
687 Map
<String
, UserStatus
> registered
;
689 registered
= m
.getUserStatus(new HashSet
<>(numbers
));
690 } catch (IOException e
) {
691 throw new Error
.Failure(e
.getMessage());
692 } catch (RateLimitException e
) {
693 throw new Error
.Failure(e
.getMessage()
695 + DateUtils
.formatTimestamp(e
.getNextAttemptTimestamp()));
698 return numbers
.stream().map(number
-> registered
.get(number
).uuid() != null).toList();
702 public void updateProfile(
708 final boolean removeAvatar
711 givenName
= nullIfEmpty(givenName
);
712 familyName
= nullIfEmpty(familyName
);
713 about
= nullIfEmpty(about
);
714 aboutEmoji
= nullIfEmpty(aboutEmoji
);
715 avatarPath
= nullIfEmpty(avatarPath
);
716 final var avatarFile
= removeAvatar
|| avatarPath
== null ?
null : avatarPath
;
717 m
.updateProfile(UpdateProfile
.newBuilder()
718 .withGivenName(givenName
)
719 .withFamilyName(familyName
)
721 .withAboutEmoji(aboutEmoji
)
722 .withAvatar(avatarFile
)
723 .withDeleteAvatar(removeAvatar
)
725 } catch (IOException e
) {
726 throw new Error
.Failure(e
.getMessage());
731 public void updateProfile(
734 final String aboutEmoji
,
736 final boolean removeAvatar
738 updateProfile(name
, "", about
, aboutEmoji
, avatarPath
, removeAvatar
);
742 public void removePin() {
744 m
.setRegistrationLockPin(Optional
.empty());
745 } catch (IOException e
) {
746 throw new Error
.Failure("Remove pin error: " + e
.getMessage());
747 } catch (NotPrimaryDeviceException e
) {
748 throw new Error
.Failure("This command doesn't work on linked devices.");
753 public void setPin(String registrationLockPin
) {
755 m
.setRegistrationLockPin(Optional
.of(registrationLockPin
));
756 } catch (IOException e
) {
757 throw new Error
.Failure("Set pin error: " + e
.getMessage());
758 } catch (NotPrimaryDeviceException e
) {
759 throw new Error
.Failure("This command doesn't work on linked devices.");
763 // Provide option to query a version string in order to react on potential
764 // future interface changes
766 public String
version() {
767 return BaseConfig
.PROJECT_VERSION
;
770 // Create a unique list of Numbers from Identities and Contacts to really get
771 // all numbers the system knows
773 public List
<String
> listNumbers() {
774 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.empty())
776 .map(r
-> r
.getAddress().number().orElse(null))
777 .filter(Objects
::nonNull
)
783 public List
<String
> getContactNumber(final String name
) {
784 return m
.getRecipients(false, Optional
.empty(), Set
.of(), Optional
.of(name
))
786 .map(r
-> r
.getAddress().getLegacyIdentifier())
792 public void quitGroup(final byte[] groupId
) {
793 var group
= getGroupId(groupId
);
795 m
.quitGroup(group
, Set
.of());
796 } catch (GroupNotFoundException
| NotAGroupMemberException e
) {
797 throw new Error
.GroupNotFound(e
.getMessage());
798 } catch (IOException
| LastGroupAdminException e
) {
799 throw new Error
.Failure(e
.getMessage());
800 } catch (UnregisteredRecipientException e
) {
801 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
806 public byte[] joinGroup(final String groupLink
) {
808 final var linkUrl
= GroupInviteLinkUrl
.fromUri(groupLink
);
809 if (linkUrl
== null) {
810 throw new Error
.Failure("Group link is invalid:");
812 final var result
= m
.joinGroup(linkUrl
);
813 return result
.first().serialize();
814 } catch (PendingAdminApprovalException e
) {
815 throw new Error
.Failure("Pending admin approval: " + e
.getMessage());
816 } catch (GroupInviteLinkUrl
.InvalidGroupLinkException
| InactiveGroupLinkException e
) {
817 throw new Error
.Failure("Group link is invalid: " + e
.getMessage());
818 } catch (GroupInviteLinkUrl
.UnknownGroupLinkVersionException e
) {
819 throw new Error
.Failure("Group link was created with an incompatible version: " + e
.getMessage());
820 } catch (IOException e
) {
821 throw new Error
.Failure(e
.getMessage());
826 public boolean isContactBlocked(final String number
) {
827 return m
.isContactBlocked(getSingleRecipientIdentifier(number
, m
.getSelfNumber()));
832 public boolean isGroupBlocked(final byte[] groupId
) {
833 var group
= m
.getGroup(getGroupId(groupId
));
837 return group
.isBlocked();
843 public boolean isMember(final byte[] groupId
) {
844 var group
= m
.getGroup(getGroupId(groupId
));
848 return group
.isMember();
853 public String
uploadStickerPack(String stickerPackPath
) {
854 File path
= new File(stickerPackPath
);
856 return m
.uploadStickerPack(path
).toString();
857 } catch (IOException e
) {
858 throw new Error
.Failure("Upload error (maybe image size is too large):" + e
.getMessage());
859 } catch (StickerPackInvalidException e
) {
860 throw new Error
.Failure("Invalid sticker pack: " + e
.getMessage());
864 private static void checkSendMessageResult(long timestamp
, SendMessageResult result
) throws DBusExecutionException
{
865 var error
= SendMessageResultUtils
.getErrorMessageFromSendMessageResult(result
);
871 final var message
= "\nFailed to send message:\n" + error
+ '\n' + timestamp
;
873 if (result
.isIdentityFailure()) {
874 throw new Error
.UntrustedIdentity(message
);
876 throw new Error
.Failure(message
);
880 private void checkSendMessageResults(final SendMessageResults results
) {
881 final var sendMessageResults
= results
.results().values().stream().findFirst();
882 if (results
.results().size() == 1 && sendMessageResults
.get().size() == 1) {
883 checkSendMessageResult(results
.timestamp(), sendMessageResults
.get().stream().findFirst().get());
887 if (results
.hasSuccess()) {
891 var message
= new StringBuilder();
892 message
.append("Failed to send messages:\n");
893 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
.results());
894 for (var error
: errors
) {
895 message
.append(error
).append('\n');
897 message
.append(results
.timestamp());
899 throw new Error
.Failure(message
.toString());
902 private static void checkGroupSendMessageResults(
903 long timestamp
, Collection
<SendMessageResult
> results
904 ) throws DBusExecutionException
{
905 if (results
.size() == 1) {
906 checkSendMessageResult(timestamp
, results
.stream().findFirst().get());
910 var errors
= SendMessageResultUtils
.getErrorMessagesFromSendMessageResults(results
);
911 if (errors
.isEmpty() || errors
.size() < results
.size()) {
915 var message
= new StringBuilder();
916 message
.append("Failed to send message:\n");
917 for (var error
: errors
) {
918 message
.append(error
).append('\n');
920 message
.append(timestamp
);
922 throw new Error
.Failure(message
.toString());
925 private static List
<String
> getRecipientStrings(final Set
<RecipientAddress
> members
) {
926 return members
.stream().map(RecipientAddress
::getLegacyIdentifier
).toList();
929 private static Set
<RecipientIdentifier
.Single
> getSingleRecipientIdentifiers(
930 final Collection
<String
> recipientStrings
, final String localNumber
931 ) throws DBusExecutionException
{
932 final var identifiers
= new HashSet
<RecipientIdentifier
.Single
>();
933 for (var recipientString
: recipientStrings
) {
934 identifiers
.add(getSingleRecipientIdentifier(recipientString
, localNumber
));
939 private static RecipientIdentifier
.Single
getSingleRecipientIdentifier(
940 final String recipientString
, final String localNumber
941 ) throws DBusExecutionException
{
943 return RecipientIdentifier
.Single
.fromString(recipientString
, localNumber
);
944 } catch (InvalidNumberException e
) {
945 throw new Error
.InvalidNumber(e
.getMessage());
949 private RecipientIdentifier
.Group
getGroupRecipientIdentifier(final byte[] groupId
) {
950 return new RecipientIdentifier
.Group(getGroupId(groupId
));
953 private static GroupId
getGroupId(byte[] groupId
) throws DBusExecutionException
{
955 return GroupId
.unknownVersion(groupId
);
956 } catch (Throwable e
) {
957 throw new Error
.InvalidGroupId("Invalid group id: " + e
.getMessage());
961 private byte[] nullIfEmpty(final byte[] array
) {
962 return array
.length
== 0 ?
null : array
;
965 private String
nullIfEmpty(final String name
) {
966 return name
.isEmpty() ?
null : name
;
969 private String
emptyIfNull(final String string
) {
970 return string
== null ?
"" : string
;
973 private static String
getDeviceObjectPath(String basePath
, long deviceId
) {
974 return basePath
+ "/Devices/" + deviceId
;
977 private void updateDevices() {
978 List
<org
.asamk
.signal
.manager
.api
.Device
> linkedDevices
;
980 linkedDevices
= m
.getLinkedDevices();
981 } catch (IOException e
) {
982 throw new Error
.Failure("Failed to get linked devices: " + e
.getMessage());
987 linkedDevices
.forEach(d
-> {
988 final var object
= new DbusSignalDeviceImpl(d
);
989 final var deviceObjectPath
= object
.getObjectPath();
990 exportObject(object
);
991 if (d
.isThisDevice()) {
992 thisDevice
= new DBusPath(deviceObjectPath
);
994 this.devices
.add(new StructDevice(new DBusPath(deviceObjectPath
), (long) d
.id(), emptyIfNull(d
.name())));
998 private void unExportDevices() {
999 this.devices
.stream()
1000 .map(StructDevice
::getObjectPath
)
1001 .map(DBusPath
::getPath
)
1002 .forEach(connection
::unExportObject
);
1003 this.devices
.clear();
1006 private static String
getGroupObjectPath(String basePath
, byte[] groupId
) {
1007 return basePath
+ "/Groups/" + makeValidObjectPathElement(Base64
.getEncoder().encodeToString(groupId
));
1010 private void updateGroups() {
1011 List
<org
.asamk
.signal
.manager
.api
.Group
> groups
;
1012 groups
= m
.getGroups();
1016 groups
.forEach(g
-> {
1017 final var object
= new DbusSignalGroupImpl(g
.groupId());
1018 exportObject(object
);
1019 this.groups
.add(new StructGroup(new DBusPath(object
.getObjectPath()),
1020 g
.groupId().serialize(),
1021 emptyIfNull(g
.title())));
1025 private void unExportGroups() {
1026 this.groups
.stream().map(StructGroup
::getObjectPath
).map(DBusPath
::getPath
).forEach(connection
::unExportObject
);
1027 this.groups
.clear();
1030 private static String
getConfigurationObjectPath(String basePath
) {
1031 return basePath
+ "/Configuration";
1034 private void updateConfiguration() {
1035 unExportConfiguration();
1036 final var object
= new DbusSignalConfigurationImpl();
1037 exportObject(object
);
1040 private void unExportConfiguration() {
1041 final var objectPath
= getConfigurationObjectPath(this.objectPath
);
1042 connection
.unExportObject(objectPath
);
1045 private void exportObject(final DBusInterface object
) {
1047 connection
.exportObject(object
);
1048 logger
.debug("Exported dbus object: " + object
.getObjectPath());
1049 } catch (DBusException e
) {
1050 logger
.warn("Failed to export dbus object (" + object
.getObjectPath() + "): " + e
.getMessage());
1054 private void updateIdentities() {
1055 List
<org
.asamk
.signal
.manager
.api
.Identity
> identities
;
1056 identities
= m
.getIdentities();
1058 unExportIdentities();
1060 identities
.forEach(i
-> {
1061 final var object
= new DbusSignalIdentityImpl(i
);
1062 exportObject(object
);
1063 this.identities
.add(new StructIdentity(new DBusPath(object
.getObjectPath()),
1064 i
.recipient().uuid().map(UUID
::toString
).orElse(""),
1065 i
.recipient().number().orElse("")));
1069 private static String
getIdentityObjectPath(String basePath
, String id
) {
1070 return basePath
+ "/Identities/" + makeValidObjectPathElement(id
);
1073 private void unExportIdentities() {
1074 this.identities
.stream()
1075 .map(StructIdentity
::getObjectPath
)
1076 .map(DBusPath
::getPath
)
1077 .forEach(connection
::unExportObject
);
1078 this.identities
.clear();
1082 public DBusPath
getIdentity(String number
) throws Error
.Failure
{
1083 final var found
= identities
.stream()
1084 .filter(identity
-> identity
.getNumber().equals(number
) || identity
.getUuid().equals(number
))
1087 if (found
.isEmpty()) {
1088 throw new Error
.Failure("Identity for " + number
+ " unknown");
1090 return found
.get().getObjectPath();
1094 public List
<StructIdentity
> listIdentities() {
1096 return this.identities
;
1099 public class DbusSignalIdentityImpl
extends DbusProperties
implements Signal
.Identity
{
1101 private final org
.asamk
.signal
.manager
.api
.Identity identity
;
1103 public DbusSignalIdentityImpl(final org
.asamk
.signal
.manager
.api
.Identity identity
) {
1104 this.identity
= identity
;
1105 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity",
1106 List
.of(new DbusProperty
<>("Number", () -> identity
.recipient().number().orElse("")),
1107 new DbusProperty
<>("Uuid",
1108 () -> identity
.recipient().uuid().map(UUID
::toString
).orElse("")),
1109 new DbusProperty
<>("Fingerprint", identity
::fingerprint
),
1110 new DbusProperty
<>("SafetyNumber", identity
::safetyNumber
),
1111 new DbusProperty
<>("ScannableSafetyNumber", identity
::scannableSafetyNumber
),
1112 new DbusProperty
<>("TrustLevel", identity
::trustLevel
),
1113 new DbusProperty
<>("AddedDate", identity
::dateAddedTimestamp
))));
1117 public String
getObjectPath() {
1118 return getIdentityObjectPath(objectPath
,
1119 identity
.recipient().getLegacyIdentifier() + "_" + identity
.recipient().getIdentifier());
1123 public void trust() throws Error
.Failure
{
1124 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1126 m
.trustIdentityAllKeys(recipient
);
1127 } catch (UnregisteredRecipientException e
) {
1128 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1134 public void trustVerified(String safetyNumber
) throws Error
.Failure
{
1135 var recipient
= RecipientIdentifier
.Single
.fromAddress(identity
.recipient());
1137 if (safetyNumber
== null) {
1138 throw new Error
.Failure("You need to specify a fingerprint/safety number");
1140 final IdentityVerificationCode verificationCode
;
1142 verificationCode
= IdentityVerificationCode
.parse(safetyNumber
);
1143 } catch (Exception e
) {
1144 throw new Error
.Failure(
1145 "Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
1149 final var res
= m
.trustIdentityVerified(recipient
, verificationCode
);
1151 throw new Error
.Failure(
1152 "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct.");
1154 } catch (UnregisteredRecipientException e
) {
1155 throw new Error
.Failure("The user " + e
.getSender().getIdentifier() + " is not registered.");
1161 public class DbusSignalDeviceImpl
extends DbusProperties
implements Signal
.Device
{
1163 private final org
.asamk
.signal
.manager
.api
.Device device
;
1165 public DbusSignalDeviceImpl(final org
.asamk
.signal
.manager
.api
.Device device
) {
1166 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
1167 List
.of(new DbusProperty
<>("Id", device
::id
),
1168 new DbusProperty
<>("Name", () -> emptyIfNull(device
.name()), this::setDeviceName
),
1169 new DbusProperty
<>("Created", device
::created
),
1170 new DbusProperty
<>("LastSeen", device
::lastSeen
))));
1171 this.device
= device
;
1175 public String
getObjectPath() {
1176 return getDeviceObjectPath(objectPath
, device
.id());
1180 public void removeDevice() throws Error
.Failure
{
1182 m
.removeLinkedDevices(device
.id());
1184 } catch (NotPrimaryDeviceException e
) {
1185 throw new Error
.Failure("This command doesn't work on linked devices.");
1186 } catch (IOException e
) {
1187 throw new Error
.Failure(e
.getMessage());
1191 private void setDeviceName(String name
) {
1192 if (!device
.isThisDevice()) {
1193 throw new Error
.Failure("Only the name of this device can be changed");
1196 m
.updateAccountAttributes(name
, null, null, null);
1197 // update device list
1199 } catch (IOException e
) {
1200 throw new Error
.Failure(e
.getMessage());
1205 public class DbusSignalConfigurationImpl
extends DbusProperties
implements Signal
.Configuration
{
1207 public DbusSignalConfigurationImpl() {
1208 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
1209 List
.of(new DbusProperty
<>("ReadReceipts", this::getReadReceipts
, this::setReadReceipts
),
1210 new DbusProperty
<>("UnidentifiedDeliveryIndicators",
1211 this::getUnidentifiedDeliveryIndicators
,
1212 this::setUnidentifiedDeliveryIndicators
),
1213 new DbusProperty
<>("TypingIndicators",
1214 this::getTypingIndicators
,
1215 this::setTypingIndicators
),
1216 new DbusProperty
<>("LinkPreviews", this::getLinkPreviews
, this::setLinkPreviews
))));
1221 public String
getObjectPath() {
1222 return getConfigurationObjectPath(objectPath
);
1225 public void setReadReceipts(Boolean readReceipts
) {
1226 setConfiguration(readReceipts
, null, null, null);
1229 public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators
) {
1230 setConfiguration(null, unidentifiedDeliveryIndicators
, null, null);
1233 public void setTypingIndicators(Boolean typingIndicators
) {
1234 setConfiguration(null, null, typingIndicators
, null);
1237 public void setLinkPreviews(Boolean linkPreviews
) {
1238 setConfiguration(null, null, null, linkPreviews
);
1241 private void setConfiguration(
1242 Boolean readReceipts
,
1243 Boolean unidentifiedDeliveryIndicators
,
1244 Boolean typingIndicators
,
1245 Boolean linkPreviews
1248 m
.updateConfiguration(new org
.asamk
.signal
.manager
.api
.Configuration(Optional
.ofNullable(readReceipts
),
1249 Optional
.ofNullable(unidentifiedDeliveryIndicators
),
1250 Optional
.ofNullable(typingIndicators
),
1251 Optional
.ofNullable(linkPreviews
)));
1252 } catch (NotPrimaryDeviceException e
) {
1253 throw new Error
.Failure("This command doesn't work on linked devices.");
1257 private boolean getReadReceipts() {
1258 return m
.getConfiguration().readReceipts().orElse(false);
1261 private boolean getUnidentifiedDeliveryIndicators() {
1262 return m
.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
1265 private boolean getTypingIndicators() {
1266 return m
.getConfiguration().typingIndicators().orElse(false);
1269 private boolean getLinkPreviews() {
1270 return m
.getConfiguration().linkPreviews().orElse(false);
1274 public class DbusSignalGroupImpl
extends DbusProperties
implements Signal
.Group
{
1276 private final GroupId groupId
;
1278 public DbusSignalGroupImpl(final GroupId groupId
) {
1279 this.groupId
= groupId
;
1280 super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Group",
1281 List
.of(new DbusProperty
<>("Id", groupId
::serialize
),
1282 new DbusProperty
<>("Name", () -> emptyIfNull(getGroup().title()), this::setGroupName
),
1283 new DbusProperty
<>("Description",
1284 () -> emptyIfNull(getGroup().description()),
1285 this::setGroupDescription
),
1286 new DbusProperty
<>("Avatar", this::setGroupAvatar
),
1287 new DbusProperty
<>("IsBlocked", () -> getGroup().isBlocked(), this::setIsBlocked
),
1288 new DbusProperty
<>("IsMember", () -> getGroup().isMember()),
1289 new DbusProperty
<>("IsAdmin", () -> getGroup().isAdmin()),
1290 new DbusProperty
<>("MessageExpirationTimer",
1291 () -> getGroup().messageExpirationTimer(),
1292 this::setMessageExpirationTime
),
1293 new DbusProperty
<>("Members",
1294 () -> new Variant
<>(getRecipientStrings(getGroup().members()), "as")),
1295 new DbusProperty
<>("PendingMembers",
1296 () -> new Variant
<>(getRecipientStrings(getGroup().pendingMembers()), "as")),
1297 new DbusProperty
<>("RequestingMembers",
1298 () -> new Variant
<>(getRecipientStrings(getGroup().requestingMembers()), "as")),
1299 new DbusProperty
<>("Admins",
1300 () -> new Variant
<>(getRecipientStrings(getGroup().adminMembers()), "as")),
1301 new DbusProperty
<>("Banned",
1302 () -> new Variant
<>(getRecipientStrings(getGroup().bannedMembers()), "as")),
1303 new DbusProperty
<>("PermissionAddMember",
1304 () -> getGroup().permissionAddMember().name(),
1305 this::setGroupPermissionAddMember
),
1306 new DbusProperty
<>("PermissionEditDetails",
1307 () -> getGroup().permissionEditDetails().name(),
1308 this::setGroupPermissionEditDetails
),
1309 new DbusProperty
<>("PermissionSendMessage",
1310 () -> getGroup().permissionSendMessage().name(),
1311 this::setGroupPermissionSendMessage
),
1312 new DbusProperty
<>("GroupInviteLink", () -> {
1313 final var groupInviteLinkUrl
= getGroup().groupInviteLinkUrl();
1314 return groupInviteLinkUrl
== null ?
"" : groupInviteLinkUrl
.getUrl();
1319 public String
getObjectPath() {
1320 return getGroupObjectPath(objectPath
, groupId
.serialize());
1324 public void quitGroup() throws Error
.Failure
{
1326 m
.quitGroup(groupId
, Set
.of());
1327 } catch (GroupNotFoundException e
) {
1328 throw new Error
.GroupNotFound(e
.getMessage());
1329 } catch (NotAGroupMemberException e
) {
1330 throw new Error
.NotAGroupMember(e
.getMessage());
1331 } catch (IOException e
) {
1332 throw new Error
.Failure(e
.getMessage());
1333 } catch (LastGroupAdminException e
) {
1334 throw new Error
.LastGroupAdmin(e
.getMessage());
1335 } catch (UnregisteredRecipientException e
) {
1336 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");
1341 public void deleteGroup() throws Error
.Failure
, Error
.LastGroupAdmin
{
1343 m
.deleteGroup(groupId
);
1344 } catch (IOException e
) {
1345 throw new Error
.Failure(e
.getMessage());
1351 public void addMembers(final List
<String
> recipients
) throws Error
.Failure
{
1352 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1353 updateGroup(UpdateGroup
.newBuilder().withMembers(memberIdentifiers
).build());
1357 public void removeMembers(final List
<String
> recipients
) throws Error
.Failure
{
1358 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1359 updateGroup(UpdateGroup
.newBuilder().withRemoveMembers(memberIdentifiers
).build());
1363 public void addAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1364 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1365 updateGroup(UpdateGroup
.newBuilder().withAdmins(memberIdentifiers
).build());
1369 public void removeAdmins(final List
<String
> recipients
) throws Error
.Failure
{
1370 final var memberIdentifiers
= getSingleRecipientIdentifiers(recipients
, m
.getSelfNumber());
1371 updateGroup(UpdateGroup
.newBuilder().withRemoveAdmins(memberIdentifiers
).build());
1375 public void resetLink() throws Error
.Failure
{
1376 updateGroup(UpdateGroup
.newBuilder().withResetGroupLink(true).build());
1380 public void disableLink() throws Error
.Failure
{
1381 updateGroup(UpdateGroup
.newBuilder().withGroupLinkState(GroupLinkState
.DISABLED
).build());
1385 public void enableLink(final boolean requiresApproval
) throws Error
.Failure
{
1386 updateGroup(UpdateGroup
.newBuilder()
1387 .withGroupLinkState(requiresApproval
1388 ? GroupLinkState
.ENABLED_WITH_APPROVAL
1389 : GroupLinkState
.ENABLED
)
1393 private org
.asamk
.signal
.manager
.api
.Group
getGroup() {
1394 return m
.getGroup(groupId
);
1397 private void setGroupName(final String name
) {
1398 updateGroup(UpdateGroup
.newBuilder().withName(name
).build());
1401 private void setGroupDescription(final String description
) {
1402 updateGroup(UpdateGroup
.newBuilder().withDescription(description
).build());
1405 private void setGroupAvatar(final String avatar
) {
1406 updateGroup(UpdateGroup
.newBuilder().withAvatarFile(avatar
).build());
1409 private void setMessageExpirationTime(final int expirationTime
) {
1410 updateGroup(UpdateGroup
.newBuilder().withExpirationTimer(expirationTime
).build());
1413 private void setGroupPermissionAddMember(final String permission
) {
1414 updateGroup(UpdateGroup
.newBuilder().withAddMemberPermission(GroupPermission
.valueOf(permission
)).build());
1417 private void setGroupPermissionEditDetails(final String permission
) {
1418 updateGroup(UpdateGroup
.newBuilder()
1419 .withEditDetailsPermission(GroupPermission
.valueOf(permission
))
1423 private void setGroupPermissionSendMessage(final String permission
) {
1424 updateGroup(UpdateGroup
.newBuilder()
1425 .withIsAnnouncementGroup(GroupPermission
.valueOf(permission
) == GroupPermission
.ONLY_ADMINS
)
1429 private void setIsBlocked(final boolean isBlocked
) {
1431 m
.setGroupsBlocked(List
.of(groupId
), isBlocked
);
1432 } catch (NotPrimaryDeviceException e
) {
1433 throw new Error
.Failure("This command doesn't work on linked devices.");
1434 } catch (GroupNotFoundException e
) {
1435 throw new Error
.GroupNotFound(e
.getMessage());
1436 } catch (IOException e
) {
1437 throw new Error
.Failure(e
.getMessage());
1441 private void updateGroup(final UpdateGroup updateGroup
) {
1443 m
.updateGroup(groupId
, updateGroup
);
1444 } catch (IOException e
) {
1445 throw new Error
.Failure(e
.getMessage());
1446 } catch (GroupNotFoundException
| NotAGroupMemberException
| GroupSendingNotAllowedException e
) {
1447 throw new Error
.GroupNotFound(e
.getMessage());
1448 } catch (AttachmentInvalidException e
) {
1449 throw new Error
.AttachmentInvalid(e
.getMessage());
1450 } catch (UnregisteredRecipientException e
) {
1451 throw new Error
.UntrustedIdentity(e
.getSender().getIdentifier() + " is not registered.");