77use App \Enums \CommentStateEnum ;
88use App \Enums \LivewireEventEnum ;
99use App \Enums \ModerationTypeEnum ;
10+ use App \Enums \RoleNameEnum ;
1011use App \Models \Comment ;
1112use App \Traits \CommentComponentTrait ;
1213use Illuminate \Contracts \View \View ;
1314use Illuminate \Support \Collection ;
14- use Livewire \Attributes \Computed ;
1515use Livewire \Attributes \On ;
1616use Livewire \Component ;
1717
@@ -22,12 +22,6 @@ final class CommentComponent extends Component
2222 // State
2323 public CommentStateEnum $ state = CommentStateEnum::Viewing;
2424
25- #[Computed]
26- public function isInitiallyBlurred (): bool
27- {
28- return $ this ->moderatorCommentsByType ?->get(ModerationTypeEnum::Blur->value ) !== null ;
29- }
30-
3125 public function mount (int $ commentId , ?Comment $ comment , ?Collection $ childComments ): void
3226 {
3327 // On mount we expect the comment list to provide the comment model
@@ -42,31 +36,17 @@ public function mount(int $commentId, ?Comment $comment, ?Collection $childComme
4236
4337 public function render (): View
4438 {
45- // If the comment has been replaced, just render the moderation message.
46- // TODO: if it is possible to have a top-level comment be marked with a
47- // moderation type, we may want to render it via this view. But it may
48- // also just be about changing the border for a regular rendering.
49- $ moderatorReplaceComment = $ this ->moderatorCommentsByType ?->get(ModerationTypeEnum::Replace->value );
50- $ moderatorWrapComment = $ this ->moderatorCommentsByType ?->get(ModerationTypeEnum::Wrap->value );
51- $ moderatorBlurComment = $ this ->moderatorCommentsByType ?->get(ModerationTypeEnum::Blur->value );
52- $ moderationType = null ;
53-
54- if ($ moderatorReplaceComment !== null &&
55- ($ moderatorWrapComment === null || $ moderatorReplaceComment ->created_at > $ moderatorWrapComment ->created_at )) {
56- $ moderationType = ModerationTypeEnum::Replace;
57- } elseif ($ moderatorWrapComment !== null ) {
58- $ moderationType = ModerationTypeEnum::Wrap;
59- }
39+ $ moderationType = $ this ->appearanceComment ?->moderation_type ?? null ;
6040
6141 // If there are no decorations to apply, just render the basic comment component.
6242 return view ('livewire.comments.comment-component ' , [
6343 'comment ' => $ this ->comment ,
6444 'childComments ' => $ this ->childComments ,
6545 'moderationType ' => $ moderationType ,
6646 'isInitiallyBlurred ' => $ this ->isInitiallyBlurred ,
67- 'replacedByCommentId ' => $ moderatorReplaceComment ?->id ,
68- 'wrappedByCommentId ' => $ moderatorWrapComment ?->id,
69- 'blurredByCommentId ' => $ moderatorBlurComment ?->id,
47+ 'isRemoved ' => $ moderationType === ModerationTypeEnum::Remove && ! auth ()-> user () ?->hasRole(RoleNameEnum:: MODERATOR -> value ) ,
48+ 'appearanceCommentId ' => $ this -> appearanceComment ?->id,
49+ 'blurCommentId ' => $ this -> blurComment ?->id,
7050 'isEditing ' => $ this ->state === CommentStateEnum::Editing,
7151 'isFlagging ' => $ this ->state === CommentStateEnum::Flagging,
7252 'isReplying ' => $ this ->state === CommentStateEnum::Replying,
@@ -90,7 +70,7 @@ public function reloadChildComments(int $id, ?int $parentId): void
9070 {
9171 if ($ parentId === $ this ->commentId ) {
9272 $ this ->childComments = $ this ->commentRepository ->getCommentsByParentId ($ parentId );
93- unset($ this ->moderatorCommentsByType , $ this ->isInitiallyBlurred );
73+ unset($ this ->appearanceComment , $ this -> blurComment , $ this ->isInitiallyBlurred );
9474
9575 // Re-evaluate whether the comment should be blurred.
9676 $ this ->isBlurred = $ this ->isInitiallyBlurred ;
0 commit comments