diff --git a/src/app.jsx b/src/app.jsx index 148f2760..63357bff 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -112,7 +112,7 @@ function App() { const masto = initClient({ instance: instanceURL, accessToken }); await Promise.allSettled([ - initInstance(masto), + initInstance(masto, instanceURL), initAccount(masto, instanceURL, accessToken), ]); initPreferences(masto); @@ -124,13 +124,13 @@ function App() { const account = getCurrentAccount(); if (account) { store.session.set('currentAccount', account.info.id); - const { masto } = api({ account }); + const { masto, instance } = api({ account }); console.log('masto', masto); initPreferences(masto); setUIState('loading'); (async () => { try { - await initInstance(masto); + await initInstance(masto, instance); } catch (e) { } finally { setIsLoggedIn(true); diff --git a/src/utils/api.js b/src/utils/api.js index 15522581..c9c6a589 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -48,7 +48,7 @@ export function initClient({ instance, accessToken }) { // Get the instance information // The config is needed for composing -export async function initInstance(client) { +export async function initInstance(client, instance) { const masto = client; // Request v2, fallback to v1 if fail let info; @@ -70,16 +70,19 @@ export async function initInstance(client) { domain, configuration: { urls: { streaming } = {} } = {}, } = info; + const instances = store.local.getJSON('instances') || {}; if (uri || domain) { - const instances = store.local.getJSON('instances') || {}; instances[ (domain || uri) .replace(/^https?:\/\//, '') .replace(/\/+$/, '') .toLowerCase() ] = info; - store.local.setJSON('instances', instances); } + if (instance) { + instances[instance.toLowerCase()] = info; + } + store.local.setJSON('instances', instances); // This is a weird place to put this but here's updating the masto instance with the streaming API URL set in the configuration // Reason: Streaming WebSocket URL may change, unlike the standard API REST URLs if (streamingApi || streaming) {