mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Implement GIF sending
This commit is contained in:
parent
df36d5e539
commit
74dfac6fd1
@ -152,6 +152,7 @@ import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
|||||||
import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob;
|
import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
||||||
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate;
|
import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate;
|
||||||
@ -2180,11 +2181,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
long expiresIn = recipient.getExpireMessages() * 1000L;
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
||||||
boolean initiating = threadId == -1;
|
boolean initiating = threadId == -1;
|
||||||
boolean needsSplit = !transport.isSms() && message.length() > transport.calculateCharacters(message).maxPrimaryMessageSize;
|
boolean needsSplit = !transport.isSms() && message.length() > transport.calculateCharacters(message).maxPrimaryMessageSize;
|
||||||
boolean isMediaMessage = attachmentManager.isAttachmentPresent() ||
|
boolean isMediaMessage = attachmentManager.isAttachmentPresent() ||
|
||||||
recipient.isGroupRecipient() ||
|
recipient.isGroupRecipient() ||
|
||||||
recipient.getAddress().isEmail() ||
|
recipient.getAddress().isEmail() ||
|
||||||
inputPanel.getQuote().isPresent() ||
|
inputPanel.getQuote().isPresent() ||
|
||||||
linkPreviewViewModel.hasLinkPreview() ||
|
linkPreviewViewModel.hasLinkPreview() ||
|
||||||
|
LinkPreviewUtil.isWhitelistedMediaUrl(message) ||
|
||||||
needsSplit;
|
needsSplit;
|
||||||
|
|
||||||
Log.i(TAG, "isManual Selection: " + sendButton.isManualSelection());
|
Log.i(TAG, "isManual Selection: " + sendButton.isManualSelection());
|
||||||
|
@ -95,7 +95,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
|||||||
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
||||||
List<Attachment> attachments = new LinkedList<>();
|
List<Attachment> 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.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());
|
attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList());
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
|||||||
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
||||||
List<Attachment> attachments = new LinkedList<>();
|
List<Attachment> 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.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());
|
attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList());
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ public class LinkPreviewDomains {
|
|||||||
"redd.it",
|
"redd.it",
|
||||||
"imgur.com",
|
"imgur.com",
|
||||||
"pinimg.com",
|
"pinimg.com",
|
||||||
"giphy.com",
|
"giphy.com"
|
||||||
"tenor.com"
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
|||||||
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
||||||
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
||||||
import org.thoughtcrime.securesms.jobs.SmsSendJob;
|
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.logging.Log;
|
||||||
import org.thoughtcrime.securesms.mms.MmsException;
|
import org.thoughtcrime.securesms.mms.MmsException;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
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.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||||
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
||||||
@ -93,28 +96,42 @@ public class MessageSender {
|
|||||||
final boolean forceSms,
|
final boolean forceSms,
|
||||||
final SmsDatabase.InsertListener insertListener)
|
final SmsDatabase.InsertListener insertListener)
|
||||||
{
|
{
|
||||||
try {
|
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
||||||
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
||||||
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
|
||||||
|
|
||||||
long allocatedThreadId;
|
long allocatedThreadId;
|
||||||
|
|
||||||
if (threadId == -1) {
|
if (threadId == -1) {
|
||||||
allocatedThreadId = threadDatabase.getThreadIdFor(message.getRecipient(), message.getDistributionType());
|
allocatedThreadId = threadDatabase.getThreadIdFor(message.getRecipient(), message.getDistributionType());
|
||||||
} else {
|
} else {
|
||||||
allocatedThreadId = threadId;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
public static void resendGroupMessage(Context context, MessageRecord messageRecord, Address filterAddress) {
|
||||||
|
Loading…
Reference in New Issue
Block a user