use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by WhisperSystems.
the class ConversationFragment method performSave.
private void performSave(final MediaMmsMessageRecord message) {
List<SaveAttachmentTask.Attachment> attachments = Stream.of(message.getSlideDeck().getSlides()).filter(s -> s.getUri() != null && (s.hasImage() || s.hasVideo() || s.hasAudio() || s.hasDocument())).map(s -> new SaveAttachmentTask.Attachment(s.getUri(), s.getContentType(), message.getDateReceived(), s.getFileName().orNull())).toList();
if (!Util.isEmpty(attachments)) {
SaveAttachmentTask saveTask = new SaveAttachmentTask(getActivity());
saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, attachments.toArray(new SaveAttachmentTask.Attachment[0]));
return;
}
Log.w(TAG, "No slide with attachable media found, failing nicely.");
Toast.makeText(getActivity(), getResources().getQuantityString(R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card, 1), Toast.LENGTH_LONG).show();
}
use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by WhisperSystems.
the class ConversationItem method setQuote.
private void setQuote(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread, @NonNull ChatColors chatColors) {
boolean startOfCluster = isStartOfMessageCluster(current, previous, isGroupThread);
if (current.isMms() && !current.isMmsNotification() && ((MediaMmsMessageRecord) current).getQuote() != null) {
if (quoteView == null) {
throw new AssertionError();
}
Quote quote = ((MediaMmsMessageRecord) current).getQuote();
// noinspection ConstantConditions
quoteView.setQuote(glideRequests, quote.getId(), Recipient.live(quote.getAuthor()).get(), quote.getDisplayText(), quote.isOriginalMissing(), quote.getAttachment(), chatColors);
quoteView.setVisibility(View.VISIBLE);
quoteView.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
quoteView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
quoteView.setOnClickListener(view -> {
if (eventListener != null && batchSelected.isEmpty()) {
eventListener.onQuoteClicked((MmsMessageRecord) current);
} else {
passthroughClickListener.onClick(view);
}
});
quoteView.setOnLongClickListener(passthroughClickListener);
if (startOfCluster) {
if (current.isOutgoing()) {
quoteView.setTopCornerSizes(true, true);
} else if (isGroupThread) {
quoteView.setTopCornerSizes(false, false);
} else {
quoteView.setTopCornerSizes(true, true);
}
} else if (!isSingularMessage(current, previous, next, isGroupThread)) {
if (current.isOutgoing()) {
quoteView.setTopCornerSizes(true, false);
} else {
quoteView.setTopCornerSizes(false, true);
}
}
if (mediaThumbnailStub.resolved()) {
ViewUtil.setTopMargin(mediaThumbnailStub.require(), readDimen(R.dimen.message_bubble_top_padding));
}
if (linkPreviewStub.resolved() && !hasBigImageLinkPreview(current)) {
ViewUtil.setTopMargin(linkPreviewStub.get(), readDimen(R.dimen.message_bubble_top_padding));
}
} else {
if (quoteView != null) {
quoteView.dismiss();
}
int topMargin = (current.isOutgoing() || !startOfCluster || !groupThread) ? 0 : readDimen(R.dimen.message_bubble_top_image_margin);
if (mediaThumbnailStub.resolved()) {
ViewUtil.setTopMargin(mediaThumbnailStub.require(), topMargin);
}
}
}
use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by WhisperSystems.
the class ConversationDataSource method load.
@Override
@Nullable
public ConversationMessage load(@NonNull MessageId messageId) {
Stopwatch stopwatch = new Stopwatch("load(" + messageId + "), thread " + threadId);
MessageDatabase database = messageId.isMms() ? SignalDatabase.mms() : SignalDatabase.sms();
MessageRecord record = database.getMessageRecordOrNull(messageId.getId());
stopwatch.split("message");
try {
if (record != null) {
List<Mention> mentions;
if (messageId.isMms()) {
mentions = SignalDatabase.mentions().getMentionsForMessage(messageId.getId());
} else {
mentions = Collections.emptyList();
}
stopwatch.split("mentions");
List<ReactionRecord> reactions = SignalDatabase.reactions().getReactions(messageId);
record = ReactionHelper.recordWithReactions(record, reactions);
stopwatch.split("reactions");
if (messageId.isMms()) {
List<DatabaseAttachment> attachments = SignalDatabase.attachments().getAttachmentsForMessage(messageId.getId());
if (attachments.size() > 0) {
record = ((MediaMmsMessageRecord) record).withAttachments(context, attachments);
}
}
stopwatch.split("attachments");
return ConversationMessage.ConversationMessageFactory.createWithUnresolvedData(ApplicationDependencies.getApplication(), record, mentions);
} else {
return null;
}
} finally {
stopwatch.stop(TAG);
}
}
use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by signalapp.
the class MenuState method getMenuState.
static MenuState getMenuState(@NonNull Recipient conversationRecipient, @NonNull Set<MultiselectPart> selectedParts, boolean shouldShowMessageRequest, boolean isNonAdminInAnnouncementGroup) {
Builder builder = new Builder();
boolean actionMessage = false;
boolean hasText = false;
boolean sharedContact = false;
boolean viewOnce = false;
boolean remoteDelete = false;
boolean hasInMemory = false;
boolean hasPendingMedia = false;
boolean mediaIsSelected = false;
for (MultiselectPart part : selectedParts) {
MessageRecord messageRecord = part.getMessageRecord();
if (isActionMessage(messageRecord)) {
actionMessage = true;
if (messageRecord.isInMemoryMessageRecord()) {
hasInMemory = true;
}
}
if (!(part instanceof MultiselectPart.Attachments)) {
if (messageRecord.getBody().length() > 0) {
hasText = true;
}
} else {
mediaIsSelected = true;
if (messageRecord.isMediaPending()) {
hasPendingMedia = true;
}
}
if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
sharedContact = true;
}
if (messageRecord.isViewOnce()) {
viewOnce = true;
}
if (messageRecord.isRemoteDelete()) {
remoteDelete = true;
}
}
boolean shouldShowForwardAction = !actionMessage && !sharedContact && !viewOnce && !remoteDelete && !hasPendingMedia && selectedParts.size() <= MAX_FORWARDABLE_COUNT;
int uniqueRecords = selectedParts.stream().map(MultiselectPart::getMessageRecord).collect(Collectors.toSet()).size();
if (uniqueRecords > 1) {
builder.shouldShowForwardAction(shouldShowForwardAction).shouldShowReplyAction(false).shouldShowDetailsAction(false).shouldShowSaveAttachmentAction(false).shouldShowResendAction(false);
} else {
MessageRecord messageRecord = selectedParts.iterator().next().getMessageRecord();
builder.shouldShowResendAction(messageRecord.isFailed()).shouldShowSaveAttachmentAction(mediaIsSelected && !actionMessage && !viewOnce && messageRecord.isMms() && !hasPendingMedia && !messageRecord.isMmsNotification() && ((MediaMmsMessageRecord) messageRecord).containsMediaSlide() && ((MediaMmsMessageRecord) messageRecord).getSlideDeck().getStickerSlide() == null).shouldShowForwardAction(shouldShowForwardAction).shouldShowDetailsAction(!actionMessage && !conversationRecipient.isReleaseNotes()).shouldShowReplyAction(canReplyToMessage(conversationRecipient, actionMessage, messageRecord, shouldShowMessageRequest, isNonAdminInAnnouncementGroup));
}
return builder.shouldShowCopyAction(!actionMessage && !remoteDelete && hasText).shouldShowDeleteAction(!hasInMemory && onlyContainsCompleteMessages(selectedParts)).shouldShowReactions(!conversationRecipient.isReleaseNotes()).build();
}
use of org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord in project Signal-Android by WhisperSystems.
the class ConversationFragment method handleForwardMessage.
private void handleForwardMessage(MessageRecord message) {
Intent composeIntent = new Intent(getActivity(), ShareActivity.class);
composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody().toString());
if (message.isMms()) {
MediaMmsMessageRecord mediaMessage = (MediaMmsMessageRecord) message;
if (mediaMessage.containsMediaSlide()) {
Slide slide = mediaMessage.getSlideDeck().getSlides().get(0);
composeIntent.putExtra(Intent.EXTRA_STREAM, slide.getUri());
composeIntent.setType(slide.getContentType());
}
}
startActivity(composeIntent);
}
Aggregations