Skip to content

Commit

Permalink
* Save community post publish time in absolute time not relative time…
Browse files Browse the repository at this point in the history
… text
  • Loading branch information
PikachuEXE committed Sep 9, 2024
1 parent 52a4367 commit 26e2328
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import autolinker from 'autolinker'

import { A11y, Navigation, Pagination } from 'swiper/modules'

import { createWebURL, deepCopy, toLocalePublicationString } from '../../helpers/utils'
import {
createWebURL,
deepCopy,
getRelativeTimeFromDate,
toLocalePublicationString,
} from '../../helpers/utils'
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'

export default defineComponent({
Expand Down Expand Up @@ -121,7 +126,7 @@ export default defineComponent({
this.postContent = this.data.postContent
this.postId = this.data.postId
this.publishedText = toLocalePublicationString({
publishText: this.data.publishedText,
publishText: getRelativeTimeFromDate(this.data.publishedTime),
isLive: this.isLive,
isUpcoming: this.isUpcoming,
isRSS: this.data.isRSS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineComponent } from 'vue'
import { mapActions, mapMutations } from 'vuex'
import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue'

import { calculatePublishedDate, copyToClipboard, getRelativeTimeFromDate, showToast } from '../../helpers/utils'
import { copyToClipboard, getRelativeTimeFromDate, showToast } from '../../helpers/utils'
import { getLocalChannelCommunity } from '../../helpers/api/local'
import { invidiousGetCommunityPosts } from '../../helpers/api/invidious'

Expand Down Expand Up @@ -122,7 +122,7 @@ export default defineComponent({
})

postList.sort((a, b) => {
return calculatePublishedDate(b.publishedText) - calculatePublishedDate(a.publishedText)
return b.publishedTime - a.publishedTime
})

this.postList = postList
Expand Down Expand Up @@ -194,7 +194,7 @@ export default defineComponent({
}))).flatMap((o) => o)
postList.push(...postListFromRemote)
postList.sort((a, b) => {
return calculatePublishedDate(b.publishedText) - calculatePublishedDate(a.publishedText)
return b.publishedTime - a.publishedTime
})

this.postList = postList
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/helpers/api/invidious.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import store from '../../store/index'
import { stripHTML, toLocalePublicationString } from '../utils'
import {
calculatePublishedDate,
stripHTML,
toLocalePublicationString,
} from '../utils'
import { isNullOrEmpty } from '../strings'
import autolinker from 'autolinker'
import { FormatUtils, Misc, Player } from 'youtubei.js'
Expand Down Expand Up @@ -208,7 +212,7 @@ function parseInvidiousCommunityData(data) {
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
return thumbnail
}),
publishedText: data.publishedText,
publishedTime: calculatePublishedDate(data.publishedText),
voteCount: data.likeCount,
postContent: parseInvidiousCommunityAttachments(data.attachment),
commentCount: data?.replyCount ?? 0, // https://github.com/iv-org/invidious/pull/3635/
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ function parseLocalCommunityPost(post) {
postText: post.content.isEmpty() ? '' : Autolinker.link(parseLocalTextRuns(post.content.runs, 16)),
postId: post.id,
authorThumbnails: post.author.thumbnails,
publishedText: post.published.text,
publishedTime: calculatePublishedDate(post.published.text),
voteCount: post.vote_count.text,
postContent: parseLocalAttachment(post.attachment),
commentCount: replyCount,
Expand Down

0 comments on commit 26e2328

Please sign in to comment.