1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-01-30 17:15:16 +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:
AkiraFukushima 2019-08-12 16:43:55 +09:00 committed by GitHub
commit 4f53919a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 15 deletions

View File

@ -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 { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
@ -27,6 +27,7 @@ const account: Account = {
fields: null,
bot: false
}
const status1: Status = {
id: '1',
uri: 'http://example.com',
@ -58,6 +59,7 @@ const status1: Status = {
language: null,
pinned: null
}
const status2: Status = {
id: '2',
uri: 'http://example.com',
@ -90,6 +92,20 @@ const status2: Status = {
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 => {
return {
lazyLoading: false,
@ -139,9 +155,9 @@ describe('Home', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status1],
return new Promise<Response<Array<Conversation>>>(resolve => {
const res: Response<Array<Conversation>> = {
data: [conversation1],
status: 200,
statusText: 'OK',
headers: {}
@ -176,9 +192,9 @@ describe('Home', () => {
it('should be updated', async () => {
const mockClient = {
get: (_path: string, _params: object) => {
return new Promise<Response<Array<Status>>>(resolve => {
const res: Response<Array<Status>> = {
data: [status2],
return new Promise<Response<Array<Conversation>>>(resolve => {
const res: Response<Array<Conversation>> = {
data: [conversation2],
status: 200,
statusText: 'OK',
headers: {}

View File

@ -1,4 +1,4 @@
import Mastodon, { Status, Response } from 'megalodon'
import Mastodon, { Status, Response, Conversation } from 'megalodon'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
@ -97,10 +97,10 @@ const mutations: MutationTree<DirectMessagesState> = {
const actions: ActionTree<DirectMessagesState, RootState> = {
fetchTimeline: async ({ commit, rootState }): Promise<Array<Status>> => {
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 })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
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, statuses)
return statuses
},
lazyFetchTimeline: ({ state, commit, rootState }, lastStatus: Status): Promise<Array<Status> | null> => {
if (state.lazyLoading) {
@ -109,10 +109,11 @@ const actions: ActionTree<DirectMessagesState, RootState> = {
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
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 => {
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
return res.data
const statuses: Array<Status> = res.data.map(con => con.last_status!)
commit(MUTATION_TYPES.INSERT_TIMELINE, statuses)
return statuses
})
.finally(() => {
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)