From 500b704c0f93059b75b8943e3351cdac63270b0f Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 29 Oct 2016 01:38:41 +0200 Subject: [PATCH] Fix up nsfw and some styling. --- src/components/attachment/attachment.js | 21 ++++++++++++++--- src/components/attachment/attachment.vue | 30 +++++++++++++++--------- src/components/status/status.js | 3 --- src/components/status/status.vue | 12 +++++++++- src/components/timeline/timeline.vue | 6 +++++ src/modules/statuses.js | 21 +++++++++++++++-- 6 files changed, 73 insertions(+), 20 deletions(-) diff --git a/src/components/attachment/attachment.js b/src/components/attachment/attachment.js index c21cd65662..161c6b2b80 100644 --- a/src/components/attachment/attachment.js +++ b/src/components/attachment/attachment.js @@ -3,17 +3,32 @@ import nsfwImage from '../../assets/nsfw.jpg' const Attachment = { props: [ 'attachment', - 'nsfw' + 'nsfw', + 'statusId' ], data: () => ({ nsfwImage }), computed: { type () { - return 'image' + let type = 'unknown' + + if(this.attachment.mimetype.match(/text\/html/)) { + type = 'html'; + } + + if(this.attachment.mimetype.match(/image/)) { + type = 'image'; + } + + if(this.attachment.mimetype.match(/video\/webm/)) { + type = 'webm'; + }; + + return type } }, methods: { showNsfw () { - this.nsfw = false + this.$store.commit('setNsfw', { id: this.statusId, nsfw: false }) } } } diff --git a/src/components/attachment/attachment.vue b/src/components/attachment/attachment.vue index 67c6ac18ed..d20b704bc1 100644 --- a/src/components/attachment/attachment.vue +++ b/src/components/attachment/attachment.vue @@ -5,21 +5,29 @@ - +
+
+ +
+ +
+ + diff --git a/src/components/status/status.js b/src/components/status/status.js index 2842ef0ffd..6ee8f0dd95 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -2,9 +2,6 @@ import Attachment from '../attachment/attachment.vue' const Status = { props: [ 'statusoid' ], - data: () => ({ - nsfw: true - }), computed: { retweet () { return !!this.statusoid.retweeted_status }, retweeter () { return this.statusoid.user.name }, diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 04a55f6787..a6a5aac232 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -26,7 +26,7 @@
- +
@@ -49,3 +49,13 @@ + + diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index db18d5217c..8fdcc42ff1 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -11,3 +11,9 @@ + + diff --git a/src/modules/statuses.js b/src/modules/statuses.js index b042769491..d6bdba65c6 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -51,13 +51,18 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib addedStatuses = statusesAndFaves['status'] || [] - // Add some html to the statuses. + // Add some html and nsfw to the statuses. each(addedStatuses, (status) => { const statusoid = status.retweeted_status || status if (statusoid.parsedText === undefined) { // statusoid.parsedText = statusParserService.parse(statusoid) statusoid.parsedText = statusoid.text } + + if (statusoid.nsfw === undefined) { + const nsfwRegex = /#nsfw/i + statusoid.nsfw = statusoid.text.match(nsfwRegex) + } }) const newStatuses = sortBy( @@ -88,7 +93,9 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib } const updateTimestampsInStatuses = (statuses) => { - return map(statuses, (status) => { + return map(statuses, (statusoid) => { + const status = statusoid.retweeted_status || statusoid + // Parse date status.created_at_parsed = moment(status.created_at).fromNow() return status @@ -110,6 +117,16 @@ const statuses = { }, updateTimestamps (state) { updateTimestampsInStatuses(state.allStatuses) + }, + setNsfw (state, { id, nsfw }) { + // For now, walk through all the statuses because the stuff might be in the replied_to_status + // TODO: Save the replied_tos as references. + each(state.allStatuses, (statusoid) => { + const status = statusoid.retweeted_status || statusoid + if (status.id === id) { + status.nsfw = nsfw + } + }) } } }