From 9a8bc245a6f76f1a41da9d05408dadc36625ffe9 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 13 Jan 2021 22:17:10 +0200 Subject: fixed few-posts TLs when streaming is enabled --- src/modules/users.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 655db4c7..ac52be1f 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -547,6 +547,8 @@ const users = { } if (store.getters.mergedConfig.useStreamingApi) { + store.dispatch('fetchTimeline', 'friends', { since: null }) + store.dispatch('fetchNotifications', { since: null }) store.dispatch('enableMastoSockets').catch((error) => { console.error('Failed initializing MastoAPI Streaming socket', error) startPolling() -- cgit v1.2.3-70-g09d2 From a8967d85bd7ae1541f1d4e41e95fc8fa111f2360 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 9 Mar 2021 02:38:10 +0200 Subject: streamlined WS flow, reduced spam amount related to WS reconnections --- src/modules/api.js | 69 ++++++++++++---------- src/modules/users.js | 3 +- src/services/api/api.service.js | 5 +- .../notifications_fetcher.service.js | 14 ++--- .../timeline_fetcher/timeline_fetcher.service.js | 14 ++--- 5 files changed, 56 insertions(+), 49 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/api.js b/src/modules/api.js index e392d5b0..8654b90a 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -3,9 +3,10 @@ import { WSConnectionStatus } from '../services/api/api.service.js' import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js' import { Socket } from 'phoenix' +const retryTimeout = (multiplier) => 1000 * multiplier + const api = { state: { - connectionBroken: false, retryMultiplier: 1, backendInteractor: backendInteractorService(), fetchers: {}, @@ -37,16 +38,20 @@ const api = { setMastoUserSocketStatus (state, value) { state.mastoUserSocketStatus = value }, - recoverConnection (state) { - state.connectionBroken = false + incrementRetryMultiplier (state) { + state.retryMultiplier = Math.max(++state.retryMultiplier, 3) }, - breakConnection (state) { - state.connectionBroken = true + resetRetryMultiplier (state) { + state.retryMultiplier = 1 } }, actions: { - // Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets - enableMastoSockets (store) { + /** + * Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets + * + * @param {Boolean} [initial] - whether this enabling happened at boot time or not + */ + enableMastoSockets (store, initial) { const { state, dispatch, commit } = store // Do not initialize unless nonexistent or closed if ( @@ -58,13 +63,17 @@ const api = { ) { return } - commit('recoverConnection') + if (initial) { + commit('setMastoUserSocketStatus', WSConnectionStatus.STARTING_INITIAL) + } else { + commit('setMastoUserSocketStatus', WSConnectionStatus.STARTING) + } return dispatch('startMastoUserSocket') }, disableMastoSockets (store) { const { state, dispatch, commit } = store if (!state.mastoUserSocket) return - commit('recoverConnection') + commit('setMastoUserSocketStatus', WSConnectionStatus.DISABLED) return dispatch('stopMastoUserSocket') }, @@ -111,19 +120,28 @@ const api = { ) state.mastoUserSocket.addEventListener('open', () => { // Do not show notification when we just opened up the page - if (state.mastoUserSocketStatus !== null) { - commit('recoverConnection') + if (state.mastoUserSocketStatus !== WSConnectionStatus.STARTING_INITIAL) { dispatch('pushGlobalNotice', { level: 'success', messageKey: 'timeline.socket_reconnected', timeout: 5000 }) } + // Stop polling if we were errored or disabled + if (new Set([ + WSConnectionStatus.ERROR, + WSConnectionStatus.DISABLED + ]).has(state.mastoUserSocketStatus)) { + dispatch('stopFetchingTimeline', { timeline: 'friends' }) + dispatch('stopFetchingNotifications') + dispatch('stopFetchingChats') + } + commit('resetRetryMultiplier') commit('setMastoUserSocketStatus', WSConnectionStatus.JOINED) }) state.mastoUserSocket.addEventListener('error', ({ detail: error }) => { console.error('Error in MastoAPI websocket:', error) - commit('setMastoUserSocketStatus', WSConnectionStatus.ERROR) + // TODO is this needed? dispatch('clearOpenedChats') }) state.mastoUserSocket.addEventListener('close', ({ detail: closeEvent }) => { @@ -134,16 +152,17 @@ const api = { const { code } = closeEvent if (ignoreCodes.has(code)) { console.debug(`Not restarting socket becasue of closure code ${code} is in ignore list`) + commit('setMastoUserSocketStatus', WSConnectionStatus.CLOSED) } else { console.warn(`MastoAPI websocket disconnected, restarting. CloseEvent code: ${code}`) - dispatch('startFetchingTimeline', { timeline: 'friends' }) - dispatch('startFetchingNotifications') - dispatch('startFetchingChats') setTimeout(() => { - console.log('TEST') - dispatch('restartMastoUserSocket') - }, 1000) - if (!state.connectionBroken) { + dispatch('startMastoUserSocket') + }, retryTimeout(state.retryMultiplier)) + commit('incrementRetryMultiplier') + if (state.mastoUserSocketStatus !== WSConnectionStatus.ERROR) { + dispatch('startFetchingTimeline', { timeline: 'friends' }) + dispatch('startFetchingNotifications') + dispatch('startFetchingChats') dispatch('pushGlobalNotice', { level: 'error', messageKey: 'timeline.socket_broke', @@ -151,9 +170,8 @@ const api = { timeout: 5000 }) } - commit('breakConnection') + commit('setMastoUserSocketStatus', WSConnectionStatus.ERROR) } - commit('setMastoUserSocketStatus', WSConnectionStatus.CLOSED) dispatch('clearOpenedChats') }) resolve() @@ -162,15 +180,6 @@ const api = { } }) }, - restartMastoUserSocket ({ dispatch }) { - // This basically starts MastoAPI user socket and stops conventional - // fetchers when connection reestablished - return dispatch('startMastoUserSocket').then(() => { - dispatch('stopFetchingTimeline', { timeline: 'friends' }) - dispatch('stopFetchingNotifications') - dispatch('stopFetchingChats') - }) - }, stopMastoUserSocket ({ state, dispatch }) { dispatch('startFetchingTimeline', { timeline: 'friends' }) dispatch('startFetchingNotifications') diff --git a/src/modules/users.js b/src/modules/users.js index ac52be1f..8a764a16 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -549,9 +549,8 @@ const users = { if (store.getters.mergedConfig.useStreamingApi) { store.dispatch('fetchTimeline', 'friends', { since: null }) store.dispatch('fetchNotifications', { since: null }) - store.dispatch('enableMastoSockets').catch((error) => { + store.dispatch('enableMastoSockets', true).catch((error) => { console.error('Failed initializing MastoAPI Streaming socket', error) - startPolling() }).then(() => { store.dispatch('fetchChats', { latest: true }) setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index d3d5c68d..436b8b0a 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1184,7 +1184,10 @@ export const handleMastoWS = (wsEvent) => { export const WSConnectionStatus = Object.freeze({ 'JOINED': 1, 'CLOSED': 2, - 'ERROR': 3 + 'ERROR': 3, + 'DISABLED': 4, + 'STARTING': 5, + 'STARTING_INITIAL': 6 }) const chats = ({ credentials }) => { diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index fc5e76ba..f83f871e 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -57,14 +57,12 @@ const fetchNotifications = ({ store, args, older }) => { return notifications }) .catch((error) => { - if (!store.rootState.api.connectionBroken) { - store.dispatch('pushGlobalNotice', { - level: 'error', - messageKey: 'notifications.error', - messageArgs: [error.message], - timeout: 5000 - }) - } + store.dispatch('pushGlobalNotice', { + level: 'error', + messageKey: 'notifications.error', + messageArgs: [error.message], + timeout: 5000 + }) }) } diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index eb4a3e0d..46bba41a 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -66,14 +66,12 @@ const fetchAndUpdate = ({ return { statuses, pagination } }) .catch((error) => { - if (!store.rootState.api.connectionBroken) { - store.dispatch('pushGlobalNotice', { - level: 'error', - messageKey: 'timeline.error', - messageArgs: [error.message], - timeout: 5000 - }) - } + store.dispatch('pushGlobalNotice', { + level: 'error', + messageKey: 'timeline.error', + messageArgs: [error.message], + timeout: 5000 + }) }) } -- cgit v1.2.3-70-g09d2 From 0604b1d5b7b19db41096876d0d911ea95c3c778f Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 3 Aug 2020 18:44:35 -0500 Subject: Rename legacy PleromaFE Chat functionality to "Shout" --- src/App.js | 6 +- src/App.vue | 6 +- src/boot/after_store.js | 2 +- src/boot/routes.js | 4 +- src/components/chat_panel/chat_panel.js | 53 -------- src/components/chat_panel/chat_panel.vue | 148 ----------------------- src/components/features_panel/features_panel.js | 2 +- src/components/features_panel/features_panel.vue | 4 +- src/components/shout_panel/shout_panel.js | 53 ++++++++ src/components/shout_panel/shout_panel.vue | 148 +++++++++++++++++++++++ src/components/side_drawer/side_drawer.js | 2 +- src/main.js | 4 +- src/modules/api.js | 4 +- src/modules/chat.js | 34 ------ src/modules/instance.js | 6 +- src/modules/shout.js | 33 +++++ src/modules/users.js | 2 +- static/config.json | 2 +- 18 files changed, 256 insertions(+), 257 deletions(-) delete mode 100644 src/components/chat_panel/chat_panel.js delete mode 100644 src/components/chat_panel/chat_panel.vue create mode 100644 src/components/shout_panel/shout_panel.js create mode 100644 src/components/shout_panel/shout_panel.vue delete mode 100644 src/modules/chat.js create mode 100644 src/modules/shout.js (limited to 'src/modules/users.js') diff --git a/src/App.js b/src/App.js index 231c6ae1..fe4c30cb 100644 --- a/src/App.js +++ b/src/App.js @@ -4,7 +4,7 @@ import Notifications from './components/notifications/notifications.vue' import InstanceSpecificPanel from './components/instance_specific_panel/instance_specific_panel.vue' import FeaturesPanel from './components/features_panel/features_panel.vue' import WhoToFollowPanel from './components/who_to_follow_panel/who_to_follow_panel.vue' -import ChatPanel from './components/chat_panel/chat_panel.vue' +import ShoutPanel from './components/shout_panel/shout_panel.vue' import SettingsModal from './components/settings_modal/settings_modal.vue' import MediaModal from './components/media_modal/media_modal.vue' import SideDrawer from './components/side_drawer/side_drawer.vue' @@ -26,7 +26,7 @@ export default { InstanceSpecificPanel, FeaturesPanel, WhoToFollowPanel, - ChatPanel, + ShoutPanel, MediaModal, SideDrawer, MobilePostStatusButton, @@ -65,7 +65,7 @@ export default { } } }, - chat () { return this.$store.state.chat.channel.state === 'joined' }, + shout () { return this.$store.state.shout.channel.state === 'joined' }, suggestionsEnabled () { return this.$store.state.instance.suggestionsEnabled }, showInstanceSpecificPanel () { return this.$store.state.instance.showInstanceSpecificPanel && diff --git a/src/App.vue b/src/App.vue index 1a166778..6c582c03 100644 --- a/src/App.vue +++ b/src/App.vue @@ -49,10 +49,10 @@ - diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 45090e5d..613228e9 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -240,7 +240,7 @@ const getNodeInfo = async ({ store }) => { store.dispatch('setInstanceOption', { name: 'registrationOpen', value: data.openRegistrations }) store.dispatch('setInstanceOption', { name: 'mediaProxyAvailable', value: features.includes('media_proxy') }) store.dispatch('setInstanceOption', { name: 'safeDM', value: features.includes('safe_dm_mentions') }) - store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') }) + store.dispatch('setInstanceOption', { name: 'shoutAvailable', value: features.includes('shout') }) store.dispatch('setInstanceOption', { name: 'pleromaChatMessagesAvailable', value: features.includes('pleroma_chat_messages') }) store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') }) store.dispatch('setInstanceOption', { name: 'pollsAvailable', value: features.includes('polls') }) diff --git a/src/boot/routes.js b/src/boot/routes.js index b5d3c631..1bc1f9f7 100644 --- a/src/boot/routes.js +++ b/src/boot/routes.js @@ -16,7 +16,7 @@ import FollowRequests from 'components/follow_requests/follow_requests.vue' import OAuthCallback from 'components/oauth_callback/oauth_callback.vue' import Notifications from 'components/notifications/notifications.vue' import AuthForm from 'components/auth_form/auth_form.js' -import ChatPanel from 'components/chat_panel/chat_panel.vue' +import ShoutPanel from 'components/shout_panel/shout_panel.vue' import WhoToFollow from 'components/who_to_follow/who_to_follow.vue' import About from 'components/about/about.vue' import RemoteUserResolver from 'components/remote_user_resolver/remote_user_resolver.vue' @@ -64,7 +64,7 @@ export default (store) => { { name: 'friend-requests', path: '/friend-requests', component: FollowRequests, beforeEnter: validateAuthenticatedRoute }, { name: 'notifications', path: '/:username/notifications', component: Notifications, beforeEnter: validateAuthenticatedRoute }, { name: 'login', path: '/login', component: AuthForm }, - { name: 'chat-panel', path: '/chat-panel', component: ChatPanel, props: () => ({ floating: false }) }, + { name: 'shout-panel', path: '/shout-panel', component: ShoutPanel, props: () => ({ floating: false }) }, { name: 'oauth-callback', path: '/oauth-callback', component: OAuthCallback, props: (route) => ({ code: route.query.code }) }, { name: 'search', path: '/search', component: Search, props: (route) => ({ query: route.query.query }) }, { name: 'who-to-follow', path: '/who-to-follow', component: WhoToFollow, beforeEnter: validateAuthenticatedRoute }, diff --git a/src/components/chat_panel/chat_panel.js b/src/components/chat_panel/chat_panel.js deleted file mode 100644 index 556694ae..00000000 --- a/src/components/chat_panel/chat_panel.js +++ /dev/null @@ -1,53 +0,0 @@ -import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' -import { library } from '@fortawesome/fontawesome-svg-core' -import { - faBullhorn, - faTimes -} from '@fortawesome/free-solid-svg-icons' - -library.add( - faBullhorn, - faTimes -) - -const chatPanel = { - props: [ 'floating' ], - data () { - return { - currentMessage: '', - channel: null, - collapsed: true - } - }, - computed: { - messages () { - return this.$store.state.chat.messages - } - }, - methods: { - submit (message) { - this.$store.state.chat.channel.push('new_msg', { text: message }, 10000) - this.currentMessage = '' - }, - togglePanel () { - this.collapsed = !this.collapsed - }, - userProfileLink (user) { - return generateProfileLink(user.id, user.username, this.$store.state.instance.restrictedNicknames) - } - }, - watch: { - messages (newVal) { - const scrollEl = this.$el.querySelector('.chat-window') - if (!scrollEl) return - if (scrollEl.scrollTop + scrollEl.offsetHeight + 20 > scrollEl.scrollHeight) { - this.$nextTick(() => { - if (!scrollEl) return - scrollEl.scrollTop = scrollEl.scrollHeight - scrollEl.offsetHeight - }) - } - } - } -} - -export default chatPanel diff --git a/src/components/chat_panel/chat_panel.vue b/src/components/chat_panel/chat_panel.vue deleted file mode 100644 index 8a829115..00000000 --- a/src/components/chat_panel/chat_panel.vue +++ /dev/null @@ -1,148 +0,0 @@ -