mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 20:40:38 +00:00
Add dbus methods: deleteContact and deleteRecipient
This commit is contained in:
parent
7e7e4150e1
commit
b32580c5af
6 changed files with 49 additions and 5 deletions
|
@ -194,6 +194,9 @@ public final class ProfileHelper {
|
|||
}
|
||||
|
||||
profile = decryptProfileIfKeyKnown(recipientId, encryptedProfile);
|
||||
if (profile.getGivenName() == null && profile.getFamilyName() == null) {
|
||||
return profile;
|
||||
}
|
||||
account.getProfileStore().storeProfile(recipientId, profile);
|
||||
|
||||
return profile;
|
||||
|
|
|
@ -261,7 +261,12 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
public void storeProfile(final RecipientId recipientId, final Profile profile) {
|
||||
synchronized (recipients) {
|
||||
final var recipient = recipients.get(recipientId);
|
||||
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withProfile(profile).build());
|
||||
if (recipient != null) {
|
||||
storeRecipientLocked(recipientId, Recipient.newBuilder(recipient).withProfile(profile).build());
|
||||
} else {
|
||||
storeRecipientLocked(recipientId,
|
||||
Recipient.newBuilder().withRecipientId(recipientId).withProfile(profile).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,6 +464,10 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
final var base64 = Base64.getEncoder();
|
||||
var storage = new Storage(recipients.entrySet().stream().map(pair -> {
|
||||
final var recipient = pair.getValue();
|
||||
final var number = recipient.getAddress() == null ? null : recipient.getAddress().getNumber().orElse(null);
|
||||
final var uuid = recipient.getAddress() == null
|
||||
? null
|
||||
: recipient.getAddress().getUuid().map(UUID::toString).orElse(null);
|
||||
final var contact = recipient.getContact() == null
|
||||
? null
|
||||
: new Storage.Recipient.Contact(recipient.getContact().getName(),
|
||||
|
@ -481,8 +490,8 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
|
|||
.map(Enum::name)
|
||||
.collect(Collectors.toSet()));
|
||||
return new Storage.Recipient(pair.getKey().id(),
|
||||
recipient.getAddress().getNumber().orElse(null),
|
||||
recipient.getAddress().getUuid().map(UUID::toString).orElse(null),
|
||||
number,
|
||||
uuid,
|
||||
recipient.getProfileKey() == null
|
||||
? null
|
||||
: base64.encodeToString(recipient.getProfileKey().serialize()),
|
||||
|
|
|
@ -519,6 +519,16 @@ setContactName(number<s>,name<>) -> <>::
|
|||
|
||||
Exceptions: InvalidNumber, Failure
|
||||
|
||||
deleteContact(number<s>) -> <>::
|
||||
* number : Phone number
|
||||
|
||||
Exceptions: Failure
|
||||
|
||||
deleteRecipient(number<s>) -> <>::
|
||||
* number : Phone number
|
||||
|
||||
Exceptions: Failure
|
||||
|
||||
setExpirationTimer(number<s>, expiration<i>) -> <>::
|
||||
* number : Phone number of recipient
|
||||
* expiration : int32 for the number of seconds before messages to this recipient disappear. Set to 0 to disable expiration.
|
||||
|
|
|
@ -76,6 +76,10 @@ public interface Signal extends DBusInterface {
|
|||
|
||||
void sendEndSessionMessage(List<String> recipients) throws Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
|
||||
|
||||
void deleteRecipient(final String recipient) throws Error.Failure;
|
||||
|
||||
void deleteContact(final String recipient) throws Error.Failure;
|
||||
|
||||
long sendGroupMessage(
|
||||
String message, List<String> attachments, byte[] groupId
|
||||
) throws Error.GroupNotFound, Error.Failure, Error.AttachmentInvalid, Error.InvalidGroupId;
|
||||
|
|
|
@ -383,12 +383,12 @@ public class DbusManagerImpl implements Manager {
|
|||
|
||||
@Override
|
||||
public void deleteRecipient(final RecipientIdentifier.Single recipient) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
signal.deleteRecipient(recipient.getIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContact(final RecipientIdentifier.Single recipient) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
signal.deleteContact(recipient.getIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -387,6 +387,24 @@ public class DbusSignalImpl implements Signal {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecipient(final String recipient) throws Error.Failure {
|
||||
try {
|
||||
m.deleteRecipient(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("Recipient not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContact(final String recipient) throws Error.Failure {
|
||||
try {
|
||||
m.deleteContact(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("Contact not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue