Revert "track attachment data (#671 and #316)"

This reverts commit 8aed357994.
This commit is contained in:
John Freed 2021-08-12 14:38:47 +02:00
parent 0f437dbfd1
commit 5059925b22
20 changed files with 52 additions and 519 deletions

View file

@ -1,238 +0,0 @@
package org.asamk.signal.dbus;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
import org.whispersystems.signalservice.api.util.StreamDetails;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.annotations.Position;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.asamk.signal.manager.util.Utils;
import org.freedesktop.dbus.Struct;
public final class DbusAttachment extends Struct
{
@Position(0)
private String contentType;
@Position(1)
private String fileName;
@Position(2)
private String id;
@Position(3)
private Long size;
@Position(4)
private Integer keyLength;
@Position(5)
private boolean voiceNote;
@Position(6)
private Integer width;
@Position(7)
private Integer height;
@Position(8)
private String caption;
@Position(9)
private String blurHash;
/*
* API = 2.15.3 from https://github.com/Turasa/libsignal-service-java (nonstandard)
public SignalServiceAttachmentStream(InputStream inputStream,
String contentType,
long length,
Optional<String> fileName,
boolean voiceNote,
boolean borderless,
boolean gif, //nonstandard
Optional<byte[]> preview,
int width,
int height,
long uploadTimestamp,
Optional<String> caption,
Optional<String> blurHash,
ProgressListener listener, //Android OS
CancellationSignal cancellationSignal, //Android OS, Signal developers misspelled class name
Optional<ResumableUploadSpec> resumableUploadSpec)
public SignalServiceAttachmentPointer(int cdnNumber,
SignalServiceAttachmentRemoteId remoteId,
String contentType,
byte[] key,
Optional<Integer> size,
Optional<byte[]> preview,
int width,
int height,
Optional<byte[]> digest,
Optional<String> fileName,
boolean voiceNote,
boolean borderless,
Optional<String> caption,
Optional<String> blurHash,
long uploadTimestamp)
other stuff :
private long id; // used by v2 attachments, see note
private int keyLength; //TODO: if you're going to do that, probably should have previewLength and digestLength
notes :
"size" appears to be the same as "length" but is int rather than long
"length" represents file size (or stream/attachment size)
"preview" is also known as "thumbnail"
from SignalServiceAttachmentRemoteId.java :
* Represents a signal service attachment identifier. This can be either a CDN key or a long, but
* not both at once. Attachments V2 used a long as an attachment identifier. This lacks sufficient
* entropy to reduce the likelihood of any two uploads going to the same location within a 30-day
* window. Attachments V3 uses an opaque string as an attachment identifier which provides more
* flexibility in the amount of entropy present.
*/
public DbusAttachment(SignalServiceAttachment attachment) {
this.contentType = attachment.getContentType();
if (attachment.isPointer()) {
final var pointer = attachment.asPointer();
this.id = pointer.getRemoteId().toString();
this.fileName = pointer.getFileName().orNull();
if (this.fileName == null) {
this.fileName = "";
}
this.size = pointer.getSize().transform(Integer::longValue).orNull();
if (this.size == null) {
this.size = 0L;
}
this.setKeyLength(pointer.getKey().length);
this.setWidth(pointer.getWidth());
this.setHeight(pointer.getHeight());
this.setVoiceNote(pointer.getVoiceNote());
if (pointer.getCaption().isPresent()) {
this.setCaption(pointer.getCaption().get());
} else {
this.setCaption("");
}
this.setBlurHash("");
} else {
final var stream = attachment.asStream();
this.fileName = stream.getFileName().orNull();
if (this.fileName == null) {
this.fileName = "";
}
this.id = "";
this.size = stream.getLength();
this.setKeyLength(0);
this.setWidth(0);
this.setHeight(0);
this.setVoiceNote(false);
this.setCaption("");
this.setBlurHash("");
}
}
public DbusAttachment(String fileName) {
this.contentType = "application/octet-stream";
try {
final File file = new File(fileName);
this.contentType = Utils.getFileMimeType(file, "application/octet-stream");
this.size = file.length();
} catch (IOException e) {
//no such file, try URL
try {
final URL aURL = new URL(fileName);
this.contentType = aURL.openConnection().getContentType();
this.size = aURL.openConnection().getContentLengthLong();
} catch (IOException f) {
f.printStackTrace();
}
}
this.fileName = fileName;
this.id = "";
this.setKeyLength(0);
this.setWidth(0);
this.setHeight(0);
this.setVoiceNote(false);
this.setCaption("");
this.setBlurHash("");
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public Long getFileSize() {
return size;
}
public void setFileSize(Long size) {
this.size = size;
}
public Integer getKeyLength() {
return keyLength;
}
public void setKeyLength(Integer keyLength) {
this.keyLength = keyLength;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
public boolean isVoiceNote() {
return voiceNote;
}
public boolean getVoiceNote() {
return voiceNote;
}
public void setVoiceNote(boolean voiceNote) {
this.voiceNote = voiceNote;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
public String getBlurHash() {
return blurHash;
}
public void setBlurHash(String blurHash) {
this.blurHash = blurHash;
}
}

View file

@ -150,6 +150,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
return BaseConfig.PROJECT_VERSION;
}
@Override
public List<DBusPath> listAccounts() {
synchronized (receiveThreads) {
return receiveThreads.stream()

View file

@ -7,7 +7,6 @@ import org.asamk.signal.PlainTextWriter;
import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.dbus.DbusAttachment;
import org.asamk.signal.manager.AttachmentInvalidException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException;
@ -112,36 +111,10 @@ public class DbusSignalImpl implements Signal {
return results;
}
@Override
public long sendMessageWithDBusAttachments(final String message, final List<DbusAttachment> dBusAttachments, final String recipient) {
public long sendMessage(final String message, final List<String> attachments, final String recipient) {
var recipients = new ArrayList<String>(1);
recipients.add(recipient);
return sendMessageWithDBusAttachments(message, dBusAttachments, recipients);
}
@Override
public long sendMessageWithDBusAttachments(final String message, final List<DbusAttachment> dBusAttachments, final List<String> recipients) {
try {
ArrayList<String> attachmentNames = new ArrayList<>();
for (var dBusAttachment : dBusAttachments) {
attachmentNames.add(dBusAttachment.getFileName());
}
final var results = m.sendMessage(message, attachmentNames, recipients);
checkSendMessageResults(results.first(), results.second());
return results.first();
} catch (InvalidNumberException e) {
throw new Error.InvalidNumber(e.getMessage());
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
}
@Override
public long sendMessage(final String message, final List<String> attachmentNames, final String recipient) {
var recipients = new ArrayList<String>(1);
recipients.add(recipient);
return sendMessage(message, attachmentNames, recipients);
return sendMessage(message, attachments, recipients);
}
private static void checkSendMessageResult(long timestamp, SendMessageResult result) throws DBusExecutionException {
@ -184,9 +157,9 @@ public class DbusSignalImpl implements Signal {
}
@Override
public long sendMessage(final String message, final List<String> attachmentNames, final List<String> recipients) {
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
try {
final var results = m.sendMessage(message, attachmentNames, recipients);
final var results = m.sendMessage(message, attachments, recipients);
checkSendMessageResults(results.first(), results.second());
return results.first();
} catch (InvalidNumberException e) {
@ -271,10 +244,10 @@ public class DbusSignalImpl implements Signal {
@Override
public long sendNoteToSelfMessage(
final String message, final List<String> attachmentNames
final String message, final List<String> attachments
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
try {
final var results = m.sendSelfMessage(message, attachmentNames);
final var results = m.sendSelfMessage(message, attachments);
checkSendMessageResult(results.first(), results.second());
return results.first();
} catch (AttachmentInvalidException e) {
@ -284,25 +257,6 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public long sendNoteToSelfMessageWithDBusAttachments(
final String message, final List<DbusAttachment> dBusAttachments
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
try {
ArrayList<String> attachmentNames = new ArrayList<>();
for (var dBusAttachment : dBusAttachments) {
attachmentNames.add(dBusAttachment.getFileName());
}
final var results = m.sendSelfMessage(message, attachmentNames);
checkSendMessageResult(results.first(), results.second());
return results.first();
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
}
@Override
public void sendEndSessionMessage(final List<String> recipients) {
try {
@ -316,9 +270,9 @@ public class DbusSignalImpl implements Signal {
}
@Override
public long sendGroupMessage(final String message, final List<String> attachmentNames, final byte[] groupId) {
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
try {
var results = m.sendGroupMessage(message, attachmentNames, GroupId.unknownVersion(groupId));
var results = m.sendGroupMessage(message, attachments, GroupId.unknownVersion(groupId));
checkSendMessageResults(results.first(), results.second());
return results.first();
} catch (IOException e) {
@ -330,26 +284,6 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public long sendGroupMessageWithDBusAttachments(final String message, final List<DbusAttachment> dBusAttachments, final byte[] groupId) {
try {
ArrayList<String> attachmentNames = new ArrayList<>();
for (var dBusAttachment : dBusAttachments) {
attachmentNames.add(dBusAttachment.getFileName());
}
var results = m.sendGroupMessage(message, attachmentNames, GroupId.unknownVersion(groupId));
checkSendMessageResults(results.first(), results.second());
return results.first();
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException e) {
throw new Error.GroupNotFound(e.getMessage());
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
}
}
@Override
public long sendGroupMessageReaction(
final String emoji,
@ -397,17 +331,6 @@ public class DbusSignalImpl implements Signal {
}
}
@Override
public void setExpirationTimer(final String number, final int expiration) {
try {
m.setExpirationTimer(number, expiration);
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
} catch (InvalidNumberException e) {
throw new Error.InvalidNumber(e.getMessage());
}
}
@Override
public void setContactBlocked(final String number, final boolean blocked) {
try {