| @@ -7,16 +7,36 @@ | ||
| 7 | 7 | use FluentCommunity\App\Models\Activity; |
| 8 | 8 | use FluentCommunity\App\Services\FeedsHelper; |
| 9 | 9 | use FluentCommunity\App\Services\Helper; |
| 10 | 10 | |
| 11 | +/** | |
| 12 | + * @property int $id | |
| 13 | + * @property int|null $user_id | |
| 14 | + * @property int|null $post_id | |
| 15 | + * @property int|null $parent_id | |
| 16 | + * @property string|null $message | |
| 17 | + * @property string|null $message_rendered | |
| 18 | + * @property mixed $meta | |
| 19 | + * @property string|null $type | |
| 20 | + * @property string|null $content_type | |
| 21 | + * @property string|null $status | |
| 22 | + * @property int|null $is_sticky | |
| 23 | + * @property int $reactions_count | |
| 24 | + * @property string|null $created_at | |
| 25 | + * @property string|null $updated_at | |
| 26 | + * @property-read User|null $user | |
| 27 | + * @property-read XProfile|null $xprofile | |
| 28 | + * @property-read Feed|null $post | |
| 29 | + * @property-read mixed $media | |
| 30 | + */ | |
| 11 | 31 | class Comment extends Model |
| 12 | 32 | { |
| 13 | 33 | protected $table = 'fcom_post_comments'; |
| 14 | 34 | |
| 15 | - protected $guarded = ['id']; | |
| 35 | + protected $guarded = [ 'id' ]; | |
| 16 | 36 | |
| 17 | 37 | protected $casts = [ |
| 18 | - 'is_sticky' => 'int' | |
| 38 | + 'is_sticky' => 'int', | |
| 19 | 39 | ]; |
| 20 | 40 | |
| 21 | 41 | protected $fillable = [ |
| 22 | 42 | 'user_id', |
| @@ -30,13 +50,13 @@ | ||
| 30 | 50 | 'status', |
| 31 | 51 | 'is_sticky', |
| 32 | 52 | 'reactions_count', |
| 33 | 53 | 'created_at', |
| 34 | - 'updated_at' | |
| 54 | + 'updated_at', | |
| 35 | 55 | ]; |
| 36 | 56 | |
| 37 | 57 | protected $searchable = [ |
| 38 | - 'message' | |
| 58 | + 'message', | |
| 39 | 59 | ]; |
| 40 | 60 | |
| 41 | 61 | public static function boot() |
| 42 | 62 | { |
| @@ -57,11 +77,13 @@ | ||
| 57 | 77 | static::deleting(function ($comment) { |
| 58 | 78 | Media::where('sub_object_id', $comment->id) |
| 59 | 79 | ->where('object_source', 'comment') |
| 60 | 80 | ->update([ |
| 61 | - 'is_active' => 0 | |
| 81 | + 'is_active' => 0, | |
| 62 | 82 | ]); |
| 63 | 83 | |
| 84 | + $comment->reactions()->delete(); | |
| 85 | + | |
| 64 | 86 | Activity::where('feed_id', $comment->post_id) |
| 65 | 87 | ->where('action_name', 'comment_added') |
| 66 | 88 | ->where('related_id', $comment->id) |
| 67 | 89 | ->delete(); |
| @@ -150,9 +172,9 @@ | ||
| 150 | 172 | if ( |
| 151 | 173 | $user->hasCommunityModeratorAccess() || |
| 152 | 174 | ($space && $user->hasSpacePermission('edit_any_comment', $space)) |
| 153 | 175 | ) { |
| 154 | - return $query->whereIn('status', ['published', 'pending']); | |
| 176 | + return $query->whereIn('status', [ 'published', 'pending' ]); | |
| 155 | 177 | } |
| 156 | 178 | |
| 157 | 179 | // This is a normal User. |
| 158 | 180 | return $query->where(function ($q) use ($user) { |
| @@ -173,11 +195,11 @@ | ||
| 173 | 195 | if (!$this->parent_id) { |
| 174 | 196 | return []; |
| 175 | 197 | } |
| 176 | 198 | |
| 177 | - $parentComment = Comment::select(['user_id'])->find($this->parent_id); | |
| 178 | - $allUserIds = Comment::where('parent_id', $this->parent_id) | |
| 179 | - ->select(['user_id']) | |
| 199 | + $parentComment = self::select([ 'user_id' ])->find($this->parent_id); | |
| 200 | + $allUserIds = self::where('parent_id', $this->parent_id) | |
| 201 | + ->select([ 'user_id' ]) | |
| 180 | 202 | ->distinct('user_id') |
| 181 | 203 | ->when($lastUserId, function ($query) use ($lastUserId) { |
| 182 | 204 | $query->where('user_id', '>', $lastUserId); |
| 183 | 205 | }) |
| @@ -206,9 +228,9 @@ | ||
| 206 | 228 | if (!$meta) { |
| 207 | 229 | $meta = []; |
| 208 | 230 | } |
| 209 | 231 | |
| 210 | - return $meta; | |
| 232 | + return Helper::sanitizeStoredMediaPreview($meta); | |
| 211 | 233 | } |
| 212 | 234 | |
| 213 | 235 | public function getHumanExcerpt($length = 30) |
| 214 | 236 | { |
| @@ -230,16 +252,14 @@ | ||
| 230 | 252 | } else { |
| 231 | 253 | /* translators: %1$s is the post title and %2$s is the comment author name */ |
| 232 | 254 | $emailSubject = \sprintf(__('New reply of a comment in a post on %1$s - %2$s', 'fluent-community'), $this->post->getHumanExcerpt(40), $this->xprofile->display_name); |
| 233 | 255 | } |
| 234 | - } else { | |
| 235 | - if ($feed->title) { | |
| 256 | + } elseif ($feed->title) { | |
| 236 | 257 | /* translators: %1$s is the feed title and %2$s is the comment author name */ |
| 237 | 258 | $emailSubject = \sprintf(__('New comment on %1$s - %2$s', 'fluent-community'), $feed->title, $this->xprofile->display_name); |
| 238 | - } else { | |
| 239 | - /* translators: %1$s is the post title and %2$s is the comment author name */ | |
| 240 | - $emailSubject = \sprintf(__('New comment on a post on %1$s - %2$s', 'fluent-community'), $this->post->getHumanExcerpt(40), $this->xprofile->display_name); | |
| 241 | - } | |
| 259 | + } else { | |
| 260 | + /* translators: %1$s is the post title and %2$s is the comment author name */ | |
| 261 | + $emailSubject = \sprintf(__('New comment on a post on %1$s - %2$s', 'fluent-community'), $this->post->getHumanExcerpt(40), $this->xprofile->display_name); | |
| 242 | 262 | } |
| 243 | 263 | |
| 244 | 264 | return $emailSubject; |
| 245 | 265 | } |
| @@ -265,18 +285,18 @@ | ||
| 265 | 285 | $renderedMessage = preg_replace('/<a href="([^"]+)">([^<]+)<\/a>/', '<span style="text-decoration: underline !important;">$2</span>', $renderedMessage); |
| 266 | 286 | |
| 267 | 287 | $renderedMessage .= FeedsHelper::getMediaHtml($this->meta, $postPermalink); |
| 268 | 288 | |
| 269 | - $buttonText = $buttonText ?: __('View the comment', 'fluent-community'); | |
| 289 | + $buttonText = $buttonText ? $buttonText : __('View the comment', 'fluent-community'); | |
| 270 | 290 | |
| 271 | 291 | $emailComposer->addBlock('boxed_content', $renderedMessage, [ |
| 272 | 292 | 'user' => $this->user, |
| 273 | 293 | 'permalink' => $postPermalink, |
| 274 | - 'post_content' => $postTitle | |
| 294 | + 'post_content' => $postTitle, | |
| 275 | 295 | ]); |
| 276 | 296 | |
| 277 | 297 | $emailComposer->addBlock('button', $buttonText, [ |
| 278 | - 'link' => $postPermalink | |
| 298 | + 'link' => $postPermalink, | |
| 279 | 299 | ]); |
| 280 | 300 | |
| 281 | 301 | $emailComposer->setDefaultLogo(); |
| 282 | 302 | $emailComposer->setDefaultFooter($withPlaceholder); |