Skip to content

Commit

Permalink
Merge pull request #661 from StCyr/stcyr_fix656
Browse files Browse the repository at this point in the history
Uses hashtag-regex to rewrite hashtag's href rather than linkifyjs.
  • Loading branch information
ArtificialOwl committed Jul 26, 2019
2 parents e64c1b5 + 3619ac5 commit 2dcdedd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/Model/ActivityPub/Object/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function import(array $data) {
parent::import($data);

$this->importAttachments($this->getArray('attachment', $data, []));
$this->fillHashtags();
}


Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 13 additions & 6 deletions src/components/TimelinePost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
},
Expand All @@ -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
},
Expand Down
8 changes: 4 additions & 4 deletions src/store/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2dcdedd

Please sign in to comment.