From a1f6ef1dcac2e79c5a116705ca11d6e7e51ed89c Mon Sep 17 00:00:00 2001 From: shpuld Date: Wed, 11 Apr 2018 19:34:40 +0300 Subject: Loads of fixes: notifs, autoload setting, overflow, faint text, reply form, status fadein. --- src/modules/statuses.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/statuses.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 18191424..8bc0631e 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -246,7 +246,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const addNotification = ({type, status, action}) => { // Only add a new notification if we don't have one for the same action if (!find(state.notifications, (oldNotification) => oldNotification.action.id === action.id)) { - state.notifications.push({type, status, action, seen: false}) + state.notifications.push({ type, status, action, seen: false }) if ('Notification' in window && window.Notification.permission === 'granted') { const title = action.user.name -- cgit v1.2.3-70-g09d2 From a0e7803e42afa64b03a441ed576ac4ed816cc735 Mon Sep 17 00:00:00 2001 From: shpuld Date: Fri, 13 Apr 2018 22:35:55 +0300 Subject: change timeline min/max id updating behavior to not get stuck with 20 wrong type of activities on fetch older. --- src/modules/statuses.js | 145 ++++----------------- .../timeline_fetcher/timeline_fetcher.service.js | 2 +- 2 files changed, 28 insertions(+), 119 deletions(-) (limited to 'src/modules/statuses.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 8bc0631e..bbdd87b5 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -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 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 = { allStatuses: [], allStatusesObject: {}, @@ -10,96 +26,12 @@ export const defaultState = { favorites: new Set(), error: false, timelines: { - mentions: { - statuses: [], - statusesObject: {}, - faves: [], - visibleStatuses: [], - visibleStatusesObject: {}, - 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 - } + mentions: emptyTl(), + public: emptyTl(), + user: emptyTl(), + publicAndExternal: emptyTl(), + friends: emptyTl(), + tag: emptyTl() } } @@ -174,8 +106,6 @@ const mergeOrAdd = (arr, obj, item) => { const sortTimeline = (timeline) => { timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id) timeline.statuses = sortBy(timeline.statuses, ({id}) => -id) - timeline.minVisibleId = (last(timeline.visibleStatuses) || {}).id - return timeline } @@ -189,10 +119,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const allStatusesObject = state.allStatusesObject const timelineObject = state.timelines[timeline] - // Set the maxId to the new id if it's larger. - const updateMaxId = ({id}) => { - if (!timeline || noIdUpdate) { return false } - timelineObject.maxId = max([id, timelineObject.maxId]) + if (timeline && !noIdUpdate) { + timelineObject.maxId = max([maxBy(statuses, 'id').id + 1, timelineObject.maxId]) + timelineObject.minVisibleId = min([minBy(statuses, 'id').id - 1, timelineObject.minVisibleId]) } const addStatus = (status, showImmediately, addToTimeline = true) => { @@ -200,8 +129,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us status = result.item if (result.new) { - updateMaxId(status) - if (statusType(status) === 'retweet' && status.retweeted_status.user.id === user.id) { 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. if (!state.favorites.has(favorite.id)) { state.favorites.add(favorite.id) - updateMaxId(favorite) favoriteStatus(favorite) } }, @@ -330,7 +256,6 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us }, 'deletion': (deletion) => { const uri = deletion.uri - updateMaxId(deletion) // Remove possible notification const status = find(allStatuses, {uri}) @@ -375,23 +300,7 @@ export const mutations = { each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) }, clearTimeline (state, { timeline }) { - const emptyTimeline = { - statuses: [], - statusesObject: {}, - faves: [], - visibleStatuses: [], - visibleStatusesObject: {}, - newStatusCount: 0, - maxId: 0, - minVisibleId: 0, - loading: false, - followers: [], - friends: [], - viewing: 'statuses', - flushMarker: 0 - } - - state.timelines[timeline] = emptyTimeline + state.timelines[timeline] = emptyTl() }, setFavorited (state, { status, value }) { const newStatus = state.allStatusesObject[status.id] diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index a4a80df0..bb5fdc2e 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -30,7 +30,7 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false return apiService.fetchTimeline(args) .then((statuses) => { - if (!older && statuses.length >= 20) { + if (!older && statuses.length >= 20 && !timelineData.loading) { store.dispatch('queueFlush', { timeline: timeline, id: timelineData.maxId }) } update({store, statuses, timeline, showImmediately}) -- cgit v1.2.3-70-g09d2 From dff27357d4ba19138436399cc740dce49af2781f Mon Sep 17 00:00:00 2001 From: shpuld Date: Sat, 14 Apr 2018 16:33:53 +0300 Subject: remove +1/-1 from min/max id checking --- src/modules/statuses.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/modules/statuses.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index bbdd87b5..2d49773c 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -120,8 +120,8 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const timelineObject = state.timelines[timeline] if (timeline && !noIdUpdate) { - timelineObject.maxId = max([maxBy(statuses, 'id').id + 1, timelineObject.maxId]) - timelineObject.minVisibleId = min([minBy(statuses, 'id').id - 1, timelineObject.minVisibleId]) + timelineObject.maxId = max([maxBy(statuses, 'id').id, timelineObject.maxId]) + timelineObject.minVisibleId = min([minBy(statuses, 'id').id, timelineObject.minVisibleId]) } const addStatus = (status, showImmediately, addToTimeline = true) => { -- cgit v1.2.3-70-g09d2 From 3488141fdd8362502988eadaadaa210939f318bd Mon Sep 17 00:00:00 2001 From: shpuld Date: Sat, 14 Apr 2018 17:18:07 +0300 Subject: Whoops, broke older statuses accidentally --- src/modules/statuses.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/modules/statuses.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 2d49773c..8f5a5c1d 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -119,9 +119,12 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const allStatusesObject = state.allStatusesObject const timelineObject = state.timelines[timeline] - if (timeline && !noIdUpdate) { + if (timeline && !noIdUpdate && statuses.length > 0) { timelineObject.maxId = max([maxBy(statuses, 'id').id, timelineObject.maxId]) timelineObject.minVisibleId = min([minBy(statuses, 'id').id, timelineObject.minVisibleId]) + if (timelineObject.minVisibleId <= 0) { + timelineObject.minVisibleId = minBy(statuses, 'id').id + } } const addStatus = (status, showImmediately, addToTimeline = true) => { -- cgit v1.2.3-70-g09d2 From e88bb1a23ed76a4cf2b3632d346c3372ff007f97 Mon Sep 17 00:00:00 2001 From: shpuld Date: Sat, 14 Apr 2018 22:13:28 +0300 Subject: I broke timelines again, fixed now again (hopefully). --- src/modules/statuses.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/modules/statuses.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 8f5a5c1d..98164a31 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -1,4 +1,4 @@ -import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, max, min, isArray } from 'lodash' +import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash' import apiService from '../services/api/api.service.js' // import parse from '../services/status_parser/status_parser.js' @@ -106,6 +106,7 @@ const mergeOrAdd = (arr, obj, item) => { const sortTimeline = (timeline) => { timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id) timeline.statuses = sortBy(timeline.statuses, ({id}) => -id) + timeline.minVisibleId = (last(timeline.visibleStatuses) || {}).id return timeline } @@ -119,12 +120,11 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const allStatusesObject = state.allStatusesObject const timelineObject = state.timelines[timeline] - if (timeline && !noIdUpdate && statuses.length > 0) { - timelineObject.maxId = max([maxBy(statuses, 'id').id, timelineObject.maxId]) - timelineObject.minVisibleId = min([minBy(statuses, 'id').id, timelineObject.minVisibleId]) - if (timelineObject.minVisibleId <= 0) { - timelineObject.minVisibleId = minBy(statuses, 'id').id - } + const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0 + const older = maxNew < timelineObject.maxId + + if (timeline && !noIdUpdate && statuses.length > 0 && !older) { + timelineObject.maxId = maxNew } const addStatus = (status, showImmediately, addToTimeline = true) => { @@ -289,6 +289,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us // Keep the visible statuses sorted if (timeline) { sortTimeline(timelineObject) + if ((older || timelineObject.minVisibleId <= 0) && statuses.length > 0) { + timelineObject.minVisibleId = minBy(statuses, 'id').id + } } } @@ -299,6 +302,7 @@ export const mutations = { oldTimeline.newStatusCount = 0 oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50) + oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id oldTimeline.visibleStatusesObject = {} each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) }, -- cgit v1.2.3-70-g09d2 From 208b2ed12528053efa351f1720cd316dbdac8aa9 Mon Sep 17 00:00:00 2001 From: shpuld Date: Sun, 15 Apr 2018 00:06:00 +0300 Subject: Additional check to make console shut up --- src/modules/statuses.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/statuses.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 98164a31..744d514f 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -121,7 +121,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us const timelineObject = state.timelines[timeline] const maxNew = statuses.length > 0 ? maxBy(statuses, 'id').id : 0 - const older = maxNew < timelineObject.maxId + const older = timeline && maxNew < timelineObject.maxId if (timeline && !noIdUpdate && statuses.length > 0 && !older) { timelineObject.maxId = maxNew -- cgit v1.2.3-70-g09d2 From 573f01650b4a6a647601273338cad174c26d877e Mon Sep 17 00:00:00 2001 From: shpuld Date: Mon, 16 Apr 2018 18:19:42 +0300 Subject: Copy parent status nsfw into retweeted_status --- src/modules/statuses.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/modules/statuses.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 744d514f..bd52f161 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -44,6 +44,9 @@ export const prepareStatus = (status) => { // Parse nsfw tags if (status.nsfw === undefined) { status.nsfw = isNsfw(status) + if (status.retweeted_status) { + status.retweeted_status.nsfw = status.nsfw + } } // Set deleted flag -- cgit v1.2.3-70-g09d2