Skip to content

Commit

Permalink
Added email_id property to IcsEvents to avoid duplicate generations.
Browse files Browse the repository at this point in the history
Removed attachments from ForwardEmail (doesn't work either way)
  • Loading branch information
hrsa committed May 12, 2024
1 parent a8a444c commit 48daacb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
11 changes: 1 addition & 10 deletions app/Mail/ForwardEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ public function content(): Content

public function attachments(): array
{
$attachments = [];
ray($this->inboundEmail->attachments())->label('attachments');
foreach ($this->inboundEmail->attachments() as $attachment) {
$attachmentFileName = $attachment->getFilename();
if ($attachmentFileName) {
$attachments[] = Attachment::fromData(fn () => $attachment, $attachmentFileName);
}
};

return $attachments;
return [];
}
}
2 changes: 2 additions & 0 deletions app/Models/IcsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @property string|null $ics
* @property string|null $timezone
* @property string|null $secret
* @property string|null $email_id
* @property DateTime $created_at
* @property DateTime $updated_at
* @property DateTime|null $deleted_at
Expand All @@ -33,6 +34,7 @@ class IcsEvent extends Model
'prompt',
'error',
'ics',
'email_id',
'timezone',
'secret',
];
Expand Down
10 changes: 4 additions & 6 deletions app/Services/MailProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public function process(InboundEmail $message): void
if (!$user) {
return;
}
$existingIcsEvent = IcsEvent::whereEmailId($message->id())->first();

if (Gate::forUser($user)->allows('has-credits')
&& Gate::forUser($user)->allows('errors-under-threshold')
&& !$existingIcsEvent
) {
$icsEvent = IcsEvent::create([
'user_id' => $user->id,
'prompt' => $message->text(),
'secret' => Str::random(32),
'email_id' => $message->id(),
]);

GenerateCalendarJob::dispatch($icsEvent);
Expand All @@ -36,11 +39,6 @@ public function process(InboundEmail $message): void

public function forwardToAdmin(InboundEmail $email): void
{
$email->forward(config('app.admin.email'));
// ray($email)->green();
// ray($email->id())->orange();
// $forward = new ForwardEmail($email);
// ray($forward)->red();
// Mail::to(config('app.admin.email'))->send($forward);
Mail::to(config('app.admin.email'))->send(new ForwardEmail($email));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('ics_events', function (Blueprint $table) {
$table->text('email_id')->nullable()->default(null);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('ics_events', function (Blueprint $table) {
$table->dropColumn('email_id');
});
}
};

0 comments on commit 48daacb

Please sign in to comment.