This commit is contained in:
Niels Andriesse 2019-09-09 14:30:02 +10:00
parent 1d5a31aae4
commit d1c1083751

View File

@ -123,7 +123,6 @@ import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOper
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage; import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.internal.util.concurrent.SettableFuture;
import org.whispersystems.signalservice.loki.crypto.LokiServiceCipher; import org.whispersystems.signalservice.loki.crypto.LokiServiceCipher;
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus; import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus;
import org.whispersystems.signalservice.loki.messaging.LokiServiceMessage; import org.whispersystems.signalservice.loki.messaging.LokiServiceMessage;
@ -139,7 +138,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import kotlin.Unit;
import network.loki.messenger.R; import network.loki.messenger.R;
public class PushDecryptJob extends BaseJob implements InjectableType { public class PushDecryptJob extends BaseJob implements InjectableType {
@ -742,12 +740,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
{ {
notifyTypingStoppedFromIncomingMessage(getMessageDestination(content, message), content.getSender(), content.getSenderDevice()); notifyTypingStoppedFromIncomingMessage(getMessageDestination(content, message), content.getSender(), content.getSenderDevice());
Optional<InsertResult> insertResult;
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
database.beginTransaction();
try {
Optional<QuoteModel> quote = getValidatedQuote(message.getQuote()); Optional<QuoteModel> quote = getValidatedQuote(message.getQuote());
Optional<List<Contact>> sharedContacts = getContacts(message.getSharedContacts()); Optional<List<Contact>> sharedContacts = getContacts(message.getSharedContacts());
Optional<List<LinkPreview>> linkPreviews = getLinkPreviews(message.getPreviews(), message.getBody().or("")); Optional<List<LinkPreview>> linkPreviews = getLinkPreviews(message.getPreviews(), message.getBody().or(""));
@ -767,7 +759,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
if (linkPreviews.isPresent()) { if (linkPreviews.isPresent()) {
int linkPreviewCount = linkPreviews.get().size(); int linkPreviewCount = linkPreviews.get().size();
if (linkPreviewCount != 0) { if (linkPreviewCount != 0) {
final SettableFuture<?>[] future = { new SettableFuture<Unit>() };
LinkPreviewRepository lpr = new LinkPreviewRepository(context); LinkPreviewRepository lpr = new LinkPreviewRepository(context);
final int[] count = { 0 }; final int[] count = { 0 };
for (LinkPreview linkPreview : linkPreviews.get()) { for (LinkPreview linkPreview : linkPreviews.get()) {
@ -780,20 +771,29 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
linkPreview.thumbnail = Optional.of(thumbnail); linkPreview.thumbnail = Optional.of(thumbnail);
} }
if (c == linkPreviewCount) { if (c == linkPreviewCount) {
@SuppressWarnings("unchecked") SettableFuture<Unit> f = (SettableFuture<Unit>) future[0];
f.set(Unit.INSTANCE);
}
}));
}
@SuppressWarnings("unchecked") SettableFuture<Unit> f = (SettableFuture<Unit>) future[0];
try { try {
f.get(); handleMediaMessage(content, mediaMessage, smsMessageId);
} catch (Exception e) { } catch (Exception e) {
// Do nothing // Do nothing
} }
} }
}));
}
} else {
handleMediaMessage(content, mediaMessage, smsMessageId);
}
} else {
handleMediaMessage(content, mediaMessage, smsMessageId);
}
} }
private void handleMediaMessage(@NonNull SignalServiceContent content, @NonNull IncomingMediaMessage mediaMessage, @NonNull Optional<Long> smsMessageID) throws StorageFailedException {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
database.beginTransaction();
Optional<InsertResult> insertResult;
try {
insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1); insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1);
if (insertResult.isPresent()) { if (insertResult.isPresent()) {
@ -804,13 +804,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
forceStickerDownloadIfNecessary(stickerAttachments); forceStickerDownloadIfNecessary(stickerAttachments);
for (DatabaseAttachment attachment : attachments) { for (DatabaseAttachment attachment : attachments) {
ApplicationContext.getInstance(context) ApplicationContext.getInstance(context).getJobManager().add(new AttachmentDownloadJob(insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
.getJobManager()
.add(new AttachmentDownloadJob(insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
} }
if (smsMessageId.isPresent()) { if (smsMessageID.isPresent()) {
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageID.get());
} }
database.setTransactionSuccessful(); database.setTransactionSuccessful();