mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
further cleaning up on stickers
This commit is contained in:
parent
fc62fe3b23
commit
ff36fbb6a1
@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
|
||||
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview;
|
||||
import org.session.libsession.messaging.threads.Address;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
|
@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.mediasend.Media;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.session.libsession.utilities.ViewUtil;
|
||||
|
||||
@ -229,11 +228,9 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
final Intent intent = new Intent(this, target);
|
||||
final String textExtra = getIntent().getStringExtra(Intent.EXTRA_TEXT);
|
||||
final ArrayList<Media> mediaExtra = getIntent().getParcelableArrayListExtra(ConversationActivity.MEDIA_EXTRA);
|
||||
final StickerLocator stickerExtra = getIntent().getParcelableExtra(ConversationActivity.STICKER_EXTRA);
|
||||
|
||||
intent.putExtra(ConversationActivity.TEXT_EXTRA, textExtra);
|
||||
intent.putExtra(ConversationActivity.MEDIA_EXTRA, mediaExtra);
|
||||
intent.putExtra(ConversationActivity.STICKER_EXTRA, stickerExtra);
|
||||
|
||||
if (resolvedExtra != null) intent.setDataAndType(resolvedExtra, mimeType);
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment
|
||||
public class MmsNotificationAttachment extends Attachment {
|
||||
|
||||
public MmsNotificationAttachment(int status, long size) {
|
||||
super("application/mms", getTransferStateFromStatus(status), size, null, null, null, null, null, null, false, 0, 0, false, null, null, "");
|
||||
super("application/mms", getTransferStateFromStatus(status), size, null, null, null, null, null, null, false, 0, 0, false, null, "");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -234,7 +234,6 @@ public class QuoteView extends FrameLayout implements RecipientModifiedListener
|
||||
List<Slide> documentSlides = Stream.of(attachments.getSlides()).filter(Slide::hasDocument).limit(1).toList();
|
||||
List<Slide> imageSlides = Stream.of(attachments.getSlides()).filter(Slide::hasImage).limit(1).toList();
|
||||
List<Slide> videoSlides = Stream.of(attachments.getSlides()).filter(Slide::hasVideo).limit(1).toList();
|
||||
List<Slide> stickerSlides = Stream.of(attachments.getSlides()).filter(Slide::hasSticker).limit(1).toList();
|
||||
|
||||
// Given that most types have images, we specifically check images last
|
||||
if (!audioSlides.isEmpty()) {
|
||||
@ -243,15 +242,13 @@ public class QuoteView extends FrameLayout implements RecipientModifiedListener
|
||||
mediaDescriptionText.setVisibility(GONE);
|
||||
} else if (!videoSlides.isEmpty()) {
|
||||
mediaDescriptionText.setText(R.string.QuoteView_video);
|
||||
} else if (!stickerSlides.isEmpty()) {
|
||||
mediaDescriptionText.setText(R.string.QuoteView_sticker);
|
||||
} else if (!imageSlides.isEmpty()) {
|
||||
mediaDescriptionText.setText(R.string.QuoteView_photo);
|
||||
}
|
||||
}
|
||||
|
||||
private void setQuoteAttachment(@NonNull GlideRequests glideRequests, @NonNull SlideDeck slideDeck) {
|
||||
List<Slide> imageVideoSlides = Stream.of(slideDeck.getSlides()).filter(s -> s.hasImage() || s.hasVideo() || s.hasSticker()).limit(1).toList();
|
||||
List<Slide> imageVideoSlides = Stream.of(slideDeck.getSlides()).filter(s -> s.hasImage() || s.hasVideo()).limit(1).toList();
|
||||
List<Slide> documentSlides = Stream.of(attachments.getSlides()).filter(Slide::hasDocument).limit(1).toList();
|
||||
|
||||
attachmentVideoOverlayView.setVisibility(GONE);
|
||||
|
@ -159,7 +159,6 @@ import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.QuoteId;
|
||||
import org.thoughtcrime.securesms.mms.Slide;
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||
import org.thoughtcrime.securesms.mms.StickerSlide;
|
||||
import org.thoughtcrime.securesms.mms.TextSlide;
|
||||
import org.thoughtcrime.securesms.mms.VideoSlide;
|
||||
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
|
||||
@ -170,7 +169,6 @@ import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.messaging.threads.recipients.RecipientFormattingException;
|
||||
import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.search.model.MessageResult;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||
import org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage;
|
||||
import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage;
|
||||
@ -185,7 +183,6 @@ import org.session.libsession.utilities.Util;
|
||||
import org.session.libsession.messaging.sending_receiving.sharecontacts.Contact;
|
||||
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview;
|
||||
import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
|
||||
import org.session.libsession.messaging.threads.GroupRecord;
|
||||
import org.session.libsession.utilities.ExpirationUtil;
|
||||
import org.session.libsession.utilities.views.Stub;
|
||||
@ -1157,12 +1154,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
final Uri draftMedia = getIntent().getData();
|
||||
final MediaType draftMediaType = MediaType.from(getIntent().getType());
|
||||
final List<Media> mediaList = getIntent().getParcelableArrayListExtra(MEDIA_EXTRA);
|
||||
final StickerLocator stickerLocator = getIntent().getParcelableExtra(STICKER_EXTRA);
|
||||
|
||||
if (stickerLocator != null && draftMedia != null) {
|
||||
sendSticker(stickerLocator, draftMedia, 0, true);
|
||||
return new SettableFuture<>(false);
|
||||
}
|
||||
|
||||
if (!Util.isEmpty(mediaList)) {
|
||||
Intent sendIntent = MediaSendActivity.buildEditorIntent(this, mediaList, recipient, draftText);
|
||||
@ -2085,19 +2076,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
linkPreviewViewModel.onTextChanged(this, composeText.getTextTrimmed(), start, end);
|
||||
}
|
||||
|
||||
private void sendSticker(@NonNull StickerLocator stickerLocator, @NonNull Uri uri, long size, boolean clearCompose) {
|
||||
long expiresIn = recipient.getExpireMessages() * 1000L;
|
||||
int subscriptionId = -1;
|
||||
boolean initiating = threadId == -1;
|
||||
SlideDeck slideDeck = new SlideDeck();
|
||||
Slide stickerSlide = new StickerSlide(this, uri, size, stickerLocator);
|
||||
|
||||
slideDeck.addSlide(stickerSlide);
|
||||
|
||||
sendMediaMessage(false, "", slideDeck, null, Collections.emptyList(), Collections.emptyList(), expiresIn, subscriptionId, initiating, clearCompose);
|
||||
|
||||
}
|
||||
|
||||
private void silentlySetComposeText(String text) {
|
||||
typingTextWatcher.setEnabled(false);
|
||||
composeText.setText(text);
|
||||
|
@ -339,10 +339,6 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||
if (slideDeck.getThumbnailSlide() != null && slideDeck.getThumbnailSlide().getFastPreflightId() != null) {
|
||||
return Long.valueOf(slideDeck.getThumbnailSlide().getFastPreflightId());
|
||||
}
|
||||
|
||||
if (slideDeck.getStickerSlide() != null && slideDeck.getStickerSlide().getFastPreflightId() != null) {
|
||||
return Long.valueOf(slideDeck.getStickerSlide().getFastPreflightId());
|
||||
}
|
||||
}
|
||||
|
||||
return record.getId();
|
||||
|
@ -94,7 +94,6 @@ import org.session.libsignal.service.loki.api.opengroups.PublicChat;
|
||||
import org.session.libsignal.service.loki.api.opengroups.PublicChatAPI;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
|
||||
import org.session.libsession.utilities.TextSecurePreferences;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsession.utilities.ViewUtil;
|
||||
@ -384,8 +383,7 @@ public class ConversationFragment extends Fragment
|
||||
menu.findItem(R.id.menu_context_save_attachment).setVisible(!actionMessage &&
|
||||
messageRecord.isMms() &&
|
||||
!messageRecord.isMmsNotification() &&
|
||||
((MediaMmsMessageRecord)messageRecord).containsMediaSlide() &&
|
||||
((MediaMmsMessageRecord)messageRecord).getSlideDeck().getStickerSlide() == null);
|
||||
((MediaMmsMessageRecord)messageRecord).containsMediaSlide());
|
||||
|
||||
menu.findItem(R.id.menu_context_reply).setVisible(!actionMessage &&
|
||||
!messageRecord.isPending() &&
|
||||
@ -653,8 +651,7 @@ public class ConversationFragment extends Fragment
|
||||
boolean isAlbum = mediaMessage.containsMediaSlide() &&
|
||||
mediaMessage.getSlideDeck().getSlides().size() > 1 &&
|
||||
mediaMessage.getSlideDeck().getAudioSlide() == null &&
|
||||
mediaMessage.getSlideDeck().getDocumentSlide() == null &&
|
||||
mediaMessage.getSlideDeck().getStickerSlide() == null;
|
||||
mediaMessage.getSlideDeck().getDocumentSlide() == null;
|
||||
|
||||
if (isAlbum) {
|
||||
ArrayList<Media> mediaList = new ArrayList<>(mediaMessage.getSlideDeck().getSlides().size());
|
||||
@ -685,10 +682,6 @@ public class ConversationFragment extends Fragment
|
||||
Slide slide = mediaMessage.getSlideDeck().getSlides().get(0);
|
||||
composeIntent.putExtra(Intent.EXTRA_STREAM, slide.getUri());
|
||||
composeIntent.setType(slide.getContentType());
|
||||
|
||||
if (slide.hasSticker()) {
|
||||
composeIntent.putExtra(ConversationActivity.STICKER_EXTRA, slide.asAttachment().getSticker());
|
||||
}
|
||||
}
|
||||
|
||||
if (mediaMessage.getSlideDeck().getTextSlide() != null && mediaMessage.getSlideDeck().getTextSlide().getUri() != null) {
|
||||
|
@ -398,15 +398,10 @@ public class ConversationItem extends LinearLayout
|
||||
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getThumbnailSlide() != null;
|
||||
}
|
||||
|
||||
private boolean hasSticker(MessageRecord messageRecord) {
|
||||
return messageRecord.isMms() && ((MmsMessageRecord)messageRecord).getSlideDeck().getStickerSlide() != null;
|
||||
}
|
||||
|
||||
private boolean hasOnlyThumbnail(MessageRecord messageRecord) {
|
||||
return hasThumbnail(messageRecord) &&
|
||||
!hasAudio(messageRecord) &&
|
||||
!hasDocument(messageRecord) &&
|
||||
!hasSticker(messageRecord);
|
||||
!hasDocument(messageRecord);
|
||||
}
|
||||
|
||||
private boolean hasOnlyDocument(MessageRecord messageRecord) {
|
||||
@ -414,7 +409,6 @@ public class ConversationItem extends LinearLayout
|
||||
!hasThumbnail(messageRecord) &&
|
||||
!hasAudio(messageRecord) &&
|
||||
hasDocument(messageRecord) &&
|
||||
!hasSticker(messageRecord) &&
|
||||
!hasQuote(messageRecord);
|
||||
}
|
||||
|
||||
@ -423,7 +417,6 @@ public class ConversationItem extends LinearLayout
|
||||
!hasThumbnail(messageRecord) &&
|
||||
!hasAudio(messageRecord) &&
|
||||
!hasDocument(messageRecord) &&
|
||||
!hasSticker(messageRecord) &&
|
||||
!hasQuote(messageRecord);
|
||||
}
|
||||
|
||||
@ -596,26 +589,6 @@ public class ConversationItem extends LinearLayout
|
||||
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
footer.setVisibility(VISIBLE);
|
||||
} else if (hasSticker(messageRecord) && isCaptionlessMms(messageRecord)) {
|
||||
bodyBubble.setBackgroundColor(Color.TRANSPARENT);
|
||||
|
||||
stickerStub.get().setVisibility(View.VISIBLE);
|
||||
if (mediaThumbnailStub.resolved()) mediaThumbnailStub.get().setVisibility(View.GONE);
|
||||
if (audioViewStub.resolved()) audioViewStub.get().setVisibility(View.GONE);
|
||||
if (documentViewStub.resolved()) documentViewStub.get().setVisibility(View.GONE);
|
||||
if (linkPreviewStub.resolved()) linkPreviewStub.get().setVisibility(GONE);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
stickerStub.get().setSticker(glideRequests, ((MmsMessageRecord) messageRecord).getSlideDeck().getStickerSlide());
|
||||
stickerStub.get().setThumbnailClickListener(new StickerClickListener());
|
||||
stickerStub.get().setDownloadClickListener(downloadClickListener);
|
||||
stickerStub.get().setOnLongClickListener(passthroughClickListener);
|
||||
stickerStub.get().setOnClickListener(passthroughClickListener);
|
||||
|
||||
ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
footer.setVisibility(VISIBLE);
|
||||
} else if (hasThumbnail(messageRecord)) {
|
||||
mediaThumbnailStub.get().setVisibility(View.VISIBLE);
|
||||
@ -870,9 +843,7 @@ public class ConversationItem extends LinearLayout
|
||||
}
|
||||
|
||||
private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) {
|
||||
if (hasSticker(messageRecord)) {
|
||||
return stickerFooter;
|
||||
} else if (hasOnlyThumbnail(messageRecord) && TextUtils.isEmpty(messageRecord.getDisplayBody(getContext()))) {
|
||||
if (hasOnlyThumbnail(messageRecord) && TextUtils.isEmpty(messageRecord.getDisplayBody(getContext()))) {
|
||||
return mediaThumbnailStub.get().getFooter();
|
||||
} else {
|
||||
return footer;
|
||||
@ -916,13 +887,8 @@ public class ConversationItem extends LinearLayout
|
||||
}
|
||||
|
||||
private void setGroupAuthorColor(@NonNull MessageRecord messageRecord) {
|
||||
if (hasSticker(messageRecord)) {
|
||||
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
|
||||
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
|
||||
} else {
|
||||
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
|
||||
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
|
||||
}
|
||||
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
|
||||
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
|
||||
}
|
||||
|
||||
private void setAuthor(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
||||
|
@ -51,7 +51,6 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachmentAudioExtras;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
|
||||
|
||||
import org.session.libsignal.utilities.JsonUtil;
|
||||
import org.session.libsession.utilities.Util;
|
||||
@ -504,7 +503,6 @@ public class AttachmentDatabase extends Database {
|
||||
mediaStream.getHeight(),
|
||||
databaseAttachment.isQuote(),
|
||||
databaseAttachment.getCaption(),
|
||||
databaseAttachment.getSticker(),
|
||||
databaseAttachment.getUrl());
|
||||
}
|
||||
|
||||
@ -689,11 +687,7 @@ public class AttachmentDatabase extends Database {
|
||||
object.getInt(HEIGHT),
|
||||
object.getInt(QUOTE) == 1,
|
||||
object.getString(CAPTION),
|
||||
object.getInt(STICKER_ID) >= 0
|
||||
? new StickerLocator(object.getString(STICKER_PACK_ID),
|
||||
object.getString(STICKER_PACK_KEY),
|
||||
object.getInt(STICKER_ID))
|
||||
: null, "")); // TODO: Not sure if this will break something
|
||||
"")); // TODO: Not sure if this will break something
|
||||
}
|
||||
}
|
||||
|
||||
@ -719,11 +713,6 @@ public class AttachmentDatabase extends Database {
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(HEIGHT)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(QUOTE)) == 1,
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(CAPTION)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(STICKER_ID)) >= 0
|
||||
? new StickerLocator(cursor.getString(cursor.getColumnIndexOrThrow(STICKER_PACK_ID)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(STICKER_PACK_KEY)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(STICKER_ID)))
|
||||
: null,
|
||||
urlIndex > 0 ? cursor.getString(urlIndex) : ""));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
@ -765,19 +754,12 @@ public class AttachmentDatabase extends Database {
|
||||
contentValues.put(CAPTION, attachment.getCaption());
|
||||
contentValues.put(URL, attachment.getUrl());
|
||||
|
||||
if (attachment.isSticker()) {
|
||||
contentValues.put(STICKER_PACK_ID, attachment.getSticker().getPackId());
|
||||
contentValues.put(STICKER_PACK_KEY, attachment.getSticker().getPackKey());
|
||||
contentValues.put(STICKER_ID, attachment.getSticker().getStickerId());
|
||||
}
|
||||
|
||||
if (dataInfo != null) {
|
||||
contentValues.put(DATA, dataInfo.file.getAbsolutePath());
|
||||
contentValues.put(SIZE, dataInfo.length);
|
||||
contentValues.put(DATA_RANDOM, dataInfo.random);
|
||||
}
|
||||
|
||||
boolean notifyPacks = attachment.isSticker() && !hasStickerAttachments();
|
||||
long rowId = database.insert(TABLE_NAME, null, contentValues);
|
||||
AttachmentId attachmentId = new AttachmentId(rowId, uniqueId);
|
||||
Uri thumbnailUri = attachment.getThumbnailUri();
|
||||
@ -817,10 +799,6 @@ public class AttachmentDatabase extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
if (notifyPacks) {
|
||||
notifyStickerPackListeners();
|
||||
}
|
||||
|
||||
return attachmentId;
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ public class GroupManager {
|
||||
|
||||
if (avatar != null) {
|
||||
Uri avatarUri = BlobProvider.getInstance().forData(avatar).createForSingleUseInMemory();
|
||||
avatarAttachment = new UriAttachment(avatarUri, MediaTypes.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false, false, null, null);
|
||||
avatarAttachment = new UriAttachment(avatarUri, MediaTypes.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false, false, null);
|
||||
}
|
||||
|
||||
OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, 0, null, Collections.emptyList(), Collections.emptyList());
|
||||
|
@ -94,8 +94,8 @@ public class AttachmentUploadJob extends BaseJob implements InjectableType {
|
||||
MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints();
|
||||
Attachment scaledAttachment = scaleAndStripExif(database, mediaConstraints, databaseAttachment);
|
||||
SignalServiceAttachment localAttachment = getAttachmentFor(scaledAttachment);
|
||||
SignalServiceAttachmentPointer remoteAttachment = messageSender.uploadAttachment(localAttachment.asStream(), databaseAttachment.isSticker(), new SignalServiceAddress(destination.serialize()));
|
||||
attachment = PointerAttachment.forPointer(Optional.of(remoteAttachment), null, databaseAttachment.getFastPreflightId()).get();
|
||||
SignalServiceAttachmentPointer remoteAttachment = messageSender.uploadAttachment(localAttachment.asStream(), false, new SignalServiceAddress(destination.serialize()));
|
||||
attachment = PointerAttachment.forPointer(Optional.of(remoteAttachment), databaseAttachment.getFastPreflightId()).get();
|
||||
} catch (Exception e) {
|
||||
// On any error make sure we mark the related DB record's transfer state as failed.
|
||||
database.updateAttachmentAfterUploadFailed(databaseAttachment.getAttachmentId());
|
||||
|
@ -375,10 +375,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
|
||||
if (insertResult.isPresent()) {
|
||||
List<DatabaseAttachment> allAttachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
|
||||
List<DatabaseAttachment> stickerAttachments = Stream.of(allAttachments).filter(Attachment::isSticker).toList();
|
||||
List<DatabaseAttachment> dbAttachments = Stream.of(allAttachments).filterNot(Attachment::isSticker).toList();
|
||||
|
||||
forceStickerDownloadIfNecessary(stickerAttachments);
|
||||
List<DatabaseAttachment> dbAttachments = Stream.of(allAttachments).toList();
|
||||
|
||||
for (DatabaseAttachment attachment : dbAttachments) {
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new AttachmentDownloadJob(insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
|
||||
@ -419,10 +416,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
|
||||
if (insertResult.isPresent()) {
|
||||
List<DatabaseAttachment> allAttachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
|
||||
List<DatabaseAttachment> stickerAttachments = Stream.of(allAttachments).filter(Attachment::isSticker).toList();
|
||||
List<DatabaseAttachment> attachments = Stream.of(allAttachments).filterNot(Attachment::isSticker).toList();
|
||||
|
||||
forceStickerDownloadIfNecessary(stickerAttachments);
|
||||
List<DatabaseAttachment> attachments = Stream.of(allAttachments).toList();
|
||||
|
||||
for (DatabaseAttachment attachment : attachments) {
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new AttachmentDownloadJob(insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
|
||||
@ -866,25 +860,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
}
|
||||
}
|
||||
|
||||
private void forceStickerDownloadIfNecessary(List<DatabaseAttachment> stickerAttachments) {
|
||||
if (stickerAttachments.isEmpty()) return;
|
||||
|
||||
DatabaseAttachment stickerAttachment = stickerAttachments.get(0);
|
||||
|
||||
if (stickerAttachment.getTransferState() != AttachmentDatabase.TRANSFER_PROGRESS_DONE) {
|
||||
AttachmentDownloadJob downloadJob = new AttachmentDownloadJob(messageId, stickerAttachment.getAttachmentId(), true);
|
||||
|
||||
try {
|
||||
ApplicationContext.getInstance(context).injectDependencies(downloadJob);
|
||||
downloadJob.setContext(context);
|
||||
downloadJob.doWork();
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Failed to download sticker inline. Scheduling.");
|
||||
ApplicationContext.getInstance(context).getJobManager().add(downloadJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
private static class StorageFailedException extends Exception {
|
||||
private final String sender;
|
||||
|
@ -238,7 +238,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
if (message.isGroup() && address.isClosedGroup()) {
|
||||
SignalServiceGroup.GroupType groupType = address.isOpenGroup() ? SignalServiceGroup.GroupType.PUBLIC_CHAT : SignalServiceGroup.GroupType.SIGNAL;
|
||||
String groupId = address.toGroupString();
|
||||
List<Attachment> attachments = Stream.of(message.getAttachments()).filterNot(Attachment::isSticker).toList();
|
||||
List<Attachment> attachments = Stream.of(message.getAttachments()).toList();
|
||||
List<SignalServiceAttachment> attachmentPointers = getAttachmentPointersFor(attachments);
|
||||
// Loki - Only send GroupUpdate or GroupQuit messages to closed groups
|
||||
OutgoingGroupMediaMessage groupMessage = (OutgoingGroupMediaMessage) message;
|
||||
@ -269,7 +269,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
Optional<Quote> quote = getQuoteFor(message);
|
||||
List<SharedContact> sharedContacts = getSharedContactsFor(message);
|
||||
List<Preview> previews = getPreviewsFor(message);
|
||||
List<Attachment> attachments = Stream.of(message.getAttachments()).filterNot(Attachment::isSticker).toList();
|
||||
List<Attachment> attachments = Stream.of(message.getAttachments()).toList();
|
||||
List<SignalServiceAttachment> attachmentPointers = getAttachmentPointersFor(attachments);
|
||||
|
||||
SignalServiceGroup group = new SignalServiceGroup(GroupUtil.getDecodedGroupIDAsData(groupId), groupType);
|
||||
|
@ -225,7 +225,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
||||
String userPublicKey = TextSecurePreferences.getLocalNumber(context);
|
||||
SignalServiceAddress address = getPushAddress(recipient.getAddress());
|
||||
SignalServiceAddress localAddress = new SignalServiceAddress(userPublicKey);
|
||||
List<Attachment> attachments = Stream.of(message.getAttachments()).filterNot(Attachment::isSticker).toList();
|
||||
List<Attachment> attachments = Stream.of(message.getAttachments()).toList();
|
||||
List<SignalServiceAttachment> serviceAttachments = getAttachmentPointersFor(attachments);
|
||||
Optional<byte[]> profileKey = getProfileKey(message.getRecipient());
|
||||
Optional<SignalServiceDataMessage.Quote> quote = getQuoteFor(message);
|
||||
|
@ -200,7 +200,6 @@ public class LinkPreviewRepository implements InjectableType {
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
null));
|
||||
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class ApnUnavailableException extends Exception {
|
||||
|
||||
public ApnUnavailableException() {
|
||||
}
|
||||
|
||||
public ApnUnavailableException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public ApnUnavailableException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public ApnUnavailableException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
}
|
@ -34,11 +34,11 @@ import org.thoughtcrime.securesms.util.ResUtil;
|
||||
public class AudioSlide extends Slide {
|
||||
|
||||
public AudioSlide(Context context, Uri uri, long dataSize, boolean voiceNote) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.AUDIO_UNSPECIFIED, dataSize, 0, 0, false, null, null, null, voiceNote, false));
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.AUDIO_UNSPECIFIED, dataSize, 0, 0, false, null, null, voiceNote, false));
|
||||
}
|
||||
|
||||
public AudioSlide(Context context, Uri uri, long dataSize, String contentType, boolean voiceNote) {
|
||||
super(context, new UriAttachment(uri, null, contentType, AttachmentDatabase.TRANSFER_PROGRESS_STARTED, dataSize, 0, 0, null, null, voiceNote, false, null, null));
|
||||
super(context, new UriAttachment(uri, null, contentType, AttachmentDatabase.TRANSFER_PROGRESS_STARTED, dataSize, 0, 0, null, null, voiceNote, false, null));
|
||||
}
|
||||
|
||||
public AudioSlide(Context context, Attachment attachment) {
|
||||
|
@ -19,7 +19,7 @@ public class DocumentSlide extends Slide {
|
||||
@NonNull String contentType, long size,
|
||||
@Nullable String fileName)
|
||||
{
|
||||
super(context, constructAttachmentFromUri(context, uri, contentType, size, 0, 0, true, ExternalStorageUtil.getCleanFileName(fileName), null, null, false, false));
|
||||
super(context, constructAttachmentFromUri(context, uri, contentType, size, 0, 0, true, ExternalStorageUtil.getCleanFileName(fileName), null, false, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,7 @@ public class GifSlide extends ImageSlide {
|
||||
}
|
||||
|
||||
public GifSlide(Context context, Uri uri, long size, int width, int height, @Nullable String caption) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_GIF, size, width, height, true, null, caption, null, false, false));
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_GIF, size, width, height, true, null, caption, false, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,7 +41,7 @@ public class ImageSlide extends Slide {
|
||||
}
|
||||
|
||||
public ImageSlide(Context context, Uri uri, long size, int width, int height, @Nullable String caption) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_JPEG, size, width, height, true, null, caption, null, false, false));
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_JPEG, size, width, height, true, null, caption, false, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,12 +7,10 @@ import org.session.libsession.messaging.sending_receiving.sharecontacts.Contact;
|
||||
import org.session.libsession.messaging.threads.Address;
|
||||
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview;
|
||||
import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel;
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient;
|
||||
import org.session.libsession.utilities.GroupUtil;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
import org.session.libsignal.service.api.messages.SignalServiceAttachment;
|
||||
import org.session.libsignal.service.api.messages.SignalServiceGroup;
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
@ -26,10 +26,6 @@ public abstract class MediaConstraints {
|
||||
return new PushMediaConstraints();
|
||||
}
|
||||
|
||||
public static MediaConstraints getMmsMediaConstraints(int subscriptionId) {
|
||||
return new MmsMediaConstraints(subscriptionId);
|
||||
}
|
||||
|
||||
public abstract int getImageMaxWidth(Context context);
|
||||
public abstract int getImageMaxHeight(Context context);
|
||||
public abstract int getImageMaxSize(Context context);
|
||||
|
@ -1,52 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.mms.service_alt.MmsConfig;
|
||||
|
||||
import org.thoughtcrime.securesms.util.dualsim.SubscriptionInfoCompat;
|
||||
import org.thoughtcrime.securesms.util.dualsim.SubscriptionManagerCompat;
|
||||
import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class MmsConfigManager {
|
||||
|
||||
private static final Map<Integer, MmsConfig> mmsConfigMap = new HashMap<>();
|
||||
|
||||
@WorkerThread
|
||||
synchronized static @NonNull MmsConfig getMmsConfig(Context context, int subscriptionId) {
|
||||
MmsConfig mmsConfig = mmsConfigMap.get(subscriptionId);
|
||||
if (mmsConfig != null) {
|
||||
return mmsConfig;
|
||||
}
|
||||
|
||||
MmsConfig loadedConfig = loadMmsConfig(context, subscriptionId);
|
||||
|
||||
mmsConfigMap.put(subscriptionId, loadedConfig);
|
||||
|
||||
return loadedConfig;
|
||||
}
|
||||
|
||||
private static @NonNull MmsConfig loadMmsConfig(Context context, int subscriptionId) {
|
||||
Optional<SubscriptionInfoCompat> subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId);
|
||||
|
||||
if (subscriptionInfo.isPresent()) {
|
||||
SubscriptionInfoCompat subscriptionInfoCompat = subscriptionInfo.get();
|
||||
Configuration configuration = context.getResources().getConfiguration();
|
||||
configuration.mcc = subscriptionInfoCompat.getMcc();
|
||||
configuration.mnc = subscriptionInfoCompat.getMnc();
|
||||
|
||||
Context subContext = context.createConfigurationContext(configuration);
|
||||
return new MmsConfig(subContext, subscriptionId);
|
||||
}
|
||||
|
||||
return new MmsConfig(context, subscriptionId);
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.mms.service_alt.MmsConfig;
|
||||
|
||||
final class MmsMediaConstraints extends MediaConstraints {
|
||||
|
||||
private final int subscriptionId;
|
||||
|
||||
private static final int MIN_IMAGE_DIMEN = 1024;
|
||||
|
||||
MmsMediaConstraints(int subscriptionId) {
|
||||
this.subscriptionId = subscriptionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageMaxWidth(Context context) {
|
||||
return Math.max(MIN_IMAGE_DIMEN, getOverriddenMmsConfig(context).getMaxImageWidth());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageMaxHeight(Context context) {
|
||||
return Math.max(MIN_IMAGE_DIMEN, getOverriddenMmsConfig(context).getMaxImageHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImageMaxSize(Context context) {
|
||||
return getMaxMessageSize(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGifMaxSize(Context context) {
|
||||
return getMaxMessageSize(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVideoMaxSize(Context context) {
|
||||
return getMaxMessageSize(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioMaxSize(Context context) {
|
||||
return getMaxMessageSize(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDocumentMaxSize(Context context) {
|
||||
return getMaxMessageSize(context);
|
||||
}
|
||||
|
||||
private int getMaxMessageSize(Context context) {
|
||||
return getOverriddenMmsConfig(context).getMaxMessageSize();
|
||||
}
|
||||
|
||||
private MmsConfig.Overridden getOverriddenMmsConfig(Context context) {
|
||||
MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(context, subscriptionId);
|
||||
|
||||
return new MmsConfig.Overridden(mmsConfig, null);
|
||||
}
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.PowerManager;
|
||||
import org.session.libsignal.utilities.logging.Log;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MmsRadio {
|
||||
|
||||
private static final String TAG = MmsRadio.class.getSimpleName();
|
||||
|
||||
private static MmsRadio instance;
|
||||
|
||||
public static synchronized MmsRadio getInstance(Context context) {
|
||||
if (instance == null)
|
||||
instance = new MmsRadio(context.getApplicationContext());
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
private static final String FEATURE_ENABLE_MMS = "enableMMS";
|
||||
private static final int APN_ALREADY_ACTIVE = 0;
|
||||
public static final int TYPE_MOBILE_MMS = 2;
|
||||
|
||||
private final Context context;
|
||||
|
||||
private ConnectivityManager connectivityManager;
|
||||
private ConnectivityListener connectivityListener;
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
private int connectedCounter = 0;
|
||||
|
||||
private MmsRadio(Context context) {
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
this.context = context;
|
||||
this.connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "signal:mms");
|
||||
this.wakeLock.setReferenceCounted(true);
|
||||
}
|
||||
|
||||
public synchronized void disconnect() {
|
||||
Log.i(TAG, "MMS Radio Disconnect Called...");
|
||||
wakeLock.release();
|
||||
connectedCounter--;
|
||||
|
||||
Log.i(TAG, "Reference count: " + connectedCounter);
|
||||
|
||||
if (connectedCounter == 0) {
|
||||
Log.i(TAG, "Turning off MMS radio...");
|
||||
try {
|
||||
final Method stopUsingNetworkFeatureMethod = connectivityManager.getClass().getMethod("stopUsingNetworkFeature", Integer.TYPE, String.class);
|
||||
stopUsingNetworkFeatureMethod.invoke(connectivityManager, ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
Log.w(TAG, nsme);
|
||||
} catch (IllegalAccessException iae) {
|
||||
Log.w(TAG, iae);
|
||||
} catch (InvocationTargetException ite) {
|
||||
Log.w(TAG, ite);
|
||||
}
|
||||
|
||||
if (connectivityListener != null) {
|
||||
Log.i(TAG, "Unregistering receiver...");
|
||||
context.unregisterReceiver(connectivityListener);
|
||||
connectivityListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void connect() throws MmsRadioException {
|
||||
int status;
|
||||
|
||||
try {
|
||||
final Method startUsingNetworkFeatureMethod = connectivityManager.getClass().getMethod("startUsingNetworkFeature", Integer.TYPE, String.class);
|
||||
status = (int)startUsingNetworkFeatureMethod.invoke(connectivityManager, ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
throw new MmsRadioException(nsme);
|
||||
} catch (IllegalAccessException iae) {
|
||||
throw new MmsRadioException(iae);
|
||||
} catch (InvocationTargetException ite) {
|
||||
throw new MmsRadioException(ite);
|
||||
}
|
||||
|
||||
Log.i(TAG, "startUsingNetworkFeature status: " + status);
|
||||
|
||||
if (status == APN_ALREADY_ACTIVE) {
|
||||
wakeLock.acquire();
|
||||
connectedCounter++;
|
||||
return;
|
||||
} else {
|
||||
wakeLock.acquire();
|
||||
connectedCounter++;
|
||||
|
||||
if (connectivityListener == null) {
|
||||
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
connectivityListener = new ConnectivityListener();
|
||||
context.registerReceiver(connectivityListener, filter);
|
||||
}
|
||||
|
||||
Util.wait(this, 30000);
|
||||
|
||||
if (!isConnected()) {
|
||||
Log.w(TAG, "Got back from connectivity wait, and not connected...");
|
||||
disconnect();
|
||||
throw new MmsRadioException("Unable to successfully enable MMS radio.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConnected() {
|
||||
NetworkInfo info = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
|
||||
|
||||
Log.i(TAG, "Connected: " + info);
|
||||
|
||||
if ((info == null) || (info.getType() != TYPE_MOBILE_MMS) || !info.isConnected())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isConnectivityPossible() {
|
||||
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
|
||||
|
||||
return networkInfo != null && networkInfo.isAvailable();
|
||||
}
|
||||
|
||||
private boolean isConnectivityFailure() {
|
||||
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
|
||||
|
||||
return networkInfo == null || networkInfo.getDetailedState() == NetworkInfo.DetailedState.FAILED;
|
||||
}
|
||||
|
||||
private synchronized void issueConnectivityChange() {
|
||||
if (isConnected()) {
|
||||
Log.i(TAG, "Notifying connected...");
|
||||
notifyAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isConnected() && (isConnectivityFailure() || !isConnectivityPossible())) {
|
||||
Log.i(TAG, "Notifying not connected...");
|
||||
notifyAll();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private class ConnectivityListener extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "Got connectivity change...");
|
||||
issueConnectivityChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class MmsRadioException extends Throwable {
|
||||
public MmsRadioException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public MmsRadioException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
public class MmsSendResult {
|
||||
|
||||
private final byte[] messageId;
|
||||
private final int responseStatus;
|
||||
|
||||
public MmsSendResult(byte[] messageId, int responseStatus) {
|
||||
this.messageId = messageId;
|
||||
this.responseStatus = responseStatus;
|
||||
}
|
||||
|
||||
public int getResponseStatus() {
|
||||
return responseStatus;
|
||||
}
|
||||
|
||||
public byte[] getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import com.google.android.mms.ContentType;
|
||||
import com.google.android.mms.pdu_alt.CharacterSets;
|
||||
import com.google.android.mms.pdu_alt.PduBody;
|
||||
import com.google.android.mms.pdu_alt.PduPart;
|
||||
|
||||
import org.session.libsignal.utilities.logging.Log;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
public class PartParser {
|
||||
public static String getMessageText(PduBody body) {
|
||||
String bodyText = null;
|
||||
|
||||
for (int i=0;i<body.getPartsNum();i++) {
|
||||
if (ContentType.isTextType(Util.toIsoString(body.getPart(i).getContentType()))) {
|
||||
String partText;
|
||||
|
||||
try {
|
||||
String characterSet = CharacterSets.getMimeName(body.getPart(i).getCharset());
|
||||
|
||||
if (characterSet.equals(CharacterSets.MIMENAME_ANY_CHARSET))
|
||||
characterSet = CharacterSets.MIMENAME_UTF_8;
|
||||
|
||||
if (body.getPart(i).getData() != null) {
|
||||
partText = new String(body.getPart(i).getData(), characterSet);
|
||||
} else {
|
||||
partText = "";
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.w("PartParser", e);
|
||||
partText = "Unsupported Encoding!";
|
||||
}
|
||||
|
||||
bodyText = (bodyText == null) ? partText : bodyText + " " + partText;
|
||||
}
|
||||
}
|
||||
|
||||
return bodyText;
|
||||
}
|
||||
|
||||
public static PduBody getSupportedMediaParts(PduBody body) {
|
||||
PduBody stripped = new PduBody();
|
||||
|
||||
for (int i=0;i<body.getPartsNum();i++) {
|
||||
if (isDisplayableMedia(body.getPart(i))) {
|
||||
stripped.addPart(body.getPart(i));
|
||||
}
|
||||
}
|
||||
|
||||
return stripped;
|
||||
}
|
||||
|
||||
public static int getSupportedMediaPartCount(PduBody body) {
|
||||
int partCount = 0;
|
||||
|
||||
for (int i=0;i<body.getPartsNum();i++) {
|
||||
if (isDisplayableMedia(body.getPart(i))) {
|
||||
partCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return partCount;
|
||||
}
|
||||
|
||||
public static boolean isImage(PduPart part) {
|
||||
return ContentType.isImageType(Util.toIsoString(part.getContentType()));
|
||||
}
|
||||
|
||||
public static boolean isAudio(PduPart part) {
|
||||
return ContentType.isAudioType(Util.toIsoString(part.getContentType()));
|
||||
}
|
||||
|
||||
public static boolean isVideo(PduPart part) {
|
||||
return ContentType.isVideoType(Util.toIsoString(part.getContentType()));
|
||||
}
|
||||
|
||||
public static boolean isText(PduPart part) {
|
||||
return ContentType.isTextType(Util.toIsoString(part.getContentType()));
|
||||
}
|
||||
|
||||
public static boolean isDisplayableMedia(PduPart part) {
|
||||
return isImage(part) || isAudio(part) || isVideo(part);
|
||||
}
|
||||
}
|
@ -29,7 +29,6 @@ import org.session.libsignal.libsignal.util.guava.Optional;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
@ -113,8 +112,6 @@ public abstract class Slide {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasSticker() { return false; }
|
||||
|
||||
public boolean hasVideo() {
|
||||
return false;
|
||||
}
|
||||
@ -167,7 +164,6 @@ public abstract class Slide {
|
||||
boolean hasThumbnail,
|
||||
@Nullable String fileName,
|
||||
@Nullable String caption,
|
||||
@Nullable StickerLocator stickerLocator,
|
||||
boolean voiceNote,
|
||||
boolean quote)
|
||||
{
|
||||
@ -184,8 +180,7 @@ public abstract class Slide {
|
||||
fastPreflightId,
|
||||
voiceNote,
|
||||
quote,
|
||||
caption,
|
||||
stickerLocator);
|
||||
caption);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,7 +88,7 @@ public class SlideDeck {
|
||||
|
||||
public boolean containsMediaSlide() {
|
||||
for (Slide slide : slides) {
|
||||
if (slide.hasImage() || slide.hasVideo() || slide.hasAudio() || slide.hasDocument() || slide.hasSticker()) {
|
||||
if (slide.hasImage() || slide.hasVideo() || slide.hasAudio() || slide.hasDocument()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -138,14 +138,4 @@ public class SlideDeck {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable StickerSlide getStickerSlide() {
|
||||
for (Slide slide: slides) {
|
||||
if (slide.hasSticker()) {
|
||||
return (StickerSlide)slide;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.net.Uri;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
|
||||
import org.session.libsession.utilities.MediaTypes;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
|
||||
public class StickerSlide extends Slide {
|
||||
|
||||
public static final int WIDTH = 512;
|
||||
public static final int HEIGHT = 512;
|
||||
|
||||
public StickerSlide(@NonNull Context context, @NonNull Attachment attachment) {
|
||||
super(context, attachment);
|
||||
}
|
||||
|
||||
public StickerSlide(Context context, Uri uri, long size, @NonNull StickerLocator stickerLocator) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_WEBP, size, WIDTH, HEIGHT, true, null, null, stickerLocator, false, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @DrawableRes int getPlaceholderRes(Theme theme) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Uri getThumbnailUri() {
|
||||
return getUri();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSticker() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getContentDescription() {
|
||||
return context.getString(R.string.Slide_sticker);
|
||||
}
|
||||
}
|
@ -16,6 +16,6 @@ public class TextSlide extends Slide {
|
||||
}
|
||||
|
||||
public TextSlide(@NonNull Context context, @NonNull Uri uri, @Nullable String filename, long size) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.LONG_TEXT, size, 0, 0, true, filename, null, null, false, false));
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.LONG_TEXT, size, 0, 0, true, filename, null, false, false));
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class VideoSlide extends Slide {
|
||||
}
|
||||
|
||||
public VideoSlide(Context context, Uri uri, long dataSize, @Nullable String caption) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.VIDEO_UNSPECIFIED, dataSize, 0, 0, MediaUtil.hasVideoThumbnail(uri), null, caption, null, false, false));
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaTypes.VIDEO_UNSPECIFIED, dataSize, 0, 0, MediaUtil.hasVideoThumbnail(uri), null, caption, false, false));
|
||||
}
|
||||
|
||||
public VideoSlide(Context context, Attachment attachment) {
|
||||
|
@ -472,9 +472,6 @@ public class DefaultMessageNotifier implements MessageNotifier {
|
||||
} else if (record.isMms() && !((MmsMessageRecord) record).getSharedContacts().isEmpty()) {
|
||||
Contact contact = ((MmsMessageRecord) record).getSharedContacts().get(0);
|
||||
body = ContactUtil.getStringSummary(context, contact);
|
||||
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getStickerSlide() != null) {
|
||||
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_sticker));
|
||||
slideDeck = ((MmsMessageRecord) record).getSlideDeck();
|
||||
} else if (record.isMms() && TextUtils.isEmpty(body) && !((MmsMessageRecord) record).getSlideDeck().getSlides().isEmpty()) {
|
||||
slideDeck = ((MediaMmsMessageRecord)record).getSlideDeck();
|
||||
body = SpanUtil.italic(slideDeck.getBody());
|
||||
|
@ -41,8 +41,7 @@ public class AttachmentUtil {
|
||||
|
||||
if (attachment.isVoiceNote() ||
|
||||
(MediaUtil.isAudio(attachment) && TextUtils.isEmpty(attachment.getFileName())) ||
|
||||
MediaUtil.isLongTextType(attachment.getContentType()) ||
|
||||
attachment.isSticker())
|
||||
MediaUtil.isLongTextType(attachment.getContentType()))
|
||||
{
|
||||
return true;
|
||||
} else if (isNonDocumentType(contentType)) {
|
||||
|
@ -27,7 +27,6 @@ import org.thoughtcrime.securesms.mms.ImageSlide;
|
||||
import org.thoughtcrime.securesms.mms.MmsSlide;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.mms.Slide;
|
||||
import org.thoughtcrime.securesms.mms.StickerSlide;
|
||||
import org.thoughtcrime.securesms.mms.TextSlide;
|
||||
import org.thoughtcrime.securesms.mms.VideoSlide;
|
||||
|
||||
@ -42,9 +41,7 @@ public class MediaUtil {
|
||||
|
||||
public static Slide getSlideForAttachment(Context context, Attachment attachment) {
|
||||
Slide slide = null;
|
||||
if (attachment.isSticker()) {
|
||||
slide = new StickerSlide(context, attachment);
|
||||
} else if (isGif(attachment.getContentType())) {
|
||||
if (isGif(attachment.getContentType())) {
|
||||
slide = new GifSlide(context, attachment);
|
||||
} else if (isImageType(attachment.getContentType())) {
|
||||
slide = new ImageSlide(context, attachment);
|
||||
|
@ -69,6 +69,6 @@ class Attachment {
|
||||
fun toDatabaseAttachment(): org.session.libsession.messaging.sending_receiving.attachments.Attachment {
|
||||
return DatabaseAttachment(null, 0, true, true, contentType, 0,
|
||||
sizeInBytes?.toLong() ?: 0, fileName, null, key.toString(), null, digest, null, kind == Kind.VOICE_MESSAGE,
|
||||
size?.width ?: 0, size?.height ?: 0, false, caption, null, url)
|
||||
size?.width ?: 0, size?.height ?: 0, false, caption, url)
|
||||
}
|
||||
}
|
@ -39,16 +39,13 @@ public abstract class Attachment {
|
||||
@Nullable
|
||||
private final String caption;
|
||||
|
||||
@Nullable
|
||||
private final StickerLocator stickerLocator;
|
||||
|
||||
// Loki
|
||||
private final String url;
|
||||
|
||||
public Attachment(@NonNull String contentType, int transferState, long size, @Nullable String fileName,
|
||||
@Nullable String location, @Nullable String key, @Nullable String relay,
|
||||
@Nullable byte[] digest, @Nullable String fastPreflightId, boolean voiceNote,
|
||||
int width, int height, boolean quote, @Nullable String caption, @Nullable StickerLocator stickerLocator, String url)
|
||||
int width, int height, boolean quote, @Nullable String caption, String url)
|
||||
{
|
||||
this.contentType = contentType;
|
||||
this.transferState = transferState;
|
||||
@ -63,7 +60,6 @@ public abstract class Attachment {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.quote = quote;
|
||||
this.stickerLocator = stickerLocator;
|
||||
this.caption = caption;
|
||||
this.url = url;
|
||||
}
|
||||
@ -138,14 +134,6 @@ public abstract class Attachment {
|
||||
return quote;
|
||||
}
|
||||
|
||||
public boolean isSticker() {
|
||||
return stickerLocator != null;
|
||||
}
|
||||
|
||||
public @Nullable StickerLocator getSticker() {
|
||||
return stickerLocator;
|
||||
}
|
||||
|
||||
public @Nullable String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ public class DatabaseAttachment extends Attachment {
|
||||
String fileName, String location, String key, String relay,
|
||||
byte[] digest, String fastPreflightId, boolean voiceNote,
|
||||
int width, int height, boolean quote, @Nullable String caption,
|
||||
@Nullable StickerLocator stickerLocator, String url)
|
||||
String url)
|
||||
{
|
||||
super(contentType, transferProgress, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, quote, caption, stickerLocator, url);
|
||||
super(contentType, transferProgress, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, quote, caption, url);
|
||||
this.attachmentId = attachmentId;
|
||||
this.hasData = hasData;
|
||||
this.hasThumbnail = hasThumbnail;
|
||||
|
@ -20,9 +20,9 @@ public class PointerAttachment extends Attachment {
|
||||
@Nullable String fileName, @NonNull String location,
|
||||
@Nullable String key, @Nullable String relay,
|
||||
@Nullable byte[] digest, @Nullable String fastPreflightId, boolean voiceNote,
|
||||
int width, int height, @Nullable String caption, @Nullable StickerLocator stickerLocator, String url)
|
||||
int width, int height, @Nullable String caption, String url)
|
||||
{
|
||||
super(contentType, transferState, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, false, caption, stickerLocator, url);
|
||||
super(contentType, transferState, size, fileName, location, key, relay, digest, fastPreflightId, voiceNote, width, height, false, caption, url);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -87,14 +87,10 @@ public class PointerAttachment extends Attachment {
|
||||
}
|
||||
|
||||
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer) {
|
||||
return forPointer(pointer, null, null);
|
||||
return forPointer(pointer, null);
|
||||
}
|
||||
|
||||
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer, @Nullable StickerLocator stickerLocator) {
|
||||
return forPointer(pointer, stickerLocator, null);
|
||||
}
|
||||
|
||||
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer, @Nullable StickerLocator stickerLocator, @Nullable String fastPreflightId) {
|
||||
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer, @Nullable String fastPreflightId) {
|
||||
if (!pointer.isPresent() || !pointer.get().isPointer()) return Optional.absent();
|
||||
|
||||
String encodedKey = null;
|
||||
@ -115,7 +111,6 @@ public class PointerAttachment extends Attachment {
|
||||
pointer.get().asPointer().getWidth(),
|
||||
pointer.get().asPointer().getHeight(),
|
||||
pointer.get().asPointer().getCaption().orNull(),
|
||||
stickerLocator,
|
||||
pointer.get().asPointer().getUrl()));
|
||||
|
||||
}
|
||||
@ -134,7 +129,6 @@ public class PointerAttachment extends Attachment {
|
||||
pointer.getWidth(),
|
||||
pointer.getHeight(),
|
||||
pointer.getCaption(),
|
||||
null,
|
||||
pointer.getUrl()));
|
||||
}
|
||||
|
||||
@ -154,7 +148,6 @@ public class PointerAttachment extends Attachment {
|
||||
thumbnail != null ? thumbnail.getWidth() : 0,
|
||||
thumbnail != null ? thumbnail.getHeight() : 0,
|
||||
thumbnail != null ? thumbnail.getCaption() : null,
|
||||
null,
|
||||
thumbnail != null ? thumbnail.getUrl() : ""));
|
||||
}
|
||||
|
||||
@ -174,7 +167,6 @@ public class PointerAttachment extends Attachment {
|
||||
thumbnail != null ? thumbnail.asPointer().getWidth() : 0,
|
||||
thumbnail != null ? thumbnail.asPointer().getHeight() : 0,
|
||||
thumbnail != null ? thumbnail.asPointer().getCaption().orNull() : null,
|
||||
null,
|
||||
thumbnail != null ? thumbnail.asPointer().getUrl() : ""));
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
package org.session.libsession.messaging.sending_receiving.attachments;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class StickerLocator implements Parcelable {
|
||||
|
||||
private final String packId;
|
||||
private final String packKey;
|
||||
private final int stickerId;
|
||||
|
||||
public StickerLocator(@NonNull String packId, @NonNull String packKey, int stickerId) {
|
||||
this.packId = packId;
|
||||
this.packKey = packKey;
|
||||
this.stickerId = stickerId;
|
||||
}
|
||||
|
||||
private StickerLocator(Parcel in) {
|
||||
packId = in.readString();
|
||||
packKey = in.readString();
|
||||
stickerId = in.readInt();
|
||||
}
|
||||
|
||||
public @NonNull String getPackId() {
|
||||
return packId;
|
||||
}
|
||||
|
||||
public @NonNull String getPackKey() {
|
||||
return packKey;
|
||||
}
|
||||
|
||||
public @NonNull int getStickerId() {
|
||||
return stickerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(packId);
|
||||
dest.writeString(packKey);
|
||||
dest.writeInt(stickerId);
|
||||
}
|
||||
|
||||
public static final Creator<StickerLocator> CREATOR = new Creator<StickerLocator>() {
|
||||
@Override
|
||||
public StickerLocator createFromParcel(Parcel in) {
|
||||
return new StickerLocator(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StickerLocator[] newArray(int size) {
|
||||
return new StickerLocator[size];
|
||||
}
|
||||
};
|
||||
}
|
@ -11,18 +11,17 @@ public class UriAttachment extends Attachment {
|
||||
private final @Nullable Uri thumbnailUri;
|
||||
|
||||
public UriAttachment(@NonNull Uri uri, @NonNull String contentType, int transferState, long size,
|
||||
@Nullable String fileName, boolean voiceNote, boolean quote, @Nullable String caption,
|
||||
@Nullable StickerLocator stickerLocator)
|
||||
@Nullable String fileName, boolean voiceNote, boolean quote, @Nullable String caption)
|
||||
{
|
||||
this(uri, uri, contentType, transferState, size, 0, 0, fileName, null, voiceNote, quote, caption, stickerLocator);
|
||||
this(uri, uri, contentType, transferState, size, 0, 0, fileName, null, voiceNote, quote, caption);
|
||||
}
|
||||
|
||||
public UriAttachment(@NonNull Uri dataUri, @Nullable Uri thumbnailUri,
|
||||
@NonNull String contentType, int transferState, long size, int width, int height,
|
||||
@Nullable String fileName, @Nullable String fastPreflightId,
|
||||
boolean voiceNote, boolean quote, @Nullable String caption, @Nullable StickerLocator stickerLocator)
|
||||
boolean voiceNote, boolean quote, @Nullable String caption)
|
||||
{
|
||||
super(contentType, transferState, size, fileName, null, null, null, null, fastPreflightId, voiceNote, width, height, quote, caption, stickerLocator, "");
|
||||
super(contentType, transferState, size, fileName, null, null, null, null, fastPreflightId, voiceNote, width, height, quote, caption, "");
|
||||
this.dataUri = dataUri;
|
||||
this.thumbnailUri = thumbnailUri;
|
||||
}
|
||||
|
@ -643,7 +643,7 @@ public class Contact implements Parcelable {
|
||||
|
||||
private static Attachment attachmentFromUri(@Nullable Uri uri) {
|
||||
if (uri == null) return null;
|
||||
return new UriAttachment(uri, MediaTypes.IMAGE_JPEG, AttachmentTransferProgress.TRANSFER_PROGRESS_DONE, 0, null, false, false, null, null);
|
||||
return new UriAttachment(uri, MediaTypes.IMAGE_JPEG, AttachmentTransferProgress.TRANSFER_PROGRESS_DONE, 0, null, false, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user