Compare commits

..

1 Commits

31 changed files with 148 additions and 172 deletions

View File

@ -1,7 +1,9 @@
package org.asamk.signal.manager.api; package org.asamk.signal.manager.api;
public record CallOffer( public record CallOffer(
long callId, Type type, byte[] opaque long callId,
Type type,
byte[] opaque
) { ) {
public enum Type { public enum Type {

View File

@ -1,9 +1,3 @@
package org.asamk.signal.manager.api; package org.asamk.signal.manager.api;
public record ReceiveConfig( public record ReceiveConfig(boolean ignoreAttachments, boolean ignoreStories, boolean ignoreAvatars, boolean ignoreStickers, boolean sendReadReceipts) {}
boolean ignoreAttachments,
boolean ignoreStories,
boolean ignoreAvatars,
boolean ignoreStickers,
boolean sendReadReceipts
) {}

View File

@ -3,5 +3,8 @@ package org.asamk.signal.manager.api;
import java.util.List; import java.util.List;
public record TurnServer( public record TurnServer(
String username, String password, List<String> urls String username,
) {} String password,
List<String> urls
) {
}

View File

@ -726,7 +726,7 @@ public class GroupHelper {
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
} }
final var newMembers = new HashSet<>(members); final var newMembers = new HashSet<>(members);
newMembers.removeAll(group.getMemberRecipientIds()); newMembers.removeAll(group.getMembers());
newMembers.removeAll(group.getRequestingMembers()); newMembers.removeAll(group.getRequestingMembers());
if (!newMembers.isEmpty()) { if (!newMembers.isEmpty()) {
var groupGroupChangePair = groupV2Helper.addMembers(group, newMembers); var groupGroupChangePair = groupV2Helper.addMembers(group, newMembers);
@ -768,8 +768,12 @@ public class GroupHelper {
newAdmins.retainAll(group.getMemberRecipientIds()); newAdmins.retainAll(group.getMemberRecipientIds());
newAdmins.removeAll(group.getAdminMemberRecipientIds()); newAdmins.removeAll(group.getAdminMemberRecipientIds());
if (!newAdmins.isEmpty()) { if (!newAdmins.isEmpty()) {
var groupGroupChangePair = groupV2Helper.setMemberAdmin(group, newAdmins, true); for (var admin : newAdmins) {
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); var groupGroupChangePair = groupV2Helper.setMemberAdmin(group, admin, true);
result = sendUpdateGroupV2Message(group,
groupGroupChangePair.first(),
groupGroupChangePair.second());
}
} }
} }
@ -777,8 +781,12 @@ public class GroupHelper {
final var existingRemoveAdmins = new HashSet<>(removeAdmins); final var existingRemoveAdmins = new HashSet<>(removeAdmins);
existingRemoveAdmins.retainAll(group.getAdminMemberRecipientIds()); existingRemoveAdmins.retainAll(group.getAdminMemberRecipientIds());
if (!existingRemoveAdmins.isEmpty()) { if (!existingRemoveAdmins.isEmpty()) {
var groupGroupChangePair = groupV2Helper.setMemberAdmin(group, existingRemoveAdmins, false); for (var admin : existingRemoveAdmins) {
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); var groupGroupChangePair = groupV2Helper.setMemberAdmin(group, admin, false);
result = sendUpdateGroupV2Message(group,
groupGroupChangePair.first(),
groupGroupChangePair.second());
}
} }
} }

View File

@ -501,25 +501,18 @@ class GroupV2Helper {
Pair<DecryptedGroup, GroupChangeResponse> setMemberAdmin( Pair<DecryptedGroup, GroupChangeResponse> setMemberAdmin(
GroupInfoV2 groupInfoV2, GroupInfoV2 groupInfoV2,
Set<RecipientId> recipientIds, RecipientId recipientId,
boolean admin boolean admin
) throws IOException { ) throws IOException {
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2); final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
final var address = context.getRecipientHelper().resolveSignalServiceAddress(recipientId);
final var newRole = admin ? Member.Role.ADMINISTRATOR : Member.Role.DEFAULT; final var newRole = admin ? Member.Role.ADMINISTRATOR : Member.Role.DEFAULT;
final var change = new GroupChange.Actions.Builder(); if (address.getServiceId() instanceof ACI aci) {
final var memberRoles = recipientIds.stream() final var change = groupOperations.createChangeMemberRole(aci, newRole);
.map(context.getRecipientHelper()::resolveSignalServiceAddress) return commitChange(groupInfoV2, change);
.map(SignalServiceAddress::getServiceId) } else {
.filter(m -> m instanceof ACI)
.map(m -> (ACI) m)
.map(aci -> new GroupChange.Actions.ModifyMemberRoleAction.Builder().userId(groupOperations.encryptServiceId(
aci)).role(newRole).build())
.toList();
if (memberRoles.size() < recipientIds.size()) {
throw new IllegalArgumentException("Can't make a PNI a group admin."); throw new IllegalArgumentException("Can't make a PNI a group admin.");
} }
change.modifyMemberRoles(memberRoles);
return commitChange(groupInfoV2, change);
} }
Pair<DecryptedGroup, GroupChangeResponse> setMessageExpirationTimer( Pair<DecryptedGroup, GroupChangeResponse> setMessageExpirationTimer(

View File

@ -192,10 +192,8 @@ public final class ProfileHelper {
final var streamDetails = avatar != null && avatar.isPresent() final var streamDetails = avatar != null && avatar.isPresent()
? Utils.createStreamDetails(avatar.get()) ? Utils.createStreamDetails(avatar.get())
.first() .first()
: forceUploadAvatar && avatar == null : forceUploadAvatar && avatar == null ? context.getAvatarStore()
? context.getAvatarStore() .retrieveProfileAvatar(account.getSelfRecipientAddress()) : null;
.retrieveProfileAvatar(account.getSelfRecipientAddress())
: null;
try (streamDetails) { try (streamDetails) {
final var avatarUploadParams = streamDetails != null final var avatarUploadParams = streamDetails != null
? AvatarUploadParams.forAvatar(streamDetails) ? AvatarUploadParams.forAvatar(streamDetails)

View File

@ -152,7 +152,6 @@ public class GroupStore {
statement.setBytes(2, groupId.serialize()); statement.setBytes(2, groupId.serialize());
final var result = Utils.executeQueryForOptional(statement, Utils::getIdMapper); final var result = Utils.executeQueryForOptional(statement, Utils::getIdMapper);
if (result.isEmpty()) { if (result.isEmpty()) {
connection.commit();
return; return;
} }
internalId = result.get(); internalId = result.get();

View File

@ -28,7 +28,6 @@ import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -51,7 +50,7 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
private final Map<Long, Long> recipientsMerged = new HashMap<>(); private final Map<Long, Long> recipientsMerged = new HashMap<>();
private final Map<ServiceId, RecipientWithAddress> recipientAddressCache = Collections.synchronizedMap(new HashMap<>()); private final Map<ServiceId, RecipientWithAddress> recipientAddressCache = new HashMap<>();
public static void createSql(Connection connection) throws SQLException { public static void createSql(Connection connection) throws SQLException {
// When modifying the CREATE statement here, also add a migration in AccountDatabase.java // When modifying the CREATE statement here, also add a migration in AccountDatabase.java
@ -185,12 +184,12 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
@Override @Override
public RecipientId resolveRecipient(final ServiceId serviceId) { public RecipientId resolveRecipient(final ServiceId serviceId) {
try (final var connection = database.getConnection()) {
connection.setAutoCommit(false);
final var recipientWithAddress = recipientAddressCache.get(serviceId); final var recipientWithAddress = recipientAddressCache.get(serviceId);
if (recipientWithAddress != null) { if (recipientWithAddress != null) {
return recipientWithAddress.id(); return recipientWithAddress.id();
} }
try (final var connection = database.getConnection()) {
connection.setAutoCommit(false);
final var recipientId = resolveRecipientLocked(connection, serviceId); final var recipientId = resolveRecipientLocked(connection, serviceId);
connection.commit(); connection.commit();
return recipientId; return recipientId;

View File

@ -303,7 +303,6 @@ public class MessageSendLogStore implements AutoCloseable {
} }
if (contentId == -1) { if (contentId == -1) {
logger.warn("Failed to insert message send log content"); logger.warn("Failed to insert message send log content");
connection.commit();
return -1; return -1;
} }
insertRecipientsForExistingContent(contentId, recipientDevices, connection); insertRecipientsForExistingContent(contentId, recipientDevices, connection);

View File

@ -194,9 +194,8 @@ public class SessionStore implements SignalServiceSessionStore {
if (session != null) { if (session != null) {
session.archiveCurrentState(); session.archiveCurrentState();
storeSession(connection, key, session); storeSession(connection, key, session);
}
connection.commit(); connection.commit();
}
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException("Failed update session store", e); throw new RuntimeException("Failed update session store", e);
} }

View File

@ -78,10 +78,8 @@ public class StickerUtils {
throw new StickerPackInvalidException("Could not find find " + pack.cover().file()); throw new StickerPackInvalidException("Could not find find " + pack.cover().file());
} }
var contentType = pack.cover().contentType() != null && !pack.cover().contentType().isEmpty() var contentType = pack.cover().contentType() != null && !pack.cover().contentType().isEmpty() ? pack.cover()
? pack.cover() .contentType() : getContentType(rootPath, zip, pack.cover().file());
.contentType()
: getContentType(rootPath, zip, pack.cover().file());
cover = new SignalServiceStickerManifestUpload.StickerInfo(data.first(), cover = new SignalServiceStickerManifestUpload.StickerInfo(data.first(),
data.second(), data.second(),
Optional.ofNullable(pack.cover().emoji()).orElse(""), Optional.ofNullable(pack.cover().emoji()).orElse(""),

View File

@ -23,7 +23,10 @@ public class AcceptCallCommand implements JsonRpcLocalCommand {
@Override @Override
public void attachToSubparser(final Subparser subparser) { public void attachToSubparser(final Subparser subparser) {
subparser.help("Accept an incoming voice call."); subparser.help("Accept an incoming voice call.");
subparser.addArgument("--call-id").type(long.class).required(true).help("The call ID to accept."); subparser.addArgument("--call-id")
.type(long.class)
.required(true)
.help("The call ID to accept.");
} }
@Override @Override

View File

@ -21,7 +21,10 @@ public class HangupCallCommand implements JsonRpcLocalCommand {
@Override @Override
public void attachToSubparser(final Subparser subparser) { public void attachToSubparser(final Subparser subparser) {
subparser.help("Hang up an active voice call."); subparser.help("Hang up an active voice call.");
subparser.addArgument("--call-id").type(long.class).required(true).help("The call ID to hang up."); subparser.addArgument("--call-id")
.type(long.class)
.required(true)
.help("The call ID to hang up.");
} }
@Override @Override

View File

@ -5,10 +5,13 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.CallInfo;
import org.asamk.signal.output.JsonWriter; import org.asamk.signal.output.JsonWriter;
import org.asamk.signal.output.OutputWriter; import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.output.PlainTextWriter; import org.asamk.signal.output.PlainTextWriter;
import java.util.List;
public class ListCallsCommand implements JsonRpcLocalCommand { public class ListCallsCommand implements JsonRpcLocalCommand {
@Override @Override

View File

@ -21,7 +21,10 @@ public class RejectCallCommand implements JsonRpcLocalCommand {
@Override @Override
public void attachToSubparser(final Subparser subparser) { public void attachToSubparser(final Subparser subparser) {
subparser.help("Reject an incoming voice call."); subparser.help("Reject an incoming voice call.");
subparser.addArgument("--call-id").type(long.class).required(true).help("The call ID to reject."); subparser.addArgument("--call-id")
.type(long.class)
.required(true)
.help("The call ID to reject.");
} }
@Override @Override

View File

@ -82,11 +82,7 @@ public class SendPollCreateCommand implements JsonRpcLocalCommand {
throw new UserErrorException("Poll options must not be empty"); throw new UserErrorException("Poll options must not be empty");
} }
if (option.length() > MAX_POLL_OPTION_LENGTH) { if (option.length() > MAX_POLL_OPTION_LENGTH) {
throw new UserErrorException("Poll option \"" throw new UserErrorException("Poll option \"" + option + "\" exceeds the maximum length of " + MAX_POLL_OPTION_LENGTH + " characters");
+ option
+ "\" exceeds the maximum length of "
+ MAX_POLL_OPTION_LENGTH
+ " characters");
} }
} }

View File

@ -18,13 +18,15 @@ public record JsonCallEvent(
) { ) {
public static JsonCallEvent from(CallInfo callInfo, String reason) { public static JsonCallEvent from(CallInfo callInfo, String reason) {
return new JsonCallEvent(callInfo.callId(), return new JsonCallEvent(
callInfo.callId(),
callInfo.state().name(), callInfo.state().name(),
callInfo.recipient().number().orElse(null), callInfo.recipient().number().orElse(null),
callInfo.recipient().aci().orElse(null), callInfo.recipient().aci().orElse(null),
callInfo.isOutgoing(), callInfo.isOutgoing(),
callInfo.inputDeviceName(), callInfo.inputDeviceName(),
callInfo.outputDeviceName(), callInfo.outputDeviceName(),
reason); reason
);
} }
} }

View File

@ -2,8 +2,11 @@ package org.asamk.signal.json;
import org.asamk.signal.manager.api.CallInfo; import org.asamk.signal.manager.api.CallInfo;
import org.asamk.signal.manager.api.RecipientAddress; import org.asamk.signal.manager.api.RecipientAddress;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -14,12 +17,7 @@ class JsonCallEventTest {
@Test @Test
void fromWithNumberAndUuid() { void fromWithNumberAndUuid() {
var recipient = new RecipientAddress("a1b2c3d4-e5f6-7890-abcd-ef1234567890", null, "+15551234567", null); var recipient = new RecipientAddress("a1b2c3d4-e5f6-7890-abcd-ef1234567890", null, "+15551234567", null);
var callInfo = new CallInfo(123L, var callInfo = new CallInfo(123L, CallInfo.State.CONNECTED, recipient, "signal_input_123", "signal_output_123", true);
CallInfo.State.CONNECTED,
recipient,
"signal_input_123",
"signal_output_123",
true);
var event = JsonCallEvent.from(callInfo, null); var event = JsonCallEvent.from(callInfo, null);
@ -36,12 +34,7 @@ class JsonCallEventTest {
@Test @Test
void fromWithUuidOnly() { void fromWithUuidOnly() {
var recipient = new RecipientAddress("a1b2c3d4-e5f6-7890-abcd-ef1234567890", null, null, null); var recipient = new RecipientAddress("a1b2c3d4-e5f6-7890-abcd-ef1234567890", null, null, null);
var callInfo = new CallInfo(456L, var callInfo = new CallInfo(456L, CallInfo.State.RINGING_INCOMING, recipient, "signal_input_456", "signal_output_456", false);
CallInfo.State.RINGING_INCOMING,
recipient,
"signal_input_456",
"signal_output_456",
false);
var event = JsonCallEvent.from(callInfo, null); var event = JsonCallEvent.from(callInfo, null);
@ -55,12 +48,7 @@ class JsonCallEventTest {
@Test @Test
void fromWithNumberOnly() { void fromWithNumberOnly() {
var recipient = new RecipientAddress(null, null, "+15559876543", null); var recipient = new RecipientAddress(null, null, "+15559876543", null);
var callInfo = new CallInfo(789L, var callInfo = new CallInfo(789L, CallInfo.State.RINGING_OUTGOING, recipient, "signal_input_789", "signal_output_789", true);
CallInfo.State.RINGING_OUTGOING,
recipient,
"signal_input_789",
"signal_output_789",
true);
var event = JsonCallEvent.from(callInfo, null); var event = JsonCallEvent.from(callInfo, null);
@ -93,12 +81,7 @@ class JsonCallEventTest {
@Test @Test
void fromConnectingState() { void fromConnectingState() {
var recipient = new RecipientAddress("uuid-5678", null, "+15552222222", null); var recipient = new RecipientAddress("uuid-5678", null, "+15552222222", null);
var callInfo = new CallInfo(200L, var callInfo = new CallInfo(200L, CallInfo.State.CONNECTING, recipient, "signal_input_200", "signal_output_200", true);
CallInfo.State.CONNECTING,
recipient,
"signal_input_200",
"signal_output_200",
true);
var event = JsonCallEvent.from(callInfo, null); var event = JsonCallEvent.from(callInfo, null);
@ -114,17 +97,8 @@ class JsonCallEventTest {
void fromWithVariousEndReasons() { void fromWithVariousEndReasons() {
var recipient = new RecipientAddress("uuid-1234", null, "+15551111111", null); var recipient = new RecipientAddress("uuid-1234", null, "+15551111111", null);
var reasons = new String[]{ var reasons = new String[]{"local_hangup", "remote_hangup", "rejected", "remote_busy",
"local_hangup", "ring_timeout", "ice_failed", "tunnel_exit", "tunnel_error", "shutdown"};
"remote_hangup",
"rejected",
"remote_busy",
"ring_timeout",
"ice_failed",
"tunnel_exit",
"tunnel_error",
"shutdown"
};
for (var reason : reasons) { for (var reason : reasons) {
var callInfo = new CallInfo(1L, CallInfo.State.ENDED, recipient, null, null, false); var callInfo = new CallInfo(1L, CallInfo.State.ENDED, recipient, null, null, false);