logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: dd3fe61cf3cfcb1b41d1d34aa23ba99325d9dd56
parent a2f21f4e131e03240699017ef92b7dba38c4fb44
Author: Henry Jameson <me@hjkos.com>
Date:   Tue, 22 Jun 2021 20:45:44 +0300

Merge branch 'better-still-emoji' into proper-attachments

* better-still-emoji:
  fix non-notifying mentions and original mention display
  fix not escaping some stuff
  fix rich images

Diffstat:

Msrc/components/mention_link/mention_link.vue3++-
Msrc/components/rich_content/rich_content.jsx25+++++++++++++++----------
Msrc/components/status_body/status_body.js14++++++++++++++
Msrc/components/status_body/status_body.vue3++-
Msrc/services/html_converter/html_line_converter.service.js2++
Mtest/unit/specs/components/rich_content.spec.js23+++++++++++++++++++++++
Mtest/unit/specs/services/html_converter/html_line_converter.spec.js7+++++++
7 files changed, 65 insertions(+), 12 deletions(-)

diff --git a/src/components/mention_link/mention_link.vue b/src/components/mention_link/mention_link.vue @@ -5,8 +5,9 @@ <!-- eslint-disable vue/no-v-html --> <a v-if="!user" - href="url" + :href="url" class="original" + target="_blank" v-html="content" /> <!-- eslint-enable vue/no-v-html --> diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx @@ -36,6 +36,10 @@ export default Vue.component('RichContent', { required: true, type: String }, + attentions: { + required: false, + default: () => [] + }, // Emoji object, as in status.emojis, note the "s" at the end... emoji: { required: true, @@ -91,8 +95,12 @@ export default Vue.component('RichContent', { </a> } - const renderMention = (attrs, children, encounteredText) => { + const renderMention = (attrs, children) => { const linkData = getLinkData(attrs, children, mentionIndex++) + linkData.notifying = this.attentions.some(a => a.statusnet_profile_url === linkData.url) + if (!linkData.notifying) { + encounteredText = true + } writtenMentions.push(linkData) if (!encounteredText) { firstMentions.push(linkData) @@ -121,14 +129,13 @@ export default Vue.component('RichContent', { if (emptyText) { return encounteredText ? item : item.trim() } - let unescapedItem = unescape(item) if (!encounteredText) { - unescapedItem = unescapedItem.trimStart() + item = item.trimStart() encounteredText = true } if (item.includes(':')) { - unescapedItem = ['', processTextForEmoji( - unescapedItem, + item = ['', processTextForEmoji( + item, this.emoji, ({ shortcode, url }) => { return <StillImage @@ -140,7 +147,7 @@ export default Vue.component('RichContent', { } )] } - return unescapedItem + return item } // Handle tag nodes @@ -149,7 +156,7 @@ export default Vue.component('RichContent', { const Tag = getTagName(opener) const attrs = getAttrs(opener) switch (Tag) { - case 'span': // replace images with StillImage + case 'span': // Replace last mentions class with mentionsline if (attrs['class'] && attrs['class'].includes('lastMentions')) { if (firstMentions.length > 1 && lastMentions.length > 1) { break @@ -189,7 +196,7 @@ export default Vue.component('RichContent', { const emptyText = item.trim() === '' if (emptyText) return item if (!encounteredTextReverse) encounteredTextReverse = true - return item + return unescape(item) } else if (Array.isArray(item)) { // Handle tag nodes const [opener, children] = item @@ -203,9 +210,7 @@ export default Vue.component('RichContent', { return renderHashtag(attrs, children, encounteredTextReverse) } else { attrs.target = '_blank' - html.includes('freenode') && console.log('PASS1', children) const newChildren = [...children].reverse().map(processItemReverse).reverse() - html.includes('freenode') && console.log('PASS1b', newChildren) return <a {...{ attrs }}> { newChildren } diff --git a/src/components/status_body/status_body.js b/src/components/status_body/status_body.js @@ -86,6 +86,20 @@ const StatusContent = { }) }, methods: { + onParseReady (event) { + this.$emit('parseReady', event) + const { writtenMentions } = event + writtenMentions + .filter(mention => !mention.notifying) + .forEach(mention => { + const { content, url } = mention + const cleanedString = content.replace(/<[^>]+?>/gi, '') // remove all tags + if (!cleanedString.startsWith('@')) return + const handle = cleanedString.slice(1) + const host = url.replace(/^https?:\/\//, '').replace(/\/.+?$/, '') + this.$store.dispatch('fetchUserIfMissing', `${handle}@${host}`) + }) + }, toggleShowMore () { if (this.mightHideBecauseTall) { this.showingTall = !this.showingTall diff --git a/src/components/status_body/status_body.vue b/src/components/status_body/status_body.vue @@ -50,7 +50,8 @@ :handle-links="true" :hide-mentions="hideMentions" :greentext="mergedConfig.greentext" - @parseReady="$emit('parseReady', $event)" + :attentions="status.attentions" + @parseReady="onParseReady" /> <button diff --git a/src/services/html_converter/html_line_converter.service.js b/src/services/html_converter/html_line_converter.service.js @@ -114,6 +114,8 @@ export const convertHtmlToLines = (html) => { } else { handleOpen(tagFull) } + } else { + textBuffer += tagFull } } else { textBuffer += tagFull diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js @@ -27,6 +27,29 @@ describe('RichContent', () => { expect(wrapper.html()).to.eql(compwrap(html)) }) + it('unescapes everything as needed', () => { + const html = [ + p('Testing &#39;em all'), + 'Testing &#39;em all' + ].join('') + const expected = [ + p('Testing \'em all'), + 'Testing \'em all' + ].join('') + const wrapper = shallowMount(RichContent, { + localVue, + propsData: { + hideMentions: true, + handleLinks: true, + greentext: true, + emoji: [], + html + } + }) + + expect(wrapper.html()).to.eql(compwrap(expected)) + }) + it('removes mentions from the beginning of post', () => { const html = p( makeMention('John'), diff --git a/test/unit/specs/services/html_converter/html_line_converter.spec.js b/test/unit/specs/services/html_converter/html_line_converter.spec.js @@ -69,6 +69,13 @@ describe('html_line_converter', () => { const comparableResult = result.map(mapOnlyText(processorKeep)).join('') expect(comparableResult).to.eql(inputOutput) }) + + it('fed with some recognized but not handled elements', () => { + const inputOutput = 'testing images\n\n<img src="benis.png">' + const result = convertHtmlToLines(inputOutput) + const comparableResult = result.map(mapOnlyText(processorKeep)).join('') + expect(comparableResult).to.eql(inputOutput) + }) }) describe('with processor that replaces lines with word "_" should match expected line when', () => { const processorReplace = (line) => '_'