From b83d1bac8ee067372422b2d9e397902900f6be28 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 24 Jan 2018 19:48:25 -0800 Subject: [PATCH] hydrate status mentions --- routes/_components/Status.html | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/routes/_components/Status.html b/routes/_components/Status.html index fe5f246b..368a0255 100644 --- a/routes/_components/Status.html +++ b/routes/_components/Status.html @@ -297,7 +297,7 @@ export default { oncreate() { - this.hashtagifyContent() + this.hydrateContent() }, components: { Avatar, @@ -342,7 +342,7 @@ let statusId = this.get('statusId') $spoilersShown[statusId] = !$spoilersShown[statusId] this.store.set({'spoilersShown': $spoilersShown}) - this.hashtagifyContent() + this.hydrateContent() this.fire('recalculateHeight') }, onClickSensitiveMediaButton() { @@ -352,27 +352,39 @@ this.store.set({'sensitivesShown': $sensitivesShown}) this.fire('recalculateHeight') }, - hashtagifyContent() { + hydrateContent() { if (!this.refs.contentNode) { return } let status = this.get('originalStatus') - mark('hydrateHashtags') + mark('hydrateContent') if (status.tags && status.tags.length) { let anchorTags = Array.from(this.refs.contentNode.querySelectorAll( 'a[class~=hashtag][href^=http]')) for (let tag of status.tags) { - let { name } = tag for (let anchorTag of anchorTags) { - if (anchorTag.getAttribute('href').endsWith(`/tags/${name}`)) { - anchorTag.setAttribute('href', `/tags/${name}`) + if (anchorTag.getAttribute('href').endsWith(`/tags/${tag.name}`)) { + anchorTag.setAttribute('href', `/tags/${tag.name}`) anchorTag.removeAttribute('target') anchorTag.removeAttribute('rel') } } } } - stop('hydrateHashtags') + if (status.mentions && status.mentions.length) { + let anchorTags = Array.from(this.refs.contentNode.querySelectorAll( + 'a[class~=mention][href^=http]')) + for (let mention of status.mentions) { + for (let anchorTag of anchorTags) { + if (anchorTag.getAttribute('href') === mention.url) { + anchorTag.setAttribute('href', `/accounts/${mention.id}`) + anchorTag.removeAttribute('target') + anchorTag.removeAttribute('rel') + } + } + } + } + stop('hydrateContent') } } }