diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 88c5404192..8da4fd994e 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -152,6 +152,7 @@ import org.thoughtcrime.securesms.jobs.RetrieveProfileJob; import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob; import org.thoughtcrime.securesms.linkpreview.LinkPreview; import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository; +import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil; import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate; @@ -2180,11 +2181,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity long expiresIn = recipient.getExpireMessages() * 1000L; boolean initiating = threadId == -1; boolean needsSplit = !transport.isSms() && message.length() > transport.calculateCharacters(message).maxPrimaryMessageSize; - boolean isMediaMessage = attachmentManager.isAttachmentPresent() || - recipient.isGroupRecipient() || - recipient.getAddress().isEmail() || - inputPanel.getQuote().isPresent() || - linkPreviewViewModel.hasLinkPreview() || + boolean isMediaMessage = attachmentManager.isAttachmentPresent() || + recipient.isGroupRecipient() || + recipient.getAddress().isEmail() || + inputPanel.getQuote().isPresent() || + linkPreviewViewModel.hasLinkPreview() || + LinkPreviewUtil.isWhitelistedMediaUrl(message) || needsSplit; Log.i(TAG, "isManual Selection: " + sendButton.isManualSelection()); diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 92c0827ccd..4d8b3e5775 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -95,7 +95,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { OutgoingMediaMessage message = database.getOutgoingMessage(messageId); List attachments = new LinkedList<>(); - attachments.addAll(message.getAttachments()); + // attachments.addAll(message.getAttachments()); // attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList()); attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList()); diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index 3f384fff8f..dd39fcb69d 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -76,7 +76,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { OutgoingMediaMessage message = database.getOutgoingMessage(messageId); List attachments = new LinkedList<>(); - attachments.addAll(message.getAttachments()); + // attachments.addAll(message.getAttachments()); // attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList()); attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList()); diff --git a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewDomains.java b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewDomains.java index 01f56ce798..6e99f84ac9 100644 --- a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewDomains.java +++ b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewDomains.java @@ -33,7 +33,6 @@ public class LinkPreviewDomains { "redd.it", "imgur.com", "pinimg.com", - "giphy.com", - "tenor.com" + "giphy.com" )); } diff --git a/src/org/thoughtcrime/securesms/sms/MessageSender.java b/src/org/thoughtcrime/securesms/sms/MessageSender.java index df61b4b164..a33ac1d25e 100644 --- a/src/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/src/org/thoughtcrime/securesms/sms/MessageSender.java @@ -39,6 +39,8 @@ import org.thoughtcrime.securesms.jobs.PushGroupSendJob; import org.thoughtcrime.securesms.jobs.PushMediaSendJob; import org.thoughtcrime.securesms.jobs.PushTextSendJob; import org.thoughtcrime.securesms.jobs.SmsSendJob; +import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository; +import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.MmsException; import org.thoughtcrime.securesms.mms.OutgoingMediaMessage; @@ -46,6 +48,7 @@ import org.thoughtcrime.securesms.push.AccountManagerFactory; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.service.ExpiringMessageManager; import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.thoughtcrime.securesms.util.Util; import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.push.ContactTokenDetails; @@ -93,28 +96,42 @@ public class MessageSender { final boolean forceSms, final SmsDatabase.InsertListener insertListener) { - try { - ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context); - MmsDatabase database = DatabaseFactory.getMmsDatabase(context); + ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context); + MmsDatabase database = DatabaseFactory.getMmsDatabase(context); - long allocatedThreadId; + long allocatedThreadId; - if (threadId == -1) { - allocatedThreadId = threadDatabase.getThreadIdFor(message.getRecipient(), message.getDistributionType()); - } else { - allocatedThreadId = threadId; - } - - Recipient recipient = message.getRecipient(); - long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); - - sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn()); - - return allocatedThreadId; - } catch (MmsException e) { - Log.w(TAG, e); - return threadId; + if (threadId == -1) { + allocatedThreadId = threadDatabase.getThreadIdFor(message.getRecipient(), message.getDistributionType()); + } else { + allocatedThreadId = threadId; } + + Recipient recipient = message.getRecipient(); + + if (message.getLinkPreviews().isEmpty() && message.getAttachments().isEmpty() && LinkPreviewUtil.isWhitelistedMediaUrl(message.getBody())) { + new LinkPreviewRepository(context).fetchGIF(context, message.getBody(), attachmentOrNull -> Util.runOnMain(() -> { + if (attachmentOrNull.isPresent()) { + Attachment attachment = attachmentOrNull.get(); + try { + message.getAttachments().add(attachment); + long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); + sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn()); + } catch (Exception e) { + // TODO: Handle + } + } else { + try { + long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); + sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn()); + } catch (MmsException e) { + // TODO: Handle + } + } + })); + } + + return allocatedThreadId; } public static void resendGroupMessage(Context context, MessageRecord messageRecord, Address filterAddress) {