nostr events added

This commit is contained in:
HolgerHatGarKeineNode
2023-02-24 10:35:07 +01:00
parent 1aaa955567
commit 38a2b63e3f
11 changed files with 167 additions and 212 deletions

View File

@@ -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());
}
}