Skip to content

Commit

Permalink
Fix revealing spoilers in text stories.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal committed Jun 9, 2023
1 parent e19c7ef commit 3a341ee
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 6 deletions.
Expand Up @@ -69,6 +69,7 @@ object SpoilerAnnotation {
if (text is Spannable) {
Selection.removeSelection(text)
}
widget.text = text
}
}

Expand Down
Expand Up @@ -3,7 +3,6 @@
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.text.util.Linkify;
import android.util.TypedValue;
Expand All @@ -29,6 +28,7 @@
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.LinkUtil;
import org.thoughtcrime.securesms.util.LongClickMovementMethod;
import org.thoughtcrime.securesms.util.Projection;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.views.Stub;
Expand Down Expand Up @@ -131,7 +131,7 @@ private void initViewModel(long messageId, boolean isMms) {

bubble.setVisibility(View.VISIBLE);
text.setText(styledBody);
text.setMovementMethod(LinkMovementMethod.getInstance());
text.setMovementMethod(LongClickMovementMethod.getInstance(getContext()));
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
if (!message.get().getMessageRecord().isOutgoing()) {
text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), ThemeUtil.isDarkTheme(requireActivity()) ? R.color.core_grey_60 : R.color.core_grey_20));
Expand Down
Expand Up @@ -140,7 +140,7 @@ data class StoryTextPostModel(
val useLargeThumbnail = source.text.isBlank()

view.setTypeface(typeface)
view.bindFromStoryTextPost(source.storyTextPost, source.bodyRanges)
view.bindFromStoryTextPost(source.storySentAtMillis, source.storyTextPost, source.bodyRanges)
view.bindLinkPreview(linkPreview, useLargeThumbnail, loadThumbnail = false)
view.postAdjustLinkPreviewTranslationY()

Expand Down
Expand Up @@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryPostCreationState
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryScale
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryTextWatcher
import org.thoughtcrime.securesms.util.LongClickMovementMethod
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture
import org.thoughtcrime.securesms.util.visible
import java.util.Locale
Expand All @@ -47,6 +48,7 @@ class StoryTextPostView @JvmOverloads constructor(

init {
TextStoryTextWatcher.install(textView)
textView.movementMethod = LongClickMovementMethod.getInstance(context)
}

fun getLinkPreviewThumbnailWidth(useLargeThumbnail: Boolean): Int {
Expand Down Expand Up @@ -122,7 +124,7 @@ class StoryTextPostView @JvmOverloads constructor(
postAdjustLinkPreviewTranslationY()
}

fun bindFromStoryTextPost(storyTextPost: StoryTextPost, bodyRanges: BodyRangeList?) {
fun bindFromStoryTextPost(id: Long, storyTextPost: StoryTextPost, bodyRanges: BodyRangeList?) {
visible = true
linkPreviewView.visible = false

Expand All @@ -134,7 +136,7 @@ class StoryTextPostView @JvmOverloads constructor(
} else {
val body = SpannableString(storyTextPost.body)
if (font == TextFont.REGULAR && bodyRanges != null) {
MessageStyler.style(System.currentTimeMillis(), bodyRanges, body)
MessageStyler.style(id, bodyRanges, body)
}
setText(body, false)
}
Expand Down
Expand Up @@ -10,6 +10,7 @@ import kotlin.time.Duration

sealed class StoryPostState {
data class TextPost(
val storyTextPostId: Long = 0L,
val storyTextPost: StoryTextPost? = null,
val linkPreview: LinkPreview? = null,
val typeface: Typeface? = null,
Expand Down
Expand Up @@ -90,6 +90,7 @@ class StoryPostViewModel(private val repository: StoryTextPostRepository) : View

store.update {
StoryPostState.TextPost(
storyTextPostId = record.id,
storyTextPost = text,
linkPreview = linkPreview,
typeface = t,
Expand Down
Expand Up @@ -21,7 +21,7 @@ class StoryTextLoader(
) {

fun load() {
text.bindFromStoryTextPost(state.storyTextPost!!, state.bodyRanges)
text.bindFromStoryTextPost(state.storyTextPostId, state.storyTextPost!!, state.bodyRanges)
text.bindLinkPreview(state.linkPreview, state.storyTextPost.body.isBlank())
text.postAdjustLinkPreviewTranslationY()

Expand Down
Expand Up @@ -16,6 +16,7 @@

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.spoiler.SpoilerAnnotation;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;

import java.lang.ref.WeakReference;

Expand Down Expand Up @@ -116,6 +117,11 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event
return super.onTouchEvent(widget, buffer, event);
}

/** This signature is available in the base class and can lead to the wrong instance being returned. */
public static LongClickMovementMethod getInstance() {
return getInstance(ApplicationDependencies.getApplication());
}

public static LongClickMovementMethod getInstance(Context context) {
if (sInstance == null) {
sInstance = new LongClickMovementMethod(context.getApplicationContext());
Expand Down

0 comments on commit 3a341ee

Please sign in to comment.