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 { classname } from '../../_utils/classname'
const PRIVACY_LEVEL = {
'direct': 1,
'private': 2,
'unlisted': 3,
'public': 4
}
export default {
oncreate() {
let realm = this.get('realm')
@ -156,7 +163,16 @@
text: (composeData) => composeData.text || '',
media: (composeData) => composeData.media || [],
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,
textLength: (text) => measureText(text),
contentWarningLength: (contentWarning) => measureText(contentWarning),

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import {
composeInput,
getNthComposeReplyInput, getNthReplyButton,
getNthComposeReplyInput, getNthPostPrivacyButton, getNthReplyButton,
getNthStatus, getUrl, goBack, homeNavButton, notificationsNavButton
} from '../utils'
import { foobarRole } from '../roles'
@ -34,3 +34,27 @@ test('replying to posts with mentions', async t => {
.click(getNthReplyButton(0))
.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')
}
export function getNthPostPrivacyButton (n) {
return getNthStatus(n).find('.compose-box-toolbar button:nth-child(3)')
}
export function getNthAutosuggestionResult (n) {
return $(`.compose-autosuggest-list-item:nth-child(${n}) button`)
}