Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Show post preview even when moderator is blocked by the author #114

Merged
merged 2 commits into from
May 8, 2024

Conversation

foysalit
Copy link
Contributor

@foysalit foysalit commented May 6, 2024

Since getPostThread does not return post record data when there's a block relationship between author and the moderator viewer, this PR builds the post data from getRecord so that post preview is displayed properly in the quick action panel.

Copy link

render bot commented May 6, 2024

Copy link

render bot commented May 6, 2024

Comment on lines 228 to 234
} else if (Array.isArray(item.post.labels?.['values'])) {
// This handles the case where the item may be built from raw record and in that case, labels value is not an array rather a self label object
const labels = item.post.labels?.['values'] as unknown as Array<{
val: string
}>
labels.forEach(({ val }) => labelVals.push(val))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than passing a raw record here and deviating in this way from the expected, valid FeedViewPost type, I wonder if it may be friendlier to instead build the labels object on the other side and avoid this special case on the consumer side.

Might look something like:

  if (data?.thread?.blocked) {
    return (
      <BaseRecordCard
        uri={uri}
        renderRecord={(record) => (
          <PostAsCard
            dense
            controls={false}
            item={{
              post: {
                uri: record.uri,
                cid: record.cid,
                author: record.repo,
                record: record.value,
                labels: isSelfLabels(record.value['labels'])
                  ? record.value['labels'].values.map(({ val }) => ({
                      val,
                      uri: record.uri,
                      src: record.repo.did,
                      cts: new Date(0).toISOString(),
                    }))
                  : [],
                indexedAt: new Date(0).toISOString(),
              },
            }}
          />
        )}
      />
    )
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that looks cleaner, thanks!

@foysalit foysalit requested a review from devinivy May 7, 2024 13:20
@foysalit foysalit merged commit c5292dc into main May 8, 2024
3 checks passed
@matthieusieben matthieusieben deleted the blocked-post-preview branch November 15, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants