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 ;
@@ -22,12 +23,6 @@ final class CommentComponent extends Component
2223 // State
2324 public CommentStateEnum $ state = CommentStateEnum::Viewing;
2425
25- #[Computed]
26- public function isInitiallyBlurred (): bool
27- {
28- return $ this ->moderatorCommentsByType ?->get(ModerationTypeEnum::Blur->value ) !== null ;
29- }
30-
3126 public function mount (int $ commentId , ?Comment $ comment , ?Collection $ childComments ): void
3227 {
3328 // On mount we expect the comment list to provide the comment model
@@ -42,31 +37,17 @@ public function mount(int $commentId, ?Comment $comment, ?Collection $childComme
4237
4338 public function render (): View
4439 {
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- }
40+ $ moderationType = $ this ->appearanceComment ?->moderation_type ?? null ;
6041
6142 // If there are no decorations to apply, just render the basic comment component.
6243 return view ('livewire.comments.comment-component ' , [
6344 'comment ' => $ this ->comment ,
6445 'childComments ' => $ this ->childComments ,
6546 'moderationType ' => $ moderationType ,
6647 'isInitiallyBlurred ' => $ this ->isInitiallyBlurred ,
67- 'replacedByCommentId ' => $ moderatorReplaceComment ?->id ,
68- 'wrappedByCommentId ' => $ moderatorWrapComment ?->id,
69- 'blurredByCommentId ' => $ moderatorBlurComment ?->id,
48+ 'isRemoved ' => $ moderationType === ModerationTypeEnum::Remove && ! auth ()-> user () ?->hasRole(RoleNameEnum:: MODERATOR -> value ) ,
49+ 'appearanceCommentId ' => $ this -> appearanceComment ?->id,
50+ 'blurCommentId ' => $ this -> blurComment ?->id,
7051 'isEditing ' => $ this ->state === CommentStateEnum::Editing,
7152 'isFlagging ' => $ this ->state === CommentStateEnum::Flagging,
7253 'isReplying ' => $ this ->state === CommentStateEnum::Replying,
@@ -90,7 +71,7 @@ public function reloadChildComments(int $id, ?int $parentId): void
9071 {
9172 if ($ parentId === $ this ->commentId ) {
9273 $ this ->childComments = $ this ->commentRepository ->getCommentsByParentId ($ parentId );
93- unset($ this ->moderatorCommentsByType , $ this ->isInitiallyBlurred );
74+ unset($ this ->appearanceComment , $ this -> blurComment , $ this ->isInitiallyBlurred );
9475
9576 // Re-evaluate whether the comment should be blurred.
9677 $ this ->isBlurred = $ this ->isInitiallyBlurred ;
0 commit comments