forked from AkkomaGang/akkoma-fe
change timeline min/max id updating behavior to not get stuck with 20 wrong type of activities on fetch older.
This commit is contained in:
parent
dc0fd8177c
commit
a0e7803e42
2 changed files with 28 additions and 119 deletions
|
@ -1,7 +1,23 @@
|
||||||
import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, last, merge, max, isArray } from 'lodash'
|
import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, max, min, isArray } from 'lodash'
|
||||||
import apiService from '../services/api/api.service.js'
|
import apiService from '../services/api/api.service.js'
|
||||||
// import parse from '../services/status_parser/status_parser.js'
|
// import parse from '../services/status_parser/status_parser.js'
|
||||||
|
|
||||||
|
const emptyTl = () => ({
|
||||||
|
statuses: [],
|
||||||
|
statusesObject: {},
|
||||||
|
faves: [],
|
||||||
|
visibleStatuses: [],
|
||||||
|
visibleStatusesObject: {},
|
||||||
|
newStatusCount: 0,
|
||||||
|
maxId: 0,
|
||||||
|
minVisibleId: 0,
|
||||||
|
loading: false,
|
||||||
|
followers: [],
|
||||||
|
friends: [],
|
||||||
|
viewing: 'statuses',
|
||||||
|
flushMarker: 0
|
||||||
|
})
|
||||||
|
|
||||||
export const defaultState = {
|
export const defaultState = {
|
||||||
allStatuses: [],
|
allStatuses: [],
|
||||||
allStatusesObject: {},
|
allStatusesObject: {},
|
||||||
|
@ -10,96 +26,12 @@ export const defaultState = {
|
||||||
favorites: new Set(),
|
favorites: new Set(),
|
||||||
error: false,
|
error: false,
|
||||||
timelines: {
|
timelines: {
|
||||||
mentions: {
|
mentions: emptyTl(),
|
||||||
statuses: [],
|
public: emptyTl(),
|
||||||
statusesObject: {},
|
user: emptyTl(),
|
||||||
faves: [],
|
publicAndExternal: emptyTl(),
|
||||||
visibleStatuses: [],
|
friends: emptyTl(),
|
||||||
visibleStatusesObject: {},
|
tag: emptyTl()
|
||||||
newStatusCount: 0,
|
|
||||||
maxId: 0,
|
|
||||||
minVisibleId: 0,
|
|
||||||
loading: false,
|
|
||||||
followers: [],
|
|
||||||
friends: [],
|
|
||||||
viewing: 'statuses',
|
|
||||||
flushMarker: 0
|
|
||||||
},
|
|
||||||
public: {
|
|
||||||
statuses: [],
|
|
||||||
statusesObject: {},
|
|
||||||
faves: [],
|
|
||||||
visibleStatuses: [],
|
|
||||||
visibleStatusesObject: {},
|
|
||||||
newStatusCount: 0,
|
|
||||||
maxId: 0,
|
|
||||||
minVisibleId: 0,
|
|
||||||
loading: false,
|
|
||||||
followers: [],
|
|
||||||
friends: [],
|
|
||||||
viewing: 'statuses',
|
|
||||||
flushMarker: 0
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
statuses: [],
|
|
||||||
statusesObject: {},
|
|
||||||
faves: [],
|
|
||||||
visibleStatuses: [],
|
|
||||||
visibleStatusesObject: {},
|
|
||||||
newStatusCount: 0,
|
|
||||||
maxId: 0,
|
|
||||||
minVisibleId: 0,
|
|
||||||
loading: false,
|
|
||||||
followers: [],
|
|
||||||
friends: [],
|
|
||||||
viewing: 'statuses',
|
|
||||||
flushMarker: 0
|
|
||||||
},
|
|
||||||
publicAndExternal: {
|
|
||||||
statuses: [],
|
|
||||||
statusesObject: {},
|
|
||||||
faves: [],
|
|
||||||
visibleStatuses: [],
|
|
||||||
visibleStatusesObject: {},
|
|
||||||
newStatusCount: 0,
|
|
||||||
maxId: 0,
|
|
||||||
minVisibleId: 0,
|
|
||||||
loading: false,
|
|
||||||
followers: [],
|
|
||||||
friends: [],
|
|
||||||
viewing: 'statuses',
|
|
||||||
flushMarker: 0
|
|
||||||
},
|
|
||||||
friends: {
|
|
||||||
statuses: [],
|
|
||||||
statusesObject: {},
|
|
||||||
faves: [],
|
|
||||||
visibleStatuses: [],
|
|
||||||
visibleStatusesObject: {},
|
|
||||||
newStatusCount: 0,
|
|
||||||
maxId: 0,
|
|
||||||
minVisibleId: 0,
|
|
||||||
loading: false,
|
|
||||||
followers: [],
|
|
||||||
friends: [],
|
|
||||||
viewing: 'statuses',
|
|
||||||
flushMarker: 0
|
|
||||||
},
|
|
||||||
tag: {
|
|
||||||
statuses: [],
|
|
||||||
statusesObject: {},
|
|
||||||
faves: [],
|
|
||||||
visibleStatuses: [],
|
|
||||||
visibleStatusesObject: {},
|
|
||||||
newStatusCount: 0,
|
|
||||||
maxId: 0,
|
|
||||||
minVisibleId: 0,
|
|
||||||
loading: false,
|
|
||||||
followers: [],
|
|
||||||
friends: [],
|
|
||||||
viewing: 'statuses',
|
|
||||||
flushMarker: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,8 +106,6 @@ const mergeOrAdd = (arr, obj, item) => {
|
||||||
const sortTimeline = (timeline) => {
|
const sortTimeline = (timeline) => {
|
||||||
timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id)
|
timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id)
|
||||||
timeline.statuses = sortBy(timeline.statuses, ({id}) => -id)
|
timeline.statuses = sortBy(timeline.statuses, ({id}) => -id)
|
||||||
timeline.minVisibleId = (last(timeline.visibleStatuses) || {}).id
|
|
||||||
|
|
||||||
return timeline
|
return timeline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,10 +119,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
const allStatusesObject = state.allStatusesObject
|
const allStatusesObject = state.allStatusesObject
|
||||||
const timelineObject = state.timelines[timeline]
|
const timelineObject = state.timelines[timeline]
|
||||||
|
|
||||||
// Set the maxId to the new id if it's larger.
|
if (timeline && !noIdUpdate) {
|
||||||
const updateMaxId = ({id}) => {
|
timelineObject.maxId = max([maxBy(statuses, 'id').id + 1, timelineObject.maxId])
|
||||||
if (!timeline || noIdUpdate) { return false }
|
timelineObject.minVisibleId = min([minBy(statuses, 'id').id - 1, timelineObject.minVisibleId])
|
||||||
timelineObject.maxId = max([id, timelineObject.maxId])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const addStatus = (status, showImmediately, addToTimeline = true) => {
|
const addStatus = (status, showImmediately, addToTimeline = true) => {
|
||||||
|
@ -200,8 +129,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
status = result.item
|
status = result.item
|
||||||
|
|
||||||
if (result.new) {
|
if (result.new) {
|
||||||
updateMaxId(status)
|
|
||||||
|
|
||||||
if (statusType(status) === 'retweet' && status.retweeted_status.user.id === user.id) {
|
if (statusType(status) === 'retweet' && status.retweeted_status.user.id === user.id) {
|
||||||
addNotification({ type: 'repeat', status: status.retweeted_status, action: status })
|
addNotification({ type: 'repeat', status: status.retweeted_status, action: status })
|
||||||
}
|
}
|
||||||
|
@ -317,7 +244,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
// Only update if this is a new favorite.
|
// Only update if this is a new favorite.
|
||||||
if (!state.favorites.has(favorite.id)) {
|
if (!state.favorites.has(favorite.id)) {
|
||||||
state.favorites.add(favorite.id)
|
state.favorites.add(favorite.id)
|
||||||
updateMaxId(favorite)
|
|
||||||
favoriteStatus(favorite)
|
favoriteStatus(favorite)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -330,7 +256,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
||||||
},
|
},
|
||||||
'deletion': (deletion) => {
|
'deletion': (deletion) => {
|
||||||
const uri = deletion.uri
|
const uri = deletion.uri
|
||||||
updateMaxId(deletion)
|
|
||||||
|
|
||||||
// Remove possible notification
|
// Remove possible notification
|
||||||
const status = find(allStatuses, {uri})
|
const status = find(allStatuses, {uri})
|
||||||
|
@ -375,23 +300,7 @@ export const mutations = {
|
||||||
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
|
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
|
||||||
},
|
},
|
||||||
clearTimeline (state, { timeline }) {
|
clearTimeline (state, { timeline }) {
|
||||||
const emptyTimeline = {
|
state.timelines[timeline] = emptyTl()
|
||||||
statuses: [],
|
|
||||||
statusesObject: {},
|
|
||||||
faves: [],
|
|
||||||
visibleStatuses: [],
|
|
||||||
visibleStatusesObject: {},
|
|
||||||
newStatusCount: 0,
|
|
||||||
maxId: 0,
|
|
||||||
minVisibleId: 0,
|
|
||||||
loading: false,
|
|
||||||
followers: [],
|
|
||||||
friends: [],
|
|
||||||
viewing: 'statuses',
|
|
||||||
flushMarker: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
state.timelines[timeline] = emptyTimeline
|
|
||||||
},
|
},
|
||||||
setFavorited (state, { status, value }) {
|
setFavorited (state, { status, value }) {
|
||||||
const newStatus = state.allStatusesObject[status.id]
|
const newStatus = state.allStatusesObject[status.id]
|
||||||
|
|
|
@ -30,7 +30,7 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false
|
||||||
|
|
||||||
return apiService.fetchTimeline(args)
|
return apiService.fetchTimeline(args)
|
||||||
.then((statuses) => {
|
.then((statuses) => {
|
||||||
if (!older && statuses.length >= 20) {
|
if (!older && statuses.length >= 20 && !timelineData.loading) {
|
||||||
store.dispatch('queueFlush', { timeline: timeline, id: timelineData.maxId })
|
store.dispatch('queueFlush', { timeline: timeline, id: timelineData.maxId })
|
||||||
}
|
}
|
||||||
update({store, statuses, timeline, showImmediately})
|
update({store, statuses, timeline, showImmediately})
|
||||||
|
|
Loading…
Reference in a new issue