Skip to content

Commit

Permalink
[lib] Don't created thin thread if call to identity server failed whe…
Browse files Browse the repository at this point in the history
…n adding friends

Summary:
https://linear.app/comm/issue/ENG-9509/accepting-a-friend-request-on-web-creates-thin-thread

Related discussion: https://phab.comm.dev/D13940#389316
Now we're throwing an error just in useUpdateRelationships(), there are no changes in getUserIdentities()
and useUsersSupportThickThreads() returns Map instead of Set

Depends on D14022

Test Plan:
Throw some error in fetchUserIdentitiesPromise() so that finding user indentity always fails
Mobile user goes to profile -> Friend list and adds the web user as a friend
Before a thin thread was created. Now mobile user sees an alert, because there is no auxUserInfo, no thick thread and call to identity server fails.

Reviewers: kamil, tomek, ashoat

Reviewed By: ashoat

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D14023
  • Loading branch information
graszka22 committed Dec 12, 2024
1 parent 470bb6f commit cb47dbd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
11 changes: 7 additions & 4 deletions lib/hooks/relationship-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function useUpdateRelationships(): (
);
const createNewThickThread = useNewThickThread();

const filterUsersSupportingThickThreads = useUsersSupportThickThreads();
const mapUsersSupportingThickThreads = useUsersSupportThickThreads();

const updateRelationshipsAndSendRobotext = React.useCallback(
async (action: RelationshipAction, userIDs: $ReadOnlyArray<string>) => {
Expand All @@ -98,10 +98,13 @@ function useUpdateRelationships(): (
return {};
}
const usersSupportingThickThreads =
await filterUsersSupportingThickThreads(userIDs);
await mapUsersSupportingThickThreads(userIDs);
const planForUsers = new Map<string, RobotextPlanForUser>();
for (const userID of userIDs) {
if (!usersSupportingThickThreads.has(userID)) {
if (usersSupportingThickThreads.get(userID) === undefined) {
throw new Error('Cannot fetch user identity');
}
if (!usersSupportingThickThreads.get(userID)) {
planForUsers.set(userID, { plan: 'send_to_thin_thread' });
continue;
}
Expand Down Expand Up @@ -220,7 +223,7 @@ function useUpdateRelationships(): (
[
viewerID,
updateRelationships,
filterUsersSupportingThickThreads,
mapUsersSupportingThickThreads,
pendingToRealizedThreadIDs,
sendRobotextToThickThread,
userInfos,
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/thread-search-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function useThreadListSearch(
filterAndSetUserResults(
identitySearchUsers.map(search => ({
...search,
supportThickThreads: userIDsSupportingThickThreads.has(search.id),
supportThickThreads: !!userIDsSupportingThickThreads.get(search.id),
})),
);
})();
Expand Down
12 changes: 8 additions & 4 deletions lib/hooks/user-identities-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { useSelector } from '../utils/redux-utils.js';

function useUsersSupportThickThreads(): (
userIDs: $ReadOnlyArray<string>,
) => Promise<$ReadOnlySet<string>> {
) => Promise<$ReadOnlyMap<string, boolean | void>> {
const findUserIdentities = useFindUserIdentities();
const auxUserInfos = useSelector(state => state.auxUserStore.auxUserInfos);

return React.useCallback(
async (userIDs: $ReadOnlyArray<string>) => {
const usersSupportingThickThreads = new Set<string>();
const usersSupportingThickThreads = new Map<string, boolean | void>();

const usersNeedingFetch = [];
for (const userID of userIDs) {
if (auxUserInfos[userID]?.deviceList) {
usersSupportingThickThreads.add(userID);
usersSupportingThickThreads.set(userID, true);
} else {
usersNeedingFetch.push(userID);
}
Expand All @@ -27,7 +27,11 @@ function useUsersSupportThickThreads(): (
const { identities } = await findUserIdentities(usersNeedingFetch);
for (const userID of usersNeedingFetch) {
if (identities[userID]) {
usersSupportingThickThreads.add(userID);
usersSupportingThickThreads.set(userID, true);
} else if (identities[userID] === undefined) {
usersSupportingThickThreads.set(userID, undefined);
} else {
usersSupportingThickThreads.set(userID, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/thread-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ function useUserProfileThreadInfo(userInfo: ?UserInfo): ?UserProfileThreadInfo {
return;
}
const result = await usersSupportThickThreads([userInfo.id]);
setSupportThickThreads(result.has(userInfo.id));
setSupportThickThreads(!!result.get(userInfo.id));
})();
}, [userInfo, usersSupportThickThreads]);

Expand Down
2 changes: 1 addition & 1 deletion native/chat/message-list-container.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ const ConnectedMessageListContainer: React.ComponentType<BaseProps> =
);
setAllUsersSupportThickThreads(
userInfoInputArray.every(userInfo =>
usersSupportingThickThreads.has(userInfo.id),
usersSupportingThickThreads.get(userInfo.id),
),
);
})();
Expand Down
2 changes: 1 addition & 1 deletion web/chat/chat-thread-composer.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function ChatThreadComposer(props: Props): React.Node {
allUsersSupportThickThreads:
user.id === viewerID
? true
: usersSupportingThickThreads.has(user.id),
: !!usersSupportingThickThreads.get(user.id),
});
dispatch({
type: updateNavInfoActionType,
Expand Down
2 changes: 1 addition & 1 deletion web/utils/thread-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function useThreadInfoForPossiblyPendingThread(
);
setAllUsersSupportThickThreads(
selectedUserInfos.every(userInfo =>
usersSupportingThickThreads.has(userInfo.id),
usersSupportingThickThreads.get(userInfo.id),
),
);
})();
Expand Down

0 comments on commit cb47dbd

Please sign in to comment.