more stuff
This commit is contained in:
parent
1396eeb71b
commit
3c80d166be
3 changed files with 34 additions and 38 deletions
|
|
@ -27,6 +27,7 @@ import { useStatusesStore } from 'src/stores/statuses.js'
|
||||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||||
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
|
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
|
||||||
import { useUsersStore } from 'src/stores/users.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'
|
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
||||||
|
|
||||||
|
|
@ -128,6 +129,9 @@ const Status = {
|
||||||
headTailLinks: null,
|
headTailLinks: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
useScrobblesStore().getLatestScrobble(this.status.user.id)
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
status() {
|
status() {
|
||||||
return this.statusoid ?? useStatusesStore().allStatuses.get(this.statusId)
|
return this.statusoid ?? useStatusesStore().allStatuses.get(this.statusId)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import {
|
||||||
fetchEmojiReactions,
|
fetchEmojiReactions,
|
||||||
fetchFavoritedByUsers,
|
fetchFavoritedByUsers,
|
||||||
fetchRebloggedByUsers,
|
fetchRebloggedByUsers,
|
||||||
fetchScrobbles,
|
|
||||||
fetchStatus,
|
fetchStatus,
|
||||||
fetchStatusSource,
|
fetchStatusSource,
|
||||||
search2,
|
search2,
|
||||||
|
|
@ -40,41 +39,6 @@ export const defaultState = () => ({
|
||||||
socket: null,
|
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', {
|
export const useStatusesStore = defineStore('statuses', {
|
||||||
state: defaultState,
|
state: defaultState,
|
||||||
actions: {
|
actions: {
|
||||||
|
|
@ -125,8 +89,6 @@ export const useStatusesStore = defineStore('statuses', {
|
||||||
// not "sub-status" i.e. retweeted/quoted/liked status
|
// not "sub-status" i.e. retweeted/quoted/liked status
|
||||||
// in case of likes (which are not statuses) it should return null
|
// in case of likes (which are not statuses) it should return null
|
||||||
const addStatus = (data) => {
|
const addStatus = (data) => {
|
||||||
getLatestScrobble(data.user)
|
|
||||||
|
|
||||||
const [status] = this.mergeOrAdd(this.allStatuses, data, timestamp)
|
const [status] = this.mergeOrAdd(this.allStatuses, data, timestamp)
|
||||||
|
|
||||||
// Add to conversation
|
// Add to conversation
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { snakeCase } from 'lodash'
|
||||||
import { setActivePinia } from 'pinia'
|
import { setActivePinia } from 'pinia'
|
||||||
|
|
||||||
import { useStatusesStore } from 'src/stores/statuses.js'
|
import { useStatusesStore } from 'src/stores/statuses.js'
|
||||||
|
import { useStreamingStore } from 'src/stores/streaming.js'
|
||||||
import { useUsersStore } from 'src/stores/users.js'
|
import { useUsersStore } from 'src/stores/users.js'
|
||||||
|
|
||||||
import * as PUBLIC_API from 'src/api/public.js'
|
import * as PUBLIC_API from 'src/api/public.js'
|
||||||
|
|
@ -96,6 +97,35 @@ describe('Statuses store', () => {
|
||||||
setActivePinia(createTestingPinia({ stubActions: false }))
|
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', () => {
|
describe('addNewStatuses', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const usersStore = useUsersStore()
|
const usersStore = useUsersStore()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue