Skip to content

Commit

Permalink
[keyserver][lib] Allow skipping createRobotextInThinThread
Browse files Browse the repository at this point in the history
Summary:
This parameter only needs to be specified for `FARCASTER_MUTUAL` and `FRIEND`. By making it optional, we can address [this feedback](https://phab.comm.dev/D13443?id=44476#inline-77071) on D13443.

Submitting it as a separate diff as I'm not sure the complexity is worth it, or whether there are other alternatives that reviewers might prefer.

Depends on D13453

Test Plan: Flow, and tested the relationship adding flow end-to-end again

Reviewers: tomek

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D13451
  • Loading branch information
Ashoat committed Sep 25, 2024
1 parent 81307fb commit 109ee3e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
48 changes: 33 additions & 15 deletions keyserver/src/responders/relationship-responders.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
legacyFarcasterRelationshipRequestValidator,
relationshipActions,
type RelationshipRequestUserInfo,
type RelationshipRequestWithRobotext,
type RelationshipRequestWithoutRobotext,
type RelationshipRequest,
relationshipActionsList,
} from 'lib/types/relationship-types.js';
import { tShape, tUserID } from 'lib/utils/validation-utils.js';

Expand Down Expand Up @@ -54,23 +55,40 @@ async function legacyUpdateRelationshipsResponder(
createRobotextInThinThread: true,
};
}
const request = {
action: legacyRequest.action,
users: requestUserInfos,
};
const { action } = legacyRequest;
let request: RelationshipRequest;
if (action === 'farcaster' || action === 'friend') {
request = { action, users: requestUserInfos };
} else {
request = { action, users: requestUserInfos };
}
return await updateRelationships(viewer, request);
}

export const updateRelationshipInputValidator: TInterface<RelationshipRequest> =
tShape<RelationshipRequest>({
action: t.enums.of(relationshipActionsList, 'relationship action'),
users: t.dict(
tUserID,
tShape<RelationshipRequestUserInfo>({
createRobotextInThinThread: t.Boolean,
}),
),
});
export const updateRelationshipInputValidator: TUnion<RelationshipRequest> =
t.union([
tShape<RelationshipRequestWithRobotext>({
action: t.enums.of(['farcaster', 'friend'], 'relationship action'),
users: t.dict(
tUserID,
tShape<RelationshipRequestUserInfo>({
createRobotextInThinThread: t.Boolean,
}),
),
}),
tShape<RelationshipRequestWithoutRobotext>({
action: t.enums.of(
['unfriend', 'block', 'unblock', 'acknowledge'],
'relationship action',
),
users: t.dict(
tUserID,
tShape<RelationshipRequestUserInfo>({
createRobotextInThinThread: t.maybe(t.Boolean),
}),
),
}),
]);

async function updateRelationshipsResponder(
viewer: Viewer,
Expand Down
29 changes: 19 additions & 10 deletions lib/hooks/relationship-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type RelationshipAction,
type RelationshipErrors,
type RelationshipRequestUserInfo,
type RelationshipRequest,
relationshipActions,
userRelationshipStatus,
} from '../types/relationship-types.js';
Expand Down Expand Up @@ -174,10 +175,14 @@ function useUpdateRelationships(): (
planForUser.plan === 'send_to_thin_thread',
};
}
const keyserverResultPromise = updateRelationships({
action,
users: usersForKeyserverCall,
});

let request: RelationshipRequest;
if (action === 'farcaster' || action === 'friend') {
request = { action, users: usersForKeyserverCall };
} else {
request = { action, users: usersForKeyserverCall };
}
const keyserverResultPromise = updateRelationships(request);

const thickThreadPromises: Array<Promise<void>> = [];
for (const [userID, planForUser] of planForUsers) {
Expand Down Expand Up @@ -288,18 +293,22 @@ function useUpdateRelationships(): (
(action !== relationshipActions.FRIEND &&
action !== relationshipActions.FARCASTER_MUTUAL)
) {
return await updateRelationships({
action,
users: Object.fromEntries(
let request: RelationshipRequest;
if (action === 'farcaster' || action === 'friend') {
const users = Object.fromEntries(
userIDs.map(userID => [
userID,
{
// this param only matters for FRIEND and FARCASTER_MUTUAL
createRobotextInThinThread: true,
},
]),
),
});
);
request = { action, users };
} else {
const users = Object.fromEntries(userIDs.map(userID => [userID, {}]));
request = { action, users };
}
return await updateRelationships(request);
}

const missingDeviceListsUserIDs: Array<string> = [];
Expand Down
11 changes: 9 additions & 2 deletions lib/types/relationship-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ export type LegacyRelationshipRequest =
export type RelationshipRequestUserInfo = {
+createRobotextInThinThread: boolean,
};
export type RelationshipRequest = {
+action: RelationshipAction,
export type RelationshipRequestWithRobotext = {
+action: 'farcaster' | 'friend',
+users: { +[userID: string]: RelationshipRequestUserInfo },
};
export type RelationshipRequestWithoutRobotext = {
+action: 'unfriend' | 'block' | 'unblock' | 'acknowledge',
+users: { +[userID: string]: $Partial<RelationshipRequestUserInfo> },
};
export type RelationshipRequest =
| RelationshipRequestWithRobotext
| RelationshipRequestWithoutRobotext;

export const legacyFarcasterRelationshipRequestValidator: TInterface<LegacyFarcasterRelationshipRequest> =
tShape<LegacyFarcasterRelationshipRequest>({
Expand Down

0 comments on commit 109ee3e

Please sign in to comment.