mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-05 18:15:40 +00:00
commit
cbada40a6e
@ -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;
|
||||||
@ -2185,6 +2186,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
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());
|
||||||
|
@ -739,7 +739,12 @@ public class AttachmentDatabase extends Database {
|
|||||||
|
|
||||||
if (thumbnailUri != null) {
|
if (thumbnailUri != null) {
|
||||||
try (InputStream attachmentStream = PartAuthority.getAttachmentStream(context, thumbnailUri)) {
|
try (InputStream attachmentStream = PartAuthority.getAttachmentStream(context, thumbnailUri)) {
|
||||||
Pair<Integer, Integer> dimens = BitmapUtil.getDimensions(attachmentStream);
|
Pair<Integer, Integer> dimens;
|
||||||
|
if (attachment.getContentType().equals(MediaUtil.IMAGE_GIF)) {
|
||||||
|
dimens = new Pair<>(attachment.getWidth(), attachment.getHeight());
|
||||||
|
} else {
|
||||||
|
dimens = BitmapUtil.getDimensions(attachmentStream);
|
||||||
|
}
|
||||||
updateAttachmentThumbnail(attachmentId,
|
updateAttachmentThumbnail(attachmentId,
|
||||||
PartAuthority.getAttachmentStream(context, thumbnailUri),
|
PartAuthority.getAttachmentStream(context, thumbnailUri),
|
||||||
(float) dimens.first / (float) dimens.second);
|
(float) dimens.first / (float) dimens.second);
|
||||||
|
@ -946,14 +946,14 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
} else {
|
} else {
|
||||||
notifyTypingStoppedFromIncomingMessage(recipient, content.getSender(), content.getSenderDevice());
|
notifyTypingStoppedFromIncomingMessage(recipient, content.getSender(), content.getSenderDevice());
|
||||||
|
|
||||||
IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromSerialized(content.getSender()),
|
IncomingTextMessage _textMessage = new IncomingTextMessage(Address.fromSerialized(content.getSender()),
|
||||||
content.getSenderDevice(),
|
content.getSenderDevice(),
|
||||||
message.getTimestamp(), body,
|
message.getTimestamp(), body,
|
||||||
message.getGroupInfo(),
|
message.getGroupInfo(),
|
||||||
message.getExpiresInSeconds() * 1000L,
|
message.getExpiresInSeconds() * 1000L,
|
||||||
content.isNeedsReceipt());
|
content.isNeedsReceipt());
|
||||||
|
|
||||||
textMessage = new IncomingEncryptedMessage(textMessage, body);
|
IncomingEncryptedMessage textMessage = new IncomingEncryptedMessage(_textMessage, body);
|
||||||
|
|
||||||
List<Link> urls = LinkPreviewUtil.findWhitelistedUrls(body);
|
List<Link> urls = LinkPreviewUtil.findWhitelistedUrls(body);
|
||||||
int urlCount = urls.size();
|
int urlCount = urls.size();
|
||||||
@ -978,9 +978,34 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
} if (LinkPreviewUtil.isWhitelistedMediaUrl(body)) {
|
||||||
|
new LinkPreviewRepository(context).fetchGIF(context, body, attachmentOrNull -> Util.runOnMain(() -> {
|
||||||
|
if (attachmentOrNull.isPresent()) {
|
||||||
|
Attachment attachment = attachmentOrNull.get();
|
||||||
|
try {
|
||||||
|
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Address.fromExternal(context, content.getSender()), message.getTimestamp(), -1,
|
||||||
|
message.getExpiresInSeconds() * 1000L, false, content.isNeedsReceipt(), message.getBody(), message.getGroupInfo(), Optional.of(new ArrayList<>()),
|
||||||
|
Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent());
|
||||||
|
mediaMessage.getAttachments().add(attachment);
|
||||||
|
handleMediaMessage(content, mediaMessage, smsMessageId, messageServerIDOrNull);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: Handle
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
handleTextMessage(message, textMessage, smsMessageId, messageServerIDOrNull);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
handleTextMessage(message, textMessage, smsMessageId, messageServerIDOrNull);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleTextMessage(@NonNull SignalServiceDataMessage message, @NonNull IncomingTextMessage textMessage, @NonNull Optional<Long> smsMessageId, @NonNull Optional<Long> messageServerIDOrNull) {
|
||||||
|
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
||||||
Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage);
|
Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage);
|
||||||
|
|
||||||
|
Long threadId;
|
||||||
if (insertResult.isPresent()) threadId = insertResult.get().getThreadId();
|
if (insertResult.isPresent()) threadId = insertResult.get().getThreadId();
|
||||||
else threadId = null;
|
else threadId = null;
|
||||||
|
|
||||||
@ -994,8 +1019,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
MessageNotifier.updateNotification(context, threadId);
|
MessageNotifier.updateNotification(context, threadId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateGroupChatMessageServerID(Optional<Long> messageServerIDOrNull, Optional<InsertResult> insertResult) {
|
private void updateGroupChatMessageServerID(Optional<Long> messageServerIDOrNull, Optional<InsertResult> insertResult) {
|
||||||
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
||||||
|
@ -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());
|
||||||
|
|
||||||
|
@ -8,8 +8,10 @@ import android.text.Html;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
|
import com.bumptech.glide.load.resource.gif.GifDrawable;
|
||||||
import com.bumptech.glide.request.FutureTarget;
|
import com.bumptech.glide.request.FutureTarget;
|
||||||
|
|
||||||
|
import com.bumptech.glide.util.ByteBufferUtil;
|
||||||
import org.thoughtcrime.securesms.ApplicationContext;
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||||
import org.thoughtcrime.securesms.attachments.UriAttachment;
|
import org.thoughtcrime.securesms.attachments.UriAttachment;
|
||||||
@ -150,6 +152,28 @@ public class LinkPreviewRepository implements InjectableType {
|
|||||||
return new CallRequestController(call);
|
return new CallRequestController(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull RequestController fetchGIF(@NonNull Context context, @NonNull String url, @NonNull Callback<Optional<Attachment>> callback) {
|
||||||
|
FutureTarget<GifDrawable> future = GlideApp.with(context).asGif().load(new ChunkedImageUrl(url)).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||||
|
.centerInside().submit(1024, 1024);
|
||||||
|
RequestController controller = () -> future.cancel(false);
|
||||||
|
SignalExecutors.UNBOUNDED.execute(() -> {
|
||||||
|
try {
|
||||||
|
GifDrawable gif = future.get();
|
||||||
|
byte[] bytes = ByteBufferUtil.toBytes(gif.getBuffer());
|
||||||
|
Uri uri = BlobProvider.getInstance().forData(bytes).createForSingleSessionInMemory();
|
||||||
|
Optional<Attachment> thumbnail = Optional.of(new UriAttachment(uri, uri, MediaUtil.IMAGE_GIF, AttachmentDatabase.TRANSFER_PROGRESS_DONE,
|
||||||
|
bytes.length, gif.getIntrinsicWidth(), gif.getIntrinsicHeight(), null, null, false, false, null, null));
|
||||||
|
callback.onComplete(thumbnail);
|
||||||
|
} catch (CancellationException | ExecutionException | InterruptedException e) {
|
||||||
|
controller.cancel();
|
||||||
|
callback.onComplete(Optional.absent());
|
||||||
|
} finally {
|
||||||
|
future.cancel(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return () -> future.cancel(true);
|
||||||
|
}
|
||||||
|
|
||||||
private @NonNull RequestController fetchThumbnail(@NonNull Context context, @NonNull String imageUrl, @NonNull Callback<Optional<Attachment>> callback) {
|
private @NonNull RequestController fetchThumbnail(@NonNull Context context, @NonNull String imageUrl, @NonNull Callback<Optional<Attachment>> callback) {
|
||||||
FutureTarget<Bitmap> bitmapFuture = GlideApp.with(context).asBitmap()
|
FutureTarget<Bitmap> bitmapFuture = GlideApp.with(context).asBitmap()
|
||||||
.load(new ChunkedImageUrl(imageUrl))
|
.load(new ChunkedImageUrl(imageUrl))
|
||||||
|
@ -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,7 +96,6 @@ 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);
|
||||||
|
|
||||||
@ -106,15 +108,30 @@ public class MessageSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Recipient recipient = message.getRecipient();
|
Recipient recipient = message.getRecipient();
|
||||||
long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener);
|
|
||||||
|
|
||||||
|
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());
|
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;
|
return allocatedThreadId;
|
||||||
} catch (MmsException e) {
|
|
||||||
Log.w(TAG, e);
|
|
||||||
return threadId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resendGroupMessage(Context context, MessageRecord messageRecord, Address filterAddress) {
|
public static void resendGroupMessage(Context context, MessageRecord messageRecord, Address filterAddress) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user