Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/responders/website-responders.js
Show All 9 Lines | |||||
import { Route, StaticRouter } from 'react-router'; | import { Route, StaticRouter } from 'react-router'; | ||||
import { createStore, type Store } from 'redux'; | import { createStore, type Store } from 'redux'; | ||||
import { promisify } from 'util'; | import { promisify } from 'util'; | ||||
import { daysToEntriesFromEntryInfos } from 'lib/reducers/entry-reducer'; | import { daysToEntriesFromEntryInfos } from 'lib/reducers/entry-reducer'; | ||||
import { freshMessageStore } from 'lib/reducers/message-reducer'; | import { freshMessageStore } from 'lib/reducers/message-reducer'; | ||||
import { mostRecentlyReadThread } from 'lib/selectors/thread-selectors'; | import { mostRecentlyReadThread } from 'lib/selectors/thread-selectors'; | ||||
import { mostRecentMessageTimestamp } from 'lib/shared/message-utils'; | import { mostRecentMessageTimestamp } from 'lib/shared/message-utils'; | ||||
import { sortIDs } from 'lib/shared/relationship-utils'; | |||||
import { | import { | ||||
threadHasPermission, | threadHasPermission, | ||||
threadIsPending, | threadIsPending, | ||||
parsePendingThreadID, | parsePendingThreadID, | ||||
createPendingThread, | createPendingThread, | ||||
} from 'lib/shared/thread-utils'; | } from 'lib/shared/thread-utils'; | ||||
import { defaultWebEnabledApps } from 'lib/types/enabled-apps'; | import { defaultWebEnabledApps } from 'lib/types/enabled-apps'; | ||||
import { defaultCalendarFilters } from 'lib/types/filter-types'; | import { defaultCalendarFilters } from 'lib/types/filter-types'; | ||||
import { defaultNumberPerThread } from 'lib/types/message-types'; | import { defaultNumberPerThread } from 'lib/types/message-types'; | ||||
import { undirectedStatus } from 'lib/types/relationship-types'; | |||||
import { defaultEnabledReports } from 'lib/types/report-types'; | import { defaultEnabledReports } from 'lib/types/report-types'; | ||||
import { defaultConnectionInfo } from 'lib/types/socket-types'; | import { defaultConnectionInfo } from 'lib/types/socket-types'; | ||||
import { threadPermissions, threadTypes } from 'lib/types/thread-types'; | import { threadPermissions, threadTypes } from 'lib/types/thread-types'; | ||||
import type { CurrentUserInfo } from 'lib/types/user-types'; | import type { CurrentUserInfo } from 'lib/types/user-types'; | ||||
import { currentDateInTimeZone } from 'lib/utils/date-utils'; | import { currentDateInTimeZone } from 'lib/utils/date-utils'; | ||||
import { ServerError } from 'lib/utils/errors'; | import { ServerError } from 'lib/utils/errors'; | ||||
import { promiseAll } from 'lib/utils/promises'; | import { promiseAll } from 'lib/utils/promises'; | ||||
import { reducer } from 'web/redux/redux-setup'; | import { reducer } from 'web/redux/redux-setup'; | ||||
import type { AppState, Action } from 'web/redux/redux-setup'; | import type { AppState, Action } from 'web/redux/redux-setup'; | ||||
import getTitle from 'web/title/getTitle'; | import getTitle from 'web/title/getTitle'; | ||||
import { navInfoFromURL } from 'web/url-utils'; | import { navInfoFromURL } from 'web/url-utils'; | ||||
import { fetchEntryInfos } from '../fetchers/entry-fetchers'; | import { fetchEntryInfos } from '../fetchers/entry-fetchers'; | ||||
import { fetchMessageInfos } from '../fetchers/message-fetchers'; | import { fetchMessageInfos } from '../fetchers/message-fetchers'; | ||||
import { fetchThreadInfos } from '../fetchers/thread-fetchers'; | import { fetchThreadInfos } from '../fetchers/thread-fetchers'; | ||||
import { | import { | ||||
fetchCurrentUserInfo, | fetchCurrentUserInfo, | ||||
fetchKnownUserInfos, | fetchKnownUserInfos, | ||||
fetchUserInfos, | |||||
} from '../fetchers/user-fetchers'; | } from '../fetchers/user-fetchers'; | ||||
import { setNewSession } from '../session/cookies'; | import { setNewSession } from '../session/cookies'; | ||||
import { Viewer } from '../session/viewer'; | import { Viewer } from '../session/viewer'; | ||||
import { updateUndirectedRelationships } from '../updaters/relationship-updaters'; | |||||
import { streamJSON, waitForStream } from '../utils/json-stream'; | import { streamJSON, waitForStream } from '../utils/json-stream'; | ||||
import { | import { | ||||
getAppURLFactsFromRequestURL, | getAppURLFactsFromRequestURL, | ||||
clientPathFromRouterPath, | clientPathFromRouterPath, | ||||
} from '../utils/urls'; | } from '../utils/urls'; | ||||
const { renderToNodeStream } = ReactDOMServer; | const { renderToNodeStream } = ReactDOMServer; | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | ): Promise<void> { | ||||
try { | try { | ||||
initialNavInfo = navInfoFromURL(req.url, { | initialNavInfo = navInfoFromURL(req.url, { | ||||
now: currentDateInTimeZone(viewer.timeZone), | now: currentDateInTimeZone(viewer.timeZone), | ||||
}); | }); | ||||
} catch (e) { | } catch (e) { | ||||
throw new ServerError(e.message); | throw new ServerError(e.message); | ||||
} | } | ||||
if ( | |||||
viewer.loggedIn && | |||||
initialNavInfo.tab === 'chat' && | |||||
initialNavInfo.chatMode === 'create' && | |||||
initialNavInfo.selectedUserList && | |||||
initialNavInfo.selectedUserList.length > 0 | |||||
) { | |||||
const userIDs = initialNavInfo.selectedUserList; | |||||
const userInfos = await fetchUserInfos(userIDs); | |||||
const validUserIDs = userIDs.filter(userID => !!userInfos[userID].username); | |||||
const rows = validUserIDs.map(userID => { | |||||
const [user1, user2] = sortIDs(viewer.userID, userID); | |||||
const status = undirectedStatus.KNOW_OF; | |||||
return { user1, user2, status }; | |||||
}); | |||||
await updateUndirectedRelationships(rows); | |||||
initialNavInfo.selectedUserList = validUserIDs; | |||||
} | |||||
ashoat: Can we avoid directly `await`ing here? This approach leads to blocking the rest of execution… | |||||
const calendarQuery = { | const calendarQuery = { | ||||
startDate: initialNavInfo.startDate, | startDate: initialNavInfo.startDate, | ||||
endDate: initialNavInfo.endDate, | endDate: initialNavInfo.endDate, | ||||
filters: defaultCalendarFilters, | filters: defaultCalendarFilters, | ||||
}; | }; | ||||
const messageSelectionCriteria = { joinedThreads: true }; | const messageSelectionCriteria = { joinedThreads: true }; | ||||
const initialTime = Date.now(); | const initialTime = Date.now(); | ||||
▲ Show 20 Lines • Show All 239 Lines • Show Last 20 Lines |
Can we avoid directly awaiting here? This approach leads to blocking the rest of execution, but instead we could start the Promise and await it where initialNavInfo is needed, eg. fetchEntryInfos and setNewSession which both need calendarQuery, and of course navInfoPromise itself.