2020-02-16 18:30:00 +00:00
|
|
|
import Vue from 'vue'
|
2020-08-05 03:44:34 +00:00
|
|
|
import { mapActions } from 'vuex'
|
2020-02-16 18:30:00 +00:00
|
|
|
import FtCard from '../ft-card/ft-card.vue'
|
|
|
|
import FtLoader from '../../components/ft-loader/ft-loader.vue'
|
2020-10-04 22:15:06 +00:00
|
|
|
import FtSelect from '../../components/ft-select/ft-select.vue'
|
2020-09-19 16:19:58 +00:00
|
|
|
import FtTimestampCatcher from '../../components/ft-timestamp-catcher/ft-timestamp-catcher.vue'
|
2020-10-07 15:48:53 +00:00
|
|
|
import autolinker from 'autolinker'
|
2020-10-15 09:51:11 +00:00
|
|
|
import { fork } from 'child_process'
|
|
|
|
import path from 'path'
|
2020-10-23 17:33:56 +00:00
|
|
|
// eslint-disable-next-line
|
|
|
|
import commentControllerRelativePath from 'file-loader!../../../process/comment-module-controller.js'
|
2020-10-04 22:15:06 +00:00
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
export default Vue.extend({
|
|
|
|
name: 'WatchVideoComments',
|
|
|
|
components: {
|
|
|
|
'ft-card': FtCard,
|
2020-09-19 16:19:58 +00:00
|
|
|
'ft-loader': FtLoader,
|
2020-10-04 22:15:06 +00:00
|
|
|
'ft-select': FtSelect,
|
2020-09-19 16:19:58 +00:00
|
|
|
'ft-timestamp-catcher': FtTimestampCatcher
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2020-10-19 14:01:24 +00:00
|
|
|
},
|
|
|
|
channelThumbnail: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
2020-02-18 20:59:01 +00:00
|
|
|
showComments: false,
|
2020-09-26 15:43:01 +00:00
|
|
|
commentScraper: null,
|
2020-02-16 18:30:00 +00:00
|
|
|
nextPageToken: null,
|
2020-10-05 17:52:26 +00:00
|
|
|
commentData: [],
|
2020-10-15 09:51:11 +00:00
|
|
|
sortNewest: false,
|
|
|
|
commentProcess: null,
|
|
|
|
sortingChanged: false
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-10-23 17:33:56 +00:00
|
|
|
isDev: function () {
|
|
|
|
return process.env.NODE_ENV === 'development'
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
backendPreference: function () {
|
|
|
|
return this.$store.getters.getBackendPreference
|
|
|
|
},
|
|
|
|
|
|
|
|
backendFallback: function () {
|
|
|
|
return this.$store.getters.getBackendFallback
|
|
|
|
},
|
|
|
|
|
|
|
|
invidiousInstance: function () {
|
|
|
|
return this.$store.getters.getInvidiousInstance
|
2020-10-04 22:15:06 +00:00
|
|
|
},
|
2020-10-06 02:27:32 +00:00
|
|
|
hideCommentLikes: function () {
|
|
|
|
return this.$store.getters.getHideCommentLikes
|
|
|
|
},
|
2020-10-04 22:15:06 +00:00
|
|
|
|
|
|
|
sortNames: function () {
|
|
|
|
return [
|
|
|
|
this.$t('Comments.Top comments'),
|
|
|
|
this.$t('Comments.Newest first')
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
sortValues: function () {
|
|
|
|
return [
|
|
|
|
'top',
|
|
|
|
'newest'
|
|
|
|
]
|
2020-10-05 17:52:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
currentSortValue: function () {
|
|
|
|
return (this.sortNewest) ? 'newest' : 'top'
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
2020-10-15 09:51:11 +00:00
|
|
|
|
|
|
|
beforeDestroy: function () {
|
|
|
|
if (this.commentProcess !== null) {
|
|
|
|
this.commentProcess.send('end')
|
|
|
|
}
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
methods: {
|
2020-10-04 22:15:06 +00:00
|
|
|
onTimestamp: function (timestamp) {
|
2020-10-04 18:30:54 +00:00
|
|
|
this.$emit('timestamp-event', timestamp)
|
2020-09-19 16:19:58 +00:00
|
|
|
},
|
|
|
|
|
2020-10-04 22:15:06 +00:00
|
|
|
handleSortChange: function (sortType) {
|
2020-10-05 17:52:26 +00:00
|
|
|
this.sortNewest = !this.sortNewest
|
2020-10-08 14:06:06 +00:00
|
|
|
switch (this.backendPreference) {
|
|
|
|
case 'local':
|
2020-10-15 09:51:11 +00:00
|
|
|
console.log('In handle')
|
|
|
|
this.sortingChanged = true
|
|
|
|
this.getCommentDataLocal()
|
2020-10-08 14:06:06 +00:00
|
|
|
break
|
|
|
|
case 'invidious':
|
|
|
|
this.isLoading = true
|
|
|
|
this.commentData = []
|
|
|
|
this.getCommentDataInvidious(null)
|
|
|
|
break
|
|
|
|
}
|
2020-10-04 22:15:06 +00:00
|
|
|
},
|
|
|
|
|
2020-10-15 09:51:11 +00:00
|
|
|
getCommentData: function () {
|
2020-02-16 18:30:00 +00:00
|
|
|
this.isLoading = true
|
|
|
|
switch (this.backendPreference) {
|
|
|
|
case 'local':
|
2020-10-15 09:51:11 +00:00
|
|
|
this.getCommentDataLocal()
|
2020-02-16 18:30:00 +00:00
|
|
|
break
|
|
|
|
case 'invidious':
|
|
|
|
this.getCommentDataInvidious(this.nextPageToken)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-09-22 22:02:20 +00:00
|
|
|
getMoreComments: function () {
|
|
|
|
if (this.commentData.length === 0 || this.nextPageToken === null || typeof this.nextPageToken === 'undefined') {
|
|
|
|
this.showToast({
|
|
|
|
message: this.$t('Comments.There are no more comments for this video')
|
|
|
|
})
|
2020-09-26 15:43:01 +00:00
|
|
|
this.getCommentData()
|
2020-09-22 22:02:20 +00:00
|
|
|
} else {
|
|
|
|
this.getCommentData()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
getCommentReplies: function (index) {
|
|
|
|
switch (this.commentData[index].dataType) {
|
|
|
|
case 'local':
|
|
|
|
this.commentData[index].showReplies = !this.commentData[index].showReplies
|
|
|
|
break
|
|
|
|
case 'invidious':
|
|
|
|
if (this.commentData[index].showReplies || this.commentData[index].replies.length > 0) {
|
|
|
|
this.commentData[index].showReplies = !this.commentData[index].showReplies
|
|
|
|
} else {
|
|
|
|
this.getCommentRepliesInvidious(index)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-15 09:51:11 +00:00
|
|
|
getCommentDataLocal: function () {
|
|
|
|
// we need the path from the working directory to fork correctly
|
|
|
|
if (this.commentProcess === null) {
|
2020-10-23 17:33:56 +00:00
|
|
|
let modulePath
|
|
|
|
if (this.isDev) {
|
|
|
|
modulePath = '../../../process/comment-module-controller.js'
|
|
|
|
} else {
|
|
|
|
modulePath = commentControllerRelativePath
|
|
|
|
}
|
|
|
|
|
|
|
|
this.commentProcess = fork(path.join(__dirname, modulePath), ['args'], {
|
2020-10-20 10:31:48 +00:00
|
|
|
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
|
2020-08-05 03:44:34 +00:00
|
|
|
})
|
2020-10-23 17:33:56 +00:00
|
|
|
|
2020-10-15 09:51:11 +00:00
|
|
|
this.commentProcess.on('message', (msg) => {
|
|
|
|
if (msg.error === null) {
|
|
|
|
const commentJSON = JSON.parse(msg.comments)
|
|
|
|
if (commentJSON === null) {
|
|
|
|
this.showToast({
|
|
|
|
message: this.$t('Comments.No more comments available'),
|
|
|
|
time: 7000,
|
|
|
|
action: () => {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.isLoading = false
|
|
|
|
} else {
|
|
|
|
// console.log(msg.comments)
|
|
|
|
const commentData = commentJSON.map((comment) => {
|
|
|
|
comment.showReplies = false
|
|
|
|
comment.dataType = 'local'
|
|
|
|
this.toLocalePublicationString({
|
|
|
|
publishText: (comment.time + ' ago'),
|
|
|
|
templateString: this.$t('Video.Publicationtemplate'),
|
|
|
|
timeStrings: this.$t('Video.Published'),
|
|
|
|
liveStreamString: this.$t('Video.Watching'),
|
|
|
|
upcomingString: this.$t('Video.Published.Upcoming'),
|
|
|
|
isLive: false,
|
|
|
|
isUpcoming: false,
|
|
|
|
isRSS: false
|
|
|
|
}).then((data) => {
|
|
|
|
comment.time = data
|
|
|
|
}).catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
})
|
|
|
|
if (this.hideCommentLikes) {
|
|
|
|
comment.likes = null
|
|
|
|
}
|
|
|
|
comment.text = autolinker.link(comment.text)
|
|
|
|
comment.replies.forEach((reply) => {
|
|
|
|
reply.text = autolinker.link(reply.text)
|
|
|
|
})
|
|
|
|
return comment
|
|
|
|
})
|
|
|
|
if (this.sortingChanged) {
|
|
|
|
this.commentData = []
|
|
|
|
this.sortingChanged = false
|
|
|
|
}
|
|
|
|
this.commentData = this.commentData.concat(commentData)
|
|
|
|
this.isLoading = false
|
|
|
|
this.showComments = true
|
|
|
|
this.nextPageToken = ''
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log(msg.error)
|
|
|
|
const errorMessage = this.$t('Local API Error (Click to copy)')
|
|
|
|
this.showToast({
|
|
|
|
message: `${errorMessage}: ${msg.error}`,
|
|
|
|
time: 10000,
|
|
|
|
action: () => {
|
|
|
|
navigator.clipboard.writeText(msg.error)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (this.backendFallback && this.backendPreference === 'local') {
|
|
|
|
this.showToast({
|
|
|
|
message: this.$t('Falling back to Invidious API')
|
|
|
|
})
|
|
|
|
this.getCommentDataInvidious()
|
|
|
|
} else {
|
|
|
|
this.isLoading = false
|
|
|
|
}
|
2020-09-26 15:43:01 +00:00
|
|
|
}
|
|
|
|
})
|
2020-10-15 09:51:11 +00:00
|
|
|
}
|
2020-10-23 17:33:56 +00:00
|
|
|
|
2020-10-15 09:51:11 +00:00
|
|
|
this.commentProcess.send({ id: this.id, sortNewest: this.sortNewest })
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getCommentDataInvidious: function () {
|
|
|
|
const payload = {
|
|
|
|
resource: 'comments',
|
|
|
|
id: this.id,
|
|
|
|
params: {
|
2020-10-08 14:06:06 +00:00
|
|
|
continuation: this.nextPageToken,
|
|
|
|
sort_by: this.sortNewest ? 'new' : 'top'
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 01:59:59 +00:00
|
|
|
this.invidiousAPICall(payload).then((response) => {
|
2020-02-16 18:30:00 +00:00
|
|
|
console.log(response)
|
|
|
|
|
|
|
|
const commentData = response.comments.map((comment) => {
|
|
|
|
comment.showReplies = false
|
2020-10-13 15:06:04 +00:00
|
|
|
comment.authorThumb = comment.authorThumbnails[1].url.replace('https://yt3.ggpht.com', `${this.invidiousInstance}/ggpht/`)
|
2020-10-06 02:27:32 +00:00
|
|
|
if (this.hideCommentLikes) {
|
|
|
|
comment.likes = null
|
|
|
|
} else {
|
|
|
|
comment.likes = comment.likeCount
|
|
|
|
}
|
2020-10-08 14:06:06 +00:00
|
|
|
comment.text = autolinker.link(comment.content)
|
2020-02-16 18:30:00 +00:00
|
|
|
comment.dataType = 'invidious'
|
|
|
|
|
|
|
|
if (typeof (comment.replies) !== 'undefined' && typeof (comment.replies.replyCount) !== 'undefined') {
|
|
|
|
comment.numReplies = comment.replies.replyCount
|
|
|
|
comment.replyContinuation = comment.replies.continuation
|
|
|
|
} else {
|
|
|
|
comment.numReplies = 0
|
|
|
|
comment.replyContinuation = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
comment.replies = []
|
|
|
|
|
2020-09-26 15:43:01 +00:00
|
|
|
comment.time = comment.publishedText
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
return comment
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(commentData)
|
|
|
|
this.commentData = this.commentData.concat(commentData)
|
|
|
|
this.nextPageToken = response.continuation
|
|
|
|
this.isLoading = false
|
2020-02-18 20:59:01 +00:00
|
|
|
this.showComments = true
|
2020-02-16 18:30:00 +00:00
|
|
|
}).catch((xhr) => {
|
|
|
|
console.log('found an error')
|
|
|
|
console.log(xhr)
|
2020-08-08 02:16:06 +00:00
|
|
|
const errorMessage = this.$t('Invidious API Error (Click to copy)')
|
|
|
|
this.showToast({
|
|
|
|
message: `${errorMessage}: ${xhr.responseText}`,
|
|
|
|
time: 10000,
|
|
|
|
action: () => {
|
|
|
|
navigator.clipboard.writeText(xhr.responseText)
|
|
|
|
}
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
if (this.backendFallback && this.backendPreference === 'invidious') {
|
2020-08-08 02:16:06 +00:00
|
|
|
this.showToast({
|
2020-09-21 01:59:59 +00:00
|
|
|
message: this.$t('Falling back to local API')
|
2020-08-08 02:16:06 +00:00
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
this.getCommentDataLocal()
|
|
|
|
} else {
|
|
|
|
this.isLoading = false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
getCommentRepliesInvidious: function (index) {
|
2020-08-08 02:16:06 +00:00
|
|
|
this.showToast({
|
2020-09-22 22:02:20 +00:00
|
|
|
message: this.$t('Comments.Getting comment replies, please wait')
|
2020-08-08 02:16:06 +00:00
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
const payload = {
|
|
|
|
resource: 'comments',
|
|
|
|
id: this.id,
|
|
|
|
params: {
|
|
|
|
continuation: this.commentData[index].replyContinuation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$store.dispatch('invidiousAPICall', payload).then((response) => {
|
|
|
|
console.log(response)
|
|
|
|
|
|
|
|
const commentData = response.comments.map((comment) => {
|
|
|
|
comment.showReplies = false
|
2020-10-13 15:06:04 +00:00
|
|
|
comment.authorThumb = comment.authorThumbnails[1].url.replace('https://yt3.ggpht.com', `${this.invidiousInstance}/ggpht/`)
|
2020-10-06 02:27:32 +00:00
|
|
|
if (this.hideCommentLikes) {
|
|
|
|
comment.likes = null
|
|
|
|
} else {
|
|
|
|
comment.likes = comment.likeCount
|
|
|
|
}
|
2020-10-08 14:06:06 +00:00
|
|
|
comment.text = autolinker.link(comment.content)
|
2020-09-26 15:43:01 +00:00
|
|
|
comment.time = comment.publishedText
|
2020-02-16 18:30:00 +00:00
|
|
|
comment.dataType = 'invidious'
|
|
|
|
comment.numReplies = 0
|
|
|
|
comment.replyContinuation = ''
|
|
|
|
comment.replies = []
|
|
|
|
|
|
|
|
return comment
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(commentData)
|
|
|
|
this.commentData[index].replies = commentData
|
|
|
|
this.commentData[index].showReplies = true
|
|
|
|
this.isLoading = false
|
|
|
|
}).catch((xhr) => {
|
|
|
|
console.log('found an error')
|
|
|
|
console.log(xhr)
|
2020-08-08 02:16:06 +00:00
|
|
|
const errorMessage = this.$t('Invidious API Error (Click to copy)')
|
|
|
|
this.showToast({
|
|
|
|
message: `${errorMessage}: ${xhr.responseText}`,
|
|
|
|
time: 10000,
|
|
|
|
action: () => {
|
|
|
|
navigator.clipboard.writeText(xhr.responseText)
|
|
|
|
}
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
this.isLoading = false
|
|
|
|
})
|
2020-08-05 03:44:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
...mapActions([
|
2020-09-21 01:59:59 +00:00
|
|
|
'showToast',
|
2020-09-26 15:43:01 +00:00
|
|
|
'toLocalePublicationString',
|
2020-09-21 01:59:59 +00:00
|
|
|
'invidiousAPICall'
|
2020-08-05 03:44:34 +00:00
|
|
|
])
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
})
|