From 50bb8865c57d098a66aafedf9c64878d8e39dba0 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Wed, 18 Dec 2019 21:17:06 +0300 Subject: [PATCH 01/15] dd --- local.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 local.json diff --git a/local.json b/local.json new file mode 100644 index 0000000000..e9f4df0b3c --- /dev/null +++ b/local.json @@ -0,0 +1,4 @@ +{ + "target": "https://aqueous-sea-10253.herokuapp.com/", + "staticConfigPreference": false +} From 2d914c331eea5f5b9036e10ef3d937628891b9e1 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 20:40:47 +0300 Subject: [PATCH 02/15] replace setInterval for timelne, notifications and follow requests --- src/modules/api.js | 2 +- src/services/fetcher/fetcher.js | 23 +++++++++++++++++++ .../follow_request_fetcher.service.js | 4 ++-- .../notifications_fetcher.service.js | 7 +++--- .../timeline_fetcher.service.js | 7 +++--- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 src/services/fetcher/fetcher.js diff --git a/src/modules/api.js b/src/modules/api.js index 5e213f0db2..7ddd8dde26 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -20,7 +20,7 @@ const api = { state.fetchers[fetcherName] = fetcher }, removeFetcher (state, { fetcherName, fetcher }) { - window.clearInterval(fetcher) + state.fetchers[fetcherName]() delete state.fetchers[fetcherName] }, setWsToken (state, token) { diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js new file mode 100644 index 0000000000..1d9239cc20 --- /dev/null +++ b/src/services/fetcher/fetcher.js @@ -0,0 +1,23 @@ + +export const makeFetcher = (call, interval) => { + let stopped = false + let timeout = null + let func = () => {} + + func = () => { + call().finally(() => { + console.log('callbacks') + if (stopped) return + timeout = window.setTimeout(func, interval) + }) + } + + const stopFetcher = () => { + stopped = true + window.cancelTimeout(timeout) + } + + func() + + return stopFetcher +} diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js index 93fac9bc0b..8d1aba7be4 100644 --- a/src/services/follow_request_fetcher/follow_request_fetcher.service.js +++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js @@ -1,4 +1,5 @@ import apiService from '../api/api.service.js' +import { makeFetcher } from '../fetcher/fetcher.js' const fetchAndUpdate = ({ store, credentials }) => { return apiService.fetchFollowRequests({ credentials }) @@ -10,9 +11,8 @@ const fetchAndUpdate = ({ store, credentials }) => { } const startFetching = ({ credentials, store }) => { - fetchAndUpdate({ credentials, store }) const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) - return setInterval(boundFetchAndUpdate, 10000) + return makeFetcher(boundFetchAndUpdate, 10000) } const followRequestFetcher = { diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 80be02caef..2a3a17bed3 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -1,4 +1,5 @@ import apiService from '../api/api.service.js' +import makeFetcher from '../fetcher/fetcher.js' const update = ({ store, notifications, older }) => { store.dispatch('setNotificationsError', { value: false }) @@ -39,6 +40,7 @@ const fetchAndUpdate = ({ store, credentials, older = false }) => { args['since'] = Math.max(...readNotifsIds) fetchNotifications({ store, args, older }) } + return result } } @@ -53,13 +55,12 @@ const fetchNotifications = ({ store, args, older }) => { } const startFetching = ({ credentials, store }) => { - fetchAndUpdate({ credentials, store }) - const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) // Initially there's set flag to silence all desktop notifications so // that there won't spam of them when user just opened up the FE we // reset that flag after a while to show new notifications once again. setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) - return setInterval(boundFetchAndUpdate, 10000) + const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store, refetch: true }) + return makeFetcher(boundFetchAndUpdate, 10000) } const notificationsFetcher = { diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index d0cddf849c..8bbec2c716 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -1,6 +1,7 @@ import { camelCase } from 'lodash' import apiService from '../api/api.service.js' +import { makeFetcher } from '../fetcher/fetcher.js' const update = ({ store, statuses, timeline, showImmediately, userId, pagination }) => { const ccTimeline = camelCase(timeline) @@ -70,9 +71,9 @@ const startFetching = ({ timeline = 'friends', credentials, store, userId = fals const timelineData = rootState.statuses.timelines[camelCase(timeline)] const showImmediately = timelineData.visibleStatuses.length === 0 timelineData.userId = userId - fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) - const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag }) - return setInterval(boundFetchAndUpdate, 10000) + const boundFetchAndUpdate = () => + fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) + return makeFetcher(boundFetchAndUpdate, 10000) } const timelineFetcher = { fetchAndUpdate, From 1b6eee049700f6fbb0c2e43877ead3ef4cf3041b Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 21:01:31 +0300 Subject: [PATCH 03/15] change chats to use custom makeFetcher --- src/components/chat/chat.js | 5 +++-- src/modules/chats.js | 11 +++++------ src/services/fetcher/fetcher.js | 3 +-- .../notifications_fetcher.service.js | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js index 9c4e5b0554..2062643def 100644 --- a/src/components/chat/chat.js +++ b/src/components/chat/chat.js @@ -5,6 +5,7 @@ import ChatMessage from '../chat_message/chat_message.vue' import PostStatusForm from '../post_status_form/post_status_form.vue' import ChatTitle from '../chat_title/chat_title.vue' import chatService from '../../services/chat_service/chat_service.js' +import { makeFetcher } from '../../services/fetcher/fetcher.js' import { getScrollPosition, getNewTopPosition, isBottomedOut, scrollableContainerHeight } from './chat_layout_utils.js' const BOTTOMED_OUT_OFFSET = 10 @@ -246,7 +247,7 @@ const Chat = { const fetchOlderMessages = !!maxId const sinceId = fetchLatest && chatMessageService.lastMessage && chatMessageService.lastMessage.id - this.backendInteractor.chatMessages({ id: chatId, maxId, sinceId }) + return this.backendInteractor.chatMessages({ id: chatId, maxId, sinceId }) .then((messages) => { // Clear the current chat in case we're recovering from a ws connection loss. if (isFirstFetch) { @@ -287,7 +288,7 @@ const Chat = { }, doStartFetching () { this.$store.dispatch('startFetchingCurrentChat', { - fetcher: () => setInterval(() => this.fetchChat({ fetchLatest: true }), 5000) + fetcher: () => makeFetcher(() => this.fetchChat({ fetchLatest: true }), 5000) }) this.fetchChat({ isFirstFetch: true }) }, diff --git a/src/modules/chats.js b/src/modules/chats.js index c760901809..45e4bdccb6 100644 --- a/src/modules/chats.js +++ b/src/modules/chats.js @@ -3,6 +3,7 @@ import { find, omitBy, orderBy, sumBy } from 'lodash' import chatService from '../services/chat_service/chat_service.js' import { parseChat, parseChatMessage } from '../services/entity_normalizer/entity_normalizer.service.js' import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js' +import { makeFetcher } from '../services/fetcher/fetcher.js' const emptyChatList = () => ({ data: [], @@ -42,12 +43,10 @@ const chats = { actions: { // Chat list startFetchingChats ({ dispatch, commit }) { - const fetcher = () => { - dispatch('fetchChats', { latest: true }) - } + const fetcher = () => dispatch('fetchChats', { latest: true }) fetcher() commit('setChatListFetcher', { - fetcher: () => setInterval(() => { fetcher() }, 5000) + fetcher: () => makeFetcher(fetcher, 5000) }) }, stopFetchingChats ({ commit }) { @@ -113,14 +112,14 @@ const chats = { setChatListFetcher (state, { commit, fetcher }) { const prevFetcher = state.chatListFetcher if (prevFetcher) { - clearInterval(prevFetcher) + prevFetcher() } state.chatListFetcher = fetcher && fetcher() }, setCurrentChatFetcher (state, { fetcher }) { const prevFetcher = state.fetcher if (prevFetcher) { - clearInterval(prevFetcher) + prevFetcher() } state.fetcher = fetcher && fetcher() }, diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js index 1d9239cc20..95b8c9d32d 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/fetcher/fetcher.js @@ -6,7 +6,6 @@ export const makeFetcher = (call, interval) => { func = () => { call().finally(() => { - console.log('callbacks') if (stopped) return timeout = window.setTimeout(func, interval) }) @@ -14,7 +13,7 @@ export const makeFetcher = (call, interval) => { const stopFetcher = () => { stopped = true - window.cancelTimeout(timeout) + window.clearTimeout(timeout) } func() diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 2a3a17bed3..c69d5b170f 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -1,5 +1,5 @@ import apiService from '../api/api.service.js' -import makeFetcher from '../fetcher/fetcher.js' +import { makeFetcher } from '../fetcher/fetcher.js' const update = ({ store, notifications, older }) => { store.dispatch('setNotificationsError', { value: false }) From d939f2ffbcb632361a0362f0f2049f99160dee64 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 21:08:06 +0300 Subject: [PATCH 04/15] document makeFetcher a bit --- src/services/fetcher/fetcher.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js index 95b8c9d32d..5a6ed4b8e1 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/fetcher/fetcher.js @@ -1,11 +1,17 @@ -export const makeFetcher = (call, interval) => { +// makeFetcher - replacement for setInterval for fetching, starts counting +// the interval only after a request is done instead of immediately. +// promiseCall is a function that returns a promise, it's called when created +// and after every interval. +// interval is the interval delay in ms. + +export const makeFetcher = (promiseCall, interval) => { let stopped = false let timeout = null let func = () => {} func = () => { - call().finally(() => { + promiseCall().finally(() => { if (stopped) return timeout = window.setTimeout(func, interval) }) From 4d080a1654ff56e9875c49486457a1ac8e19297e Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 21:26:02 +0300 Subject: [PATCH 05/15] add mention to changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 675c4b5bf2..e5521b8383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Polls will be hidden with status content if "Collapse posts with subjects" is enabled and the post is collapsed. +### Fixed +- Network fetches don't pile up anymore but wait for previous ones to finish to reduce throttling. + ## [2.1.0] - 2020-08-28 ### Added - Autocomplete domains from list of known instances From 5b403ba7d13eaf851ae43e814c583ceb018e2d20 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Wed, 2 Sep 2020 22:12:50 +0300 Subject: [PATCH 06/15] fix timeline showimmediately being set wrongly --- src/services/fetcher/fetcher.js | 8 ++++---- .../follow_request_fetcher.service.js | 1 + .../notifications_fetcher.service.js | 3 ++- src/services/timeline_fetcher/timeline_fetcher.service.js | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/fetcher/fetcher.js b/src/services/fetcher/fetcher.js index 5a6ed4b8e1..aae1c2cc19 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/fetcher/fetcher.js @@ -1,9 +1,9 @@ // makeFetcher - replacement for setInterval for fetching, starts counting // the interval only after a request is done instead of immediately. -// promiseCall is a function that returns a promise, it's called when created -// and after every interval. -// interval is the interval delay in ms. +// - promiseCall is a function that returns a promise, it's called the first +// time after the first interval. +// - interval is the interval delay in ms. export const makeFetcher = (promiseCall, interval) => { let stopped = false @@ -22,7 +22,7 @@ export const makeFetcher = (promiseCall, interval) => { window.clearTimeout(timeout) } - func() + timeout = window.setTimeout(func, interval) return stopFetcher } diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js index 8d1aba7be4..bec434aaa1 100644 --- a/src/services/follow_request_fetcher/follow_request_fetcher.service.js +++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js @@ -12,6 +12,7 @@ const fetchAndUpdate = ({ store, credentials }) => { const startFetching = ({ credentials, store }) => { const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) + boundFetchAndUpdate() return makeFetcher(boundFetchAndUpdate, 10000) } diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index c69d5b170f..90988fc459 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -59,7 +59,8 @@ const startFetching = ({ credentials, store }) => { // that there won't spam of them when user just opened up the FE we // reset that flag after a while to show new notifications once again. setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) - const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store, refetch: true }) + const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) + boundFetchAndUpdate() return makeFetcher(boundFetchAndUpdate, 10000) } diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 8bbec2c716..9f585f68c1 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -71,8 +71,9 @@ const startFetching = ({ timeline = 'friends', credentials, store, userId = fals const timelineData = rootState.statuses.timelines[camelCase(timeline)] const showImmediately = timelineData.visibleStatuses.length === 0 timelineData.userId = userId + fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) const boundFetchAndUpdate = () => - fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) + fetchAndUpdate({ timeline, credentials, store, userId, tag }) return makeFetcher(boundFetchAndUpdate, 10000) } const timelineFetcher = { From 3fb35e8123d3a8cd151571b315b7ec4d7e0875c7 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 4 Sep 2020 11:19:53 +0300 Subject: [PATCH 07/15] rename to promiseInterval --- src/components/chat/chat.js | 4 ++-- src/modules/api.js | 2 +- src/modules/chats.js | 4 ++-- .../follow_request_fetcher.service.js | 4 ++-- .../notifications_fetcher.service.js | 4 ++-- .../fetcher.js => promise_interval/promise_interval.js} | 8 ++++---- src/services/timeline_fetcher/timeline_fetcher.service.js | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) rename src/services/{fetcher/fetcher.js => promise_interval/promise_interval.js} (68%) diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js index 2062643def..151238853c 100644 --- a/src/components/chat/chat.js +++ b/src/components/chat/chat.js @@ -5,7 +5,7 @@ import ChatMessage from '../chat_message/chat_message.vue' import PostStatusForm from '../post_status_form/post_status_form.vue' import ChatTitle from '../chat_title/chat_title.vue' import chatService from '../../services/chat_service/chat_service.js' -import { makeFetcher } from '../../services/fetcher/fetcher.js' +import { promiseInterval } from '../../services/promise_interval/promise_interval.js' import { getScrollPosition, getNewTopPosition, isBottomedOut, scrollableContainerHeight } from './chat_layout_utils.js' const BOTTOMED_OUT_OFFSET = 10 @@ -288,7 +288,7 @@ const Chat = { }, doStartFetching () { this.$store.dispatch('startFetchingCurrentChat', { - fetcher: () => makeFetcher(() => this.fetchChat({ fetchLatest: true }), 5000) + fetcher: () => promiseInterval(() => this.fetchChat({ fetchLatest: true }), 5000) }) this.fetchChat({ isFirstFetch: true }) }, diff --git a/src/modules/api.js b/src/modules/api.js index 7ddd8dde26..73511442d7 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -20,7 +20,7 @@ const api = { state.fetchers[fetcherName] = fetcher }, removeFetcher (state, { fetcherName, fetcher }) { - state.fetchers[fetcherName]() + state.fetchers[fetcherName].stop() delete state.fetchers[fetcherName] }, setWsToken (state, token) { diff --git a/src/modules/chats.js b/src/modules/chats.js index 45e4bdccb6..60273a44dc 100644 --- a/src/modules/chats.js +++ b/src/modules/chats.js @@ -3,7 +3,7 @@ import { find, omitBy, orderBy, sumBy } from 'lodash' import chatService from '../services/chat_service/chat_service.js' import { parseChat, parseChatMessage } from '../services/entity_normalizer/entity_normalizer.service.js' import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js' -import { makeFetcher } from '../services/fetcher/fetcher.js' +import { promiseInterval } from '../services/promise_interval/promise_interval.js' const emptyChatList = () => ({ data: [], @@ -46,7 +46,7 @@ const chats = { const fetcher = () => dispatch('fetchChats', { latest: true }) fetcher() commit('setChatListFetcher', { - fetcher: () => makeFetcher(fetcher, 5000) + fetcher: () => promiseInterval(fetcher, 5000) }) }, stopFetchingChats ({ commit }) { diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js index bec434aaa1..74af40815e 100644 --- a/src/services/follow_request_fetcher/follow_request_fetcher.service.js +++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js @@ -1,5 +1,5 @@ import apiService from '../api/api.service.js' -import { makeFetcher } from '../fetcher/fetcher.js' +import { promiseInterval } from '../promise_interval/promise_interval.js' const fetchAndUpdate = ({ store, credentials }) => { return apiService.fetchFollowRequests({ credentials }) @@ -13,7 +13,7 @@ const fetchAndUpdate = ({ store, credentials }) => { const startFetching = ({ credentials, store }) => { const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) boundFetchAndUpdate() - return makeFetcher(boundFetchAndUpdate, 10000) + return promiseInterval(boundFetchAndUpdate, 10000) } const followRequestFetcher = { diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 90988fc459..c908b6443b 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -1,5 +1,5 @@ import apiService from '../api/api.service.js' -import { makeFetcher } from '../fetcher/fetcher.js' +import { promiseInterval } from '../promise_interval/promise_interval.js' const update = ({ store, notifications, older }) => { store.dispatch('setNotificationsError', { value: false }) @@ -61,7 +61,7 @@ const startFetching = ({ credentials, store }) => { setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store }) boundFetchAndUpdate() - return makeFetcher(boundFetchAndUpdate, 10000) + return promiseInterval(boundFetchAndUpdate, 10000) } const notificationsFetcher = { diff --git a/src/services/fetcher/fetcher.js b/src/services/promise_interval/promise_interval.js similarity index 68% rename from src/services/fetcher/fetcher.js rename to src/services/promise_interval/promise_interval.js index aae1c2cc19..ee46a236f0 100644 --- a/src/services/fetcher/fetcher.js +++ b/src/services/promise_interval/promise_interval.js @@ -1,11 +1,11 @@ -// makeFetcher - replacement for setInterval for fetching, starts counting -// the interval only after a request is done instead of immediately. +// promiseInterval - replacement for setInterval for promises, starts counting +// the interval only after a promise is done instead of immediately. // - promiseCall is a function that returns a promise, it's called the first // time after the first interval. // - interval is the interval delay in ms. -export const makeFetcher = (promiseCall, interval) => { +export const promiseInterval = (promiseCall, interval) => { let stopped = false let timeout = null let func = () => {} @@ -24,5 +24,5 @@ export const makeFetcher = (promiseCall, interval) => { timeout = window.setTimeout(func, interval) - return stopFetcher + return { stop: stopFetcher } } diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 9f585f68c1..72ea4890ae 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -1,7 +1,7 @@ import { camelCase } from 'lodash' import apiService from '../api/api.service.js' -import { makeFetcher } from '../fetcher/fetcher.js' +import { promiseInterval } from '../promise_interval/promise_interval.js' const update = ({ store, statuses, timeline, showImmediately, userId, pagination }) => { const ccTimeline = camelCase(timeline) @@ -74,7 +74,7 @@ const startFetching = ({ timeline = 'friends', credentials, store, userId = fals fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag }) const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag }) - return makeFetcher(boundFetchAndUpdate, 10000) + return promiseInterval(boundFetchAndUpdate, 10000) } const timelineFetcher = { fetchAndUpdate, From c89ac79140e059f89d4da88ce49c9bb24db4cc20 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Fri, 4 Sep 2020 11:22:14 +0300 Subject: [PATCH 08/15] fix chat fetcher stops, change fetcher code --- src/modules/chats.js | 4 ++-- src/services/promise_interval/promise_interval.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/chats.js b/src/modules/chats.js index 60273a44dc..8e2fabb67c 100644 --- a/src/modules/chats.js +++ b/src/modules/chats.js @@ -112,14 +112,14 @@ const chats = { setChatListFetcher (state, { commit, fetcher }) { const prevFetcher = state.chatListFetcher if (prevFetcher) { - prevFetcher() + prevFetcher.stop() } state.chatListFetcher = fetcher && fetcher() }, setCurrentChatFetcher (state, { fetcher }) { const prevFetcher = state.fetcher if (prevFetcher) { - prevFetcher() + prevFetcher.stop() } state.fetcher = fetcher && fetcher() }, diff --git a/src/services/promise_interval/promise_interval.js b/src/services/promise_interval/promise_interval.js index ee46a236f0..cf17970d8b 100644 --- a/src/services/promise_interval/promise_interval.js +++ b/src/services/promise_interval/promise_interval.js @@ -8,9 +8,8 @@ export const promiseInterval = (promiseCall, interval) => { let stopped = false let timeout = null - let func = () => {} - func = () => { + const func = () => { promiseCall().finally(() => { if (stopped) return timeout = window.setTimeout(func, interval) From 947d7cd6f285c7c683b92f79d9d2c08dd2131f5d Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Mon, 7 Sep 2020 14:27:37 +0300 Subject: [PATCH 09/15] added import/export mutes --- local.json | 4 --- .../tabs/data_import_export_tab.js | 28 ++++++++++++++----- .../tabs/data_import_export_tab.vue | 17 +++++++++++ src/i18n/en.json | 6 ++++ src/services/api/api.service.js | 13 +++++++++ 5 files changed, 57 insertions(+), 11 deletions(-) delete mode 100644 local.json diff --git a/local.json b/local.json deleted file mode 100644 index e9f4df0b3c..0000000000 --- a/local.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "target": "https://aqueous-sea-10253.herokuapp.com/", - "staticConfigPreference": false -} diff --git a/src/components/settings_modal/tabs/data_import_export_tab.js b/src/components/settings_modal/tabs/data_import_export_tab.js index 168f89e191..f4b736d2dc 100644 --- a/src/components/settings_modal/tabs/data_import_export_tab.js +++ b/src/components/settings_modal/tabs/data_import_export_tab.js @@ -1,6 +1,7 @@ import Importer from 'src/components/importer/importer.vue' import Exporter from 'src/components/exporter/exporter.vue' import Checkbox from 'src/components/checkbox/checkbox.vue' +import { mapState } from 'vuex' const DataImportExportTab = { data () { @@ -18,21 +19,26 @@ const DataImportExportTab = { Checkbox }, computed: { - user () { - return this.$store.state.users.currentUser - } + ...mapState({ + backendInteractor: (state) => state.api.backendInteractor, + user: (state) => state.users.currentUser + }) }, methods: { getFollowsContent () { - return this.$store.state.api.backendInteractor.exportFriends({ id: this.$store.state.users.currentUser.id }) + return this.backendInteractor.exportFriends({ id: this.user.id }) .then(this.generateExportableUsersContent) }, getBlocksContent () { - return this.$store.state.api.backendInteractor.fetchBlocks() + return this.backendInteractor.fetchBlocks() + .then(this.generateExportableUsersContent) + }, + getMutesContent () { + return this.backendInteractor.fetchMutes() .then(this.generateExportableUsersContent) }, importFollows (file) { - return this.$store.state.api.backendInteractor.importFollows({ file }) + return this.backendInteractor.importFollows({ file }) .then((status) => { if (!status) { throw new Error('failed') @@ -40,7 +46,15 @@ const DataImportExportTab = { }) }, importBlocks (file) { - return this.$store.state.api.backendInteractor.importBlocks({ file }) + return this.backendInteractor.importBlocks({ file }) + .then((status) => { + if (!status) { + throw new Error('failed') + } + }) + }, + importMutes (file) { + return this.backendInteractor.importMutes({ file }) .then((status) => { if (!status) { throw new Error('failed') diff --git a/src/components/settings_modal/tabs/data_import_export_tab.vue b/src/components/settings_modal/tabs/data_import_export_tab.vue index b5d0f5ed18..a406077d03 100644 --- a/src/components/settings_modal/tabs/data_import_export_tab.vue +++ b/src/components/settings_modal/tabs/data_import_export_tab.vue @@ -36,6 +36,23 @@ :export-button-label="$t('settings.block_export_button')" /> +
+

{{ $t('settings.mute_import') }}

+

{{ $t('settings.import_mutes_from_a_csv_file') }}

+ +
+
+

{{ $t('settings.mute_export') }}

+ +
diff --git a/src/i18n/en.json b/src/i18n/en.json index 8540f551fc..cf0a7e7c6e 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -276,6 +276,12 @@ "block_import": "Block import", "block_import_error": "Error importing blocks", "blocks_imported": "Blocks imported! Processing them will take a while.", + "mute_export": "Mute export", + "mute_export_button": "Export your mutes to a csv file", + "mute_import": "Mute import", + "mute_import_error": "Error importing mutes", + "mutes_imported": "Mutes imported! Processing them will take a while.", + "import_mutes_from_a_csv_file": "Import mutes from a csv file", "blocks_tab": "Blocks", "bot": "This is a bot account", "btnRadius": "Buttons", diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index da51900123..34f86f9317 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -3,6 +3,7 @@ import { parseStatus, parseUser, parseNotification, parseAttachment, parseChat, import { RegistrationError, StatusCodeError } from '../errors/errors' /* eslint-env browser */ +const MUTES_IMPORT_URL = '/api/pleroma/mutes_import' const BLOCKS_IMPORT_URL = '/api/pleroma/blocks_import' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' @@ -710,6 +711,17 @@ const setMediaDescription = ({ id, description, credentials }) => { }).then((data) => parseAttachment(data)) } +const importMutes = ({ file, credentials }) => { + const formData = new FormData() + formData.append('list', file) + return fetch(MUTES_IMPORT_URL, { + body: formData, + method: 'POST', + headers: authHeaders(credentials) + }) + .then((response) => response.ok) +} + const importBlocks = ({ file, credentials }) => { const formData = new FormData() formData.append('list', file) @@ -1280,6 +1292,7 @@ const apiService = { getCaptcha, updateProfileImages, updateProfile, + importMutes, importBlocks, importFollows, deleteAccount, From 5942001626d01f6438e53943f1b8a8a2448d1378 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 18 Sep 2020 22:09:05 +0300 Subject: [PATCH 10/15] updated changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c56ac821a0..15aeb7cc45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Fixed chats list not updating its order when new messages come in -- Fixed chat messages sometimes getting lost when you receive a message at the same time +- Fixed chat messages sometimes getting lost when you receive a message at the same time +### Added +- Import/export a muted users ## [2.1.1] - 2020-09-08 ### Changed From f9977dbb3c9b316521b6be40ddd1a34411f2d835 Mon Sep 17 00:00:00 2001 From: Dym Sohin Date: Sat, 19 Sep 2020 21:28:03 +0200 Subject: [PATCH 11/15] fix excessive underline in sidebar --- src/App.scss | 1 + src/components/nav_panel/nav_panel.vue | 10 +++++----- src/components/timeline_menu/timeline_menu.vue | 6 +----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/App.scss b/src/App.scss index e2e2d079c9..8b1bbd2d35 100644 --- a/src/App.scss +++ b/src/App.scss @@ -809,6 +809,7 @@ nav { .button-icon { font-size: 1.2em; + margin-right: 0.5em; } @keyframes shakeError { diff --git a/src/components/nav_panel/nav_panel.vue b/src/components/nav_panel/nav_panel.vue index f8459fd162..080e547f59 100644 --- a/src/components/nav_panel/nav_panel.vue +++ b/src/components/nav_panel/nav_panel.vue @@ -7,12 +7,12 @@ :to="{ name: timelinesRoute }" :class="onTimelineRoute && 'router-link-active'" > - {{ $t("nav.timelines") }} + {{ $t("nav.timelines") }}
  • - {{ $t("nav.interactions") }} + {{ $t("nav.interactions") }}
  • @@ -23,12 +23,12 @@ > {{ unreadChatCount }} - {{ $t("nav.chats") }} + {{ $t("nav.chats") }}
  • - {{ $t("nav.friend_requests") }} + {{ $t("nav.friend_requests") }}
  • - {{ $t("nav.about") }} + {{ $t("nav.about") }}
  • diff --git a/src/components/timeline_menu/timeline_menu.vue b/src/components/timeline_menu/timeline_menu.vue index be512d605e..3c029093fd 100644 --- a/src/components/timeline_menu/timeline_menu.vue +++ b/src/components/timeline_menu/timeline_menu.vue @@ -64,7 +64,7 @@ .timeline-menu-popover-wrap { overflow: hidden; // Match panel heading padding to line up menu with bottom of heading - margin-top: 0.6rem; + margin-top: 0.6rem 0.65em; padding: 0 15px 15px 15px; } .timeline-menu-popover { @@ -138,10 +138,6 @@ &:last-child { border: none; } - - i { - margin: 0 0.5em; - } } a { From 3dacef944cf6980dc3a3c1843d5b3f94b851240a Mon Sep 17 00:00:00 2001 From: Dym Sohin Date: Thu, 24 Sep 2020 12:05:51 +0200 Subject: [PATCH 12/15] remove bio-table's max-width --- src/components/user_profile/user_profile.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index c7c67c0a0b..b26499b43b 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -156,8 +156,7 @@ .user-profile-field { display: flex; - margin: 0.25em auto; - max-width: 32em; + margin: 0.25em; border: 1px solid var(--border, $fallback--border); border-radius: $fallback--inputRadius; border-radius: var(--inputRadius, $fallback--inputRadius); From f174f289a93e6bef1182a2face00bb809da49d18 Mon Sep 17 00:00:00 2001 From: Shpuld Shpludson Date: Tue, 29 Sep 2020 10:18:37 +0000 Subject: [PATCH 13/15] Timeline virtual scrolling --- CHANGELOG.md | 3 + src/components/attachment/attachment.vue | 4 ++ src/components/conversation/conversation.js | 20 +++++- src/components/conversation/conversation.vue | 11 +++- src/components/react_button/react_button.js | 5 +- .../retweet_button/retweet_button.js | 5 +- .../settings_modal/tabs/general_tab.vue | 5 ++ src/components/status/status.js | 31 +++++++-- src/components/status/status.scss | 5 ++ src/components/status/status.vue | 7 +- .../status_content/status_content.vue | 2 + src/components/still-image/still-image.js | 10 +-- src/components/timeline/timeline.js | 64 ++++++++++++++++++- src/components/timeline/timeline.vue | 6 +- .../video_attachment/video_attachment.js | 47 ++++++++++---- .../video_attachment/video_attachment.vue | 3 +- src/i18n/en.json | 1 + src/modules/config.js | 3 +- src/modules/instance.js | 1 + src/modules/statuses.js | 6 ++ src/services/api/api.service.js | 2 + 21 files changed, 203 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18dafa8e26..eebc7115ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- New option to optimize timeline rendering to make the site more responsive (enabled by default) + ## [Unreleased patch] ### Changed diff --git a/src/components/attachment/attachment.vue b/src/components/attachment/attachment.vue index 63e0cebad2..7fabc963e0 100644 --- a/src/components/attachment/attachment.vue +++ b/src/components/attachment/attachment.vue @@ -80,6 +80,8 @@ class="video" :attachment="attachment" :controls="allowPlay" + @play="$emit('play')" + @pause="$emit('pause')" />
    @@ -18,6 +20,7 @@
    +
    @@ -53,8 +60,8 @@ .conversation-status { border-color: $fallback--border; border-color: var(--border, $fallback--border); - border-left: 4px solid $fallback--cRed; - border-left: 4px solid var(--cRed, $fallback--cRed); + border-left-color: $fallback--cRed; + border-left-color: var(--cRed, $fallback--cRed); } .conversation-status:last-child { diff --git a/src/components/react_button/react_button.js b/src/components/react_button/react_button.js index abcf04555c..11627e9cbb 100644 --- a/src/components/react_button/react_button.js +++ b/src/components/react_button/react_button.js @@ -1,5 +1,4 @@ import Popover from '../popover/popover.vue' -import { mapGetters } from 'vuex' const ReactButton = { props: ['status'], @@ -35,7 +34,9 @@ const ReactButton = { } return this.$store.state.instance.emoji || [] }, - ...mapGetters(['mergedConfig']) + mergedConfig () { + return this.$store.getters.mergedConfig + } } } diff --git a/src/components/retweet_button/retweet_button.js b/src/components/retweet_button/retweet_button.js index d9a0f92e61..5a41f22d84 100644 --- a/src/components/retweet_button/retweet_button.js +++ b/src/components/retweet_button/retweet_button.js @@ -1,4 +1,3 @@ -import { mapGetters } from 'vuex' const RetweetButton = { props: ['status', 'loggedIn', 'visibility'], @@ -28,7 +27,9 @@ const RetweetButton = { 'animate-spin': this.animated } }, - ...mapGetters(['mergedConfig']) + mergedConfig () { + return this.$store.getters.mergedConfig + } } } diff --git a/src/components/settings_modal/tabs/general_tab.vue b/src/components/settings_modal/tabs/general_tab.vue index 7f06d0bd3a..13482de701 100644 --- a/src/components/settings_modal/tabs/general_tab.vue +++ b/src/components/settings_modal/tabs/general_tab.vue @@ -58,6 +58,11 @@ {{ $t('settings.emoji_reactions_on_timeline') }} +
  • + + {{ $t('settings.virtual_scrolling') }} + +
  • diff --git a/src/components/status/status.js b/src/components/status/status.js index d263da682e..cd6e2f729f 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -15,7 +15,6 @@ import generateProfileLink from 'src/services/user_profile_link_generator/user_p import { highlightClass, highlightStyle } from '../../services/user_highlighter/user_highlighter.js' import { muteWordHits } from '../../services/status_parser/status_parser.js' import { unescape, uniqBy } from 'lodash' -import { mapGetters, mapState } from 'vuex' const Status = { name: 'Status', @@ -54,6 +53,8 @@ const Status = { replying: false, unmuted: false, userExpanded: false, + mediaPlaying: [], + suspendable: true, error: null } }, @@ -157,7 +158,7 @@ const Status = { return this.mergedConfig.hideFilteredStatuses }, hideStatus () { - return this.deleted || (this.muted && this.hideFilteredStatuses) + return this.deleted || (this.muted && this.hideFilteredStatuses) || this.virtualHidden }, isFocused () { // retweet or root of an expanded conversation @@ -207,11 +208,18 @@ const Status = { hidePostStats () { return this.mergedConfig.hidePostStats }, - ...mapGetters(['mergedConfig']), - ...mapState({ - betterShadow: state => state.interface.browserSupport.cssFilter, - currentUser: state => state.users.currentUser - }) + currentUser () { + return this.$store.state.users.currentUser + }, + betterShadow () { + return this.$store.state.interface.browserSupport.cssFilter + }, + mergedConfig () { + return this.$store.getters.mergedConfig + }, + isSuspendable () { + return !this.replying && this.mediaPlaying.length === 0 + } }, methods: { visibilityIcon (visibility) { @@ -251,6 +259,12 @@ const Status = { }, generateUserProfileLink (id, name) { return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames) + }, + addMediaPlaying (id) { + this.mediaPlaying.push(id) + }, + removeMediaPlaying (id) { + this.mediaPlaying = this.mediaPlaying.filter(mediaId => mediaId !== id) } }, watch: { @@ -280,6 +294,9 @@ const Status = { if (this.isFocused && this.statusFromGlobalRepository.favoritedBy && this.statusFromGlobalRepository.favoritedBy.length !== num) { this.$store.dispatch('fetchFavs', this.status.id) } + }, + 'isSuspendable': function (val) { + this.suspendable = val } }, filters: { diff --git a/src/components/status/status.scss b/src/components/status/status.scss index 8d292d3f7a..c92d870bbb 100644 --- a/src/components/status/status.scss +++ b/src/components/status/status.scss @@ -25,6 +25,11 @@ $status-margin: 0.75em; --icon: var(--selectedPostIcon, $fallback--icon); } + &.-conversation { + border-left-width: 4px; + border-left-style: solid; + } + .status-container { display: flex; padding: $status-margin; diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 282ad37dd6..aa67e433f3 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -16,7 +16,7 @@ />
    diff --git a/src/i18n/en.json b/src/i18n/en.json index 8540f551fc..8d831e3dd3 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -430,6 +430,7 @@ "false": "no", "true": "yes" }, + "virtual_scrolling": "Optimize timeline rendering", "fun": "Fun", "greentext": "Meme arrows", "notifications": "Notifications", diff --git a/src/modules/config.js b/src/modules/config.js index 409d77a451..444b8ec7c3 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -65,7 +65,8 @@ export const defaultState = { useContainFit: false, greentext: undefined, // instance default hidePostStats: undefined, // instance default - hideUserStats: undefined // instance default + hideUserStats: undefined, // instance default + virtualScrolling: undefined // instance default } // caching the instance default properties diff --git a/src/modules/instance.js b/src/modules/instance.js index 3fe3bbf3c0..b3cbffc6c1 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -41,6 +41,7 @@ const defaultState = { sidebarRight: false, subjectLineBehavior: 'email', theme: 'pleroma-dark', + virtualScrolling: true, // Nasty stuff customEmoji: [], diff --git a/src/modules/statuses.js b/src/modules/statuses.js index e108b2a799..155cc4b91e 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -568,6 +568,9 @@ export const mutations = { updateStatusWithPoll (state, { id, poll }) { const status = state.allStatusesObject[id] status.poll = poll + }, + setVirtualHeight (state, { statusId, height }) { + state.allStatusesObject[statusId].virtualHeight = height } } @@ -753,6 +756,9 @@ const statuses = { store.commit('addNewStatuses', { statuses: data.statuses }) return data }) + }, + setVirtualHeight ({ commit }, { statusId, height }) { + commit('setVirtualHeight', { statusId, height }) } }, mutations diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index da51900123..d1842e17ca 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -539,8 +539,10 @@ const fetchTimeline = ({ const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') url += `?${queryString}` + let status = '' let statusText = '' + let pagination = {} return fetch(url, { headers: authHeaders(credentials) }) .then((data) => { From 1675f1a133934956a39ca4ade99b809789bb84a2 Mon Sep 17 00:00:00 2001 From: Dym Sohin Date: Tue, 29 Sep 2020 13:13:42 +0200 Subject: [PATCH 14/15] scoped back margin-right on icons --- src/App.scss | 1 - src/components/nav_panel/nav_panel.vue | 4 ++++ src/components/timeline_menu/timeline_menu.vue | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/App.scss b/src/App.scss index 8b1bbd2d35..e2e2d079c9 100644 --- a/src/App.scss +++ b/src/App.scss @@ -809,7 +809,6 @@ nav { .button-icon { font-size: 1.2em; - margin-right: 0.5em; } @keyframes shakeError { diff --git a/src/components/nav_panel/nav_panel.vue b/src/components/nav_panel/nav_panel.vue index 080e547f59..4f944c9565 100644 --- a/src/components/nav_panel/nav_panel.vue +++ b/src/components/nav_panel/nav_panel.vue @@ -125,6 +125,10 @@ } } +.nav-panel .button-icon { + margin-right: 0.5em; +} + .nav-panel .button-icon:before { width: 1.1em; } diff --git a/src/components/timeline_menu/timeline_menu.vue b/src/components/timeline_menu/timeline_menu.vue index 3c029093fd..481b1d0912 100644 --- a/src/components/timeline_menu/timeline_menu.vue +++ b/src/components/timeline_menu/timeline_menu.vue @@ -170,6 +170,10 @@ text-decoration: underline; } } + + i { + margin: 0 0.5em; + } } } From c17012cfe19ecab7efc27a54c90c4369c36de343 Mon Sep 17 00:00:00 2001 From: Dym Sohin Date: Tue, 29 Sep 2020 13:20:16 +0200 Subject: [PATCH 15/15] fix appended 0.65em on wrong line --- src/components/timeline_menu/timeline_menu.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/timeline_menu/timeline_menu.vue b/src/components/timeline_menu/timeline_menu.vue index 481b1d0912..b7e5f2da9e 100644 --- a/src/components/timeline_menu/timeline_menu.vue +++ b/src/components/timeline_menu/timeline_menu.vue @@ -64,7 +64,7 @@ .timeline-menu-popover-wrap { overflow: hidden; // Match panel heading padding to line up menu with bottom of heading - margin-top: 0.6rem 0.65em; + margin-top: 0.6rem; padding: 0 15px 15px 15px; } .timeline-menu-popover { @@ -142,7 +142,7 @@ a { display: block; - padding: 0.6em 0; + padding: 0.6em 0.65em; &:hover { background-color: $fallback--lightBg; @@ -172,7 +172,7 @@ } i { - margin: 0 0.5em; + margin-right: 0.5em; } } }