value.':'.$fingerprint; $existing = InboxMessage::query()->where('fingerprint', $fingerprint)->first(); if ($existing) { $due = $this->reminderDue($existing); $existing->forceFill(['last_seen_at' => now(), ...($due ? ['notified_at' => now()] : [])])->save(); return $due ? $existing : null; } try { return InboxMessage::create([ 'kind' => $kind, 'fingerprint' => $fingerprint, 'subject' => mb_substr($subject, 0, 255), 'body' => $body, 'channel_id' => $channel?->id, 'property_id' => $channel?->property_id ?? $propertyId, 'action_url' => $actionUrl, 'notified_at' => now(), 'last_seen_at' => now(), ]); } catch (UniqueConstraintViolationException) { return null; } } /** * Unread messages are repeated once the reminder interval has passed; reading one ends its reminders. */ public function reminderDue(InboxMessage $message): bool { $days = Settings::reminderIntervalDays($message->tenant); return $days > 0 && ! $message->isRead() && ($message->notified_at === null || $message->notified_at->lessThanOrEqualTo(now()->subDays($days))); } }