mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-03 12:50:37 +00:00
Refactor retrieving of attachments to use StreamDetails
This commit is contained in:
parent
589f5378df
commit
c66e78b0ad
6 changed files with 26 additions and 30 deletions
|
@ -2,8 +2,10 @@ package org.asamk.signal.manager;
|
|||
|
||||
import org.asamk.signal.manager.util.IOUtils;
|
||||
import org.asamk.signal.manager.util.MimeUtils;
|
||||
import org.asamk.signal.manager.util.Utils;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
|
||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -39,10 +41,12 @@ public class AttachmentStore {
|
|||
Optional.ofNullable(pointer.getContentType()));
|
||||
}
|
||||
|
||||
public File getAttachmentFile(AttachmentPointer pointer) {
|
||||
return getAttachmentFile(SignalServiceAttachmentRemoteId.from(pointer.id()),
|
||||
Optional.ofNullable(pointer.fileName()),
|
||||
Optional.ofNullable(pointer.contentType()));
|
||||
public StreamDetails retrieveAttachment(final String id) throws IOException {
|
||||
final var attachmentFile = new File(attachmentsPath, id);
|
||||
if (!attachmentFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
return Utils.createStreamDetailsFromFile(attachmentFile);
|
||||
}
|
||||
|
||||
private void storeAttachment(final File attachmentFile, final AttachmentStorer storer) throws IOException {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
|
|||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
|
@ -272,7 +273,7 @@ public interface Manager extends Closeable {
|
|||
|
||||
void addClosedListener(Runnable listener);
|
||||
|
||||
File getAttachmentFile(AttachmentPointer pointer);
|
||||
InputStream retrieveAttachment(final String id) throws IOException;
|
||||
|
||||
@Override
|
||||
void close() throws IOException;
|
||||
|
|
|
@ -82,6 +82,7 @@ import org.whispersystems.signalservice.internal.util.Util;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
|
@ -1147,8 +1148,9 @@ class ManagerImpl implements Manager {
|
|||
}
|
||||
}
|
||||
|
||||
public File getAttachmentFile(AttachmentPointer pointer) {
|
||||
return context.getAttachmentHelper().getAttachmentFile(pointer);
|
||||
@Override
|
||||
public InputStream retrieveAttachment(final String id) throws IOException {
|
||||
return context.getAttachmentHelper().retrieveAttachment(id).getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.asamk.signal.manager.helper;
|
||||
|
||||
import org.asamk.signal.manager.AttachmentPointer;
|
||||
import org.asamk.signal.manager.AttachmentStore;
|
||||
import org.asamk.signal.manager.SignalDependencies;
|
||||
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
||||
|
@ -14,6 +13,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
|||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -39,8 +39,8 @@ public class AttachmentHelper {
|
|||
return attachmentStore.getAttachmentFile(pointer);
|
||||
}
|
||||
|
||||
public File getAttachmentFile(AttachmentPointer pointer) {
|
||||
return attachmentStore.getAttachmentFile(pointer);
|
||||
public StreamDetails retrieveAttachment(final String id) throws IOException {
|
||||
return attachmentStore.retrieveAttachment(id);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue