Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #65 from tabuna/notify
Browse files Browse the repository at this point in the history
Уведомления для упоминаний, вакансии, Ссылки и листалка
  • Loading branch information
tabuna authored Jan 19, 2024
2 parents a6a405a + 82a4a8b commit 05aea7d
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 68 deletions.
6 changes: 6 additions & 0 deletions app/Http/Controllers/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
use App\Models\Post;
use App\Notifications\CommentNotification;
use App\Notifications\IdeaRequestAcceptedNotification;
use App\Notifications\MentionNotification;
use App\Notifications\Remind;
use App\Notifications\ReplyCommentNotification;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;

class CommentsController extends Controller
{
Expand Down Expand Up @@ -53,6 +56,7 @@ public function store(Request $request)
$comment->save();

$comment->post->author->notify(new CommentNotification($comment));
Notification::send($comment->getMentionedUsers(), new MentionNotification($comment));


return turbo_stream([
Expand Down Expand Up @@ -118,7 +122,9 @@ public function reply(Request $request, Comment $comment)
]);

$request->user()->comments()->saveMany([$reply]);

$comment->post->author->notify(new ReplyCommentNotification($reply));
Notification::send($comment->getMentionedUsers(), new MentionNotification($reply));

return turbo_stream([
turbo_stream()->append(@dom_id($comment, 'thread'), view('comments._comment', ['comment' => $reply])),
Expand Down
15 changes: 15 additions & 0 deletions app/Http/Controllers/PositionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,19 @@ public function list(Request $request)
]);
}

