Skip to content

Add 'type' to user blocking#4064

Merged
TimWolla merged 8 commits intomasterfrom
block-variants
Apr 23, 2021
Merged

Add 'type' to user blocking#4064
TimWolla merged 8 commits intomasterfrom
block-variants

Conversation

@TimWolla
Copy link
Copy Markdown
Member

Still a draft, because the type needs to be integrated into the consumers.
For now only the blocking UI has been adjusted.


Resolves #3981

@TimWolla TimWolla requested a review from dtdesign March 10, 2021 11:32
Comment thread ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Ignore.ts Outdated
Copy link
Copy Markdown
Member

@dtdesign dtdesign left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread wcfsetup/install/files/lib/data/user/ignore/UserIgnoreAction.class.php Outdated
Comment thread ts/WoltLabSuite/Core/Ui/User/Profile/Menu/Item/Ignore.ts Outdated
@joshuaruesweg joshuaruesweg self-requested a review March 12, 2021 14:00
@TimWolla TimWolla force-pushed the block-variants branch 3 times, most recently from bff78d8 to 9fba27b Compare March 16, 2021 11:33
@TimWolla TimWolla marked this pull request as ready for review March 16, 2021 11:34
@TimWolla
Copy link
Copy Markdown
Member Author

I believe I made all the changes required for WoltLab/WCF, so this one is ready to review.

ghost
ghost previously requested changes Mar 16, 2021
Comment thread wcfsetup/install/lang/de.xml Outdated
Comment thread wcfsetup/setup/db/install.sql
Comment thread com.woltlab.wcf/templates/membersList.tpl
Comment thread com.woltlab.wcf/templates/boxRecentActivitySidebar.tpl
@TimWolla TimWolla requested a review from dtdesign March 17, 2021 12:50
@dtdesign
Copy link
Copy Markdown
Member

dtdesign commented Mar 17, 2021

I do not like the use of the class parameter constant for the "type" of blocking, it clearly shows its ugly face in templates. Instead, I would like to see this getting split up into two methods:

  1. isIgnoredByUser($userID) - Behaves as before, full block (equals TYPE_HIDE_MESSAGES).
  2. isBlockedByUser($userID) - Equals TYPE_BLOCK_DIRECT_CONTACT.

The naming ain't perfect, but it is close enough to both preserve backwards compatibility and enables cleaner code by avoding magic numbers.

@TimWolla
Copy link
Copy Markdown
Member Author

The naming ain't perfect, but it is close enough to both preserve backwards compatibility and enables cleaner code by avoding magic numbers.

Should I preserve the $type parameter and just make isBlockedByUser a small wrapper around isIgnoredByUser, passing an appropriate $type for use in templates?

@dtdesign
Copy link
Copy Markdown
Member

dtdesign commented Mar 17, 2021

Should I preserve the $type parameter and just make isBlockedByUser a small wrapper around isIgnoredByUser, passing an appropriate $type for use in templates?

Can't we just drop the $type parameter? It does create some redundancy, but I think that is acceptable.

@TimWolla
Copy link
Copy Markdown
Member Author

Can't we just drop the $type parameter? It does create some redundancy, but I think that is acceptable.

For backwards compatibility the existing methods must not perform any filtering, because in some places they are used to check whether the other user is blocked without caring exactly about what type of block. e.g.:

{if !$user->isIgnoredUser($__wcf->user->userID)}
new UiUserProfileMenuItemFollow({@$user->userID}, {if $__wcf->getUserProfileHandler()->isFollowing($user->userID)}true{else}false{/if});
{/if}
, or
new UiUserProfileMenuItemIgnore({@$user->userID}, {if $__wcf->getUserProfileHandler()->isIgnoredUser($user->userID)}true{else}false{/if});

Even if TYPE_HIDE_MESSAGES matches all types of blocks as of right now, this might hold true after a simple refactoring, thus allowing for accidentally breaking the behavior in the future.

IMO an explicit $type parameter would be the simplest safe solution here.

@dtdesign
Copy link
Copy Markdown
Member

Okay, then I would like to suggest to keep the method isIgnoredUser() as it is, returning true if the user is blocked, regardless of what setting is enforced. Do we even need to distinguish between these types for the reverse lookup? isBlockedByUser(int $userID): bool should be sufficient to prevent any notifications from being generated and things like a direct contact / follow. The content blocking is not relevant for a reverse lookup.

@TimWolla
Copy link
Copy Markdown
Member Author

isBlockedByUser(int $userID): bool should be sufficient to prevent any notifications from being generated and things like a direct contact / follow. The content blocking is not relevant for a reverse lookup.

Indeed. This might even leak some data that is considered private. I'll fix this and will think about the rest.

@ghost ghost added the Feature label Mar 30, 2021
@TimWolla
Copy link
Copy Markdown
Member Author

TimWolla commented Apr 8, 2021

Okay, I looked into this again. I don't think we are able to easily get rid of the magic number in templates:

  • getIgnoredUsers() / isIgnoredUser() cannot be modified for compatibility reasons and thus must return all blocked / ignored users regardless of type.
  • Most conditions in the template want to know whether messages should be hidden, thus the users with type = direct contact need to be excluded.

Currently this exclusion is performed by explicitly passing the 2 magic number as the filter parameter. A helper method could theoretically be added, but naming is hard and the obvious name (“isIgnoredUser”) is taken. A “isBlockedUser” method would be useless, because this is rarely, if ever needed in templates – we want to get the users for whom messages should be hidden.

Thus the choice is between:

  • Magic '2' in templates, and
  • Awkwardly named helper method (suggestions?).

It still uses the legacy jQuery based JavaScript which does not work well with
the new `type` parameter. Additionally it distracts from more useful buttons.
It's not like users are going to ignore other users en masse.
The type of ignore is not relevant when checking whether one is ignored by
another user. In fact it might leak information that the ignoror might not want
to share with the ignoree.
@ghost
Copy link
Copy Markdown

ghost commented Apr 22, 2021

@TimWolla You can add return types to the new methods in the action class.

@TimWolla
Copy link
Copy Markdown
Member Author

@TimWolla You can add return types to the new methods in the action class.

I feel that array is pretty much useless there, especially since the methods are never called directly. I'd rather wait for more useful type support.

@ghost ghost dismissed their stale review April 22, 2021 12:52

Obsolete

@TimWolla TimWolla requested a review from a user April 22, 2021 13:35
Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

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

I think that instead of the delete icon on the page listing the currently blocked users, the dialog should be shown for also being able to change the setting.

Comment thread wcfsetup/install/files/lib/data/user/ignore/UserIgnoreAction.class.php Outdated
@TimWolla
Copy link
Copy Markdown
Member Author

I think that instead of the delete icon on the page listing the currently blocked users, the dialog should be shown for also being able to change the setting.

I'll create a follow up for this: #4140

@TimWolla TimWolla requested a review from a user April 22, 2021 14:45
@TimWolla TimWolla merged commit dfbcb50 into master Apr 23, 2021
@TimWolla TimWolla deleted the block-variants branch April 23, 2021 08:38
TimWolla added a commit to WoltLab/com.woltlab.wcf.conversation that referenced this pull request Apr 23, 2021
TimWolla added a commit that referenced this pull request Apr 23, 2021
This was missed in #4064, because it was recently added.

see 1f559e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split the block feature into two modes

2 participants