Skip to content

Add social sharing posts on twitter #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ TORCHLIGHT_TOKEN=
MIX_TORCHLIGHT_TOKEN="${TORCHLIGHT_TOKEN}"
UNSPLASH_ACCESS_KEY=
TELEGRAM_BOT_TOKEN=
TELEGRAM_CHANNEL=
MEDIA_DISK=media
SENTRY_LARAVEL_DSN=
SENTRY_TRACES_SAMPLE_RATE=
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function schedule(Schedule $schedule)
{
$schedule->command('media-library:delete-old-temporary-uploads')->daily();
$schedule->command('lcm:delete-old-unverified-users')->daily();
// $schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
$schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
$schedule->command('lcm:post-article-to-telegram')->everyFourHours();
$schedule->command('lcm:send-unverified-mails')->weeklyOn(1, '8:00');
$schedule->command('sitemap:generate')->daily();
Expand Down
16 changes: 16 additions & 0 deletions app/Events/ArticleWasSubmittedForApproval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Events;

use App\Models\Article;
use Illuminate\Queue\SerializesModels;

class ArticleWasSubmittedForApproval
{
use SerializesModels;

public function __construct(
public Article $article
) {
}
}
9 changes: 4 additions & 5 deletions app/Http/Livewire/Articles/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Http\Livewire\Articles;

use App\Events\ArticleWasSubmittedForApproval;
use App\Gamify\Points\PostCreated;
use App\Models\Article;
use App\Models\Tag;
use App\Models\User;
use App\Notifications\SendSubmittedArticle;
use App\Traits\WithArticleAttributes;
use App\Traits\WithTagsAssociation;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -67,10 +67,9 @@ public function store()
$article->addMedia($this->file->getRealPath())->toMediaCollection('media');
}

if ($article->submitted_at) {
// Envoi du mail à l'admin pour la validation de l'article.
$admin = User::findByEmailAddress('[email protected]');
Notification::send($admin, new SendSubmittedArticle($article));
if ($article->isAwaitingApproval()) {
// Envoi de la notification sur le channel Telegram pour la validation de l'article.
event(new ArticleWasSubmittedForApproval($article));

session()->flash('status', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.');
}
Expand Down
19 changes: 19 additions & 0 deletions app/Listeners/SendNewArticleNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Listeners;

use App\Events\ArticleWasSubmittedForApproval;
use App\Notifications\ArticleSubmitted;
use Illuminate\Notifications\AnonymousNotifiable;

final class SendNewArticleNotification
{
public function __construct(private AnonymousNotifiable $notifiable)
{
}

public function handle(ArticleWasSubmittedForApproval $event): void
{
$this->notifiable->notify(new ArticleSubmitted($event->article));
}
}
50 changes: 50 additions & 0 deletions app/Notifications/ArticleSubmitted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Notifications;

use App\Models\Article;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;

class ArticleSubmitted extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(private Article $article)
{
}

public function via($notifiable)
{
if (
! empty(config('services.telegram-bot-api.token')) &&
! empty(config('services.telegram-bot-api.channel'))
) {
return [TelegramChannel::class];
}

return [];
}

public function toTelegram($notifiable)
{
$url = route('articles.show', $this->article->slug());

return TelegramMessage::create()
->to(config('services.telegram-bot-api.channel'))
->content($this->content())
->button('Voir l\'article', $url);
}

private function content(): string
{
$content = "*Nouvel Article Soumis!*\n\n";
$content .= 'Titre: ' . $this->article->title . "\n";
$content .= 'Par: [@' . $this->article->author->username . '](' . route('profile', $this->article->author->username) . ')';

return $content;
}
}
38 changes: 0 additions & 38 deletions app/Notifications/SendSubmittedArticle.php

This file was deleted.

5 changes: 5 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace App\Providers;

use App\Events\ArticleWasSubmittedForApproval;
use App\Events\CommentWasAdded;
use App\Events\ReplyWasCreated;
use App\Events\ThreadWasCreated;
use App\Listeners\NotifyMentionedUsers;
use App\Listeners\PostNewThreadNotification;
use App\Listeners\SendNewArticleNotification;
use App\Listeners\SendNewCommentNotification;
use App\Listeners\SendNewReplyNotification;
use App\Listeners\SendNewThreadNotification;
Expand All @@ -33,6 +35,9 @@ class EventServiceProvider extends ServiceProvider
SendNewThreadNotification::class,
PostNewThreadNotification::class,
],
ArticleWasSubmittedForApproval::class => [
SendNewArticleNotification::class,
],
CommentWasAdded::class => [
SendNewCommentNotification::class,
],
Expand Down
8 changes: 0 additions & 8 deletions auth.json.example

This file was deleted.

5 changes: 3 additions & 2 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
'client_id' => env('TWITTER_CLIENT_ID'),
'client_secret' => env('TWITTER_CLIENT_SECRET'),
'redirect' => env('TWITTER_REDIRECT'),
'consumer_key' => env('TWITTER_CONSUMER_KEY'),
'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
'consumer_key' => env('TWITTER_CLIENT_ID'),
'consumer_secret' => env('TWITTER_CLIENT_SECRET'),
'access_token' => env('TWITTER_ACCESS_TOKEN'),
'access_secret' => env('TWITTER_ACCESS_SECRET'),
'scopes' => [],
Expand All @@ -56,6 +56,7 @@

