Added Fetch Email on page load
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\ZEmail;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class EmailInbox extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public $currentEmail;
|
||||
public $messages = [];
|
||||
public $selectedMessage = null;
|
||||
public $searchTerm = '';
|
||||
public $refreshInterval = 30; // seconds
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->currentEmail = ZEmail::getEmail();
|
||||
$this->loadMessages();
|
||||
}
|
||||
|
||||
public function loadMessages()
|
||||
{
|
||||
if ($this->currentEmail) {
|
||||
$this->messages = ZEmail::getMessages($this->currentEmail);
|
||||
}
|
||||
}
|
||||
|
||||
public function selectMessage($messageId)
|
||||
{
|
||||
$this->selectedMessage = $messageId;
|
||||
}
|
||||
|
||||
public function deleteMessage($messageId)
|
||||
{
|
||||
ZEmail::deleteMessage($messageId);
|
||||
$this->loadMessages();
|
||||
$this->selectedMessage = null;
|
||||
}
|
||||
|
||||
public function generateNewEmail()
|
||||
{
|
||||
$this->currentEmail = ZEmail::generateRandomEmail();
|
||||
$this->loadMessages();
|
||||
}
|
||||
|
||||
public function getPollingInterval()
|
||||
{
|
||||
return $this->refreshInterval * 1000; // Convert to milliseconds
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.email-inbox', [
|
||||
'messages' => $this->messages,
|
||||
'currentEmail' => $this->currentEmail
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,8 @@ class Action extends Component
|
||||
$this->dispatch('closeModal');
|
||||
}
|
||||
|
||||
public function deleteEmail() {
|
||||
public function deleteEmail(): void
|
||||
{
|
||||
ZEmail::removeEmail($this->email);
|
||||
// if (count($this->emails) <= 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
|
||||
// return redirect()->route('home');
|
||||
@@ -82,7 +83,8 @@ class Action extends Component
|
||||
$this->dispatch('showAlert', ['type' => $type, 'message' => $message]);
|
||||
}
|
||||
|
||||
private function checkEmailLimit() {
|
||||
private function checkEmailLimit(): bool
|
||||
{
|
||||
$logs = Log::select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Carbon::now()->subDay())->groupBy('email')->groupBy('ip')->get();
|
||||
if (count($logs) >= json_decode(config('app.settings.configuration_settings'))->email_limit) {
|
||||
return false;
|
||||
@@ -90,7 +92,8 @@ class Action extends Component
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkUsedEmail() {
|
||||
private function checkUsedEmail(): bool
|
||||
{
|
||||
if (json_decode(config('app.settings.configuration_settings'))->disable_used_email) {
|
||||
$check = Log::where('email', $this->user . '@' . $this->domain)->where('ip', '<>', request()->ip())->count();
|
||||
if ($check > 0) {
|
||||
|
||||
15
app/Livewire/Frontend/Components/Mail.php
Normal file
15
app/Livewire/Frontend/Components/Mail.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend\Components;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Mail extends Component
|
||||
{
|
||||
public $message;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.components.mail')->with(['message' => $this->message]);
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,8 @@ class Email extends Component
|
||||
$this->dispatch('getEmail');
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
$this->dispatch('syncMailbox', $this->email);
|
||||
$this->dispatch('fetchMessages');
|
||||
}
|
||||
|
||||
public function generateEmail(): void
|
||||
|
||||
@@ -7,30 +7,34 @@ use App\Models\ZEmail;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
|
||||
class App extends Component
|
||||
class Mailbox extends Component
|
||||
{
|
||||
public $messages = [];
|
||||
public $deleted = [];
|
||||
public $error = '';
|
||||
public $email;
|
||||
public $initial;
|
||||
public $initial = false;
|
||||
public $type;
|
||||
public $overflow = false;
|
||||
|
||||
protected $listeners = ['fetchMessages' => 'fetch', 'syncEmail'];
|
||||
protected $listeners = ['fetchMessages' => 'fetch', 'syncMailbox' => 'syncEmail'];
|
||||
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$this->email = ZEmail::getEmails();
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->initial = false;
|
||||
}
|
||||
public function syncEmail($email): void
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->initial = false;
|
||||
}
|
||||
|
||||
public function syncEmail($email) {
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function fetch() {
|
||||
public function fetch(): void
|
||||
{
|
||||
try {
|
||||
$count = count($this->messages);
|
||||
|
||||
$responses = [];
|
||||
if (config('app.beta_feature') || !json_decode(config('app.settings.imap_settings'))->cc_check) {
|
||||
$responses = [
|
||||
@@ -46,18 +50,36 @@ class App extends Component
|
||||
'cc' => ZEmail::getMessages($this->email, 'cc', $this->deleted)
|
||||
];
|
||||
}
|
||||
|
||||
// $responses = [
|
||||
// 'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
|
||||
// ];
|
||||
// $imapSettings = json_decode(config('app.settings.imap_settings'));
|
||||
// $betaFeature = config('app.beta_feature');
|
||||
//
|
||||
// if ($betaFeature || empty($imapSettings?->cc_check)) {
|
||||
// $responses['cc'] = [
|
||||
// 'data' => [],
|
||||
// 'notifications' => []
|
||||
// ];
|
||||
// } else {
|
||||
// $responses['cc'] = ZEmail::getMessages($this->email, 'cc', $this->deleted);
|
||||
// }
|
||||
|
||||
$this->deleted = [];
|
||||
$this->messages = array_merge($responses['to']['data'], $responses['cc']['data']);
|
||||
$notifications = array_merge($responses['to']['notifications'], $responses['cc']['notifications']);
|
||||
|
||||
if (count($notifications)) {
|
||||
if ($this->overflow == false && count($this->messages) == $count) {
|
||||
if (!$this->overflow && count($this->messages) == $count) {
|
||||
$this->overflow = true;
|
||||
}
|
||||
} else {
|
||||
$this->overflow = false;
|
||||
}
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$this->dispatchBrowserEvent('showNewMailNotification', $notification);
|
||||
$this->dispatch('showNewMailNotification', $notification);
|
||||
}
|
||||
ZEmail::incrementMessagesStats(count($notifications));
|
||||
} catch (\Exception $e) {
|
||||
@@ -67,8 +89,8 @@ class App extends Component
|
||||
$this->error = 'Not able to connect to Mail Server';
|
||||
}
|
||||
}
|
||||
$this->dispatchBrowserEvent('stopLoader');
|
||||
$this->dispatchBrowserEvent('loadDownload');
|
||||
$this->dispatch('stopLoader');
|
||||
$this->dispatch('loadDownload');
|
||||
$this->initial = true;
|
||||
}
|
||||
|
||||
@@ -88,8 +110,9 @@ class App extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.app');
|
||||
return view('livewire.frontend.mailbox')->with(['messages' => $this->messages, 'email' => $this->email, 'initial' => $this->initial, 'error' => $this->error]);
|
||||
}
|
||||
|
||||
private function rrmdir($dir): void
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
@@ -105,5 +128,4 @@ class App extends Component
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user