|
|
|
@ -1,9 +1,7 @@
|
|
|
|
|
import api from '../api';
|
|
|
|
|
import openDB from '../storage/db';
|
|
|
|
|
import { evictStatus } from '../storage/modifier';
|
|
|
|
|
|
|
|
|
|
import { deleteFromTimelines } from './timelines';
|
|
|
|
|
import { importFetchedStatus, importFetchedStatuses, importAccount, importStatus, importFetchedAccount } from './importer';
|
|
|
|
|
import { importFetchedStatus, importFetchedStatuses, importFetchedAccount } from './importer';
|
|
|
|
|
import { ensureComposeIsVisible } from './compose';
|
|
|
|
|
|
|
|
|
|
export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
|
|
|
|
@ -40,48 +38,6 @@ export function fetchStatusRequest(id, skipLoading) {
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getFromDB(dispatch, getState, accountIndex, index, id) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const request = index.get(id);
|
|
|
|
|
|
|
|
|
|
request.onerror = reject;
|
|
|
|
|
|
|
|
|
|
request.onsuccess = () => {
|
|
|
|
|
const promises = [];
|
|
|
|
|
|
|
|
|
|
if (!request.result) {
|
|
|
|
|
reject();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispatch(importStatus(request.result));
|
|
|
|
|
|
|
|
|
|
if (getState().getIn(['accounts', request.result.account], null) === null) {
|
|
|
|
|
promises.push(new Promise((accountResolve, accountReject) => {
|
|
|
|
|
const accountRequest = accountIndex.get(request.result.account);
|
|
|
|
|
|
|
|
|
|
accountRequest.onerror = accountReject;
|
|
|
|
|
accountRequest.onsuccess = () => {
|
|
|
|
|
if (!request.result) {
|
|
|
|
|
accountReject();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispatch(importAccount(accountRequest.result));
|
|
|
|
|
accountResolve();
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.result.reblog && getState().getIn(['statuses', request.result.reblog], null) === null) {
|
|
|
|
|
promises.push(getFromDB(dispatch, getState, accountIndex, index, request.result.reblog));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(Promise.all(promises));
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchStatus(id) {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
const skipLoading = getState().getIn(['statuses', id], null) !== null;
|
|
|
|
@ -94,23 +50,10 @@ export function fetchStatus(id) {
|
|
|
|
|
|
|
|
|
|
dispatch(fetchStatusRequest(id, skipLoading));
|
|
|
|
|
|
|
|
|
|
openDB().then(db => {
|
|
|
|
|
const transaction = db.transaction(['accounts', 'statuses'], 'read');
|
|
|
|
|
const accountIndex = transaction.objectStore('accounts').index('id');
|
|
|
|
|
const index = transaction.objectStore('statuses').index('id');
|
|
|
|
|
|
|
|
|
|
return getFromDB(dispatch, getState, accountIndex, index, id).then(() => {
|
|
|
|
|
db.close();
|
|
|
|
|
}, error => {
|
|
|
|
|
db.close();
|
|
|
|
|
throw error;
|
|
|
|
|
});
|
|
|
|
|
}).then(() => {
|
|
|
|
|
dispatch(fetchStatusSuccess(skipLoading));
|
|
|
|
|
}, () => api(getState).get(`/api/v1/statuses/${id}`).then(response => {
|
|
|
|
|
api(getState).get(`/api/v1/statuses/${id}`).then(response => {
|
|
|
|
|
dispatch(importFetchedStatus(response.data));
|
|
|
|
|
dispatch(fetchStatusSuccess(skipLoading));
|
|
|
|
|
})).catch(error => {
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch(fetchStatusFail(id, error, skipLoading));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
@ -152,7 +95,6 @@ export function deleteStatus(id, routerHistory, withRedraft = false) {
|
|
|
|
|
dispatch(deleteStatusRequest(id));
|
|
|
|
|
|
|
|
|
|
api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
|
|
|
|
|
evictStatus(id);
|
|
|
|
|
dispatch(deleteStatusSuccess(id));
|
|
|
|
|
dispatch(deleteFromTimelines(id));
|
|
|
|
|
dispatch(importFetchedAccount(response.data.account));
|
|
|
|
|