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

[MBL-1026] Filter comments from blocked users #1883

Merged
merged 8 commits into from
Nov 14, 2023
Merged

[MBL-1026] Filter comments from blocked users #1883

merged 8 commits into from
Nov 14, 2023

Conversation

ifosli
Copy link
Contributor

@ifosli ifosli commented Nov 13, 2023

📲 What

Filter comments from blocked users by replacing the author name, avatar, and comment text with "Blocked user" placeholders.

Note: This also deletes the RootCommentCellViewModel and switches the RootCommentCell to using the CommentCellViewModel instead. The RootCommentCellViewModel code was just a subset of the entire CommentCellViewModel and keeping it as a separate copy just meant that we needed to duplicate work to keep them in sync. With this change, all comment cells (RootCommentCell, CommentCell, CommentRemovedCell, CommentPostFailedCell) all use the same view model, so the author filtering will apply to all of them.

👀 See

Jira

image

♿️ Accessibility / 🏎 Performance

Not tested; this change doesn't add any new UI.

✅ Acceptance criteria

  • There are currently no blocked users (and this isn't wired up to an API anyways), so the only way to test that the UI works as intended is to switch the default isBlocked value to true or have it read from some other field instead. But when the isBlocked value is true, the author's name and avatar as well as the comment text should be hidden (comment functionality is unchanged).
  • It should not be possible to block a user that's already blocked.

⏰ TODO

  • A future PR will set the isBlocked field based on backend info.
  • Strings will be updated in a future PR once translations are ready.
  • When user is blocked, comments should be refreshed. This will be implemented in a separate PR as well. (That way, we can test it properly before merging, once blocking is possible.)

@ifosli ifosli added the draft label Nov 13, 2023
@ifosli ifosli self-assigned this Nov 13, 2023
@ifosli ifosli modified the milestones: release-5.10.0, release-5.11.0 Nov 13, 2023
Copy link

codecov bot commented Nov 13, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (6abd404) 87.78% compared to head (1d6ca14) 83.75%.

Files Patch % Lines
...nts/Controllers/CommentRepliesViewController.swift 0.00% 1 Missing ⚠️
.../Comments/Controllers/CommentsViewController.swift 0.00% 1 Missing ⚠️
...eatures/Comments/Views/Cells/RootCommentCell.swift 75.00% 1 Missing ⚠️
KsApi/models/User.swift 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1883      +/-   ##
==========================================
- Coverage   87.78%   83.75%   -4.03%     
==========================================
  Files         860     1222     +362     
  Lines       76998   111393   +34395     
  Branches    20411    29623    +9212     
==========================================
+ Hits        67591    93299   +25708     
- Misses       8667    17077    +8410     
- Partials      740     1017     +277     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -34,7 +34,7 @@ final class RootCommentCell: UITableViewCell, ValueCell {
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private let viewModel = RootCommentCellViewModel()
private let viewModel = CommentCellViewModel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice cleanup here 👍

.map(\.author.imageUrl)
.map {
if $0.author.isBlocked {
return "" // Use default avatar.
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this default avatar URL. be hardcoded somewhere? Or is some other piece of code checking for this empty string?

You could also throw this in the model code, instead. It's a little sneaky but means anyone working with/implementing comment code in the future doesn't need to remember this edge case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we may want to replace the current gray circle with an icon instead, but for now empty string -> nil url -> gray placeholder circle. I added the comment since I didn't feel "" was clear about that by itself. Glad to see I was right about that! Would it be more clear if I said "Keep placeholder avatar" instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, maybe something like // Use placeholder avatar instead of URL?

// TODO(MBL-1026): Use translated string once available.
return "Blocked User"
} else {
return $0.author.name
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments here, re: putting this directly in the model. Would it make it simpler at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this belongs in the model. I think it would complicate things (the model would no longer be encodable which would mess with tests & decoding would be more of a pain). Also, whether a user is blocked or not isn't purely a display thing; it also affects functionality, so it's not like we could do no special handling at all. We also can't consistently always hide blocked user info, since we do want to display usernames of blocked users in messages. Plus, at some point, we might want to add an "unblock" option here, in which case the view model will need to know the real user info.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair!

Copy link
Contributor

@amy-at-kickstarter amy-at-kickstarter left a comment

Choose a reason for hiding this comment

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

LGTM; a few stylistic suggestions, but nothing blocking. Love to see all that code deleted.

@ifosli ifosli merged commit d841813 into main Nov 14, 2023
7 checks passed
@ifosli ifosli deleted the filterComments branch November 14, 2023 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants