mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
nostr events added
This commit is contained in:
@@ -2,50 +2,41 @@
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Enums\LibraryItemType;
|
||||
use App\Models\LibraryItem;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LibraryItemObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the LibraryItem "created" event.
|
||||
*/
|
||||
public function created(LibraryItem $libraryItem): void
|
||||
{
|
||||
// todo: we can change this later
|
||||
try {
|
||||
$libraryItem->setStatus('published');
|
||||
|
||||
$libraryItemName = $libraryItem->name;
|
||||
if ($libraryItem->lecturer->twitter_username && $libraryItem->type !== 'markdown_article') {
|
||||
$libraryItemName .= ' von @'.$libraryItem->lecturer->twitter_username;
|
||||
}
|
||||
if (! $libraryItem->lecturer->twitter_username) {
|
||||
$libraryItemName .= ' von '.$libraryItem->lecturer->name;
|
||||
}
|
||||
$libraryItemName .= ' von '.$libraryItem->lecturer->name;
|
||||
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
// http://localhost/de/library/library-item?l=de&table[filters][id]=2
|
||||
|
||||
if ($libraryItem->type !== 'markdown_article') {
|
||||
if ($libraryItem->whereDoesntHave('libraries',
|
||||
fn ($query) => $query->where('libraries.is_public', false))
|
||||
->exists()) {
|
||||
$text = sprintf("Es gibt was Neues zum Lesen oder Anhören:\n\n%s\n\n%s\n\n#Bitcoin #Wissen #Einundzwanzig #gesundesgeld",
|
||||
$libraryItemName,
|
||||
url()->route('article.view',
|
||||
['libraryItem' => $libraryItem->slug]),
|
||||
);
|
||||
$this->postTweet($text);
|
||||
}
|
||||
if ($libraryItem->type !== LibraryItemType::MarkdownArticle()) {
|
||||
if ($libraryItem->whereDoesntHave('libraries',
|
||||
fn($query) => $query->where('libraries.is_public', false))
|
||||
->exists()) {
|
||||
$text = sprintf("Es gibt was Neues zum Lesen oder Anhören:\n\n%s\n\n%s\n\n#Bitcoin #Wissen #Einundzwanzig #gesundesgeld",
|
||||
$libraryItemName,
|
||||
url()->route('article.view',
|
||||
['libraryItem' => $libraryItem->slug]),
|
||||
);
|
||||
$this->publishOnNostr($libraryItem, $text);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// todo: log this
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user