/**
* @return \Illuminate\Contracts\View\View|\Tonysm\TurboLaravel\Http\MultiplePendingTurboStreamResponse|\Tonysm\TurboLaravel\Http\PendingTurboStreamResponse|null
*/
public function latest()
{
$positions = Position::with(['author'])
->whereDate('created_at','>=',now()->subMonth())
->orderBy('id', 'desc')
->limit(3)->get();

return view('positions.latest', [
'positions' => $positions,
]);
}

}
13 changes: 12 additions & 1 deletion app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function mentionedUserToHtmlUrl(string $text = null): string
{
return Str::of($text)
->replaceMatches('/\@([a-zA-Z0-9_]+)/u', function ($mention) {
$href = route('user.show', $mention[1]);
$href = route('user.show', $mention[1]);// над наверное заменить на route('profile', $mention[1])
$name = Str::of($mention[0])->trim();

return "<a href='$href' class='text-decoration-none'>$name</a>";
Expand Down Expand Up @@ -184,4 +184,15 @@ public function prettyComment(): string

return $this->nl2br($withMention);
}


public function getMentionedUsers()
{
$usersNikNames = Str::of($this->content)->matchAll('/\@([a-zA-Z0-9_]+)/u');
if($usersNikNames->isEmpty()){
return collect();
}
return User::whereIn('nickname', $usersNikNames)->get();

}
}
99 changes: 99 additions & 0 deletions app/Notifications/MentionNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace App\Notifications;

use App\Models\Comment;
use App\Models\IdeaKey;
use App\Models\Post;
use App\Models\User;
use App\Notifications\Channels\SiteChannel;
use App\Notifications\Channels\SiteMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;

class MentionNotification extends Notification implements ShouldQueue
{
use Queueable;

private Comment $comment;

/**
* FriendlyHugs constructor.
*
* @param IdeaKey $ideaKey
*/
public function __construct(Comment $comment)
{
$this->comment = $comment;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
*/
public function via(User $user)
{
return [
SiteChannel::class,
WebPushChannel::class
];
}

/**
* Get the app representation of the notification.
*
* @param mixed $user
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toSite(User $user)
{
$url = route('post.show',$this->comment->post).'#'.dom_id($this->comment);
return (new SiteMessage())
->title(' упомянул вас в комментарии к публикации')
->setCommentAuthor($this->comment->author->name)
->img($this->comment->author->avatar)
->action($url, $this->comment->post->title);
}

/**
* @param \App\Models\User $user
*
* @return \NotificationChannels\WebPush\WebPushMessage
*/
public function toWebPush(User $user)
{
$url = route('post.show', $this->comment->post) . '#' . dom_id($this->comment);

return (new WebPushMessage)
->title('Вас упомянули')
->icon($this->comment->author->avatar)
->body('Пользователь '.$this->comment->author->name." упомянул вас в комментарии")
->action('посмотреть',$url)
->vibrate([300, 200, 300])
->options([
'TTL' => 86400, // in seconds - 24 hours,
'urgency' => 'high',
]);
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
4 changes: 2 additions & 2 deletions resources/views/comments/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class="mb-3 d-flex flex-column position-relative me-2"
minlength="3"
data-action="keydown.enter->comment#send:prevent input->comment#toggleSubmitButton"
placeholder="Ваш комментарий"
class="form-control p-5"
class="form-control p-4 pb-5"
name="message"
rows="1">{{ $comment->content }}</textarea>
rows="3">{{ $comment->content }}</textarea>
<div
class="d-grid gap-3 d-md-flex justify-content-md-start position-absolute bottom-0 end-0 my-2 my-sm-3 mx-3 mx-sm-5">
<button type="submit" class="btn btn-primary fade"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/comments/reply.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class="my-3 d-flex flex-column position-relative"
data-textarea-autogrow-resize-debounce-delay-value="500"
required
placeholder="Написать комментарий"
class="form-control p-4"
class="form-control p-4 pb-5"
name="message"
rows="3"
minlength="3"
Expand Down
33 changes: 18 additions & 15 deletions resources/views/components/comment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,7 @@
<div class="d-flex flex-column flex-md-row">
<h6 class="m-0 me-auto">{{ $comment->author->name }}</h6>

<div class="me-3 small opacity-50">
@can('update', $comment)
<a href="{{ route('comments.show.edit', $comment) }}" data-turbo-method="post"
class="link-body-emphasis text-decoration-none">Редактировать</a>
@endcan

@can('delete', $comment)
· <a href="{{ route('comments.delete', $comment) }}"
class="link-body-emphasis text-decoration-none"
data-turbo-method="DELETE"
data-turbo-confirm="Вы уверены, что хотите удалить комментарий?">
Удалить
</a>
@endcan
</div>

</div>
<div class="small opacity-50">
<a
Expand All @@ -50,8 +36,10 @@ class="link-body-emphasis text-decoration-none"
href="#comment_{{ $comment->getKey() }}"
@endif
class="link-body-emphasis text-decoration-none">
{{ '@'.$comment->author->nickname}} ·
<time
datetime="{{ now()->toISOString() }}">{{ $comment->created_at->diffForHumans() }}</time>

</a>
</div>
</div>
Expand All @@ -64,6 +52,21 @@ class="link-body-emphasis text-decoration-none">

<x-like :model="$comment"/>

@can('update', $comment)
<a href="{{ route('comments.show.edit', $comment) }}" data-turbo-method="post"
class="btn btn-link link-body-emphasis btn-sm">Редактировать</a>
@endcan

@can('delete', $comment)
· <a href="{{ route('comments.delete', $comment) }}"
class="btn btn-link link-body-emphasis btn-sm"
data-turbo-method="DELETE"
data-turbo-confirm="Вы уверены, что хотите удалить комментарий?">
Удалить
</a>
@endcan


@can('reply', $comment)
<a href="{{ route('comments.show.reply', $comment) }}" class="btn btn-link link-body-emphasis btn-sm"
data-turbo-method="post">Ответить</a>
Expand Down
12 changes: 6 additions & 6 deletions resources/views/pages/feature.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class="fill-gray-900"></path>
URL-адреса. Это позволяет легко настраивать маршруты для обработки запросов и
определять, какие действия и контроллеры должны быть вызваны при поступлении запроса.
</p>
<a href="{{ route('packages') }}"
<a href="{{ route('docs',['page'=>'routing']) }}"
class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-hover">
Подробнее
<x-icon path="bs.arrow-right" /></a>
Expand All @@ -453,7 +453,7 @@ class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-h
Вставляйте переменные, используйте условия, циклы и другие
операции в шаблонах, что делает их более читабельными и удобными для разработки.
</p>
<a href="{{ route('packages') }}"
<a href="{{ route('docs',['page'=>'blade']) }}"
class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-hover">
Подробнее
<x-icon path="bs.arrow-right" /></a>
Expand All @@ -471,7 +471,7 @@ class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-h
можете легко добавить систему регистрации, входа и выхода из системы на свой веб-сайт
Laravel.
</p>
<a href="{{ route('packages') }}"
<a href="{{ route('docs',['page'=>'authentication']) }}"
class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-hover">
Подробнее
<x-icon path="bs.arrow-right" /></a>
Expand All @@ -488,7 +488,7 @@ class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-h
определенным ресурсам или действиям. Это позволяет легко определить, какие пользователи
имеют право выполнять определенные операции в вашем приложении.
</p>
<a href="{{ route('packages') }}"
<a href="{{ route('docs',['page'=>'authorization']) }}"
class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-hover">
Подробнее
<x-icon path="bs.arrow-right" /></a>
Expand All @@ -506,7 +506,7 @@ class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-h
упрощают разработку, улучшают производительность и помогают взаимодействовать с вашим
приложением Laravel из командной строки.
</p>
<a href="{{ route('packages') }}"
<a href="{{ route('docs',['page'=>'artisan']) }}"
class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-hover">
Подробнее
<x-icon path="bs.arrow-right" /></a>
Expand All @@ -524,7 +524,7 @@ class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-h
модели и другие компоненты вашего приложения, чтобы гарантировать их работоспособность и
соответствие ожиданиям.
</p>
<a href="{{ route('packages') }}"
<a href="{{ route('docs',['page'=>'testing']) }}"
class="link-body-emphasis fw-semibold text-decoration-none icon-link icon-link-hover">
Подробнее
<x-icon path="bs.arrow-right" /></a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/particles/comments/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
data-comment-target="textarea"
data-controller="textarea-autogrow"
data-textarea-autogrow-resize-debounce-delay-value="500"
class="form-control p-4"
class="form-control p-4 pb-5"
name="message"
rows="3"
minlength="3"
Expand Down
54 changes: 54 additions & 0 deletions resources/views/positions/latest.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<turbo-frame id="latest-positions">
<div class="row">
@forelse($positions as $position)
<div class="col-4 position-relative" id="@domid($position)">
<div
class="bg-body-secondary p-4 rounded">

<div class="d-flex align-items-center d-md-block">
<span class="badge bg-secondary rounded-pill">{{$position->schedule->text()}}</span>

</div>

<div class="mt-2">

<a href="{{route('position.show', $position)}}"
class="h5 link-body-emphasis stretched-link text-decoration-none">{{$position->title}}</a>

</div>

<div class="d-flex flex-column gap-2 mt-3">
<span class="opacity-50 d-flex align-items-center">
<x-icon path="bs.geo-alt-fill" class="me-2"/>
{{$position->location}}
</span>
</div>
<div class="d-flex fw-medium mt-3 h5">

@if (!is_null($position->salary_min) && !is_null($position->salary_max))
{{ $position->salary_min }} - {{ $position->salary_max }}
@elseif (!is_null($position->salary_min))
от {{ $position->salary_min }}
@elseif (!is_null($position->salary_max))
до {{ $position->salary_max }}
@endif

</div>

</div>
</div>

@empty
<div class="col-12">
<div class="bg-body-tertiary rounded p-4 p-md-5 align-items-center justify-content-between
position-relative">

<div class="text-center">
Здесь еще нет публикаций
</div>

</div>
</div>
@endforelse
</div>
</turbo-frame>
Loading

0 comments on commit 05aea7d

Please sign in to comment.