diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2018-11-17 03:25:48 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2018-11-17 03:25:48 +0900 |
| commit | 0bf54b3ff6899f4eb5e2bb42c6466094c8f0b8c4 (patch) | |
| tree | 4f19682385b6371dee4eaa1c9d733877f72ed56c /src | |
| parent | Hide unused login method (#3285) (diff) | |
| download | sharkey-0bf54b3ff6899f4eb5e2bb42c6466094c8f0b8c4.tar.gz sharkey-0bf54b3ff6899f4eb5e2bb42c6466094c8f0b8c4.tar.bz2 sharkey-0bf54b3ff6899f4eb5e2bb42c6466094c8f0b8c4.zip | |
Renote visibility (#3290)
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/app/desktop/views/components/renote-form.vue | 15 | ||||
| -rw-r--r-- | src/remote/activitypub/kernel/announce/note.ts | 33 | ||||
| -rw-r--r-- | src/remote/activitypub/renderer/announce.ts | 17 | ||||
| -rw-r--r-- | src/remote/activitypub/renderer/index.ts | 2 |
4 files changed, 51 insertions, 16 deletions
diff --git a/src/client/app/desktop/views/components/renote-form.vue b/src/client/app/desktop/views/components/renote-form.vue index c538b90dac..e6a09c3eea 100644 --- a/src/client/app/desktop/views/components/renote-form.vue +++ b/src/client/app/desktop/views/components/renote-form.vue @@ -5,7 +5,8 @@ <footer> <a class="quote" v-if="!quote" @click="onQuote">{{ $t('quote') }}</a> <ui-button class="button cancel" inline @click="cancel">{{ $t('cancel') }}</ui-button> - <ui-button class="button ok" inline primary @click="ok" :disabled="wait">{{ wait ? this.$t('reposting') : this.$t('renote') }}</ui-button> + <ui-button class="button home" inline :primary="visibility != 'public'" @click="ok('home')" :disabled="wait">{{ wait ? this.$t('reposting') : this.$t('renote-home') }}</ui-button> + <ui-button class="button ok" inline :primary="visibility == 'public'" @click="ok('public')" :disabled="wait">{{ wait ? this.$t('reposting') : this.$t('renote') }}</ui-button> </footer> </template> <template v-if="quote"> @@ -24,14 +25,16 @@ export default Vue.extend({ data() { return { wait: false, - quote: false + quote: false, + visibility: this.$store.state.settings.defaultNoteVisibility }; }, methods: { - ok() { + ok(v: string) { this.wait = true; this.$root.api('notes/create', { - renoteId: this.note.id + renoteId: this.note.id, + visibility: v || this.visibility }).then(data => { this.$emit('posted'); this.$notify(this.$t('success')); @@ -81,7 +84,11 @@ export default Vue.extend({ height 40px &.cancel + right 280px + + &.home right 148px + font-size 13px &.ok right 16px diff --git a/src/remote/activitypub/kernel/announce/note.ts b/src/remote/activitypub/kernel/announce/note.ts index 60f2b9baa0..19ea6306e3 100644 --- a/src/remote/activitypub/kernel/announce/note.ts +++ b/src/remote/activitypub/kernel/announce/note.ts @@ -35,17 +35,11 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity: log(`Creating the (Re)Note: ${uri}`); //#region Visibility - let visibility = 'public'; + const visibility = getVisibility(activity.to, activity.cc, actor); + let visibleUsers: IUser[] = []; - if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) { - if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) { - visibility = 'home'; - } else if (note.to.includes(`${actor.uri}/followers`)) { // TODO: person.followerと照合するべき? - visibility = 'followers'; - } else { - visibility = 'specified'; - visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri))); - } + if (visibility == 'specified') { + visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri))); } //#endergion @@ -57,3 +51,22 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity: uri }); } + +type visibility = 'public' | 'home' | 'followers' | 'specified' | 'private'; + +function getVisibility(to: string[], cc: string[], actor: IRemoteUser): visibility { + const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; + + to = to || []; + cc = cc || []; + + if (to.includes(PUBLIC)) { + return 'public'; + } else if (cc.includes(PUBLIC)) { + return 'home'; + } else if (to.includes(`${actor.uri}/followers`)) { + return 'followers'; + } else { + return 'specified'; + } +} diff --git a/src/remote/activitypub/renderer/announce.ts b/src/remote/activitypub/renderer/announce.ts index 18e23cc336..f6f2f9bdcd 100644 --- a/src/remote/activitypub/renderer/announce.ts +++ b/src/remote/activitypub/renderer/announce.ts @@ -4,13 +4,26 @@ import { INote } from '../../../models/note'; export default (object: any, note: INote) => { const attributedTo = `${config.url}/users/${note.userId}`; + let to: string[] = []; + let cc: string[] = []; + + if (note.visibility == 'public') { + to = ['https://www.w3.org/ns/activitystreams#Public']; + cc = [`${attributedTo}/followers`]; + } else if (note.visibility == 'home') { + to = [`${attributedTo}/followers`]; + cc = ['https://www.w3.org/ns/activitystreams#Public']; + } else { + return null; + } + return { id: `${config.url}/notes/${note._id}/activity`, actor: `${config.url}/users/${note.userId}`, type: 'Announce', published: note.createdAt.toISOString(), - to: ['https://www.w3.org/ns/activitystreams#Public'], - cc: [attributedTo, `${attributedTo}/followers`], + to, + cc, object }; }; diff --git a/src/remote/activitypub/renderer/index.ts b/src/remote/activitypub/renderer/index.ts index 55b2801cad..30f5f1cff5 100644 --- a/src/remote/activitypub/renderer/index.ts +++ b/src/remote/activitypub/renderer/index.ts @@ -2,6 +2,8 @@ import config from '../../../config'; import * as uuid from 'uuid'; export default (x: any) => { + if (x == null) return null; + if (x !== null && typeof x === 'object' && x.id == null) { x.id = `${config.url}/${uuid.v4()}`; } |