2023-01-13 16:42:41 -08:00
|
|
|
|
|
|
|
import { PLEROMA, parseVersion } from './features';
|
|
|
|
|
2023-01-25 14:32:59 -08:00
|
|
|
import type { RootState } from 'soapbox/store';
|
|
|
|
import type { Instance } from 'soapbox/types/entities';
|
|
|
|
|
2023-01-13 16:42:41 -08:00
|
|
|
/**
|
|
|
|
* Get the OAuth scopes to use for login & signup.
|
|
|
|
* Mastodon will refuse scopes it doesn't know, so care is needed.
|
|
|
|
*/
|
2023-01-25 14:32:59 -08:00
|
|
|
const getInstanceScopes = (instance: Instance) => {
|
2023-01-13 16:42:41 -08:00
|
|
|
const v = parseVersion(instance.version);
|
|
|
|
|
|
|
|
switch (v.software) {
|
|
|
|
case PLEROMA:
|
|
|
|
return 'read write follow push admin';
|
|
|
|
default:
|
|
|
|
return 'read write follow push';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-25 14:32:59 -08:00
|
|
|
/** Convenience function to get scopes from instance in store. */
|
|
|
|
const getScopes = (state: RootState) => {
|
|
|
|
return getInstanceScopes(state.instance);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-01-13 16:42:41 -08:00
|
|
|
export {
|
2023-01-25 14:32:59 -08:00
|
|
|
getInstanceScopes,
|
2023-01-13 16:42:41 -08:00
|
|
|
getScopes,
|
|
|
|
};
|