'telegram-bot-api' => [
'token' => env('TELEGRAM_BOT_TOKEN'),
'channel' => env('TELEGRAM_CHANNEL'),
],

];
37 changes: 17 additions & 20 deletions resources/views/vendor/wireui/components/notifications.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
x-on:wireui:notification.window="addNotification($event.detail)"
x-on:wireui:confirm-notification.window="addConfirmNotification($event.detail)"
wire:ignore>
<div class="max-w-sm w-full space-y-2 pointer-events-auto flex flex-col-reverse">
<div class="flex flex-col-reverse w-full max-w-sm space-y-2 pointer-events-auto">
<template x-for="notification in notifications" :key="`notification-${notification.id}`">
<div class="max-w-sm w-full bg-skin-card shadow-lg rounded-lg ring-1 ring-black
ring-opacity-5 relative overflow-hidden pointer-events-auto"
<div class="relative w-full max-w-sm overflow-hidden rounded-lg shadow-lg pointer-events-auto bg-skin-card ring-1 ring-black ring-opacity-5"
:class="{ 'flex': notification.rightButtons }"
:id="`notification.${notification.id}`"
x-transition:enter="transform ease-out duration-300 transition"
x-transition:enter-start="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
x-transition:enter-end="translate-y-0 opacity-100 sm:translate-x-0"
x-on:mouseenter="pauseNotification(notification)"
x-on:mouseleave="resumeNotification(notification)">
<div class="bg-secondary-300 rounded-full transition-all duration-150 ease-linear absolute top-0 left-0"
<div class="absolute top-0 left-0 transition-all duration-150 ease-linear rounded-full bg-secondary-300"
style="height: 2px; width: 100%;"
:id="`timeout.bar.${notification.id}`"
x-show="Boolean(notification.timer) && notification.progressbar !== false">
Expand All @@ -40,7 +39,7 @@
</template>

<template x-if="notification.img">
<img class="h-10 w-10 rounded-full" :src="notification.img" />
<img class="w-10 h-10 rounded-full" :src="notification.img" />
</template>
</div>
</template>
Expand All @@ -59,8 +58,8 @@

<!-- actions buttons -->
<template x-if="!notification.dense && !notification.rightButtons && (notification.accept || notification.reject)">
<div class="mt-3 flex gap-x-3">
<button class="rounded-md text-sm font-medium focus:outline-none"
<div class="flex mt-3 gap-x-3">
<button class="text-sm font-medium rounded-md focus:outline-none"
:class="{
'bg-skin-card text-primary-600 hover:text-primary-500': !Boolean($wireui.dataGet(notification, 'accept.style')),
[$wireui.dataGet(notification, 'accept.style')]: Boolean($wireui.dataGet(notification, 'accept.style')),
Expand All @@ -71,7 +70,7 @@
x-text="$wireui.dataGet(notification, 'accept.label', '')">
</button>

<button class="rounded-md text-sm font-medium focus:outline-none"
<button class="text-sm font-medium rounded-md focus:outline-none"
:class="{
'bg-skin-card text-skin-inverted-muted hover:text-skin-base': !Boolean($wireui.dataGet(notification, 'reject.style')),
[$wireui.dataGet(notification, 'reject.style')]: Boolean($wireui.dataGet(notification, 'reject.style')),
Expand All @@ -85,9 +84,9 @@
</template>
</div>

<div class="ml-4 shrink-0 flex">
<div class="flex ml-4 shrink-0">
<!-- accept button -->
<button class="mr-4 shrink-0 rounded-md text-sm font-medium focus:outline-none"
<button class="mr-4 text-sm font-medium rounded-md shrink-0 focus:outline-none"
:class="{
'text-primary-600 hover:text-primary-500': !Boolean($wireui.dataGet(notification, 'accept.style')),
[$wireui.dataGet(notification, 'accept.style')]: Boolean($wireui.dataGet(notification, 'accept.style'))
Expand All @@ -98,14 +97,14 @@
</button>

<!-- close button -->
<button class="rounded-md inline-flex text-skin-muted hover:text-skin-base focus:outline-none"
<button class="inline-flex rounded-md text-skin-muted hover:text-skin-base focus:outline-none"
x-show="notification.closeButton"
x-on:click="closeNotification(notification)">
<span class="sr-only">Close</span>
<x-dynamic-component
:component="WireUiComponent::resolve('icon')"
class="h-5 w-5"
name="x"
:component="WireUi::component('icon')"
class="w-5 h-5"
name="x"
/>
</button>
</div>
Expand All @@ -116,11 +115,10 @@ class="h-5 w-5"
<template x-if="notification.rightButtons">
<div class="flex flex-col border-l border-secondary-200">
<template x-if="notification.accept">
<div class="h-0 flex-1 flex" :class="{
<div class="flex flex-1 h-0" :class="{
'border-b border-secondary-200': notification.reject
}">
<button class="w-full rounded-none rounded-tr-lg px-4 py-3 flex items-center
justify-center text-sm font-medium focus:outline-none"
<button class="flex items-center justify-center w-full px-4 py-3 text-sm font-medium rounded-none rounded-tr-lg focus:outline-none"
:class="{
'text-primary-600 hover:text-primary-500 hover:bg-secondary-50': !Boolean(notification.accept.style),
[notification.accept.style]: Boolean(notification.accept.style),
Expand All @@ -133,9 +131,8 @@ class="h-5 w-5"
</template>

<template x-if="notification.reject">
<div class="h-0 flex-1 flex">
<button class="w-full rounded-none rounded-br-lg px-4 py-3 flex items-center
justify-center text-sm font-medium focus:outline-none"
<div class="flex flex-1 h-0">
<button class="flex items-center justify-center w-full px-4 py-3 text-sm font-medium rounded-none rounded-br-lg focus:outline-none"
:class="{
'text-skin-inverted-muted hover:text-skin-base': !Boolean(notification.reject.style),
[notification.reject.style]: Boolean(notification.reject.style),
Expand Down