mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Fix inspections
This commit is contained in:
parent
d51dd7ae57
commit
fc2e9bbfae
27 changed files with 158 additions and 158 deletions
|
@ -92,7 +92,7 @@ public interface Manager extends Closeable {
|
|||
|
||||
Configuration getConfiguration();
|
||||
|
||||
void updateConfiguration(Configuration configuration) throws IOException, NotPrimaryDeviceException;
|
||||
void updateConfiguration(Configuration configuration) throws NotPrimaryDeviceException;
|
||||
|
||||
/**
|
||||
* Update the user's profile.
|
||||
|
@ -160,11 +160,11 @@ public interface Manager extends Closeable {
|
|||
|
||||
SendMessageResults sendReadReceipt(
|
||||
RecipientIdentifier.Single sender, List<Long> messageIds
|
||||
) throws IOException;
|
||||
);
|
||||
|
||||
SendMessageResults sendViewedReceipt(
|
||||
RecipientIdentifier.Single sender, List<Long> messageIds
|
||||
) throws IOException;
|
||||
);
|
||||
|
||||
SendMessageResults sendMessage(
|
||||
Message message, Set<RecipientIdentifier> recipients
|
||||
|
@ -199,7 +199,7 @@ public interface Manager extends Closeable {
|
|||
|
||||
void setContactName(
|
||||
RecipientIdentifier.Single recipient, String givenName, final String familyName
|
||||
) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
|
||||
) throws NotPrimaryDeviceException, UnregisteredRecipientException;
|
||||
|
||||
void setContactsBlocked(
|
||||
Collection<RecipientIdentifier.Single> recipient, boolean blocked
|
||||
|
@ -299,7 +299,7 @@ public interface Manager extends Closeable {
|
|||
InputStream retrieveAttachment(final String id) throws IOException;
|
||||
|
||||
@Override
|
||||
void close() throws IOException;
|
||||
void close();
|
||||
|
||||
interface ReceiveMessageHandler {
|
||||
|
||||
|
|
|
@ -4,5 +4,5 @@ import org.asamk.signal.manager.api.TrustNewIdentity;
|
|||
|
||||
public record Settings(TrustNewIdentity trustNewIdentity, boolean disableMessageSendLog) {
|
||||
|
||||
public static Settings DEFAULT = new Settings(TrustNewIdentity.ON_FIRST_USE, false);
|
||||
public static final Settings DEFAULT = new Settings(TrustNewIdentity.ON_FIRST_USE, false);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,9 @@ public class SendRetryMessageRequestAction implements HandleAction {
|
|||
envelopeType = messageContent.getType();
|
||||
} else {
|
||||
originalContent = envelope.getContent();
|
||||
envelopeType = envelopeTypeToCiphertextMessageType(envelope.getType());
|
||||
envelopeType = envelope.getType() == null
|
||||
? CiphertextMessage.WHISPER_TYPE
|
||||
: envelopeTypeToCiphertextMessageType(envelope.getType());
|
||||
}
|
||||
|
||||
DecryptionErrorMessage decryptionErrorMessage = DecryptionErrorMessage.forOriginalMessage(originalContent,
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMes
|
|||
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
@ -234,7 +235,7 @@ public record MessageEnvelope(
|
|||
return new Quote(quote.getId(),
|
||||
addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(quote.getAuthor()))
|
||||
.toApiRecipientAddress(),
|
||||
Optional.ofNullable(quote.getText()),
|
||||
Optional.of(quote.getText()),
|
||||
quote.getMentions() == null
|
||||
? List.of()
|
||||
: quote.getMentions()
|
||||
|
@ -291,9 +292,9 @@ public record MessageEnvelope(
|
|||
boolean isBorderless
|
||||
) {
|
||||
|
||||
static Attachment from(SignalServiceAttachment attachment, AttachmentFileProvider fileProvider) {
|
||||
if (attachment.isPointer()) {
|
||||
final var a = attachment.asPointer();
|
||||
static Attachment from(SignalServiceAttachment signalAttachment, AttachmentFileProvider fileProvider) {
|
||||
if (signalAttachment.isPointer()) {
|
||||
final var a = signalAttachment.asPointer();
|
||||
final var attachmentFile = fileProvider.getFile(a);
|
||||
return new Attachment(Optional.of(attachmentFile.getName()),
|
||||
Optional.of(attachmentFile),
|
||||
|
@ -310,21 +311,26 @@ public record MessageEnvelope(
|
|||
a.isGif(),
|
||||
a.isBorderless());
|
||||
} else {
|
||||
final var a = attachment.asStream();
|
||||
return new Attachment(Optional.empty(),
|
||||
Optional.empty(),
|
||||
a.getFileName(),
|
||||
a.getContentType(),
|
||||
a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
|
||||
Optional.of(a.getLength()),
|
||||
a.getPreview(),
|
||||
Optional.empty(),
|
||||
a.getCaption(),
|
||||
a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
|
||||
a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
|
||||
a.getVoiceNote(),
|
||||
a.isGif(),
|
||||
a.isBorderless());
|
||||
Attachment attachment = null;
|
||||
try (final var a = signalAttachment.asStream()) {
|
||||
attachment = new Attachment(Optional.empty(),
|
||||
Optional.empty(),
|
||||
a.getFileName(),
|
||||
a.getContentType(),
|
||||
a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
|
||||
Optional.of(a.getLength()),
|
||||
a.getPreview(),
|
||||
Optional.empty(),
|
||||
a.getCaption(),
|
||||
a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
|
||||
a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
|
||||
a.getVoiceNote(),
|
||||
a.isGif(),
|
||||
a.isBorderless());
|
||||
return attachment;
|
||||
} catch (IOException e) {
|
||||
return attachment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -822,8 +822,8 @@ public class GroupHelper {
|
|||
if (avatarFile == null) {
|
||||
return null;
|
||||
}
|
||||
try (final var avatar = Utils.createStreamDetails(avatarFile).first().getStream()) {
|
||||
return IOUtils.readFully(avatar);
|
||||
try (final var avatar = Utils.createStreamDetails(avatarFile).first()) {
|
||||
return IOUtils.readFully(avatar.getStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
|
@ -112,12 +111,8 @@ public class IdentityHelper {
|
|||
}
|
||||
|
||||
account.getIdentityKeyStore().setIdentityTrustLevel(serviceId, identity.getIdentityKey(), trustLevel);
|
||||
try {
|
||||
context.getSyncHelper()
|
||||
.sendVerifiedMessage(address.toSignalServiceAddress(), identity.getIdentityKey(), trustLevel);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to send verification sync message: {}", e.getMessage());
|
||||
}
|
||||
context.getSyncHelper()
|
||||
.sendVerifiedMessage(address.toSignalServiceAddress(), identity.getIdentityKey(), trustLevel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -212,10 +212,11 @@ public final class ProfileHelper {
|
|||
|
||||
if (avatar != null) {
|
||||
if (avatar.isPresent()) {
|
||||
final var streamDetails = Utils.createStreamDetails(avatar.get()).first();
|
||||
context.getAvatarStore()
|
||||
.storeProfileAvatar(account.getSelfRecipientAddress(),
|
||||
outputStream -> IOUtils.copyStream(streamDetails.getStream(), outputStream));
|
||||
try (final var streamDetails = Utils.createStreamDetails(avatar.get()).first()) {
|
||||
context.getAvatarStore()
|
||||
.storeProfileAvatar(account.getSelfRecipientAddress(),
|
||||
outputStream -> IOUtils.copyStream(streamDetails.getStream(), outputStream));
|
||||
}
|
||||
} else {
|
||||
context.getAvatarStore().deleteProfileAvatar(account.getSelfRecipientAddress());
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.asamk.signal.manager.util.MimeUtils;
|
|||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
|
||||
|
@ -73,8 +74,8 @@ public class SyncHelper {
|
|||
requestSyncData(SyncMessage.Request.Type.PNI_IDENTITY);
|
||||
}
|
||||
|
||||
public void sendSyncFetchProfileMessage() {
|
||||
context.getSendHelper()
|
||||
public SendMessageResult sendSyncFetchProfileMessage() {
|
||||
return context.getSendHelper()
|
||||
.sendSyncMessage(SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.LOCAL_PROFILE));
|
||||
}
|
||||
|
||||
|
@ -193,7 +194,7 @@ public class SyncHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void sendBlockedList() {
|
||||
public SendMessageResult sendBlockedList() {
|
||||
var addresses = new ArrayList<SignalServiceAddress>();
|
||||
for (var record : account.getContactStore().getContacts()) {
|
||||
if (record.second().isBlocked()) {
|
||||
|
@ -206,30 +207,33 @@ public class SyncHelper {
|
|||
groupIds.add(record.getGroupId().serialize());
|
||||
}
|
||||
}
|
||||
context.getSendHelper()
|
||||
return context.getSendHelper()
|
||||
.sendSyncMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(addresses, groupIds)));
|
||||
}
|
||||
|
||||
public void sendVerifiedMessage(
|
||||
public SendMessageResult sendVerifiedMessage(
|
||||
SignalServiceAddress destination, IdentityKey identityKey, TrustLevel trustLevel
|
||||
) throws IOException {
|
||||
) {
|
||||
var verifiedMessage = new VerifiedMessage(destination,
|
||||
identityKey,
|
||||
trustLevel.toVerifiedState(),
|
||||
System.currentTimeMillis());
|
||||
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
|
||||
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
|
||||
}
|
||||
|
||||
public void sendKeysMessage() {
|
||||
public SendMessageResult sendKeysMessage() {
|
||||
var keysMessage = new KeysMessage(Optional.ofNullable(account.getStorageKey()));
|
||||
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forKeys(keysMessage));
|
||||
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forKeys(keysMessage));
|
||||
}
|
||||
|
||||
public void sendStickerOperationsMessage(List<StickerPack> installStickers, List<StickerPack> removeStickers) {
|
||||
public SendMessageResult sendStickerOperationsMessage(
|
||||
List<StickerPack> installStickers, List<StickerPack> removeStickers
|
||||
) {
|
||||
var installStickerMessages = installStickers.stream().map(s -> getStickerPackOperationMessage(s, true));
|
||||
var removeStickerMessages = removeStickers.stream().map(s -> getStickerPackOperationMessage(s, false));
|
||||
var stickerMessages = Stream.concat(installStickerMessages, removeStickerMessages).toList();
|
||||
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forStickerPackOperations(stickerMessages));
|
||||
return context.getSendHelper()
|
||||
.sendSyncMessage(SignalServiceSyncMessage.forStickerPackOperations(stickerMessages));
|
||||
}
|
||||
|
||||
private static StickerPackOperationMessage getStickerPackOperationMessage(
|
||||
|
@ -240,13 +244,13 @@ public class SyncHelper {
|
|||
installed ? StickerPackOperationMessage.Type.INSTALL : StickerPackOperationMessage.Type.REMOVE);
|
||||
}
|
||||
|
||||
public void sendConfigurationMessage() {
|
||||
public SendMessageResult sendConfigurationMessage() {
|
||||
final var config = account.getConfigurationStore();
|
||||
var configurationMessage = new ConfigurationMessage(Optional.ofNullable(config.getReadReceipts()),
|
||||
Optional.ofNullable(config.getUnidentifiedDeliveryIndicators()),
|
||||
Optional.ofNullable(config.getTypingIndicators()),
|
||||
Optional.ofNullable(config.getLinkPreviews()));
|
||||
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forConfiguration(configurationMessage));
|
||||
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forConfiguration(configurationMessage));
|
||||
}
|
||||
|
||||
public void handleSyncDeviceGroups(final InputStream input) {
|
||||
|
@ -344,10 +348,10 @@ public class SyncHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void requestSyncData(final SyncMessage.Request.Type type) {
|
||||
private SendMessageResult requestSyncData(final SyncMessage.Request.Type type) {
|
||||
var r = new SyncMessage.Request.Builder().type(type).build();
|
||||
var message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
|
||||
context.getSendHelper().sendSyncMessage(message);
|
||||
return context.getSendHelper().sendSyncMessage(message);
|
||||
}
|
||||
|
||||
private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(RecipientAddress address) throws IOException {
|
||||
|
|
|
@ -125,11 +125,7 @@ public class MultiAccountManagerImpl implements MultiAccountManager {
|
|||
public void close() {
|
||||
synchronized (managers) {
|
||||
for (var m : new ArrayList<>(managers)) {
|
||||
try {
|
||||
m.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("Cleanup failed", e);
|
||||
}
|
||||
m.close();
|
||||
}
|
||||
managers.clear();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public abstract class Database implements AutoCloseable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
public void close() {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -1610,11 +1610,7 @@ public class SignalAccount implements Closeable {
|
|||
public void close() {
|
||||
synchronized (fileChannel) {
|
||||
if (accountDatabase != null) {
|
||||
try {
|
||||
accountDatabase.close();
|
||||
} catch (SQLException e) {
|
||||
logger.warn("Failed to close account database: {}", e.getMessage(), e);
|
||||
}
|
||||
accountDatabase.close();
|
||||
}
|
||||
if (messageSendLogStore != null) {
|
||||
messageSendLogStore.close();
|
||||
|
|
|
@ -252,18 +252,14 @@ public class AccountsStore {
|
|||
}
|
||||
|
||||
private void saveAccountsLocked(FileChannel fileChannel, AccountsStorage accountsStorage) throws IOException {
|
||||
try {
|
||||
try (var output = new ByteArrayOutputStream()) {
|
||||
// Write to memory first to prevent corrupting the file in case of serialization errors
|
||||
objectMapper.writeValue(output, accountsStorage);
|
||||
var input = new ByteArrayInputStream(output.toByteArray());
|
||||
fileChannel.position(0);
|
||||
input.transferTo(Channels.newOutputStream(fileChannel));
|
||||
fileChannel.truncate(fileChannel.position());
|
||||
fileChannel.force(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error saving accounts file: {}", e.getMessage(), e);
|
||||
try (var output = new ByteArrayOutputStream()) {
|
||||
// Write to memory first to prevent corrupting the file in case of serialization errors
|
||||
objectMapper.writeValue(output, accountsStorage);
|
||||
var input = new ByteArrayInputStream(output.toByteArray());
|
||||
fileChannel.position(0);
|
||||
input.transferTo(Channels.newOutputStream(fileChannel));
|
||||
fileChannel.truncate(fileChannel.position());
|
||||
fileChannel.force(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ import java.util.Date;
|
|||
public class LegacyIdentityInfo {
|
||||
|
||||
RecipientAddress address;
|
||||
IdentityKey identityKey;
|
||||
TrustLevel trustLevel;
|
||||
Date added;
|
||||
final IdentityKey identityKey;
|
||||
final TrustLevel trustLevel;
|
||||
final Date added;
|
||||
|
||||
LegacyIdentityInfo(RecipientAddress address, IdentityKey identityKey, TrustLevel trustLevel, Date added) {
|
||||
this.address = address;
|
||||
|
|
|
@ -4,11 +4,11 @@ import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
|||
|
||||
public class LegacySessionInfo {
|
||||
|
||||
public RecipientAddress address;
|
||||
public final RecipientAddress address;
|
||||
|
||||
public int deviceId;
|
||||
public final int deviceId;
|
||||
|
||||
public byte[] sessionRecord;
|
||||
public final byte[] sessionRecord;
|
||||
|
||||
LegacySessionInfo(final RecipientAddress address, final int deviceId, final byte[] sessionRecord) {
|
||||
this.address = address;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package org.asamk.signal.manager.storage.recipients;
|
||||
|
||||
record RecipientWithAddress(RecipientId id, RecipientAddress address) {}
|
||||
public record RecipientWithAddress(RecipientId id, RecipientAddress address) {}
|
||||
|
|
|
@ -328,7 +328,7 @@ public class SessionStore implements SignalServiceSessionStore {
|
|||
return new Key(address, deviceId);
|
||||
}
|
||||
|
||||
private SessionRecord getSessionRecordFromResultSet(ResultSet resultSet) throws SQLException {
|
||||
private SessionRecord getSessionRecordFromResultSet(ResultSet resultSet) {
|
||||
try {
|
||||
final var record = resultSet.getBytes("record");
|
||||
return new SessionRecord(record);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class LegacyJsonThreadStore {
|
|||
@JsonProperty("threads")
|
||||
@JsonSerialize(using = MapToListSerializer.class)
|
||||
@JsonDeserialize(using = ThreadsDeserializer.class)
|
||||
private Map<String, LegacyThreadInfo> threads = new HashMap<>();
|
||||
private final Map<String, LegacyThreadInfo> threads = new HashMap<>();
|
||||
|
||||
public List<LegacyThreadInfo> getThreads() {
|
||||
return new ArrayList<>(threads.values());
|
||||
|
|
|
@ -69,7 +69,7 @@ public class MessageCacheUtils {
|
|||
if (version >= 2) {
|
||||
serverReceivedTimestamp = in.readLong();
|
||||
uuid = in.readUTF();
|
||||
if ("".equals(uuid)) {
|
||||
if (uuid.isEmpty()) {
|
||||
uuid = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@ class MergeRecipientHelperTest {
|
|||
static final PartialAddresses ADDR_A = new PartialAddresses(SERVICE_ID_A, PNI_A, NUMBER_A);
|
||||
static final PartialAddresses ADDR_B = new PartialAddresses(SERVICE_ID_B, PNI_B, NUMBER_B);
|
||||
|
||||
static T[] testInstancesNone = new T[]{
|
||||
static final T[] testInstancesNone = new T[]{
|
||||
new T(Set.of(), ADDR_A.FULL, Set.of(rec(1000000, ADDR_A.FULL))),
|
||||
new T(Set.of(), ADDR_A.ACI_NUM, Set.of(rec(1000000, ADDR_A.ACI_NUM))),
|
||||
new T(Set.of(), ADDR_A.ACI_PNI, Set.of(rec(1000000, ADDR_A.ACI_PNI))),
|
||||
new T(Set.of(), ADDR_A.PNI_NUM, Set.of(rec(1000000, ADDR_A.PNI_NUM))),
|
||||
};
|
||||
|
||||
static T[] testInstancesSingle = new T[]{
|
||||
static final T[] testInstancesSingle = new T[]{
|
||||
new T(Set.of(rec(1, ADDR_A.FULL)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.PNI)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
|
@ -74,7 +74,7 @@ class MergeRecipientHelperTest {
|
|||
new T(Set.of(rec(1, ADDR_A.FULL)), ADDR_B.FULL, Set.of(rec(1, ADDR_A.FULL), rec(1000000, ADDR_B.FULL))),
|
||||
};
|
||||
|
||||
static T[] testInstancesTwo = new T[]{
|
||||
static final T[] testInstancesTwo = new T[]{
|
||||
new T(Set.of(rec(1, ADDR_A.ACI), rec(2, ADDR_A.PNI)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI), rec(2, ADDR_A.NUM)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
new T(Set.of(rec(1, ADDR_A.ACI), rec(2, ADDR_A.PNI_NUM)), ADDR_A.FULL, Set.of(rec(1, ADDR_A.FULL))),
|
||||
|
@ -100,7 +100,7 @@ class MergeRecipientHelperTest {
|
|||
new T(Set.of(rec(1, ADDR_A.PNI), rec(2, ADDR_A.ACI_NUM)), ADDR_A.ACI_PNI, Set.of(rec(2, ADDR_A.FULL))),
|
||||
};
|
||||
|
||||
static T[] testInstancesThree = new T[]{
|
||||
static final T[] testInstancesThree = new T[]{
|
||||
new T(Set.of(rec(1, ADDR_A.ACI), rec(2, ADDR_A.PNI), rec(3, ADDR_A.NUM)),
|
||||
ADDR_A.FULL,
|
||||
Set.of(rec(1, ADDR_A.FULL))),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue