mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-01-31 01:27:26 +01:00
Merge pull request #1001 from h3poteto/iss-999
closes #999 Fix API endpoint for direct messages, use conversations
This commit is contained in:
commit
4f53919a96
@ -1,4 +1,4 @@
|
|||||||
import { Response, Status, Account, Application } from 'megalodon'
|
import { Response, Status, Account, Application, Conversation } from 'megalodon'
|
||||||
import mockedMegalodon from '~/spec/mock/megalodon'
|
import mockedMegalodon from '~/spec/mock/megalodon'
|
||||||
import { createLocalVue } from '@vue/test-utils'
|
import { createLocalVue } from '@vue/test-utils'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
@ -27,6 +27,7 @@ const account: Account = {
|
|||||||
fields: null,
|
fields: null,
|
||||||
bot: false
|
bot: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const status1: Status = {
|
const status1: Status = {
|
||||||
id: '1',
|
id: '1',
|
||||||
uri: 'http://example.com',
|
uri: 'http://example.com',
|
||||||
@ -58,6 +59,7 @@ const status1: Status = {
|
|||||||
language: null,
|
language: null,
|
||||||
pinned: null
|
pinned: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const status2: Status = {
|
const status2: Status = {
|
||||||
id: '2',
|
id: '2',
|
||||||
uri: 'http://example.com',
|
uri: 'http://example.com',
|
||||||
@ -90,6 +92,20 @@ const status2: Status = {
|
|||||||
pinned: null
|
pinned: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const conversation1: Conversation = {
|
||||||
|
id: '1',
|
||||||
|
accounts: [account],
|
||||||
|
last_status: status1,
|
||||||
|
unread: false
|
||||||
|
}
|
||||||
|
|
||||||
|
const conversation2: Conversation = {
|
||||||
|
id: '2',
|
||||||
|
accounts: [account],
|
||||||
|
last_status: status2,
|
||||||
|
unread: false
|
||||||
|
}
|
||||||
|
|
||||||
let state = (): DirectMessagesState => {
|
let state = (): DirectMessagesState => {
|
||||||
return {
|
return {
|
||||||
lazyLoading: false,
|
lazyLoading: false,
|
||||||
@ -139,9 +155,9 @@ describe('Home', () => {
|
|||||||
it('should be updated', async () => {
|
it('should be updated', async () => {
|
||||||
const mockClient = {
|
const mockClient = {
|
||||||
get: (_path: string, _params: object) => {
|
get: (_path: string, _params: object) => {
|
||||||
return new Promise<Response<Array<Status>>>(resolve => {
|
return new Promise<Response<Array<Conversation>>>(resolve => {
|
||||||
const res: Response<Array<Status>> = {
|
const res: Response<Array<Conversation>> = {
|
||||||
data: [status1],
|
data: [conversation1],
|
||||||
status: 200,
|
status: 200,
|
||||||
statusText: 'OK',
|
statusText: 'OK',
|
||||||
headers: {}
|
headers: {}
|
||||||
@ -176,9 +192,9 @@ describe('Home', () => {
|
|||||||
it('should be updated', async () => {
|
it('should be updated', async () => {
|
||||||
const mockClient = {
|
const mockClient = {
|
||||||
get: (_path: string, _params: object) => {
|
get: (_path: string, _params: object) => {
|
||||||
return new Promise<Response<Array<Status>>>(resolve => {
|
return new Promise<Response<Array<Conversation>>>(resolve => {
|
||||||
const res: Response<Array<Status>> = {
|
const res: Response<Array<Conversation>> = {
|
||||||
data: [status2],
|
data: [conversation2],
|
||||||
status: 200,
|
status: 200,
|
||||||
statusText: 'OK',
|
statusText: 'OK',
|
||||||
headers: {}
|
headers: {}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Mastodon, { Status, Response } from 'megalodon'
|
import Mastodon, { Status, Response, Conversation } from 'megalodon'
|
||||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
|
|
||||||
@ -97,10 +97,10 @@ const mutations: MutationTree<DirectMessagesState> = {
|
|||||||
const actions: ActionTree<DirectMessagesState, RootState> = {
|
const actions: ActionTree<DirectMessagesState, RootState> = {
|
||||||
fetchTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
|
fetchTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
|
||||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||||
const res: Response<Array<Status>> = await client.get<Array<Status>>('/timelines/direct', { limit: 40 })
|
const res: Response<Array<Conversation>> = await client.get<Array<Conversation>>('/conversations', { limit: 40 })
|
||||||
|
const statuses: Array<Status> = res.data.map(con => con.last_status!)
|
||||||
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
|
commit(MUTATION_TYPES.UPDATE_TIMELINE, statuses)
|
||||||
return res.data
|
return statuses
|
||||||
},
|
},
|
||||||
lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Status): Promise<Array<Status> | null> => {
|
lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Status): Promise<Array<Status> | null> => {
|
||||||
if (state.lazyLoading) {
|
if (state.lazyLoading) {
|
||||||
@ -109,10 +109,11 @@ const actions: ActionTree<DirectMessagesState, RootState> = {
|
|||||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
|
||||||
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
|
||||||
return client
|
return client
|
||||||
.get<Array<Status>>('/timelines/direct', { max_id: lastStatus.id, limit: 40 })
|
.get<Array<Conversation>>('/conversations', { max_id: lastStatus.id, limit: 40 })
|
||||||
.then(res => {
|
.then(res => {
|
||||||
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
|
const statuses: Array<Status> = res.data.map(con => con.last_status!)
|
||||||
return res.data
|
commit(MUTATION_TYPES.INSERT_TIMELINE, statuses)
|
||||||
|
return statuses
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
|
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user