mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Update dependencies
This commit is contained in:
parent
a486b752e8
commit
26840a2f0f
7 changed files with 60 additions and 29 deletions
|
@ -17,7 +17,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.turasa:signal-service-java:2.15.3_unofficial_7'
|
compile 'com.github.turasa:signal-service-java:2.15.3_unofficial_8'
|
||||||
compile 'org.bouncycastle:bcprov-jdk15on:1.64'
|
compile 'org.bouncycastle:bcprov-jdk15on:1.64'
|
||||||
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
||||||
compile 'com.github.hypfvieh:dbus-java:3.2.0'
|
compile 'com.github.hypfvieh:dbus-java:3.2.0'
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
|
||||||
if (message.getAttachments().isPresent()) {
|
if (message.getAttachments().isPresent()) {
|
||||||
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
||||||
if (attachment.isPointer()) {
|
if (attachment.isPointer()) {
|
||||||
attachments.add(m.getAttachmentFile(attachment.asPointer().getId()).getAbsolutePath());
|
attachments.add(m.getAttachmentFile(attachment.asPointer().getRemoteId()).getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,12 +358,12 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||||
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
|
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
|
||||||
if (attachment.isPointer()) {
|
if (attachment.isPointer()) {
|
||||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||||
System.out.println(" Id: " + pointer.getId() + " Key length: " + pointer.getKey().length);
|
System.out.println(" Id: " + pointer.getRemoteId() + " Key length: " + pointer.getKey().length);
|
||||||
System.out.println(" Filename: " + (pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-"));
|
System.out.println(" Filename: " + (pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-"));
|
||||||
System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
|
System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
|
||||||
System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no"));
|
System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no"));
|
||||||
System.out.println(" Dimensions: " + pointer.getWidth() + "x" + pointer.getHeight());
|
System.out.println(" Dimensions: " + pointer.getWidth() + "x" + pointer.getHeight());
|
||||||
File file = m.getAttachmentFile(pointer.getId());
|
File file = m.getAttachmentFile(pointer.getRemoteId());
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
System.out.println(" Stored plaintext in: " + file);
|
System.out.println(" Stored plaintext in: " + file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class JsonAttachment {
|
||||||
|
|
||||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||||
if (attachment.isPointer()) {
|
if (attachment.isPointer()) {
|
||||||
this.id = String.valueOf(pointer.getId());
|
this.id = String.valueOf(pointer.getRemoteId());
|
||||||
if (pointer.getFileName().isPresent()) {
|
if (pointer.getFileName().isPresent()) {
|
||||||
this.filename = pointer.getFileName().get();
|
this.filename = pointer.getFileName().get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.asamk.signal.manager;
|
package org.asamk.signal.manager;
|
||||||
|
|
||||||
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||||
import org.whispersystems.signalservice.api.push.TrustStore;
|
import org.whispersystems.signalservice.api.push.TrustStore;
|
||||||
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
|
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
|
||||||
|
@ -10,8 +11,11 @@ import org.whispersystems.signalservice.internal.configuration.SignalServiceUrl;
|
||||||
import org.whispersystems.signalservice.internal.configuration.SignalStorageUrl;
|
import org.whispersystems.signalservice.internal.configuration.SignalStorageUrl;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import okhttp3.Dns;
|
||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
|
|
||||||
public class BaseConfig {
|
public class BaseConfig {
|
||||||
|
@ -27,10 +31,13 @@ public class BaseConfig {
|
||||||
|
|
||||||
private final static String URL = "https://textsecure-service.whispersystems.org";
|
private final static String URL = "https://textsecure-service.whispersystems.org";
|
||||||
private final static String CDN_URL = "https://cdn.signal.org";
|
private final static String CDN_URL = "https://cdn.signal.org";
|
||||||
|
private final static String CDN2_URL = "https://cdn2.signal.org";
|
||||||
private final static String SIGNAL_KEY_BACKUP_URL = "https://api.backup.signal.org";
|
private final static String SIGNAL_KEY_BACKUP_URL = "https://api.backup.signal.org";
|
||||||
private final static String STORAGE_URL = "https://storage.signal.org";
|
private final static String STORAGE_URL = "https://storage.signal.org";
|
||||||
private final static TrustStore TRUST_STORE = new WhisperTrustStore();
|
private final static TrustStore TRUST_STORE = new WhisperTrustStore();
|
||||||
|
|
||||||
|
private final static Optional<Dns> dns = Optional.absent();
|
||||||
|
|
||||||
private final static Interceptor userAgentInterceptor = chain ->
|
private final static Interceptor userAgentInterceptor = chain ->
|
||||||
chain.proceed(chain.request().newBuilder()
|
chain.proceed(chain.request().newBuilder()
|
||||||
.header("User-Agent", USER_AGENT)
|
.header("User-Agent", USER_AGENT)
|
||||||
|
@ -42,16 +49,24 @@ public class BaseConfig {
|
||||||
|
|
||||||
final static SignalServiceConfiguration serviceConfiguration = new SignalServiceConfiguration(
|
final static SignalServiceConfiguration serviceConfiguration = new SignalServiceConfiguration(
|
||||||
new SignalServiceUrl[]{new SignalServiceUrl(URL, TRUST_STORE)},
|
new SignalServiceUrl[]{new SignalServiceUrl(URL, TRUST_STORE)},
|
||||||
new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)},
|
makeSignalCdnUrlMapFor(new SignalCdnUrl[]{new SignalCdnUrl(CDN_URL, TRUST_STORE)}, new SignalCdnUrl[]{new SignalCdnUrl(CDN2_URL, TRUST_STORE)}),
|
||||||
new SignalContactDiscoveryUrl[0],
|
new SignalContactDiscoveryUrl[0],
|
||||||
new SignalKeyBackupServiceUrl[]{new SignalKeyBackupServiceUrl(SIGNAL_KEY_BACKUP_URL, TRUST_STORE)},
|
new SignalKeyBackupServiceUrl[]{new SignalKeyBackupServiceUrl(SIGNAL_KEY_BACKUP_URL, TRUST_STORE)},
|
||||||
new SignalStorageUrl[]{new SignalStorageUrl(STORAGE_URL, TRUST_STORE)},
|
new SignalStorageUrl[]{new SignalStorageUrl(STORAGE_URL, TRUST_STORE)},
|
||||||
interceptors,
|
interceptors,
|
||||||
|
dns,
|
||||||
zkGroupServerPublicParams
|
zkGroupServerPublicParams
|
||||||
);
|
);
|
||||||
|
|
||||||
static final SignalServiceProfile.Capabilities capabilities = new SignalServiceProfile.Capabilities(false, false);
|
static final SignalServiceProfile.Capabilities capabilities = new SignalServiceProfile.Capabilities(false, false, false);
|
||||||
|
|
||||||
private BaseConfig() {
|
private BaseConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<Integer, SignalCdnUrl[]> makeSignalCdnUrlMapFor(SignalCdnUrl[] cdn0Urls, SignalCdnUrl[] cdn2Urls) {
|
||||||
|
Map<Integer, SignalCdnUrl[]> result = new HashMap<>();
|
||||||
|
result.put(0, cdn0Urls);
|
||||||
|
result.put(2, cdn2Urls);
|
||||||
|
return Collections.unmodifiableMap(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.AttachmentInvalidException;
|
import org.asamk.signal.AttachmentInvalidException;
|
||||||
import org.asamk.signal.DbusConfig;
|
|
||||||
import org.asamk.signal.GroupNotFoundException;
|
import org.asamk.signal.GroupNotFoundException;
|
||||||
import org.asamk.signal.NotAGroupMemberException;
|
import org.asamk.signal.NotAGroupMemberException;
|
||||||
import org.asamk.signal.StickerPackInvalidException;
|
import org.asamk.signal.StickerPackInvalidException;
|
||||||
|
@ -47,6 +46,7 @@ import org.signal.libsignal.metadata.SelfSendException;
|
||||||
import org.signal.libsignal.metadata.certificate.InvalidCertificateException;
|
import org.signal.libsignal.metadata.certificate.InvalidCertificateException;
|
||||||
import org.signal.zkgroup.InvalidInputException;
|
import org.signal.zkgroup.InvalidInputException;
|
||||||
import org.signal.zkgroup.VerificationFailedException;
|
import org.signal.zkgroup.VerificationFailedException;
|
||||||
|
import org.signal.zkgroup.profiles.ClientZkProfileOperations;
|
||||||
import org.signal.zkgroup.profiles.ProfileKey;
|
import org.signal.zkgroup.profiles.ProfileKey;
|
||||||
import org.whispersystems.libsignal.IdentityKey;
|
import org.whispersystems.libsignal.IdentityKey;
|
||||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||||
|
@ -75,6 +75,7 @@ import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
|
@ -100,6 +101,7 @@ import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||||
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||||
|
import org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
@ -109,6 +111,7 @@ import org.whispersystems.signalservice.api.util.UptimeSleepTimer;
|
||||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
||||||
import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageException;
|
import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageException;
|
||||||
|
import org.whispersystems.signalservice.internal.push.VerifyAccountResponse;
|
||||||
import org.whispersystems.signalservice.internal.util.Hex;
|
import org.whispersystems.signalservice.internal.util.Hex;
|
||||||
import org.whispersystems.util.Base64;
|
import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
|
@ -125,11 +128,13 @@ import java.net.URLEncoder;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
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.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Deque;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -236,7 +241,7 @@ public class Manager implements Signal {
|
||||||
if (JsonGroupStore.groupsWithLegacyAvatarId.size() > 0) {
|
if (JsonGroupStore.groupsWithLegacyAvatarId.size() > 0) {
|
||||||
for (GroupInfo g : JsonGroupStore.groupsWithLegacyAvatarId) {
|
for (GroupInfo g : JsonGroupStore.groupsWithLegacyAvatarId) {
|
||||||
File avatarFile = getGroupAvatarFile(g.groupId);
|
File avatarFile = getGroupAvatarFile(g.groupId);
|
||||||
File attachmentFile = getAttachmentFile(g.getAvatarId());
|
File attachmentFile = getAttachmentFile(new SignalServiceAttachmentRemoteId(g.getAvatarId()));
|
||||||
if (!avatarFile.exists() && attachmentFile.exists()) {
|
if (!avatarFile.exists() && attachmentFile.exists()) {
|
||||||
try {
|
try {
|
||||||
IOUtils.createPrivateDirectories(avatarsPath);
|
IOUtils.createPrivateDirectories(avatarsPath);
|
||||||
|
@ -432,8 +437,10 @@ public class Manager implements Signal {
|
||||||
verificationCode = verificationCode.replace("-", "");
|
verificationCode = verificationCode.replace("-", "");
|
||||||
account.setSignalingKey(KeyUtils.createSignalingKey());
|
account.setSignalingKey(KeyUtils.createSignalingKey());
|
||||||
// TODO make unrestricted unidentified access configurable
|
// TODO make unrestricted unidentified access configurable
|
||||||
UUID uuid = accountManager.verifyAccountWithCode(verificationCode, account.getSignalingKey(), account.getSignalProtocolStore().getLocalRegistrationId(), true, pin, null, getSelfUnidentifiedAccessKey(), false, BaseConfig.capabilities);
|
VerifyAccountResponse response = accountManager.verifyAccountWithCode(verificationCode, account.getSignalingKey(), account.getSignalProtocolStore().getLocalRegistrationId(), true, pin, null, getSelfUnidentifiedAccessKey(), false, BaseConfig.capabilities);
|
||||||
|
|
||||||
|
UUID uuid = UuidUtil.parseOrNull(response.getUuid());
|
||||||
|
// TODO response.isStorageCapable()
|
||||||
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
||||||
account.setRegistered(true);
|
account.setRegistered(true);
|
||||||
account.setUuid(uuid);
|
account.setUuid(uuid);
|
||||||
|
@ -450,7 +457,7 @@ public class Manager implements Signal {
|
||||||
throw new RuntimeException("Not implemented anymore, will be replaced with KBS");
|
throw new RuntimeException("Not implemented anymore, will be replaced with KBS");
|
||||||
} else {
|
} else {
|
||||||
account.setRegistrationLockPin(null);
|
account.setRegistrationLockPin(null);
|
||||||
accountManager.removeV1Pin();
|
accountManager.removeRegistrationLockV1();
|
||||||
}
|
}
|
||||||
account.save();
|
account.save();
|
||||||
}
|
}
|
||||||
|
@ -464,12 +471,17 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceMessageReceiver getMessageReceiver() {
|
private SignalServiceMessageReceiver getMessageReceiver() {
|
||||||
return new SignalServiceMessageReceiver(BaseConfig.serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(), account.getDeviceId(), account.getSignalingKey(), BaseConfig.USER_AGENT, null, timer);
|
// TODO implement ZkGroup support
|
||||||
|
final ClientZkProfileOperations clientZkProfileOperations = null;
|
||||||
|
return new SignalServiceMessageReceiver(BaseConfig.serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(), account.getDeviceId(), account.getSignalingKey(), BaseConfig.USER_AGENT, null, timer, clientZkProfileOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceMessageSender getMessageSender() {
|
private SignalServiceMessageSender getMessageSender() {
|
||||||
|
// TODO implement ZkGroup support
|
||||||
|
final ClientZkProfileOperations clientZkProfileOperations = null;
|
||||||
|
final boolean attachmentsV3 = false;
|
||||||
return new SignalServiceMessageSender(BaseConfig.serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(),
|
return new SignalServiceMessageSender(BaseConfig.serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(),
|
||||||
account.getDeviceId(), account.getSignalProtocolStore(), BaseConfig.USER_AGENT, account.isMultiDevice(), Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.absent());
|
account.getDeviceId(), account.getSignalProtocolStore(), BaseConfig.USER_AGENT, account.isMultiDevice(), attachmentsV3, Optional.fromNullable(messagePipe), Optional.fromNullable(unidentifiedMessagePipe), Optional.absent(), clientZkProfileOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceProfile getRecipientProfile(SignalServiceAddress address, Optional<UnidentifiedAccess> unidentifiedAccess) throws IOException {
|
private SignalServiceProfile getRecipientProfile(SignalServiceAddress address, Optional<UnidentifiedAccess> unidentifiedAccess) throws IOException {
|
||||||
|
@ -1288,8 +1300,8 @@ public class Manager implements Signal {
|
||||||
if (avatar.isPointer()) {
|
if (avatar.isPointer()) {
|
||||||
try {
|
try {
|
||||||
retrieveGroupAvatarAttachment(avatar.asPointer(), group.groupId);
|
retrieveGroupAvatarAttachment(avatar.asPointer(), group.groupId);
|
||||||
} catch (IOException | InvalidMessageException e) {
|
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
|
||||||
System.err.println("Failed to retrieve group avatar (" + avatar.asPointer().getId() + "): " + e.getMessage());
|
System.err.println("Failed to retrieve group avatar (" + avatar.asPointer().getRemoteId() + "): " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1372,8 +1384,8 @@ public class Manager implements Signal {
|
||||||
if (attachment.isPointer()) {
|
if (attachment.isPointer()) {
|
||||||
try {
|
try {
|
||||||
retrieveAttachment(attachment.asPointer());
|
retrieveAttachment(attachment.asPointer());
|
||||||
} catch (IOException | InvalidMessageException e) {
|
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
|
||||||
System.err.println("Failed to retrieve attachment (" + attachment.asPointer().getId() + "): " + e.getMessage());
|
System.err.println("Failed to retrieve attachment (" + attachment.asPointer().getRemoteId() + "): " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1405,8 +1417,8 @@ public class Manager implements Signal {
|
||||||
SignalServiceAttachmentPointer attachment = preview.getImage().get().asPointer();
|
SignalServiceAttachmentPointer attachment = preview.getImage().get().asPointer();
|
||||||
try {
|
try {
|
||||||
retrieveAttachment(attachment);
|
retrieveAttachment(attachment);
|
||||||
} catch (IOException | InvalidMessageException e) {
|
} catch (IOException | InvalidMessageException | MissingConfigurationException e) {
|
||||||
System.err.println("Failed to retrieve attachment (" + attachment.getId() + "): " + e.getMessage());
|
System.err.println("Failed to retrieve attachment (" + attachment.getRemoteId() + "): " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1482,7 +1494,8 @@ public class Manager implements Signal {
|
||||||
envelope = messagePipe.read(timeout, unit, envelope1 -> {
|
envelope = messagePipe.read(timeout, unit, envelope1 -> {
|
||||||
// store message on disk, before acknowledging receipt to the server
|
// store message on disk, before acknowledging receipt to the server
|
||||||
try {
|
try {
|
||||||
File cacheFile = getMessageCacheFile(envelope1.getSourceE164().get(), now, envelope1.getTimestamp());
|
String source = envelope1.getSourceE164().isPresent() ? envelope1.getSourceE164().get() : "";
|
||||||
|
File cacheFile = getMessageCacheFile(source, now, envelope1.getTimestamp());
|
||||||
Utils.storeEnvelope(envelope1, cacheFile);
|
Utils.storeEnvelope(envelope1, cacheFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Failed to store encrypted message in disk cache, ignoring: " + e.getMessage());
|
System.err.println("Failed to store encrypted message in disk cache, ignoring: " + e.getMessage());
|
||||||
|
@ -1744,7 +1757,7 @@ public class Manager implements Signal {
|
||||||
return new File(avatarsPath, "contact-" + number);
|
return new File(avatarsPath, "contact-" + number);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File retrieveContactAvatarAttachment(SignalServiceAttachment attachment, String number) throws IOException, InvalidMessageException {
|
private File retrieveContactAvatarAttachment(SignalServiceAttachment attachment, String number) throws IOException, InvalidMessageException, MissingConfigurationException {
|
||||||
IOUtils.createPrivateDirectories(avatarsPath);
|
IOUtils.createPrivateDirectories(avatarsPath);
|
||||||
if (attachment.isPointer()) {
|
if (attachment.isPointer()) {
|
||||||
SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||||
|
@ -1759,7 +1772,7 @@ public class Manager implements Signal {
|
||||||
return new File(avatarsPath, "group-" + Base64.encodeBytes(groupId).replace("/", "_"));
|
return new File(avatarsPath, "group-" + Base64.encodeBytes(groupId).replace("/", "_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private File retrieveGroupAvatarAttachment(SignalServiceAttachment attachment, byte[] groupId) throws IOException, InvalidMessageException {
|
private File retrieveGroupAvatarAttachment(SignalServiceAttachment attachment, byte[] groupId) throws IOException, InvalidMessageException, MissingConfigurationException {
|
||||||
IOUtils.createPrivateDirectories(avatarsPath);
|
IOUtils.createPrivateDirectories(avatarsPath);
|
||||||
if (attachment.isPointer()) {
|
if (attachment.isPointer()) {
|
||||||
SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||||
|
@ -1770,16 +1783,16 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getAttachmentFile(long attachmentId) {
|
public File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId) {
|
||||||
return new File(attachmentsPath, attachmentId + "");
|
return new File(attachmentsPath, attachmentId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private File retrieveAttachment(SignalServiceAttachmentPointer pointer) throws IOException, InvalidMessageException {
|
private File retrieveAttachment(SignalServiceAttachmentPointer pointer) throws IOException, InvalidMessageException, MissingConfigurationException {
|
||||||
IOUtils.createPrivateDirectories(attachmentsPath);
|
IOUtils.createPrivateDirectories(attachmentsPath);
|
||||||
return retrieveAttachment(pointer, getAttachmentFile(pointer.getId()), true);
|
return retrieveAttachment(pointer, getAttachmentFile(pointer.getRemoteId()), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File retrieveAttachment(SignalServiceAttachmentPointer pointer, File outputFile, boolean storePreview) throws IOException, InvalidMessageException {
|
private File retrieveAttachment(SignalServiceAttachmentPointer pointer, File outputFile, boolean storePreview) throws IOException, InvalidMessageException, MissingConfigurationException {
|
||||||
if (storePreview && pointer.getPreview().isPresent()) {
|
if (storePreview && pointer.getPreview().isPresent()) {
|
||||||
File previewFile = new File(outputFile + ".preview");
|
File previewFile = new File(outputFile + ".preview");
|
||||||
try (OutputStream output = new FileOutputStream(previewFile)) {
|
try (OutputStream output = new FileOutputStream(previewFile)) {
|
||||||
|
@ -1816,7 +1829,7 @@ public class Manager implements Signal {
|
||||||
return outputFile;
|
return outputFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream retrieveAttachmentAsStream(SignalServiceAttachmentPointer pointer, File tmpFile) throws IOException, InvalidMessageException {
|
private InputStream retrieveAttachmentAsStream(SignalServiceAttachmentPointer pointer, File tmpFile) throws IOException, InvalidMessageException, MissingConfigurationException {
|
||||||
final SignalServiceMessageReceiver messageReceiver = getMessageReceiver();
|
final SignalServiceMessageReceiver messageReceiver = getMessageReceiver();
|
||||||
return messageReceiver.retrieveAttachment(pointer, tmpFile, BaseConfig.MAX_ATTACHMENT_SIZE);
|
return messageReceiver.retrieveAttachment(pointer, tmpFile, BaseConfig.MAX_ATTACHMENT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||||
|
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
|
||||||
import org.whispersystems.util.Base64;
|
import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
@ -76,10 +77,12 @@ class Utils {
|
||||||
final long attachmentSize = attachmentFile.length();
|
final long attachmentSize = attachmentFile.length();
|
||||||
final String mime = getFileMimeType(attachmentFile);
|
final String mime = getFileMimeType(attachmentFile);
|
||||||
// TODO mabybe add a parameter to set the voiceNote, preview, width, height and caption option
|
// TODO mabybe add a parameter to set the voiceNote, preview, width, height and caption option
|
||||||
|
final long uploadTimestamp = System.currentTimeMillis();
|
||||||
Optional<byte[]> preview = Optional.absent();
|
Optional<byte[]> preview = Optional.absent();
|
||||||
Optional<String> caption = Optional.absent();
|
Optional<String> caption = Optional.absent();
|
||||||
Optional<String> blurHash = Optional.absent();
|
Optional<String> blurHash = Optional.absent();
|
||||||
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, preview, 0, 0, caption, blurHash, null, null);
|
final Optional<ResumableUploadSpec> resumableUploadSpec = Optional.absent();
|
||||||
|
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, preview, 0, 0, uploadTimestamp, caption, blurHash, null, null, resumableUploadSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static StreamDetails createStreamDetailsFromFile(File file) throws IOException {
|
static StreamDetails createStreamDetailsFromFile(File file) throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue