forked from AkkomaGang/akkoma-fe
more fixes
This commit is contained in:
parent
1fdfc42159
commit
636dbdaba8
3 changed files with 113 additions and 7 deletions
|
@ -140,7 +140,7 @@ export default Vue.component('RichContent', {
|
||||||
switch (Tag) {
|
switch (Tag) {
|
||||||
case 'span': // replace images with StillImage
|
case 'span': // replace images with StillImage
|
||||||
if (attrs['class'] && attrs['class'].includes('lastMentions')) {
|
if (attrs['class'] && attrs['class'].includes('lastMentions')) {
|
||||||
if (firstMentions.length > 1) {
|
if (firstMentions.length > 1 && lastMentions.length > 1) {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
return ''
|
return ''
|
||||||
|
@ -249,7 +249,9 @@ export const preProcessPerLine = (html, greentext, handleLinks) => {
|
||||||
const greentextHandle = new Set(['p', 'div'])
|
const greentextHandle = new Set(['p', 'div'])
|
||||||
|
|
||||||
let nonEmptyIndex = -1
|
let nonEmptyIndex = -1
|
||||||
const newHtml = convertHtmlToLines(html).reverse().map((item, index, array) => {
|
const lines = convertHtmlToLines(html)
|
||||||
|
const linesNum = lines.filter(c => c.text).length
|
||||||
|
const newHtml = lines.reverse().map((item, index, array) => {
|
||||||
// Going over each line in reverse to detect last mentions,
|
// Going over each line in reverse to detect last mentions,
|
||||||
// keeping non-text stuff as-is
|
// keeping non-text stuff as-is
|
||||||
if (!item.text) return item
|
if (!item.text) return item
|
||||||
|
@ -281,7 +283,7 @@ export const preProcessPerLine = (html, greentext, handleLinks) => {
|
||||||
// If line has loose text, i.e. text outside a mention or a tag
|
// If line has loose text, i.e. text outside a mention or a tag
|
||||||
// we won't touch mentions.
|
// we won't touch mentions.
|
||||||
let hasLooseText = false
|
let hasLooseText = false
|
||||||
let hasMentions = false
|
let mentionsNum = 0
|
||||||
const process = (item) => {
|
const process = (item) => {
|
||||||
if (Array.isArray(item)) {
|
if (Array.isArray(item)) {
|
||||||
const [opener, children, closer] = item
|
const [opener, children, closer] = item
|
||||||
|
@ -292,7 +294,7 @@ export const preProcessPerLine = (html, greentext, handleLinks) => {
|
||||||
const attrs = getAttrs(opener)
|
const attrs = getAttrs(opener)
|
||||||
if (attrs['class'] && attrs['class'].includes('mention')) {
|
if (attrs['class'] && attrs['class'].includes('mention')) {
|
||||||
// Got mentions
|
// Got mentions
|
||||||
hasMentions = true
|
mentionsNum++
|
||||||
return [opener, children, closer]
|
return [opener, children, closer]
|
||||||
} else {
|
} else {
|
||||||
// Not a mention? Means we have loose text or whatever
|
// Not a mention? Means we have loose text or whatever
|
||||||
|
@ -321,8 +323,13 @@ export const preProcessPerLine = (html, greentext, handleLinks) => {
|
||||||
// We now processed our tree, now we need to mark line as lastMentions
|
// We now processed our tree, now we need to mark line as lastMentions
|
||||||
const result = [...tree].map(process)
|
const result = [...tree].map(process)
|
||||||
|
|
||||||
// Only check last (first since list is reversed) line
|
if (
|
||||||
if (handleLinks && hasMentions && !hasLooseText && nonEmptyIndex++ === 0) {
|
handleLinks && // Do we handle links at all?
|
||||||
|
mentionsNum > 1 && // Does it have more than one mention?
|
||||||
|
!hasLooseText && // Don't do anything if it has something besides mentions
|
||||||
|
nonEmptyIndex === 0 && // Only check last (first since list is reversed) line
|
||||||
|
nonEmptyIndex !== linesNum - 1 // Don't do anything if there's only one line
|
||||||
|
) {
|
||||||
let mentionIndex = 0
|
let mentionIndex = 0
|
||||||
const process = (item) => {
|
const process = (item) => {
|
||||||
if (Array.isArray(item)) {
|
if (Array.isArray(item)) {
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
@parseReady="setHeadTailLinks"
|
@parseReady="setHeadTailLinks"
|
||||||
/>
|
/>
|
||||||
<MentionsLine
|
<MentionsLine
|
||||||
v-if="!hideMentions && lastMentions.length > 0 && firstMentions.length <= 1"
|
v-if="!hideMentions && lastMentions.length > 1 && firstMentions.length <= 1"
|
||||||
:mentions="lastMentions"
|
:mentions="lastMentions"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -416,4 +416,103 @@ describe('RichContent', () => {
|
||||||
|
|
||||||
expect(wrapper.html()).to.eql(compwrap(expected))
|
expect(wrapper.html()).to.eql(compwrap(expected))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Don\'t remove last mention if it\'s the only one', () => {
|
||||||
|
const html = [
|
||||||
|
'Bruh',
|
||||||
|
'Bruh',
|
||||||
|
makeMention('foo'),
|
||||||
|
makeMention('bar'),
|
||||||
|
makeMention('baz')
|
||||||
|
].join('<br>')
|
||||||
|
|
||||||
|
const wrapper = shallowMount(RichContent, {
|
||||||
|
localVue,
|
||||||
|
propsData: {
|
||||||
|
handleLinks: true,
|
||||||
|
greentext: true,
|
||||||
|
emoji: [],
|
||||||
|
html
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(wrapper.html()).to.eql(compwrap(html))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Don\'t remove last mentions if there are more than one first mention - remove first instead', () => {
|
||||||
|
const html = [
|
||||||
|
[
|
||||||
|
makeMention('foo'),
|
||||||
|
makeMention('bar')
|
||||||
|
].join(' '),
|
||||||
|
'Bruh',
|
||||||
|
'Bruh',
|
||||||
|
[
|
||||||
|
makeMention('foo'),
|
||||||
|
makeMention('bar'),
|
||||||
|
makeMention('baz')
|
||||||
|
].join(' ')
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
const expected = [
|
||||||
|
[
|
||||||
|
removedMentionSpan,
|
||||||
|
removedMentionSpan,
|
||||||
|
'Bruh' // Due to trim we remove extra newline
|
||||||
|
].join(''),
|
||||||
|
'Bruh',
|
||||||
|
lastMentions([
|
||||||
|
stubMention('foo'),
|
||||||
|
stubMention('bar'),
|
||||||
|
stubMention('baz')
|
||||||
|
].join(' '))
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
const wrapper = shallowMount(RichContent, {
|
||||||
|
localVue,
|
||||||
|
propsData: {
|
||||||
|
handleLinks: true,
|
||||||
|
greentext: true,
|
||||||
|
emoji: [],
|
||||||
|
html
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(wrapper.html()).to.eql(compwrap(expected))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Remove last mentions if there\'s just one first mention - remove all', () => {
|
||||||
|
const html = [
|
||||||
|
[
|
||||||
|
makeMention('foo')
|
||||||
|
].join(' '),
|
||||||
|
'Bruh',
|
||||||
|
'Bruh',
|
||||||
|
[
|
||||||
|
makeMention('foo'),
|
||||||
|
makeMention('bar'),
|
||||||
|
makeMention('baz')
|
||||||
|
].join(' ')
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
const expected = [
|
||||||
|
[
|
||||||
|
removedMentionSpan,
|
||||||
|
'Bruh' // Due to trim we remove extra newline
|
||||||
|
].join(''),
|
||||||
|
'Bruh\n' // Can't remove this one yet
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
const wrapper = shallowMount(RichContent, {
|
||||||
|
localVue,
|
||||||
|
propsData: {
|
||||||
|
handleLinks: true,
|
||||||
|
greentext: true,
|
||||||
|
emoji: [],
|
||||||
|
html
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(wrapper.html()).to.eql(compwrap(expected))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue