Enable profile sharing when accepting message request

This commit is contained in:
AsamK 2024-02-18 21:26:36 +01:00
parent 3b3377e6e9
commit 9051f68ba6
2 changed files with 15 additions and 4 deletions

View file

@ -49,6 +49,13 @@ public class ContactHelper {
account.getContactStore().storeContact(recipientId, builder.withIsBlocked(blocked).build());
}
public void setContactProfileSharing(RecipientId recipientId, boolean profileSharing) {
var contact = account.getContactStore().getContact(recipientId);
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
builder.withIsProfileSharingEnabled(profileSharing);
account.getContactStore().storeContact(recipientId, builder.build());
}
public void setContactHidden(RecipientId recipientId, boolean hidden) {
var contact = account.getContactStore().getContact(recipientId);
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);

View file

@ -2,7 +2,7 @@ package org.asamk.signal.manager.helper;
import org.asamk.signal.manager.api.Contact;
import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.MessageEnvelope;
import org.asamk.signal.manager.api.MessageEnvelope.Sync.MessageRequestResponse;
import org.asamk.signal.manager.api.TrustLevel;
import org.asamk.signal.manager.storage.SignalAccount;
import org.asamk.signal.manager.storage.groups.GroupInfoV1;
@ -368,19 +368,23 @@ public class SyncHelper {
}
public SendMessageResult sendMessageRequestResponse(
final MessageEnvelope.Sync.MessageRequestResponse.Type type, final GroupId groupId
final MessageRequestResponse.Type type, final GroupId groupId
) {
final var response = MessageRequestResponseMessage.forGroup(groupId.serialize(), localToRemoteType(type));
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forMessageRequestResponse(response));
}
public SendMessageResult sendMessageRequestResponse(
final MessageEnvelope.Sync.MessageRequestResponse.Type type, final RecipientId recipientId
final MessageRequestResponse.Type type, final RecipientId recipientId
) {
final var address = account.getRecipientAddressResolver().resolveRecipientAddress(recipientId);
if (address.serviceId().isEmpty()) {
return null;
}
context.getContactHelper()
.setContactProfileSharing(recipientId,
type == MessageRequestResponse.Type.ACCEPT
|| type == MessageRequestResponse.Type.UNBLOCK_AND_ACCEPT);
final var response = MessageRequestResponseMessage.forIndividual(address.serviceId().get(),
localToRemoteType(type));
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forMessageRequestResponse(response));
@ -411,7 +415,7 @@ public class SyncHelper {
}
}
private MessageRequestResponseMessage.Type localToRemoteType(final MessageEnvelope.Sync.MessageRequestResponse.Type type) {
private MessageRequestResponseMessage.Type localToRemoteType(final MessageRequestResponse.Type type) {
return switch (type) {
case UNKNOWN -> MessageRequestResponseMessage.Type.UNKNOWN;
case ACCEPT -> MessageRequestResponseMessage.Type.ACCEPT;