From 50dc9df8a44d408dd83ae4b17c407fa36c85cf8e Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 14 Nov 2019 00:18:14 +0200 Subject: adds greentext, also small fixes --- src/components/status/status.js | 49 +++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'src/components/status/status.js') diff --git a/src/components/status/status.js b/src/components/status/status.js index 4fbd5ac3..6dbb2199 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -13,10 +13,11 @@ import Timeago from '../timeago/timeago.vue' import StatusPopover from '../status_popover/status_popover.vue' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import fileType from 'src/services/file_type/file_type.service' +import { processHtml } from 'src/services/tiny_post_html_processor/tiny_post_html_processor.service.js' import { highlightClass, highlightStyle } from '../../services/user_highlighter/user_highlighter.js' import { mentionMatchesUrl, extractTagFromUrl } from 'src/services/matcher/matcher.service.js' import { filter, unescape, uniqBy } from 'lodash' -import { mapGetters } from 'vuex' +import { mapGetters, mapState } from 'vuex' const Status = { name: 'Status', @@ -42,8 +43,8 @@ const Status = { showingTall: this.inConversation && this.focused, showingLongSubject: false, error: null, + // Initial state expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject, - betterShadow: this.$store.state.interface.browserSupport.cssFilter } }, computed: { @@ -103,7 +104,7 @@ const Status = { return this.$store.state.statuses.allStatusesObject[this.status.id] }, loggedIn () { - return !!this.$store.state.users.currentUser + return !!this.currentUser }, muteWordHits () { const statusText = this.status.text.toLowerCase() @@ -163,7 +164,7 @@ const Status = { if (this.inConversation || !this.isReply) { return false } - if (this.status.user.id === this.$store.state.users.currentUser.id) { + if (this.status.user.id === this.currentUser.id) { return false } if (this.status.type === 'retweet') { @@ -178,7 +179,7 @@ const Status = { if (checkFollowing && taggedUser && taggedUser.following) { return false } - if (this.status.attentions[i].id === this.$store.state.users.currentUser.id) { + if (this.status.attentions[i].id === this.currentUser.id) { return false } } @@ -255,11 +256,37 @@ const Status = { maxThumbnails () { return this.mergedConfig.maxThumbnails }, + postBodyHtml () { + const html = this.status.statusnet_html + + try { + if (html.includes('>')) { + // This checks if post has '>' at the beginning, excluding mentions so that @mention >impying works + return processHtml(html, (string) => { + if (string.includes('>') && + string + .replace(/<[^>]+?>/gi, '') // remove all tags + .replace(/@\w+/gi, '') // remove mentions (even failed ones) + .trim() + .startsWith('>')) { + return `${string}` + } else { + return string + } + }) + } else { + return html + } + } catch (e) { + console.err('Failed to process status html', e) + return html + } + }, contentHtml () { if (!this.status.summary_html) { - return this.status.statusnet_html + return this.postBodyHtml } - return this.status.summary_html + '
' + this.status.statusnet_html + return this.status.summary_html + '
' + this.postBodyHtml }, combinedFavsAndRepeatsUsers () { // Use the status from the global status repository since favs and repeats are saved in it @@ -270,7 +297,7 @@ const Status = { return uniqBy(combinedUsers, 'id') }, ownStatus () { - return this.status.user.id === this.$store.state.users.currentUser.id + return this.status.user.id === this.currentUser.id }, tags () { return this.status.tags.filter(tagObj => tagObj.hasOwnProperty('name')).map(tagObj => tagObj.name).join(' ') @@ -278,7 +305,11 @@ const Status = { hidePostStats () { return this.mergedConfig.hidePostStats }, - ...mapGetters(['mergedConfig']) + ...mapGetters(['mergedConfig']), + ...mapState({ + betterShadow: state => state.interface.browserSupport.cssFilter, + currentUser: state => state.users.currentUser + }) }, components: { Attachment, -- cgit v1.2.3-70-g09d2 From 692ee0e95a852b1f803b7ae92d65cbf4f3ce3445 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 14 Nov 2019 00:41:14 +0200 Subject: Fix regex, tag detector condition --- src/components/status/status.js | 2 +- .../tiny_post_html_processor.service.js | 25 +++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src/components/status/status.js') diff --git a/src/components/status/status.js b/src/components/status/status.js index 6dbb2199..416aa36a 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -43,7 +43,7 @@ const Status = { showingTall: this.inConversation && this.focused, showingLongSubject: false, error: null, - // Initial state + // not as computed because it sets the initial state which will be changed later expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject, } }, diff --git a/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js b/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js index c9ff81e1..b96c1ccf 100644 --- a/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js +++ b/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js @@ -9,17 +9,15 @@ export const processHtml = (html, processor) => { const handledTags = new Set(['p', 'br', 'div']) const openCloseTags = new Set(['p', 'div']) - const tagRegex = /(?:<\/(\w+)>|<(\w+)\s?[^/]*?\/?>)/gi let buffer = '' // Current output buffer const level = [] // How deep we are in tags and which tags were there let textBuffer = '' // Current line content let tagBuffer = null // Current tag buffer, if null = we are not currently reading a tag - // Extracts tagname from tag, i.e. => span + // Extracts tag name from tag, i.e. => span const getTagName = (tag) => { - // eslint-disable-next-line no-unused-vars - const result = tagRegex.exec(tag) + const result = /(?:<\/(\w+)>|<(\w+)\s?[^/]*?\/?>)/gi.exec(tag) return result && (result[1] || result[2]) } @@ -49,28 +47,29 @@ export const processHtml = (html, processor) => { for (let i = 0; i < html.length; i++) { const char = html[i] - if (char === '<' && tagBuffer !== null) { + if (char === '<' && tagBuffer === null) { tagBuffer = char } else if (char !== '>' && tagBuffer !== null) { tagBuffer += char } else if (char === '>' && tagBuffer !== null) { tagBuffer += char - const tagName = getTagName(tagBuffer) + const tagFull = tagBuffer + tagBuffer = null + const tagName = getTagName(tagFull) if (handledTags.has(tagName)) { if (tagName === 'br') { - handleBr(tagBuffer) + handleBr(tagFull) } - if (openCloseTags.has(tagBuffer)) { - if (tagBuffer[1] === '/') { - handleClose(tagBuffer) + if (openCloseTags.has(tagFull)) { + if (tagFull[1] === '/') { + handleClose(tagFull) } else { - handleOpen(tagBuffer) + handleOpen(tagFull) } } } else { - textBuffer += tagBuffer + textBuffer += tagFull } - tagBuffer = null } else if (char === '\n') { handleBr(char) } else { -- cgit v1.2.3-70-g09d2 From 897131572f62c36277e06e464f328f37cf6acad2 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 14 Nov 2019 00:47:20 +0200 Subject: Made it optional --- src/components/settings/settings.vue | 11 ++++++++++ src/components/status/status.js | 40 ++++++++++++++++++++---------------- src/components/status/status.vue | 5 +++-- src/i18n/en.json | 2 ++ src/modules/config.js | 1 + src/modules/instance.js | 1 + 6 files changed, 40 insertions(+), 20 deletions(-) (limited to 'src/components/status/status.js') diff --git a/src/components/settings/settings.vue b/src/components/settings/settings.vue index a83489d2..c4021137 100644 --- a/src/components/settings/settings.vue +++ b/src/components/settings/settings.vue @@ -270,6 +270,17 @@ + +
+

{{ $t('settings.fun') }}

+
    +
  • + + {{ $t('settings.greentext') }} {{ $t('settings.instance_default', { value: greentextLocalizedValue }) }} + +
  • +
+
diff --git a/src/components/status/status.js b/src/components/status/status.js index 416aa36a..dd0ce3ab 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -259,26 +259,30 @@ const Status = { postBodyHtml () { const html = this.status.statusnet_html - try { - if (html.includes('>')) { - // This checks if post has '>' at the beginning, excluding mentions so that @mention >impying works - return processHtml(html, (string) => { - if (string.includes('>') && - string - .replace(/<[^>]+?>/gi, '') // remove all tags - .replace(/@\w+/gi, '') // remove mentions (even failed ones) - .trim() - .startsWith('>')) { - return `${string}` - } else { - return string - } - }) - } else { + if (this.mergedConfig.greentext) { + try { + if (html.includes('>')) { + // This checks if post has '>' at the beginning, excluding mentions so that @mention >impying works + return processHtml(html, (string) => { + if (string.includes('>') && + string + .replace(/<[^>]+?>/gi, '') // remove all tags + .replace(/@\w+/gi, '') // remove mentions (even failed ones) + .trim() + .startsWith('>')) { + return `${string}` + } else { + return string + } + }) + } else { + return html + } + } catch (e) { + console.err('Failed to process status html', e) return html } - } catch (e) { - console.err('Failed to process status html', e) + } else { return html } }, diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 65778b2e..d291e762 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -606,7 +606,7 @@ $status-margin: 0.75em; height: 100%; mask: linear-gradient(to top, white, transparent) bottom/100% 70px no-repeat, linear-gradient(to top, white, white); - // Autoprefixed seem to ignore this one, and also syntax is different + /* Autoprefixed seem to ignore this one, and also syntax is different */ -webkit-mask-composite: xor; mask-composite: exclude; } @@ -752,7 +752,8 @@ $status-margin: 0.75em; } .greentext { - color: green; + color: $fallback--cGreen; + color: var(--cGreen, $fallback--cGreen); } .status-conversation { diff --git a/src/i18n/en.json b/src/i18n/en.json index ead333c1..7b0b3b94 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -370,6 +370,8 @@ "false": "no", "true": "yes" }, + "fun": "Fun", + "greentext": "Meme arrows", "notifications": "Notifications", "notification_setting": "Receive notifications from:", "notification_setting_follows": "Users you follow", diff --git a/src/modules/config.js b/src/modules/config.js index d4819ee8..329b4091 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -45,6 +45,7 @@ export const defaultState = { playVideosInModal: false, useOneClickNsfw: false, useContainFit: false, + greentext: undefined, // instance default hidePostStats: undefined, // instance default hideUserStats: undefined // instance default } diff --git a/src/modules/instance.js b/src/modules/instance.js index 7b0e0da4..96f14ed5 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -32,6 +32,7 @@ const defaultState = { noAttachmentLinks: false, showFeaturesPanel: true, minimalScopesMode: false, + greentext: false, // Nasty stuff pleromaBackend: true, -- cgit v1.2.3-70-g09d2 From 51ea295704c52b1f9a922868aedf264e53a5ec92 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 14 Nov 2019 00:52:38 +0200 Subject: eslint --- src/components/status/status.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/components/status/status.js') diff --git a/src/components/status/status.js b/src/components/status/status.js index dd0ce3ab..714ea6d2 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -44,7 +44,7 @@ const Status = { showingLongSubject: false, error: null, // not as computed because it sets the initial state which will be changed later - expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject, + expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject } }, computed: { @@ -266,10 +266,10 @@ const Status = { return processHtml(html, (string) => { if (string.includes('>') && string - .replace(/<[^>]+?>/gi, '') // remove all tags - .replace(/@\w+/gi, '') // remove mentions (even failed ones) - .trim() - .startsWith('>')) { + .replace(/<[^>]+?>/gi, '') // remove all tags + .replace(/@\w+/gi, '') // remove mentions (even failed ones) + .trim() + .startsWith('>')) { return `${string}` } else { return string -- cgit v1.2.3-70-g09d2