From 3c80d166beb677a26d787b068f5a668df63ca7e1 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 18 Aug 2026 18:24:57 +0300 Subject: [PATCH] more stuff --- src/components/status/status.js | 4 +++ src/stores/statuses.js | 38 ------------------------- test/unit/specs/stores/statuses.spec.js | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/components/status/status.js b/src/components/status/status.js index 8fc7db75a..ba0380931 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -27,6 +27,7 @@ import { useStatusesStore } from 'src/stores/statuses.js' import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useUserHighlightStore } from 'src/stores/user_highlight.js' import { useUsersStore } from 'src/stores/users.js' +import { useScrobblesStore } from 'src/stores/scrobbles.js' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' @@ -128,6 +129,9 @@ const Status = { headTailLinks: null, } }, + created() { + useScrobblesStore().getLatestScrobble(this.status.user.id) + }, computed: { status() { return this.statusoid ?? useStatusesStore().allStatuses.get(this.statusId) diff --git a/src/stores/statuses.js b/src/stores/statuses.js index 878515687..70c2b9b21 100644 --- a/src/stores/statuses.js +++ b/src/stores/statuses.js @@ -10,7 +10,6 @@ import { fetchEmojiReactions, fetchFavoritedByUsers, fetchRebloggedByUsers, - fetchScrobbles, fetchStatus, fetchStatusSource, search2, @@ -40,41 +39,6 @@ export const defaultState = () => ({ socket: null, }) -const getLatestScrobble = (user) => { - const scrobblesSupport = - useInstanceCapabilitiesStore().pleromaScrobblesAvailable - - if (!scrobblesSupport || !user.name || user.id === 'undefined') { - return - } - - if ( - this.scrobblesNextFetch[user.id] && - this.scrobblesNextFetch[user.id] > Date.now() - ) { - return - } - - this.scrobblesNextFetch[user.id] = Date.now() + 24 * 60 * 60 * 1000 - if (!scrobblesSupport) return - fetchScrobbles({ accountId: user.id }) - .then(({ data: scrobbles }) => { - if (scrobbles?.error) { - useInstanceCapabilitiesStore().set('pleromaScrobblesAvailable', false) - return - } - - if (scrobbles.length > 0) { - user.latestScrobble = scrobbles[0] - - this.scrobblesNextFetch[user.id] = Date.now() + 60 * 1000 - } - }) - .catch((e) => { - console.warn('cannot fetch scrobbles', e) - }) -} - export const useStatusesStore = defineStore('statuses', { state: defaultState, actions: { @@ -125,8 +89,6 @@ export const useStatusesStore = defineStore('statuses', { // not "sub-status" i.e. retweeted/quoted/liked status // in case of likes (which are not statuses) it should return null const addStatus = (data) => { - getLatestScrobble(data.user) - const [status] = this.mergeOrAdd(this.allStatuses, data, timestamp) // Add to conversation diff --git a/test/unit/specs/stores/statuses.spec.js b/test/unit/specs/stores/statuses.spec.js index 01795b25d..2e8f630fd 100644 --- a/test/unit/specs/stores/statuses.spec.js +++ b/test/unit/specs/stores/statuses.spec.js @@ -3,6 +3,7 @@ import { snakeCase } from 'lodash' import { setActivePinia } from 'pinia' import { useStatusesStore } from 'src/stores/statuses.js' +import { useStreamingStore } from 'src/stores/streaming.js' import { useUsersStore } from 'src/stores/users.js' import * as PUBLIC_API from 'src/api/public.js' @@ -96,6 +97,35 @@ describe('Statuses store', () => { setActivePinia(createTestingPinia({ stubActions: false })) }) + it('init', () => { + const store = useStatusesStore() + const sub = vi.fn() + useStreamingStore().addSubscriber = sub + + store.attachSocket() + + expect(store.socket).to.not.be.null + expect(sub).to.have.been.called + }) + + it('resetStatuses', () => { + const store = useStatusesStore() + const statuses = [...new Array(20)].map((empty, index) => + mockStatus({ + id: 's' + index, + statusUser: mockUser({ id: 'u' + index }), + }), + ) + + store.attachSocket() + store.addNewStatuses({ + statuses, + timestamp: 1, + }) + store.resetStatuses() + expect(store.allStatuses).to.have.length(0) + }) + describe('addNewStatuses', () => { beforeEach(() => { const usersStore = useUsersStore()