update: comments system

This commit is contained in:
HDVinnie
2023-04-26 19:38:22 -04:00
parent 1345c61c40
commit dd923eed95
4 changed files with 42 additions and 36 deletions
+16 -13
View File
@@ -149,32 +149,35 @@ class Comment extends Component
$this->user->addProgress(new UserMade900Comments(), 1);
}
// Set Polymorhic Model Name
$modelName = str()->snake(class_basename($this->comment->commentable_type), ' ');
// New Comment Notification
if ($this->user->id !== $this->comment->user_id && strtolower(class_basename($this->comment->commentable_type)) !== 'collection') {
User::find($this->comment->user_id)->notify(new NewComment(strtolower(class_basename($this->comment->commentable_type)), $reply));
if ($this->user->id !== $this->comment->user_id && $modelName !== 'collection') {
User::find($this->comment->user_id)->notify(new NewComment($modelName, $reply));
}
// User Tagged Notification
$users = User::whereIn('username', $this->taggedUsers())->get();
Notification::sendNow($users, new NewCommentTag(strtolower(class_basename($this->comment->commentable_type)), $reply));
Notification::sendNow($users, new NewCommentTag($modelName, $reply));
// Auto Shout
$profileUrl = href_profile($this->user);
$modelUrl = match (strtolower(class_basename($this->comment->commentable_type))) {
'article' => href_article($this->comment->commentable_type),
'collection' => href_collection($this->comment->commentable_type),
'playlist' => href_playlist($this->comment->commentable_type),
'request' => href_request($this->comment->commentable_type),
'torrent' => href_torrent($this->comment->commentable_type),
default => "#"
$modelUrl = match ($modelName) {
'article' => href_article($this->comment->commentable_id),
'collection' => href_collection($this->comment->commentable_id),
'playlist' => href_playlist($this->comment->commentable_id),
'torrent request' => href_request($this->comment->commentable_id),
'torrent' => href_torrent($this->comment->commentable_id),
default => "#"
};
if (strtolower(class_basename($this->comment->commentable_type)) !== 'ticket') {
if ($modelName !== 'ticket') {
if ($reply->anon == 0) {
$this->chatRepository->systemMessage(
sprintf(
'[url=%s]%s[/url] has left a comment on '.strtolower(class_basename($this->comment->commentable_type)).' [url=%s]%s[/url]',
'[url=%s]%s[/url] has left a comment on '.$modelName.' [url=%s]%s[/url]',
$profileUrl,
$this->user->username,
$modelUrl,
@@ -184,7 +187,7 @@ class Comment extends Component
} else {
$this->chatRepository->systemMessage(
sprintf(
'An anonymous user has left a comment on '.strtolower(class_basename($this->comment->commentable_type)).' [url=%s]%s[/url]',
'An anonymous user has left a comment on '.$modelName.' [url=%s]%s[/url]',
$modelUrl,
$this->comment->commentable->name ?? $this->comment->commentable->title
)
+16 -13
View File
@@ -121,32 +121,35 @@ class Comments extends Component
$this->user->addProgress(new UserMade900Comments(), 1);
}
// Set Polymorhic Model Name
$modelName = str()->snake(class_basename($this->model), ' ');
// New Comment Notification
if ($this->user->id !== $this->model->user_id && strtolower(class_basename($this->model)) !== 'collection') {
User::find($this->model->user_id)->notify(new NewComment(strtolower(class_basename($this->model)), $comment));
if ($this->user->id !== $this->model->user_id && $modelName !== 'collection') {
User::find($this->model->user_id)->notify(new NewComment($modelName, $comment));
}
// User Tagged Notification
$users = User::whereIn('username', $this->taggedUsers())->get();
Notification::sendNow($users, new NewCommentTag(strtolower(class_basename($this->model)), $comment));
Notification::sendNow($users, new NewCommentTag($modelName, $comment));
// Auto Shout
$profileUrl = href_profile($this->user);
$modelUrl = match (strtolower(class_basename($this->model))) {
'article' => href_article($this->model),
'collection' => href_collection($this->model),
'playlist' => href_playlist($this->model),
'request' => href_request($this->model),
'torrent' => href_torrent($this->model),
default => "#"
$modelUrl = match ($modelName) {
'article' => href_article($this->model),
'collection' => href_collection($this->model),
'playlist' => href_playlist($this->model),
'torrent request' => href_request($this->model),
'torrent' => href_torrent($this->model),
default => "#"
};
if (strtolower(class_basename($this->model)) !== 'ticket') {
if ($modelName !== 'ticket') {
if ($comment->anon == 0) {
$this->chatRepository->systemMessage(
sprintf(
'[url=%s]%s[/url] has left a comment on '.strtolower(class_basename($this->model)).' [url=%s]%s[/url]',
'[url=%s]%s[/url] has left a comment on '.$modelName.' [url=%s]%s[/url]',
$profileUrl,
$this->user->username,
$modelUrl,
@@ -156,7 +159,7 @@ class Comments extends Component
} else {
$this->chatRepository->systemMessage(
sprintf(
'An anonymous user has left a comment on '.strtolower(class_basename($this->model)).' [url=%s]%s[/url]',
'An anonymous user has left a comment on '.$modelName.' [url=%s]%s[/url]',
$modelUrl,
$this->model->name ?? $this->model->title
)
+5 -5
View File
@@ -41,7 +41,7 @@ class NewComment extends Notification
*/
public function toArray($notifiable): array
{
if ($this->type == 'torrent') {
if ($this->type === 'torrent') {
if ($this->comment->anon == 0) {
return [
'title' => 'New Torrent Comment Received',
@@ -57,7 +57,7 @@ class NewComment extends Notification
];
}
if ($this->type == 'torrentrequest') {
if ($this->type === 'torrent request') {
if ($this->comment->anon == 0) {
return [
'title' => 'New Request Comment Received',
@@ -73,7 +73,7 @@ class NewComment extends Notification
];
}
if ($this->type == 'ticket') {
if ($this->type === 'ticket') {
if ($this->comment->anon == 0) {
return [
'title' => 'New Ticket Comment Received',
@@ -89,7 +89,7 @@ class NewComment extends Notification
];
}
if ($this->type == 'playlist') {
if ($this->type === 'playlist') {
if ($this->comment->anon == 0) {
return [
'title' => 'New Playlist Comment Received',
@@ -105,7 +105,7 @@ class NewComment extends Notification
];
}
if ($this->type == 'collection') {
if ($this->type === 'collection') {
if ($this->comment->anon == 0) {
return [
'title' => 'New Collection Comment Received',
+5 -5
View File
@@ -42,7 +42,7 @@ class NewCommentTag extends Notification implements ShouldQueue
*/
public function toArray($notifiable): array
{
if ($this->type == 'torrent') {
if ($this->type === 'torrent') {
if ($this->comment->anon == 0) {
return [
'title' => $this->comment->user->username.' Has Tagged You',
@@ -58,7 +58,7 @@ class NewCommentTag extends Notification implements ShouldQueue
];
}
if ($this->type == 'torrentrequest') {
if ($this->type === 'torrent request') {
if ($this->comment->anon == 0) {
return [
'title' => $this->comment->user->username.' Has Tagged You',
@@ -74,7 +74,7 @@ class NewCommentTag extends Notification implements ShouldQueue
];
}
if ($this->type == 'ticket') {
if ($this->type === 'ticket') {
if ($this->comment->anon == 0) {
return [
'title' => $this->comment->user->username.' Has Tagged You',
@@ -90,7 +90,7 @@ class NewCommentTag extends Notification implements ShouldQueue
];
}
if ($this->type == 'playlist') {
if ($this->type === 'playlist') {
if ($this->comment->anon == 0) {
return [
'title' => $this->comment->user->username.' Has Tagged You',
@@ -106,7 +106,7 @@ class NewCommentTag extends Notification implements ShouldQueue
];
}
if ($this->type == 'collection') {
if ($this->type === 'collection') {
if ($this->comment->anon == 0) {
return [
'title' => $this->comment->user->username.' Has Tagged You',