diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-07-26 14:12:40 -0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-26 14:12:40 -0100 |
commit | 2dcdedd3defa7b043ffc5cad839abf697b13f79b (patch) | |
tree | 1f1b1247fd6f045213bf89f4cba80da385ee8ab7 | |
parent | e64c1b5244b22a8a7f8124c835adb8145c195db3 (diff) | |
parent | 3619ac594cf8677f3b521b5b7b85c5f3db762ba8 (diff) |
Merge pull request #661 from StCyr/stcyr_fix656
Uses hashtag-regex to rewrite hashtag's href rather than linkifyjs.
-rw-r--r-- | lib/Model/ActivityPub/Object/Note.php | 1 | ||||
-rw-r--r-- | package-lock.json | 5 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/components/TimelinePost.vue | 19 | ||||
-rw-r--r-- | src/store/timeline.js | 8 |
5 files changed, 24 insertions, 10 deletions
diff --git a/lib/Model/ActivityPub/Object/Note.php b/lib/Model/ActivityPub/Object/Note.php index 3cf9b683..0cbc5238 100644 --- a/lib/Model/ActivityPub/Object/Note.php +++ b/lib/Model/ActivityPub/Object/Note.php @@ -129,6 +129,7 @@ class Note extends Stream implements JsonSerializable { parent::import($data); $this->importAttachments($this->getArray('attachment', $data, [])); + $this->fillHashtags(); } diff --git a/package-lock.json b/package-lock.json index c6ebd5bf..f968668e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6800,6 +6800,11 @@ "minimalistic-assert": "^1.0.1" } }, + "hashtag-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hashtag-regex/-/hashtag-regex-2.0.0.tgz", + "integrity": "sha512-6qWo1g10ggwyorTjMEswX/z8DkODD1XnfjBjndIAj7rnUOgVlwYQz4UPQU9yBz2jBGd3Im1D1wlzzI/o6Q1Ptw==" + }, "he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", diff --git a/package.json b/package.json index 69f301da..742b43ea 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ }, "dependencies": { "vue-masonry-css": "^1.0.3", + "hashtag-regex": "^2.0.0", "linkifyjs": "^2.1.8", "nextcloud-axios": "^0.2.0", "nextcloud-vue": "^0.11.4", diff --git a/src/components/TimelinePost.vue b/src/components/TimelinePost.vue index c97546bc..ed542881 100644 --- a/src/components/TimelinePost.vue +++ b/src/components/TimelinePost.vue @@ -52,16 +52,16 @@ <script> import Avatar from 'nextcloud-vue/dist/Components/Avatar' import * as linkify from 'linkifyjs' -import pluginTag from 'linkifyjs/plugins/hashtag' import pluginMention from 'linkifyjs/plugins/mention' import 'linkifyjs/string' import popoverMenu from './../mixins/popoverMenu' import currentUser from './../mixins/currentUserMixin' import PostAttachment from './PostAttachment' -pluginTag(linkify) pluginMention(linkify) +const hashtagRegex = require('hashtag-regex') + export default { name: 'TimelinePost', components: { @@ -102,21 +102,19 @@ export default { return Date.parse(this.item.published) }, formatedMessage() { - let message = this.item.content + var message = this.item.content if (typeof message === 'undefined') { return '' } message = message.replace(/(?:\r\n|\r|\n)/g, '<br />') message = message.linkify({ formatHref: { - hashtag: function(href) { - return OC.generateUrl('/apps/social/timeline/tags/' + href.substring(1)) - }, mention: function(href) { return OC.generateUrl('/apps/social/@' + href.substring(1)) } } }) + message = this.mangleHashtags(message) message = this.$twemoji.parse(message) return message }, @@ -140,6 +138,15 @@ export default { } }, methods: { + mangleHashtags(msg) { + // Replace hashtag's href parameter with local ones + const regex = hashtagRegex() + msg = msg.replace(regex, function(matched) { + var a = '<a href="' + OC.generateUrl('/apps/social/timeline/tags/' + matched.substring(1)) + '">' + matched + '</a>' + return a + }) + return msg + }, userDisplayName(actorInfo) { return actorInfo.name !== '' ? actorInfo.name : actorInfo.preferredUsername }, diff --git a/src/store/timeline.js b/src/store/timeline.js index 978154b0..72c29677 100644 --- a/src/store/timeline.js +++ b/src/store/timeline.js @@ -144,10 +144,10 @@ const actions = { postUnlike(context, { post, parentAnnounce }) { return axios.delete(OC.generateUrl(`apps/social/api/v1/post/like?postId=${post.id}`)).then((response) => { context.commit('unlikePost', { post, parentAnnounce }) - // Remove post from list if we are in the 'liked' timeline - if (state.type === 'liked') { - context.commit('removePost', post) - } + // Remove post from list if we are in the 'liked' timeline + if (state.type === 'liked') { + context.commit('removePost', post) + } }).catch((error) => { OC.Notification.showTemporary('Failed to unlike post') console.error('Failed to unlike post', error) |