refs #630 Fix id type for renderer

This commit is contained in:
AkiraFukushima 2019-05-27 22:56:54 +09:00
parent b6239a5f1e
commit 070dbef653
15 changed files with 79 additions and 102 deletions

View File

@ -607,7 +607,7 @@ ipcMain.on('stop-public-streaming', () => {
let listStreaming: StreamingManager | null = null
type ListID = {
listID: number
listID: string
}
ipcMain.on('start-list-streaming', (event: Event, obj: ListID & StreamingSetting) => {

View File

@ -116,7 +116,7 @@ export default {
return false
}
this.$store.dispatch('TimelineSpace/Modals/NewToot/openModal')
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaId')
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaCount')
this.$store.dispatch('TimelineSpace/Modals/NewToot/uploadImage', file).catch(() => {
this.$message({
message: this.$t('message.attach_error'),

View File

@ -208,7 +208,7 @@ export default {
methods: {
close() {
this.filteredAccount = []
this.$store.dispatch('TimelineSpace/Modals/NewToot/resetMediaId')
this.$store.dispatch('TimelineSpace/Modals/NewToot/resetMediaCount')
this.$store.dispatch('TimelineSpace/Modals/NewToot/closeModal')
},
async toot() {
@ -277,7 +277,7 @@ export default {
this.updateImage(file)
},
updateImage(file) {
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaId')
this.$store.dispatch('TimelineSpace/Modals/NewToot/incrementMediaCount')
this.$store.dispatch('TimelineSpace/Modals/NewToot/uploadImage', file).catch(() => {
this.$message({
message: this.$t('message.attach_error'),

View File

@ -4,7 +4,7 @@ import { Module, MutationTree } from 'vuex'
import { RootState } from '@/store'
export interface SettingsState {
accountID: number | null
accountID: string | null
}
const state = (): SettingsState => ({
@ -16,14 +16,14 @@ export const MUTATION_TYPES = {
}
const mutations: MutationTree<SettingsState> = {
[MUTATION_TYPES.CHANGE_ACCOUNT_ID]: (state, id: number) => {
[MUTATION_TYPES.CHANGE_ACCOUNT_ID]: (state, id: string) => {
state.accountID = id
}
}
export interface SettingsModuleState extends SettingsState {
General: GeneralState,
Timeline: TimelineState,
General: GeneralState
Timeline: TimelineState
}
const Settings: Module<SettingsState, RootState> = {

View File

@ -104,7 +104,7 @@ const mutations: MutationTree<TimelineSpaceState> = {
}
const actions: ActionTree<TimelineSpaceState, RootState> = {
initLoad: async ({ dispatch, commit }, accountId: number): Promise<Account> => {
initLoad: async ({ dispatch, commit }, accountId: string): Promise<Account> => {
commit(MUTATION_TYPES.CHANGE_LOADING, true)
dispatch('watchShortcutEvents')
const account = await dispatch('localAccount', accountId).catch(_ => {

View File

@ -5,10 +5,10 @@ import { RootState } from '@/store'
import LocalAccount from '~/src/types/localAccount'
export interface FavouritesState {
favourites: Array<Status>,
lazyLoading: boolean,
filter: string,
maxId: number | null
favourites: Array<Status>
lazyLoading: boolean
filter: string
maxId: string | null
}
const state = (): FavouritesState => ({
@ -36,7 +36,7 @@ const mutations: MutationTree<FavouritesState> = {
state.favourites = state.favourites.concat(favourites)
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => {
state.favourites = state.favourites.map((toot) => {
state.favourites = state.favourites.map(toot => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && toot.reblog.id === message.id) {
@ -52,7 +52,7 @@ const mutations: MutationTree<FavouritesState> = {
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.favourites = state.favourites.filter((toot) => {
state.favourites = state.favourites.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
return false
} else {
@ -66,24 +66,21 @@ const mutations: MutationTree<FavouritesState> = {
[MUTATION_TYPES.CHANGE_FILTER]: (state, filter: string) => {
state.filter = filter
},
[MUTATION_TYPES.CHANGE_MAX_ID]: (state, id: number | null) => {
[MUTATION_TYPES.CHANGE_MAX_ID]: (state, id: string | null) => {
state.maxId = id
}
}
const actions: ActionTree<FavouritesState, RootState> = {
fetchFavourites: async ({ commit }, account: LocalAccount): Promise<Array<Status>> => {
const client = new Mastodon(
account.accessToken!,
account.baseURL + '/api/v1'
)
const client = new Mastodon(account.accessToken!, account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { limit: 40 })
commit(MUTATION_TYPES.UPDATE_FAVOURITES, res.data)
// Parse link header
try {
const link = parse(res.headers.link)
if (link !== null) {
commit(MUTATION_TYPES.CHANGE_MAX_ID, parseInt(link.next.max_id))
commit(MUTATION_TYPES.CHANGE_MAX_ID, link.next.max_id)
} else {
commit(MUTATION_TYPES.CHANGE_MAX_ID, null)
}
@ -101,20 +98,16 @@ const actions: ActionTree<FavouritesState, RootState> = {
return Promise.resolve(null)
}
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { max_id: state.maxId, limit: 40 })
.finally(() => {
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
})
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Status>> = await client.get<Array<Status>>('/favourites', { max_id: state.maxId, limit: 40 }).finally(() => {
commit(MUTATION_TYPES.CHANGE_LAZY_LOADING, false)
})
commit(MUTATION_TYPES.INSERT_FAVOURITES, res.data)
// Parse link header
try {
const link = parse(res.headers.link)
if (link !== null) {
commit(MUTATION_TYPES.CHANGE_MAX_ID, parseInt(link.next.max_id))
commit(MUTATION_TYPES.CHANGE_MAX_ID, link.next.max_id)
} else {
commit(MUTATION_TYPES.CHANGE_MAX_ID, null)
}

View File

@ -22,11 +22,8 @@ const mutations: MutationTree<EditState> = {
}
const actions: ActionTree<EditState, RootState> = {
fetchMembers: async ({ commit, rootState }, listId: number): Promise<Array<Account>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
fetchMembers: async ({ commit, rootState }, listId: string): Promise<Array<Account>> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Array<Account>> = await client.get<Array<Account>>(`/lists/${listId}/accounts`, {
limit: 0
})
@ -34,10 +31,7 @@ const actions: ActionTree<EditState, RootState> = {
return res.data
},
removeAccount: async ({ rootState }, remove: RemoveAccountFromList): Promise<{}> => {
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.del<{}>(`/lists/${remove.listId}/accounts`, {
account_ids: [remove.account.id]
})

View File

@ -5,10 +5,10 @@ import { RootState } from '@/store'
import { LoadPositionWithList } from '@/types/loadPosition'
export interface ShowState {
timeline: Array<Status>,
unreadTimeline: Array<Status>,
lazyLoading: boolean,
heading: boolean,
timeline: Array<Status>
unreadTimeline: Array<Status>
lazyLoading: boolean
heading: boolean
filter: string
}
@ -48,22 +48,22 @@ const mutations: MutationTree<ShowState> = {
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array<Status>) => {
state.timeline = timeline
},
[MUTATION_TYPES.MERGE_TIMELINE]: (state) => {
[MUTATION_TYPES.MERGE_TIMELINE]: state => {
state.timeline = state.unreadTimeline.slice(0, 80).concat(state.timeline)
state.unreadTimeline = []
},
[MUTATION_TYPES.INSERT_TIMELINE]: (state, messages: Array<Status>) => {
state.timeline = state.timeline.concat(messages)
},
[MUTATION_TYPES.ARCHIVE_TIMELINE]: (state) => {
[MUTATION_TYPES.ARCHIVE_TIMELINE]: state => {
state.timeline = state.timeline.slice(0, 40)
},
[MUTATION_TYPES.CLEAR_TIMELINE]: (state) => {
[MUTATION_TYPES.CLEAR_TIMELINE]: state => {
state.timeline = []
state.unreadTimeline = []
},
[MUTATION_TYPES.UPDATE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.map((toot) => {
state.timeline = state.timeline.map(toot => {
if (toot.id === message.id) {
return message
} else if (toot.reblog !== null && toot.reblog.id === message.id) {
@ -79,7 +79,7 @@ const mutations: MutationTree<ShowState> = {
})
},
[MUTATION_TYPES.DELETE_TOOT]: (state, message: Status) => {
state.timeline = state.timeline.filter((toot) => {
state.timeline = state.timeline.filter(toot => {
if (toot.reblog !== null && toot.reblog.id === message.id) {
return false
} else {
@ -96,16 +96,13 @@ const mutations: MutationTree<ShowState> = {
}
const actions: ActionTree<ShowState, RootState> = {
fetchTimeline: async ({ commit, rootState }, listID: number): Promise<Array<Status>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
fetchTimeline: async ({ commit, rootState }, listID: string): 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/list/${listID}`, { limit: 40 })
commit(MUTATION_TYPES.UPDATE_TIMELINE, res.data)
return res.data
},
startStreaming: ({ state, commit, rootState }, listID: number) => {
startStreaming: ({ state, commit, rootState }, listID: string) => {
ipcRenderer.on('update-start-list-streaming', (_, update: Status) => {
commit(MUTATION_TYPES.APPEND_TIMELINE, update)
if (state.heading && Math.random() > 0.8) {
@ -113,7 +110,8 @@ const actions: ActionTree<ShowState, RootState> = {
}
})
// @ts-ignore
return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
return new Promise((resolve, reject) => {
// eslint-disable-line no-unused-vars
ipcRenderer.send('start-list-streaming', {
listID: listID,
account: rootState.TimelineSpace.account,
@ -137,11 +135,9 @@ const actions: ActionTree<ShowState, RootState> = {
return Promise.resolve(null)
}
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/list/${loadPosition.list_id}`, { max_id: loadPosition.status.id, limit: 40 })
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
return client
.get<Array<Status>>(`/timelines/list/${loadPosition.list_id}`, { max_id: loadPosition.status.id, limit: 40 })
.then(res => {
commit(MUTATION_TYPES.INSERT_TIMELINE, res.data)
return res.data

View File

@ -42,7 +42,7 @@ const mutations: MutationTree<AccountProfileState> = {
}
const actions: ActionTree<AccountProfileState, RootState> = {
fetchAccount: async ({ rootState }, accountID: number): Promise<Account> => {
fetchAccount: async ({ rootState }, accountID: string): Promise<Account> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Account> = await client.get<Account>(`/accounts/${accountID}`)
return res.data

View File

@ -34,7 +34,7 @@ const mutations: MutationTree<HeaderMenuState> = {
}
const actions: ActionTree<HeaderMenuState, RootState> = {
fetchList: async ({ commit, rootState }, listID: number): Promise<List> => {
fetchList: async ({ commit, rootState }, listID: string): Promise<List> => {
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<List> = await client.get<List>(`/lists/${listID}`)
commit(MUTATION_TYPES.UPDATE_TITLE, `#${res.data.title}`)

View File

@ -3,9 +3,9 @@ import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface AddListMemberState {
modalOpen: boolean,
accounts: Array<Account>,
targetListId: number | null
modalOpen: boolean
accounts: Array<Account>
targetListId: string | null
}
const state = (): AddListMemberState => ({
@ -27,7 +27,7 @@ const mutations: MutationTree<AddListMemberState> = {
[MUTATION_TYPES.UPDATE_ACCOUNTS]: (state, accounts: Array<Account>) => {
state.accounts = accounts
},
[MUTATION_TYPES.SET_LIST_ID]: (state, id: number) => {
[MUTATION_TYPES.SET_LIST_ID]: (state, id: string) => {
state.targetListId = id
}
}
@ -37,10 +37,7 @@ const actions: ActionTree<AddListMemberState, RootState> = {
commit(MUTATION_TYPES.CHANGE_MODAL, value)
},
search: async ({ commit, rootState }, name: string): Promise<Array<Account>> => {
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<Account>> = await client.get<Array<Account>>('/accounts/search', {
q: name,
following: true
@ -49,10 +46,7 @@ const actions: ActionTree<AddListMemberState, RootState> = {
return res.data
},
add: async ({ state, rootState }, account: Account): Promise<{}> => {
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<{}> = await client.post<{}>(`/lists/${state.targetListId}/accounts`, {
account_ids: [account.id]
})

View File

@ -16,7 +16,7 @@ import {
} from '@/errors/validations'
type MediaDescription = {
id: number
id: string
description: string
}
@ -27,10 +27,10 @@ export interface NewTootState {
replyToMessage: Status | null
blockSubmit: boolean
attachedMedias: Array<Attachment>
mediaDescriptions: { [key: number]: string | null }
mediaDescriptions: { [key: string]: string | null }
visibility: number
sensitive: boolean
attachedMediaId: number
attachedMediaCount: number
pinedHashtag: boolean
hashtags: Array<Tag>
loading: boolean
@ -50,7 +50,7 @@ const state = (): NewTootState => ({
mediaDescriptions: {},
visibility: Visibility.Public.value,
sensitive: false,
attachedMediaId: 0,
attachedMediaCount: 0,
pinedHashtag: false,
hashtags: [],
loading: false
@ -70,7 +70,7 @@ export const MUTATION_TYPES = {
REMOVE_MEDIA_DESCRIPTION: 'removeMediaDescription',
CHANGE_VISIBILITY_VALUE: 'changeVisibilityValue',
CHANGE_SENSITIVE: 'changeSensitive',
UPDATE_MEDIA_ID: 'updateMediaId',
UPDATE_MEDIA_COUNT: 'updateMediaCount',
CHANGE_PINED_HASHTAG: 'changePinedHashtag',
UPDATE_HASHTAGS: 'updateHashtags',
CHANGE_LOADING: 'changeLoading'
@ -107,7 +107,7 @@ const mutations: MutationTree<NewTootState> = {
[MUTATION_TYPES.CLEAR_MEDIA_DESCRIPTIONS]: state => {
state.mediaDescriptions = {}
},
[MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION]: (state, id: number) => {
[MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION]: (state, id: string) => {
const descriptions = state.mediaDescriptions
delete descriptions[id]
state.mediaDescriptions = descriptions
@ -124,8 +124,8 @@ const mutations: MutationTree<NewTootState> = {
[MUTATION_TYPES.CHANGE_SENSITIVE]: (state, value: boolean) => {
state.sensitive = value
},
[MUTATION_TYPES.UPDATE_MEDIA_ID]: (state, value: number) => {
state.attachedMediaId = value
[MUTATION_TYPES.UPDATE_MEDIA_COUNT]: (state, count: number) => {
state.attachedMediaCount = count
},
[MUTATION_TYPES.CHANGE_PINED_HASHTAG]: (state, value: boolean) => {
state.pinedHashtag = value
@ -286,19 +286,19 @@ const actions: ActionTree<NewTootState, RootState> = {
throw err
})
},
incrementMediaId: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_ID, state.attachedMediaId + 1)
incrementMediaCount: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, state.attachedMediaCount + 1)
},
decrementMediaId: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_ID, state.attachedMediaId - 1)
decrementMediaCount: ({ commit, state }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, state.attachedMediaCount - 1)
},
resetMediaId: ({ commit }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_ID, 0)
resetMediaCount: ({ commit }) => {
commit(MUTATION_TYPES.UPDATE_MEDIA_COUNT, 0)
},
removeMedia: ({ commit, dispatch }, media: Attachment) => {
commit(MUTATION_TYPES.REMOVE_MEDIA, media)
commit(MUTATION_TYPES.REMOVE_MEDIA_DESCRIPTION, media.id)
dispatch('decrementMediaId')
dispatch('decrementMediaCount')
},
updateHashtags: ({ commit, state }, tags: Array<Tag>) => {
if (state.pinedHashtag && tags.length > 0) {

View File

@ -9,7 +9,7 @@ export interface LoadPositionWithAccount extends LoadPosition {
}
export interface LoadPositionWithList extends LoadPosition {
list_id: number
list_id: string
}
export interface LoadPositionWithTag extends LoadPosition {

View File

@ -1,6 +1,6 @@
import { Account } from 'megalodon'
export interface RemoveAccountFromList {
account: Account,
listId: number
account: Account
listId: string
}

View File

@ -1,13 +1,13 @@
export default interface LocalAccount {
_id?: string,
baseURL: string,
domain: string,
clientId: string,
clientSecret: string,
accessToken: string | null,
refreshToken: string | null,
username: string | null,
accountId: number | null,
avatar: string | null,
_id?: string
baseURL: string
domain: string
clientId: string
clientSecret: string
accessToken: string | null
refreshToken: string | null
username: string | null
accountId: string | null
avatar: string | null
order: number
}