Merge branch 'account-by-username' into 'develop'
Mastodon: search account by username See merge request soapbox-pub/soapbox-fe!770
This commit is contained in:
commit
473ae43e71
|
@ -5,6 +5,7 @@ import {
|
||||||
importErrorWhileFetchingAccountByUsername,
|
importErrorWhileFetchingAccountByUsername,
|
||||||
} from './importer';
|
} from './importer';
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||||
|
import { getFeatures } from 'soapbox/utils/features';
|
||||||
|
|
||||||
export const ACCOUNT_CREATE_REQUEST = 'ACCOUNT_CREATE_REQUEST';
|
export const ACCOUNT_CREATE_REQUEST = 'ACCOUNT_CREATE_REQUEST';
|
||||||
export const ACCOUNT_CREATE_SUCCESS = 'ACCOUNT_CREATE_SUCCESS';
|
export const ACCOUNT_CREATE_SUCCESS = 'ACCOUNT_CREATE_SUCCESS';
|
||||||
|
@ -54,6 +55,10 @@ export const ACCOUNT_UNPIN_REQUEST = 'ACCOUNT_UNPIN_REQUEST';
|
||||||
export const ACCOUNT_UNPIN_SUCCESS = 'ACCOUNT_UNPIN_SUCCESS';
|
export const ACCOUNT_UNPIN_SUCCESS = 'ACCOUNT_UNPIN_SUCCESS';
|
||||||
export const ACCOUNT_UNPIN_FAIL = 'ACCOUNT_UNPIN_FAIL';
|
export const ACCOUNT_UNPIN_FAIL = 'ACCOUNT_UNPIN_FAIL';
|
||||||
|
|
||||||
|
export const ACCOUNT_SEARCH_REQUEST = 'ACCOUNT_SEARCH_REQUEST';
|
||||||
|
export const ACCOUNT_SEARCH_SUCCESS = 'ACCOUNT_SEARCH_SUCCESS';
|
||||||
|
export const ACCOUNT_SEARCH_FAIL = 'ACCOUNT_SEARCH_FAIL';
|
||||||
|
|
||||||
export const FOLLOWERS_FETCH_REQUEST = 'FOLLOWERS_FETCH_REQUEST';
|
export const FOLLOWERS_FETCH_REQUEST = 'FOLLOWERS_FETCH_REQUEST';
|
||||||
export const FOLLOWERS_FETCH_SUCCESS = 'FOLLOWERS_FETCH_SUCCESS';
|
export const FOLLOWERS_FETCH_SUCCESS = 'FOLLOWERS_FETCH_SUCCESS';
|
||||||
export const FOLLOWERS_FETCH_FAIL = 'FOLLOWERS_FETCH_FAIL';
|
export const FOLLOWERS_FETCH_FAIL = 'FOLLOWERS_FETCH_FAIL';
|
||||||
|
@ -129,13 +134,18 @@ export function fetchAccount(id) {
|
||||||
|
|
||||||
export function fetchAccountByUsername(username) {
|
export function fetchAccountByUsername(username) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const account = getState().get('accounts').find(account => account.get('acct') === username);
|
const state = getState();
|
||||||
|
const account = state.get('accounts').find(account => account.get('acct') === username);
|
||||||
|
|
||||||
if (account) {
|
if (account) {
|
||||||
dispatch(fetchAccount(account.get('id')));
|
dispatch(fetchAccount(account.get('id')));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const instance = state.get('instance');
|
||||||
|
const features = getFeatures(instance);
|
||||||
|
|
||||||
|
if (features.accountByUsername) {
|
||||||
api(getState).get(`/api/v1/accounts/${username}`).then(response => {
|
api(getState).get(`/api/v1/accounts/${username}`).then(response => {
|
||||||
dispatch(fetchRelationships([response.data.id]));
|
dispatch(fetchRelationships([response.data.id]));
|
||||||
dispatch(importFetchedAccount(response.data));
|
dispatch(importFetchedAccount(response.data));
|
||||||
|
@ -144,6 +154,25 @@ export function fetchAccountByUsername(username) {
|
||||||
dispatch(fetchAccountFail(null, error));
|
dispatch(fetchAccountFail(null, error));
|
||||||
dispatch(importErrorWhileFetchingAccountByUsername(username));
|
dispatch(importErrorWhileFetchingAccountByUsername(username));
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
dispatch(accountSearch({
|
||||||
|
q: username,
|
||||||
|
limit: 5,
|
||||||
|
resolve: true,
|
||||||
|
})).then(accounts => {
|
||||||
|
const found = accounts.find(a => a.acct === username);
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
dispatch(fetchRelationships([found.id]));
|
||||||
|
dispatch(fetchAccountSuccess(found));
|
||||||
|
} else {
|
||||||
|
throw accounts;
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(fetchAccountFail(null, error));
|
||||||
|
dispatch(importErrorWhileFetchingAccountByUsername(username));
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,3 +946,17 @@ export function unpinAccountFail(error) {
|
||||||
error,
|
error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function accountSearch(params) {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
dispatch({ type: ACCOUNT_SEARCH_REQUEST, params });
|
||||||
|
return api(getState).get('/api/v1/accounts/search', { params }).then(({ data: accounts }) => {
|
||||||
|
dispatch(importFetchedAccounts(accounts));
|
||||||
|
dispatch({ type: ACCOUNT_SEARCH_SUCCESS, accounts });
|
||||||
|
return accounts;
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch({ type: ACCOUNT_SEARCH_FAIL, skipAlert: true });
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ export const getFeatures = createSelector([
|
||||||
exposableReactions: features.includes('exposable_reactions'),
|
exposableReactions: features.includes('exposable_reactions'),
|
||||||
accountSubscriptions: v.software === PLEROMA && gte(v.version, '1.0.0'),
|
accountSubscriptions: v.software === PLEROMA && gte(v.version, '1.0.0'),
|
||||||
unrestrictedLists: v.software === PLEROMA,
|
unrestrictedLists: v.software === PLEROMA,
|
||||||
|
accountByUsername: v.software === PLEROMA,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue