mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Restructure removing remote
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import NetInfo from '@react-native-community/netinfo'
|
||||
import { store } from '@root/store'
|
||||
import removeInstance from '@utils/slices/instances/remove'
|
||||
import {
|
||||
localRemoveInstance,
|
||||
updateLocalAccount
|
||||
getInstanceActive,
|
||||
updateInstanceAccount
|
||||
} from '@utils/slices/instancesSlice'
|
||||
import log from './log'
|
||||
|
||||
@ -13,29 +14,28 @@ const netInfo = async (): Promise<{
|
||||
}> => {
|
||||
log('log', 'netInfo', 'initializing')
|
||||
const netInfo = await NetInfo.fetch()
|
||||
const activeIndex = store.getState().instances.local?.activeIndex
|
||||
const activeIndex = getInstanceActive(store.getState())
|
||||
|
||||
if (netInfo.isConnected) {
|
||||
log('log', 'netInfo', 'network connected')
|
||||
if (activeIndex !== null) {
|
||||
if (activeIndex !== -1) {
|
||||
log('log', 'netInfo', 'checking locally stored credentials')
|
||||
return client<Mastodon.Account>({
|
||||
return apiInstance<Mastodon.Account>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/verify_credentials`
|
||||
})
|
||||
.then(res => {
|
||||
log('log', 'netInfo', 'local credential check passed')
|
||||
if (
|
||||
res.body.id !==
|
||||
store.getState().instances.local?.instances[activeIndex].account.id
|
||||
store.getState().instances.instances[activeIndex].account.id
|
||||
) {
|
||||
log('error', 'netInfo', 'local id does not match remote id')
|
||||
store.dispatch(localRemoveInstance(activeIndex))
|
||||
store.dispatch(removeInstance(activeIndex))
|
||||
return Promise.resolve({ connected: true, corruputed: '' })
|
||||
} else {
|
||||
store.dispatch(
|
||||
updateLocalAccount({
|
||||
updateInstanceAccount({
|
||||
acct: res.body.acct,
|
||||
avatarStatic: res.body.avatar_static
|
||||
})
|
||||
@ -50,7 +50,7 @@ const netInfo = async (): Promise<{
|
||||
typeof error.status === 'number' &&
|
||||
error.status === 401
|
||||
) {
|
||||
store.dispatch(localRemoveInstance(activeIndex))
|
||||
store.dispatch(removeInstance(activeIndex))
|
||||
}
|
||||
return Promise.resolve({
|
||||
connected: true,
|
||||
|
Reference in New Issue
Block a user