added workaround for broken favorites
This commit is contained in:
parent
ef515056b5
commit
ef04a78634
6 changed files with 51 additions and 10 deletions
|
@ -46,6 +46,10 @@ const api = {
|
|||
store.commit('addFetcher', {timeline, fetcher})
|
||||
}
|
||||
},
|
||||
fetchOldPost (store, { postId }) {
|
||||
console.log(store)
|
||||
store.state.backendInteractor.fetchOldPost({ store, postId })
|
||||
},
|
||||
stopFetching (store, timeline) {
|
||||
const fetcher = store.state.fetchers[timeline]
|
||||
window.clearInterval(fetcher)
|
||||
|
|
|
@ -27,7 +27,8 @@ export const defaultState = {
|
|||
maxId: 0,
|
||||
maxSavedId: 0,
|
||||
minId: Number.POSITIVE_INFINITY,
|
||||
data: []
|
||||
data: [],
|
||||
brokenFavorites: {}
|
||||
},
|
||||
favorites: new Set(),
|
||||
error: false,
|
||||
|
@ -35,6 +36,7 @@ export const defaultState = {
|
|||
mentions: emptyTl(),
|
||||
public: emptyTl(),
|
||||
user: emptyTl(),
|
||||
own: emptyTl(),
|
||||
publicAndExternal: emptyTl(),
|
||||
friends: emptyTl(),
|
||||
tag: emptyTl()
|
||||
|
@ -140,6 +142,12 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
const result = mergeOrAdd(allStatuses, allStatusesObject, status)
|
||||
status = result.item
|
||||
|
||||
const brokenFavorites = state.notifications.brokenFavorites[status.id] || []
|
||||
brokenFavorites.forEach((fav) => {
|
||||
fav.status = status
|
||||
})
|
||||
delete state.notifications.brokenFavorites[status.id]
|
||||
|
||||
if (result.new) {
|
||||
// We are mentioned in a post
|
||||
if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) {
|
||||
|
@ -174,7 +182,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
return status
|
||||
}
|
||||
|
||||
const favoriteStatus = (favorite) => {
|
||||
const favoriteStatus = (favorite, counter) => {
|
||||
const status = find(allStatuses, { id: toInteger(favorite.in_reply_to_status_id) })
|
||||
if (status) {
|
||||
status.fave_num += 1
|
||||
|
@ -258,7 +266,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
|
|||
}
|
||||
}
|
||||
|
||||
const addNewNotifications = (state, { notifications, older }) => {
|
||||
const addNewNotifications = (state, { dispatch, notifications, older }) => {
|
||||
const allStatuses = state.allStatuses
|
||||
each(notifications, (notification) => {
|
||||
const action = notification.notice
|
||||
|
@ -267,18 +275,31 @@ const addNewNotifications = (state, { notifications, older }) => {
|
|||
state.notifications.maxId = Math.max(notification.id, state.notifications.maxId)
|
||||
state.notifications.minId = Math.min(notification.id, state.notifications.minId)
|
||||
|
||||
console.log(notification)
|
||||
const fresh = !older && !notification.is_seen && notification.id > state.notifications.maxSavedId
|
||||
const status = notification.ntype === 'like'
|
||||
? find(allStatuses, { id: action.in_reply_to_status_id })
|
||||
: action
|
||||
state.notifications.data.push({
|
||||
|
||||
const result = {
|
||||
type: notification.ntype,
|
||||
status,
|
||||
action,
|
||||
// Always assume older notifications as seen
|
||||
seen: !fresh
|
||||
})
|
||||
}
|
||||
|
||||
if (notification.ntype === 'like' && !status) {
|
||||
let broken = state.notifications.brokenFavorites[action.in_reply_to_status_id]
|
||||
if (broken) {
|
||||
broken.push(result)
|
||||
} else {
|
||||
dispatch('fetchOldPost', { postId: action.in_reply_to_status_id })
|
||||
broken = [ result ]
|
||||
state.notifications.brokenFavorites[action.in_reply_to_status_id] = broken
|
||||
}
|
||||
}
|
||||
|
||||
state.notifications.data.push(result)
|
||||
|
||||
if ('Notification' in window && window.Notification.permission === 'granted') {
|
||||
const title = action.user.name
|
||||
|
@ -370,8 +391,8 @@ const statuses = {
|
|||
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) {
|
||||
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser })
|
||||
},
|
||||
addNewNotifications ({ rootState, commit }, { notifications, older }) {
|
||||
commit('addNewNotifications', { notifications, older })
|
||||
addNewNotifications ({ rootState, commit, dispatch }, { notifications, older }) {
|
||||
commit('addNewNotifications', { dispatch, notifications, older })
|
||||
},
|
||||
setError ({ rootState, commit }, { value }) {
|
||||
commit('setError', { value })
|
||||
|
|
|
@ -103,6 +103,8 @@ const users = {
|
|||
|
||||
// Start getting fresh tweets.
|
||||
store.dispatch('startFetching', 'friends')
|
||||
// Start getting our own posts, only really needed for mitigating broken favorites
|
||||
store.dispatch('startFetching', ['own', user.id])
|
||||
|
||||
// Get user mutes and follower info
|
||||
store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
|
||||
|
|
|
@ -305,6 +305,9 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
|
|||
notifications: QVITTER_USER_NOTIFICATIONS_URL,
|
||||
'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL,
|
||||
user: QVITTER_USER_TIMELINE_URL,
|
||||
// separate timeline for own posts, so it won't break due to user timeline bugs
|
||||
// really needed only for broken favorites
|
||||
own: QVITTER_USER_TIMELINE_URL,
|
||||
tag: TAG_TIMELINE_URL
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,16 @@ const backendInteractorService = (credentials) => {
|
|||
return timelineFetcherService.startFetching({timeline, store, credentials, userId})
|
||||
}
|
||||
|
||||
const fetchOldPost = ({store, postId}) => {
|
||||
return timelineFetcherService.fetchAndUpdate({
|
||||
store,
|
||||
credentials,
|
||||
timeline: 'own',
|
||||
older: true,
|
||||
until: postId
|
||||
})
|
||||
}
|
||||
|
||||
const setUserMute = ({id, muted = true}) => {
|
||||
return apiService.setUserMute({id, muted, credentials})
|
||||
}
|
||||
|
@ -86,6 +96,7 @@ const backendInteractorService = (credentials) => {
|
|||
fetchAllFollowing,
|
||||
verifyCredentials: apiService.verifyCredentials,
|
||||
startFetching,
|
||||
fetchOldPost,
|
||||
setUserMute,
|
||||
fetchMutes,
|
||||
register,
|
||||
|
|
|
@ -14,13 +14,13 @@ const update = ({store, statuses, timeline, showImmediately}) => {
|
|||
})
|
||||
}
|
||||
|
||||
const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false}) => {
|
||||
const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false, until}) => {
|
||||
const args = { timeline, credentials }
|
||||
const rootState = store.rootState || store.state
|
||||
const timelineData = rootState.statuses.timelines[camelCase(timeline)]
|
||||
|
||||
if (older) {
|
||||
args['until'] = timelineData.minVisibleId
|
||||
args['until'] = until || timelineData.minVisibleId
|
||||
} else {
|
||||
args['since'] = timelineData.maxId
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue