mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-05-29 15:04:16 +00:00
Compare commits
2 Commits
bc8ad9e567
...
e710efd173
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e710efd173 | ||
|
|
9bc4c0ecd8 |
@ -18,7 +18,7 @@ slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
|
|||||||
slf4j-jul = { module = "org.slf4j:jul-to-slf4j", version.ref = "slf4j" }
|
slf4j-jul = { module = "org.slf4j:jul-to-slf4j", version.ref = "slf4j" }
|
||||||
logback = "ch.qos.logback:logback-classic:1.5.32"
|
logback = "ch.qos.logback:logback-classic:1.5.32"
|
||||||
|
|
||||||
signalservice = "com.github.turasa:signal-service-java:2.15.3_unofficial_142"
|
signalservice = "com.github.turasa:signal-service-java:2.15.3_unofficial_143"
|
||||||
sqlite = "org.xerial:sqlite-jdbc:3.51.2.0"
|
sqlite = "org.xerial:sqlite-jdbc:3.51.2.0"
|
||||||
hikari = "com.zaxxer:HikariCP:7.0.2"
|
hikari = "com.zaxxer:HikariCP:7.0.2"
|
||||||
junit-jupiter-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
|
junit-jupiter-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import org.asamk.signal.manager.internal.SignalDependencies;
|
|||||||
import org.asamk.signal.manager.storage.AttachmentStore;
|
import org.asamk.signal.manager.storage.AttachmentStore;
|
||||||
import org.asamk.signal.manager.util.AttachmentUtils;
|
import org.asamk.signal.manager.util.AttachmentUtils;
|
||||||
import org.asamk.signal.manager.util.IOUtils;
|
import org.asamk.signal.manager.util.IOUtils;
|
||||||
|
import org.asamk.signal.manager.util.Utils;
|
||||||
import org.signal.libsignal.protocol.InvalidMessageException;
|
import org.signal.libsignal.protocol.InvalidMessageException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -44,7 +45,10 @@ public class AttachmentHelper {
|
|||||||
return attachmentStore.retrieveAttachment(id);
|
return attachmentStore.retrieveAttachment(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SignalServiceAttachment> uploadAttachments(final List<String> attachments, boolean voiceNote) throws AttachmentInvalidException, IOException {
|
public List<SignalServiceAttachment> uploadAttachments(
|
||||||
|
final List<String> attachments,
|
||||||
|
boolean voiceNote
|
||||||
|
) throws AttachmentInvalidException, IOException {
|
||||||
final var attachmentStreams = createAttachmentStreams(attachments, voiceNote);
|
final var attachmentStreams = createAttachmentStreams(attachments, voiceNote);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -65,21 +69,41 @@ public class AttachmentHelper {
|
|||||||
return uploadAttachments(attachments, false);
|
return uploadAttachments(attachments, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SignalServiceAttachmentStream> createAttachmentStreams(List<String> attachments, boolean voiceNote) throws AttachmentInvalidException, IOException {
|
private List<SignalServiceAttachmentStream> createAttachmentStreams(
|
||||||
|
List<String> attachments,
|
||||||
|
boolean voiceNote
|
||||||
|
) throws AttachmentInvalidException, IOException {
|
||||||
if (attachments == null) {
|
if (attachments == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final var signalServiceAttachments = new ArrayList<SignalServiceAttachmentStream>(attachments.size());
|
final var signalServiceAttachments = new ArrayList<SignalServiceAttachmentStream>(attachments.size());
|
||||||
for (var attachment : attachments) {
|
for (var attachment : attachments) {
|
||||||
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
|
final var attachmentStream = getAttachmentStream(attachment, voiceNote);
|
||||||
signalServiceAttachments.add(AttachmentUtils.createAttachmentStream(attachment, voiceNote, uploadSpec));
|
signalServiceAttachments.add(attachmentStream);
|
||||||
}
|
}
|
||||||
return signalServiceAttachments;
|
return signalServiceAttachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SignalServiceAttachmentStream getAttachmentStream(
|
||||||
|
final String attachment,
|
||||||
|
final boolean voiceNote
|
||||||
|
) throws AttachmentInvalidException {
|
||||||
|
try {
|
||||||
|
final var streamDetails = Utils.createStreamDetails(attachment);
|
||||||
|
final var uploadSpec = dependencies.getMessageSender()
|
||||||
|
.getResumableUploadSpec(streamDetails.first().getLength());
|
||||||
|
|
||||||
|
return AttachmentUtils.createAttachmentStream(streamDetails.first(),
|
||||||
|
streamDetails.second(),
|
||||||
|
voiceNote,
|
||||||
|
uploadSpec);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new AttachmentInvalidException(attachment, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SignalServiceAttachmentPointer uploadAttachment(String attachment) throws IOException, AttachmentInvalidException {
|
public SignalServiceAttachmentPointer uploadAttachment(String attachment) throws IOException, AttachmentInvalidException {
|
||||||
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
|
final var attachmentStream = getAttachmentStream(attachment, false);
|
||||||
var attachmentStream = AttachmentUtils.createAttachmentStream(attachment, uploadSpec);
|
|
||||||
return uploadAttachment(attachmentStream);
|
return uploadAttachment(attachmentStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -123,7 +123,7 @@ public class GroupHelper {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
|
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec(streamDetails.getLength());
|
||||||
return Optional.of(AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty(), uploadSpec));
|
return Optional.of(AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty(), uploadSpec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -131,7 +131,9 @@ public class SyncHelper {
|
|||||||
|
|
||||||
if (groupsFile.exists() && groupsFile.length() > 0) {
|
if (groupsFile.exists() && groupsFile.length() > 0) {
|
||||||
try (var groupsFileStream = new FileInputStream(groupsFile)) {
|
try (var groupsFileStream = new FileInputStream(groupsFile)) {
|
||||||
final var uploadSpec = context.getDependencies().getMessageSender().getResumableUploadSpec();
|
final var uploadSpec = context.getDependencies()
|
||||||
|
.getMessageSender()
|
||||||
|
.getResumableUploadSpec(groupsFile.length());
|
||||||
var attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
var attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
||||||
.withStream(groupsFileStream)
|
.withStream(groupsFileStream)
|
||||||
.withContentType(MimeUtils.OCTET_STREAM)
|
.withContentType(MimeUtils.OCTET_STREAM)
|
||||||
@ -190,7 +192,9 @@ public class SyncHelper {
|
|||||||
|
|
||||||
if (contactsFile.exists() && contactsFile.length() > 0) {
|
if (contactsFile.exists() && contactsFile.length() > 0) {
|
||||||
try (var contactsFileStream = new FileInputStream(contactsFile)) {
|
try (var contactsFileStream = new FileInputStream(contactsFile)) {
|
||||||
final var uploadSpec = context.getDependencies().getMessageSender().getResumableUploadSpec();
|
final var uploadSpec = context.getDependencies()
|
||||||
|
.getMessageSender()
|
||||||
|
.getResumableUploadSpec(contactsFile.length());
|
||||||
var attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
var attachmentStream = SignalServiceAttachment.newStreamBuilder()
|
||||||
.withStream(contactsFileStream)
|
.withStream(contactsFileStream)
|
||||||
.withContentType(MimeUtils.OCTET_STREAM)
|
.withContentType(MimeUtils.OCTET_STREAM)
|
||||||
|
|||||||
@ -694,7 +694,10 @@ public class ManagerImpl implements Manager {
|
|||||||
)) {
|
)) {
|
||||||
final var result = notifySelf
|
final var result = notifySelf
|
||||||
? context.getSendHelper()
|
? context.getSendHelper()
|
||||||
.sendMessage(messageBuilder, account.getSelfRecipientId(), editTargetTimestamp, urgent)
|
.sendMessage(messageBuilder,
|
||||||
|
account.getSelfRecipientId(),
|
||||||
|
editTargetTimestamp,
|
||||||
|
urgent)
|
||||||
: context.getSendHelper().sendSelfMessage(messageBuilder, editTargetTimestamp);
|
: context.getSendHelper().sendSelfMessage(messageBuilder, editTargetTimestamp);
|
||||||
results.put(recipient, List.of(toSendMessageResult(result)));
|
results.put(recipient, List.of(toSendMessageResult(result)));
|
||||||
} else if (recipient instanceof RecipientIdentifier.Single single) {
|
} else if (recipient instanceof RecipientIdentifier.Single single) {
|
||||||
@ -833,10 +836,11 @@ public class ManagerImpl implements Manager {
|
|||||||
final var remainder = result.getSecond();
|
final var remainder = result.getSecond();
|
||||||
if (remainder != null) {
|
if (remainder != null) {
|
||||||
final var messageBytes = message.messageText().getBytes(StandardCharsets.UTF_8);
|
final var messageBytes = message.messageText().getBytes(StandardCharsets.UTF_8);
|
||||||
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
|
|
||||||
final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes),
|
final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes),
|
||||||
MimeUtils.LONG_TEXT,
|
MimeUtils.LONG_TEXT,
|
||||||
messageBytes.length);
|
messageBytes.length);
|
||||||
|
final var uploadSpec = dependencies.getMessageSender()
|
||||||
|
.getResumableUploadSpec(streamDetails.getLength());
|
||||||
final var textAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
|
final var textAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
uploadSpec);
|
uploadSpec);
|
||||||
@ -904,7 +908,7 @@ public class ManagerImpl implements Manager {
|
|||||||
if (streamDetails == null) {
|
if (streamDetails == null) {
|
||||||
throw new InvalidStickerException("Missing local sticker file");
|
throw new InvalidStickerException("Missing local sticker file");
|
||||||
}
|
}
|
||||||
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
|
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec(streamDetails.getLength());
|
||||||
final var stickerAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
|
final var stickerAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
uploadSpec);
|
uploadSpec);
|
||||||
|
|||||||
@ -1,38 +1,15 @@
|
|||||||
package org.asamk.signal.manager.util;
|
package org.asamk.signal.manager.util;
|
||||||
|
|
||||||
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvalidException;
|
import org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvalidException;
|
||||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||||
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
|
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class AttachmentUtils {
|
public class AttachmentUtils {
|
||||||
|
|
||||||
public static SignalServiceAttachmentStream createAttachmentStream(
|
|
||||||
String attachment,
|
|
||||||
boolean voiceNote,
|
|
||||||
ResumableUploadSpec resumableUploadSpec
|
|
||||||
) throws AttachmentInvalidException {
|
|
||||||
try {
|
|
||||||
final var streamDetails = Utils.createStreamDetails(attachment);
|
|
||||||
|
|
||||||
return createAttachmentStream(streamDetails.first(), streamDetails.second(), voiceNote, resumableUploadSpec);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new AttachmentInvalidException(attachment, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SignalServiceAttachmentStream createAttachmentStream(
|
|
||||||
String attachment,
|
|
||||||
ResumableUploadSpec resumableUploadSpec
|
|
||||||
) throws AttachmentInvalidException {
|
|
||||||
return createAttachmentStream(attachment, false, resumableUploadSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SignalServiceAttachmentStream createAttachmentStream(
|
public static SignalServiceAttachmentStream createAttachmentStream(
|
||||||
StreamDetails streamDetails,
|
StreamDetails streamDetails,
|
||||||
Optional<String> name,
|
Optional<String> name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user