fix post privacy for replies

This commit is contained in:
Nolan Lawson 2018-03-30 10:04:35 -07:00
parent 91402d06fc
commit f9993cac35
5 changed files with 51 additions and 4 deletions

View File

@ -102,6 +102,13 @@
import { importDialogs } from '../../_utils/asyncModules' import { importDialogs } from '../../_utils/asyncModules'
import { classname } from '../../_utils/classname' import { classname } from '../../_utils/classname'
const PRIVACY_LEVEL = {
'direct': 1,
'private': 2,
'unlisted': 3,
'public': 4
}
export default { export default {
oncreate() { oncreate() {
let realm = this.get('realm') let realm = this.get('realm')
@ -156,7 +163,16 @@
text: (composeData) => composeData.text || '', text: (composeData) => composeData.text || '',
media: (composeData) => composeData.media || [], media: (composeData) => composeData.media || [],
postPrivacy: (postPrivacyKey) => POST_PRIVACY_OPTIONS.find(_ => _.key === postPrivacyKey), postPrivacy: (postPrivacyKey) => POST_PRIVACY_OPTIONS.find(_ => _.key === postPrivacyKey),
defaultPostPrivacyKey: ($currentVerifyCredentials) => $currentVerifyCredentials.source.privacy, defaultPostPrivacyKey: ($currentVerifyCredentials, replyVisibility) => {
let defaultVisibility = $currentVerifyCredentials.source.privacy
// return the most private between the user's preferred default privacy
// and the privacy of the status they're replying to
if (replyVisibility &&
PRIVACY_LEVEL[replyVisibility] < PRIVACY_LEVEL[defaultVisibility]) {
return replyVisibility
}
return defaultVisibility
},
postPrivacyKey: (composeData, defaultPostPrivacyKey) => composeData.postPrivacy || defaultPostPrivacyKey, postPrivacyKey: (composeData, defaultPostPrivacyKey) => composeData.postPrivacy || defaultPostPrivacyKey,
textLength: (text) => measureText(text), textLength: (text) => measureText(text),
contentWarningLength: (contentWarning) => measureText(contentWarning), contentWarningLength: (contentWarning) => measureText(contentWarning),

View File

@ -38,7 +38,9 @@
:isStatusInOwnThread :uuid :visibility :replyShown :isStatusInOwnThread :uuid :visibility :replyShown
on:recalculateHeight /> on:recalculateHeight />
{{#if replyShown}} {{#if replyShown}}
<StatusComposeBox :originalStatusId :uuid on:recalculateHeight /> <StatusComposeBox :originalStatusId :uuid
:replyVisibility :visibility
on:recalculateHeight />
{{/if}} {{/if}}
</article> </article>

View File

@ -3,6 +3,7 @@
size="slim" size="slim"
autoFocus="true" autoFocus="true"
hideBottomBorder="true" hideBottomBorder="true"
replyVisibility="{{visibility}}"
on:postedStatus="onPostedStatus()" on:postedStatus="onPostedStatus()"
/> />
</div> </div>
@ -44,7 +45,7 @@
}, },
store: () => store, store: () => store,
computed: { computed: {
composeData: ($currentComposeData, originalStatusId) => $currentComposeData[originalStatusId] || {}, composeData: ($currentComposeData, originalStatusId) => $currentComposeData[originalStatusId] || {}
}, },
methods: { methods: {
onPostedStatus() { onPostedStatus() {

View File

@ -1,6 +1,6 @@
import { import {
composeInput, composeInput,
getNthComposeReplyInput, getNthReplyButton, getNthComposeReplyInput, getNthPostPrivacyButton, getNthReplyButton,
getNthStatus, getUrl, goBack, homeNavButton, notificationsNavButton getNthStatus, getUrl, goBack, homeNavButton, notificationsNavButton
} from '../utils' } from '../utils'
import { foobarRole } from '../roles' import { foobarRole } from '../roles'
@ -34,3 +34,27 @@ test('replying to posts with mentions', async t => {
.click(getNthReplyButton(0)) .click(getNthReplyButton(0))
.expect(getNthComposeReplyInput(0).value).eql('@ExternalLinks @admin @quux ') .expect(getNthComposeReplyInput(0).value).eql('@ExternalLinks @admin @quux ')
}) })
test('replies have same privacy as replied-to status by default', async t => {
await t.useRole(foobarRole)
.hover(getNthStatus(0))
.hover(getNthStatus(1))
.click(getNthReplyButton(1))
.expect(getNthPostPrivacyButton(1).getAttribute('aria-label')).eql('Adjust privacy (currently Unlisted)')
.click(getNthReplyButton(1))
.hover(getNthStatus(2))
.click(getNthReplyButton(2))
.expect(getNthPostPrivacyButton(2).getAttribute('aria-label')).eql('Adjust privacy (currently Followers-only)')
.click(getNthReplyButton(2))
.hover(getNthStatus(3))
.click(getNthReplyButton(3))
.expect(getNthPostPrivacyButton(3).getAttribute('aria-label')).eql('Adjust privacy (currently Direct)')
.click(getNthReplyButton(3))
.hover(getNthStatus(4))
.hover(getNthStatus(5))
.hover(getNthStatus(6))
.hover(getNthStatus(7))
.click(getNthReplyButton(7))
.expect(getNthPostPrivacyButton(7).getAttribute('aria-label')).eql('Adjust privacy (currently Public)')
.click(getNthReplyButton(7))
})

View File

@ -104,6 +104,10 @@ export function getNthComposeReplyButton (n) {
return getNthStatus(n).find('.compose-box-button') return getNthStatus(n).find('.compose-box-button')
} }
export function getNthPostPrivacyButton (n) {
return getNthStatus(n).find('.compose-box-toolbar button:nth-child(3)')
}
export function getNthAutosuggestionResult (n) { export function getNthAutosuggestionResult (n) {
return $(`.compose-autosuggest-list-item:nth-child(${n}) button`) return $(`.compose-autosuggest-list-item:nth-child(${n}) button`)
} }