fix: timestamp for notes from the future #38

This commit is contained in:
Gísli Kristjánsson 2023-02-02 00:24:10 +00:00 committed by Gísli Kristjánsson
parent f702155222
commit 24e5b37c25
No known key found for this signature in database
GPG Key ID: 5CE046CC652F7368

View File

@ -31,6 +31,12 @@ import DateUtils from 'src/utils/DateUtils'
import Bots from 'src/utils/bots' import Bots from 'src/utils/bots'
const feedOrder = (a, b) => b[0].createdAt - a[0].createdAt const feedOrder = (a, b) => b[0].createdAt - a[0].createdAt
const maxDate = (max) => (note) => {
if (note.createdAt > max)
note.createdAt = max
return note
}
const now = () => new Date().getTime() / 1000
const MAX_ITEMS_VISIBLE = 25 const MAX_ITEMS_VISIBLE = 25
@ -94,7 +100,8 @@ export default {
const items = notes const items = notes
.concat(data) .concat(data)
.filter((note) => this.filterNote(note, this.feed.hideBots)) .filter((note) => this.filterNote(note, this.feed.hideBots))
.map((note) => [note]) // TODO Single element thread .map(maxDate(now()))
.map(note => [note]) // TODO Single element thread
.sort(feedOrder) .sort(feedOrder)
.filter( .filter(
(item, pos, array) => !pos || item[0].id !== array[pos - 1][0].id (item, pos, array) => !pos || item[0].id !== array[pos - 1][0].id
@ -110,6 +117,7 @@ export default {
}) })
this.stream.on('update', (note) => { this.stream.on('update', (note) => {
if (!this.filterNote(note, this.feed.hideBots)) return if (!this.filterNote(note, this.feed.hideBots)) return
note = maxDate(now())(note)
if (note.createdAt >= this.timestampNewest) { if (note.createdAt >= this.timestampNewest) {
this.newer.push([note]) // TODO Single element thread this.newer.push([note]) // TODO Single element thread
} else if (note.createdAt >= this.timestampOldest) { } else if (note.createdAt >= this.timestampOldest) {