From 79e33d7938b9410a84608359224e3b24f3554c56 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 3 Apr 2018 09:45:17 -0700 Subject: [PATCH] automatically insert CWs for replies to CWs --- routes/_actions/compose.js | 12 ++++++++++++ routes/_components/compose/ComposeBox.html | 8 +++++++- routes/_components/status/Status.html | 9 +++++---- routes/_components/status/StatusComposeBox.html | 1 + 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/routes/_actions/compose.js b/routes/_actions/compose.js index c0c356b..608bf8a 100644 --- a/routes/_actions/compose.js +++ b/routes/_actions/compose.js @@ -65,3 +65,15 @@ export async function clickSelectedAutosuggestionUsername (realm) { let endIndex = selectionStart await insertUsername(realm, account.acct, startIndex, endIndex) } + +export function setReplySpoiler (realm, spoiler) { + let contentWarning = store.getComposeData(realm, 'contentWarning') + let contentWarningShown = store.getComposeData(realm, 'contentWarningShown') + if (typeof contentWarningShown === 'undefined' && !contentWarning) { + // user hasn't interacted with the CW yet + store.setComposeData(realm, { + contentWarning: spoiler, + contentWarningShown: true + }) + } +} diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html index bac78b1..4b4e1af 100644 --- a/routes/_components/compose/ComposeBox.html +++ b/routes/_components/compose/ComposeBox.html @@ -98,7 +98,7 @@ import { CHAR_LIMIT, POST_PRIVACY_OPTIONS } from '../../_static/statuses' import { store } from '../../_store/store' import { slide } from 'svelte-transitions' - import { postStatus, insertHandleForReply } from '../../_actions/compose' + import { postStatus, insertHandleForReply, setReplySpoiler } from '../../_actions/compose' import { importDialogs } from '../../_utils/asyncModules' import { classname } from '../../_utils/classname' @@ -119,6 +119,12 @@ insertHandleForReply(realm) } + let replySpoiler = this.get('replySpoiler') + if (replySpoiler) { + // default spoiler is same as the replied-to status + setReplySpoiler(realm, replySpoiler) + } + this.observe('postedStatusForRealm', postedStatusForRealm => { if (postedStatusForRealm !== realm) { return diff --git a/routes/_components/status/Status.html b/routes/_components/status/Status.html index 24846c9..7d07f44 100644 --- a/routes/_components/status/Status.html +++ b/routes/_components/status/Status.html @@ -18,12 +18,12 @@ {{/if}} - {{#if originalStatus.spoiler_text}} + {{#if spoilerText}} {{/if}} - {{#if !originalStatus.spoiler_text || spoilerShown}} + {{#if !spoilerText || spoilerShown}} {{/if}} @@ -38,8 +38,8 @@ :isStatusInOwnThread :uuid :visibility :replyShown on:recalculateHeight /> {{#if replyShown}} - {{/if}} @@ -171,6 +171,7 @@ originalAccount: (originalStatus) => originalStatus.account, originalAccountId: (originalAccount) => originalAccount.id, visibility: (originalStatus) => originalStatus.visibility, + spoilerText: (originalStatus) => originalStatus.spoiler_text, uuid: ($currentInstance, timelineType, timelineValue, notificationId, statusId) => { return `${$currentInstance}/${timelineType}/${timelineValue}/${notificationId || ''}/${statusId}` }, diff --git a/routes/_components/status/StatusComposeBox.html b/routes/_components/status/StatusComposeBox.html index f1ca12c..29d4e92 100644 --- a/routes/_components/status/StatusComposeBox.html +++ b/routes/_components/status/StatusComposeBox.html @@ -4,6 +4,7 @@ autoFocus="true" hideBottomBorder="true" replyVisibility="{{visibility}}" + replySpoiler="{{spoilerText}}" on:postedStatus="onPostedStatus()" />