Skip to content

Commit

Permalink
Format conversations before sending notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismeonmounteverest committed Sep 2, 2024
1 parent e4f42dd commit 02877e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Controller/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,14 @@ private function addMessageAndSendNotification(
): Message {
$em = $this->getDoctrine()->getManager();
$message = new Message();
$message->setMessage($body);
if (null === $parent) {
$subject = new Subject();
$subject->setSubject($subjectText);
$request = null;
$em->persist($subject);
$em->flush();
$message = $this->conversationModel->formatConversation($message);
} else {
$subject = $parent->getSubject();
$request = $parent->getRequest();
Expand All @@ -201,7 +203,6 @@ private function addMessageAndSendNotification(
$message->setParent($parent);
$message->setSender($sender);
$message->setReceiver($receiver);
$message->setMessage($body);
$message->setStatus('Sent');
$em->persist($message);
$em->flush();
Expand Down
9 changes: 3 additions & 6 deletions src/Controller/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ class RequestController extends BaseRequestAndInvitationController

private Mailer $mailer;
private Logger $logger;
private HostingRequestModel $hostingRequestModel;

public function __construct(
ConversationModel $conversationModel,
HostingRequestModel $requestModel,
EntityManagerInterface $entityManager,
Mailer $mailer,
Logger $logger, HostingRequestModel $hostingRequestModel
Logger $logger
) {
parent::__construct($requestModel, $entityManager);

$this->conversationModel = $conversationModel;
$this->mailer = $mailer;
$this->logger = $logger;
$this->hostingRequestModel = $hostingRequestModel;
}

/**
Expand Down Expand Up @@ -178,6 +176,7 @@ public function newHostingRequest(
if ($requestForm->isSubmitted() && $requestForm->isValid()) {
// Write request to database after doing some checks
$hostingRequest = $this->getMessageFromData($requestForm->getData(), $guest, $host);
$hostingRequest = $this->conversationModel->formatConversation($hostingRequest);

$em = $this->getDoctrine()->getManager();
$em->persist($hostingRequest);
Expand Down Expand Up @@ -327,9 +326,7 @@ private function sendInitialRequestNotification(Member $host, Member $guest, Mes
{
$subject = $request->getSubject()->getSubject();

if ($this->hostingRequestModel->formatRequest($request)) {
$this->sendRequestNotification($guest, $host, $host, $request, $subject, 'request', false);
}
$this->sendRequestNotification($guest, $host, $host, $request, $subject, 'request', false);
}

private function sendHostReplyNotification(
Expand Down
13 changes: 13 additions & 0 deletions src/Model/ConversationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ public function markConversationAsRead(Member $member, array $thread)
$em->flush();
}

public function formatConversation(Message $message): Message
{
$messageText = $message->getMessage();
$found = preg_match("/@|at|.at.|-at-|\(at\)/i", $messageText);

if ($found != 0) {
$message->setSpamInfo(SpamInfoType::SPAM_BLOCKED_WORD);
$message->setMessage($messageText . '<p>This might be spam.</p>');
}

return $message;
}

private function hasLimitExceeded(Member $member, string $sql, int $perHour, int $perDay): bool
{
$id = $member->getId();
Expand Down

0 comments on commit 02877e7

Please sign in to comment.