Fix crash when trying to view 1:1 conversation with reaction quote.

fork-5.53.8
Alex Hart 2022-04-14 10:27:30 -03:00 zatwierdzone przez Greyson Parrelli
rodzic 9a097d113d
commit 17b8e086c9
5 zmienionych plików z 39 dodań i 14 usunięć

Wyświetl plik

@ -181,7 +181,7 @@ public class InputPanel extends LinearLayout
@NonNull CharSequence body,
@NonNull SlideDeck attachments)
{
this.quoteView.setQuote(glideRequests, id, author, body, false, attachments, null, false);
this.quoteView.setQuote(glideRequests, id, author, body, false, attachments, null, null);
int originalHeight = this.quoteView.getVisibility() == VISIBLE ? this.quoteView.getMeasuredHeight()
: 0;

Wyświetl plik

@ -39,7 +39,9 @@ import org.thoughtcrime.securesms.stories.StoryTextPostModel;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.Projection;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
import java.io.IOException;
import java.util.List;
public class QuoteView extends FrameLayout implements RecipientForeverObserver {
@ -204,7 +206,7 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
boolean originalMissing,
@NonNull SlideDeck attachments,
@Nullable ChatColors chatColors,
boolean isStoryReaction)
@Nullable String storyReaction)
{
if (this.author != null) this.author.removeForeverObserver(this);
@ -215,7 +217,7 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
this.author.observeForever(this);
setQuoteAuthor(author);
setQuoteText(body, attachments, originalMissing, isStoryReaction);
setQuoteText(body, attachments, originalMissing, storyReaction);
setQuoteAttachment(glideRequests, body, attachments, originalMissing);
setQuoteMissingFooter(originalMissing);
@ -286,14 +288,18 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
messageType == MessageType.STORY_REPLY_PREVIEW;
}
private void setQuoteText(@Nullable CharSequence body, @NonNull SlideDeck attachments, boolean originalMissing, boolean isStoryReaction) {
private void setQuoteText(@Nullable CharSequence body,
@NonNull SlideDeck attachments,
boolean originalMissing,
@Nullable String storyReaction)
{
if (originalMissing && isStoryReply()) {
bodyView.setVisibility(GONE);
storyReactionEmoji.setVisibility(View.GONE);
mediaDescriptionText.setVisibility(VISIBLE);
mediaDescriptionText.setText(R.string.QuoteView_no_longer_available);
if (isStoryReaction) {
if (storyReaction != null) {
missingStoryReaction.setVisibility(View.VISIBLE);
missingStoryReaction.setImageEmoji(body);
} else {
@ -302,11 +308,10 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
return;
}
if (isStoryReaction) {
storyReactionEmoji.setImageEmoji(body);
if (storyReaction != null) {
storyReactionEmoji.setImageEmoji(storyReaction);
storyReactionEmoji.setVisibility(View.VISIBLE);
missingStoryReaction.setVisibility(View.INVISIBLE);
return;
} else {
storyReactionEmoji.setVisibility(View.GONE);
missingStoryReaction.setVisibility(View.GONE);
@ -317,7 +322,7 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
if (!TextUtils.isEmpty(body) || !attachments.containsMediaSlide()) {
if (isTextStory && body != null) {
try {
bodyView.setText(StoryTextPostModel.parseFrom(body.toString(), id, author.getId()).getText());
bodyView.setText(getStoryTextPost(body).getText());
} catch (Exception e) {
Log.w(TAG, "Could not parse body of text post.", e);
bodyView.setText("");
@ -369,7 +374,7 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
mainView.setMinimumHeight(isStoryReply() && originalMissing ? 0 : thumbHeight);
if (!attachments.containsMediaSlide() && isStoryReply()) {
StoryTextPostModel model = StoryTextPostModel.parseFrom(body.toString(), id, author.getId());
StoryTextPostModel model = getStoryTextPost(body);
attachmentVideoOverlayView.setVisibility(GONE);
attachmentContainerView.setVisibility(GONE);
thumbnailView.setVisibility(VISIBLE);
@ -422,6 +427,18 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
footerView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.quote_view_background));
}
private @Nullable StoryTextPostModel getStoryTextPost(@Nullable CharSequence body) {
if (Util.isEmpty(body)) {
return null;
}
try {
return StoryTextPostModel.parseFrom(body.toString(), id, author.getId());
} catch (IOException ioException) {
return null;
}
}
public void setTextSize(int unit, float size) {
bodyView.setTextSize(unit, size);
}

Wyświetl plik

@ -1429,9 +1429,15 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
}
//noinspection ConstantConditions
CharSequence body = isStoryReaction(current) ? current.getBody() : quote.getDisplayText();
//noinspection ConstantConditions
quoteView.setQuote(glideRequests, quote.getId(), Recipient.live(quote.getAuthor()).get(), body, quote.isOriginalMissing(), quote.getAttachment(), chatColors, isStoryReaction(current));
quoteView.setQuote(glideRequests,
quote.getId(),
Recipient.live(quote.getAuthor()).get(),
quote.getDisplayText(),
quote.isOriginalMissing(),
quote.getAttachment(),
chatColors,
isStoryReaction(current) ? current.getBody() : null);
quoteView.setVisibility(View.VISIBLE);
quoteView.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
quoteView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;

Wyświetl plik

@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.util.Base64
import org.thoughtcrime.securesms.util.ParcelUtil
import java.io.IOException
import java.security.MessageDigest
/**
@ -88,6 +89,7 @@ data class StoryTextPostModel(
}
@JvmStatic
@Throws(IOException::class)
fun parseFrom(body: String, storySentAtMillis: Long, storyAuthor: RecipientId): StoryTextPostModel {
return StoryTextPostModel(
storyTextPost = StoryTextPost.parseFrom(Base64.decode(body)),

Wyświetl plik

@ -106,7 +106,7 @@ class StoryReplyComposer @JvmOverloads constructor(
false,
messageRecord.slideDeck,
null,
false
null
)
quoteView.visible = true