Page MenuHomePhabricator

[native] introduce AutoJoinCommunityHandler
ClosedPublic

Authored by ginsu on May 15 2024, 8:33 PM.
Tags
None
Referenced Files
F3495388: D12065.id41473.diff
Thu, Dec 19, 8:30 AM
F3495387: D12065.id41471.diff
Thu, Dec 19, 8:30 AM
F3495386: D12065.id40275.diff
Thu, Dec 19, 8:30 AM
F3495385: D12065.id41463.diff
Thu, Dec 19, 8:30 AM
F3495384: D12065.id41429.diff
Thu, Dec 19, 8:30 AM
F3495383: D12065.id41343.diff
Thu, Dec 19, 8:30 AM
F3495377: D12065.id.diff
Thu, Dec 19, 8:29 AM
F3495376: D12065.diff
Thu, Dec 19, 8:29 AM

Details

Summary

AutoJoinCommunityHandler handles the logic for getting the user to automatically join communites that are tagged to farcaster channels that the user follows.

In a subsequent diff we will update this logic so we background these communites/threads by default

Linear task: https://linear.app/comm/issue/ENG-7959/query-the-users-channels-that-they-follow-on-app-start + https://linear.app/comm/issue/ENG-7960/download-all-the-relevant-blobs-based-on-the-viewers-farcaster

Depends on D12064

Test Plan
  1. Created a new community called Run club
  2. Tagged /sovereignty farcaster channel to Run club
  3. Logged out of my account
  4. Created a new account with my fid hardcoded with my fid hardcoded in useCurrentUserFID
  5. Confirmed that the new user auto joined run club since /sovereignty is a farcaster channel that my fid follows

Confirmed that when the authorization header is present, we were able to fetch the blobs, and when the authorization header were not present, the fetch calls failed

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ginsu requested review of this revision.May 15 2024, 8:50 PM

This needs to be updated based on feedback on previous diffs

ginsu edited the test plan for this revision. (Show Details)
ginsu edited reviewers, added: ashoat; removed: tomek.

Switching @tomek with @ashoat for my reviewer since @tomek is on vacation

ashoat added a reviewer: bartek.
ashoat added a subscriber: bartek.

Accepting, but making @bartek blocking for one specific question about blob service auth

Please merge all of the async IIFEs before landing

native/components/auto-join-community-handler.react.js
85–87 ↗(On Diff #41343)

@bartek is introducing auth for blob service. Does this need to be revised?

85–128 ↗(On Diff #41343)

You can make the code more readable by reducing the number of steps:

const promises = followedFarcasterChannelIDs.map(channelID => {
  const blobHash = farcasterChannelTagBlobHash(channelID);
  const blobURL = getBlobFetchableURL(blobHash);

  const blobResult = await fetch(blobURL, {
    method: blobService.httpEndpoints.GET_BLOB.method,
  });

  if (blobResult.status !== 200) {
    return;
  }

  const { commCommunityID } = await blobResult.json();

  const keyserverID = commCommunityID.split('|')[0];
  if (keyserverID !== authoritativeKeyserverID()) {
    return;
  }

  // The user is already in the community
  if (threadInfos[commCommunityID]) {
    return;
  }

  void dispatchActionPromise(
    joinThreadActionTypes,
    joinThreadActionPromise(commCommunityID),
  );
})();
await Promise.all(promises);

The core thing that async IIFEs enable is composing async code. It's easier to reason about the steps here when they're working on a single community at a time

bartek requested changes to this revision.Jun 16 2024, 10:34 PM

Could you apply the same changes as I did in D12437?

native/components/auto-join-community-handler.react.js
85–87 ↗(On Diff #41343)

Yes, thanks for the ping!

This revision now requires changes to proceed.Jun 16 2024, 10:34 PM
native/components/auto-join-community-handler.react.js
85–128 ↗(On Diff #41343)

Makes sense, my initial thought was that it would be more performant not to await inside a loop, but this is definitely more readable

bartek added inline comments.
native/components/auto-join-community-handler.react.js
100–102 ↗(On Diff #41429)

technically you can move it above the .map() loop to avoid recreating this each time. Headers are the same for each fetch call

This revision is now accepted and ready to land.Jun 17 2024, 11:46 PM
ashoat requested changes to this revision.Jun 18 2024, 9:50 AM

A couple more async improvements. I should be able to give this a final review either today or tomorrow, but if not feel free to remove me from the review so you can land it while I'm out.

Makes sense, my initial thought was that it would be more performant not to await inside a loop, but this is definitely more readable

This seems like a core misunderstanding of how async/await work. There is no performance cost here, and in fact you are not awaiting inside a loop at all.

native/components/auto-join-community-handler.react.js
84–90 ↗(On Diff #41429)

Why are we blocking neynarClient.fetchFollowedFarcasterChannels on getAuthMetadata?

100–102 ↗(On Diff #41429)

Yes, let's avoid doing this multiple times

This revision now requires changes to proceed.Jun 18 2024, 9:50 AM
This revision is now accepted and ready to land.Jun 18 2024, 11:18 AM
native/components/auto-join-community-handler.react.js
123–126 ↗(On Diff #41463)

Talked about this with @ginsu. He appears to be limiting Farcaster channel autojoin to the authoritative keyserver, but this doesn't make much sense as Farcaster channel association can be done regardless of keyserver.

We talked it through and it seems like he was mostly worried about the user attempting to join a community on a keyserver that the user is not part of.

It looks like @tomek recently introduced some code in useAcceptInviteLink to handle this by having the client join the linked keyserver. It would be good to adopt a similar approach here, but it's probably outside the scope of this diff.

For now, I think we should replace this check with another that checks if the user has this keyserver in their KeyserverStore (isKeyserverKnown in useAcceptInviteLink).

update keyserver check + rebase before landing

This revision was automatically updated to reflect the committed changes.