( viewer: Viewer, sessionState: SessionState, )
| 27 | import { commitSessionUpdate } from '../updaters/session-updaters.js'; |
| 28 | |
| 29 | async function fetchDataForSocketInit( |
| 30 | viewer: Viewer, |
| 31 | sessionState: SessionState, |
| 32 | ): Promise<ServerStateSyncSocketPayload> { |
| 33 | const { |
| 34 | calendarQuery, |
| 35 | updatesCurrentAsOf: oldUpdatesCurrentAsOf, |
| 36 | messagesCurrentAsOf: oldMessagesCurrentAsOf, |
| 37 | watchedIDs, |
| 38 | } = sessionState; |
| 39 | await verifyCalendarQueryThreadIDs(calendarQuery); |
| 40 | |
| 41 | const sessionInitializationResult = await initializeSession( |
| 42 | viewer, |
| 43 | calendarQuery, |
| 44 | oldUpdatesCurrentAsOf, |
| 45 | ); |
| 46 | |
| 47 | const threadCursors: { [string]: null } = {}; |
| 48 | for (const watchedThreadID of watchedIDs) { |
| 49 | threadCursors[watchedThreadID] = null; |
| 50 | } |
| 51 | const messageSelectionCriteria = { |
| 52 | threadCursors, |
| 53 | joinedThreads: true, |
| 54 | newerThan: oldMessagesCurrentAsOf, |
| 55 | }; |
| 56 | const fetchMessagesResult = await fetchMessageInfosSince( |
| 57 | viewer, |
| 58 | messageSelectionCriteria, |
| 59 | defaultNumberPerThread, |
| 60 | ); |
| 61 | const messagesResult = { |
| 62 | rawMessageInfos: fetchMessagesResult.rawMessageInfos, |
| 63 | truncationStatuses: fetchMessagesResult.truncationStatuses, |
| 64 | currentAsOf: mostRecentMessageTimestamp( |
| 65 | fetchMessagesResult.rawMessageInfos, |
| 66 | oldMessagesCurrentAsOf, |
| 67 | ), |
| 68 | }; |
| 69 | |
| 70 | if (!sessionInitializationResult.sessionContinued) { |
| 71 | const promises: { +[string]: Promise<mixed> } = Object.fromEntries( |
| 72 | values(serverStateSyncSpecs).map(spec => [ |
| 73 | spec.hashKey, |
| 74 | spec.fetchFullSocketSyncPayload(viewer, [calendarQuery]), |
| 75 | ]), |
| 76 | ); |
| 77 | // We have a type error here because Flow doesn't know spec.hashKey |
| 78 | const castPromises: { |
| 79 | +threadInfos: Promise<LegacyRawThreadInfos>, |
| 80 | +currentUserInfo: Promise<CurrentUserInfo>, |
| 81 | +entryInfos: Promise<$ReadOnlyArray<RawEntryInfo>>, |
| 82 | +userInfos: Promise<$ReadOnlyArray<UserInfo>>, |
| 83 | } = (promises: any); |
| 84 | const results = await promiseAll(castPromises); |
| 85 | let payload: ServerStateSyncFullSocketPayload = { |
| 86 | type: stateSyncPayloadTypes.FULL, |
no test coverage detected