import generator , { Entity } from 'megalodon' ; import { Module , ActionTree } from 'vuex' ; import { RootState } from '@/store' ; import { MyWindow } from '~/src/types/global' ; const win = ( window as any ) as MyWindow ; type VoteParam = { id : string ; choices : Array < number > ; } ; type ReactionParam = { status_id : string ; native : string ; } ; export type TootState = { } ; const state = ( ) : TootState => ( { } ) ; const actions = { reblog : async ( { rootState , dispatch } , message ) => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . reblogStatus ( message . id ) ; win . ipcRenderer . send ( 'fav-rt-action-sound' ) ; dispatch ( 'TimelineSpace/updateTootForAllTimelines' , res . data . reblog , { root : true } ) ; return res . data . reblog ; } , unreblog : async ( { rootState , dispatch } , message ) => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . unreblogStatus ( message . id ) ; dispatch ( 'TimelineSpace/updateTootForAllTimelines' , res . data , { root : true } ) ; return res . data ; } , addFavourite : async ( { rootState , dispatch } , message ) : Promise < Entity . Status > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . favouriteStatus ( message . id ) ; win . ipcRenderer . send ( 'fav-rt-action-sound' ) ; dispatch ( 'TimelineSpace/updateTootForAllTimelines' , res . data , { root : true } ) ; return res . data ; } , removeFavourite : async ( { rootState , dispatch } , message ) : Promise < Entity . Status > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . unfavouriteStatus ( message . id ) ; dispatch ( 'TimelineSpace/updateTootForAllTimelines' , res . data , { root : true } ) ; return res . data ; } , addBookmark : async ( { rootState , dispatch } , message ) : Promise < Entity . Status > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . bookmarkStatus ( message . id ) ; win . ipcRenderer . send ( 'fav-rt-action-sound' ) ; dispatch ( 'TimelineSpace/updateTootForAllTimelines' , res . data , { root : true } ) ; return res . data ; } , removeBookmark : async ( { rootState , dispatch } , message ) : Promise < Entity . Status > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . unbookmarkStatus ( message . id ) ; dispatch ( 'TimelineSpace/updateTootForAllTimelines' , res . data , { root : true } ) ; return res . data ; } , deleteToot : async ( { rootState } , message ) => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; await client . deleteStatus ( message . id ) ; return message ; } , block : async ( { rootState } , account ) => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; return client . blockAccount ( account . id ) ; } , vote : async ( { rootState } , params ) : Promise < Entity . Poll > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . votePoll ( params . id , params . choices ) ; return res . data ; } , refresh : async ( { rootState } , id ) : Promise < Entity . Poll > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . getPoll ( id ) ; return res . data ; } , sendReaction : async ( { rootState } , params ) : Promise < Entity . Status > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . createEmojiReaction ( params . status_id , params . native ) ; return res . data ; } , deleteReaction : async ( { rootState } , params ) : Promise < Entity . Status > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . deleteEmojiReaction ( params . status_id , params . native ) ; return res . data ; } } ; const Toot = { namespaced : true , state : state , actions : actions } ; export default Toot ;