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 7, 2024
1 parent 4ba0192 commit 960ffc7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/Controller/Admin/CheckerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CheckerController extends AbstractController
{
private const MESSAGES_REPORTED = 1;
private const MESSAGES_PROCESSED = 2;
private const MESSAGES_BLOCK_WORDS = 3;

private CheckerModel $checkerModel;

Expand All @@ -42,6 +43,18 @@ public function showReportedMessages(Request $request)
return $this->handleMessages($request, self::MESSAGES_REPORTED);
}

/**
* @Route("/admin/spam/messages/blocked", name="admin_spam_messages_block_words")
*
* @throws AccessDeniedException
*
* @return Response
*/
public function showBlockWordMessages(Request $request)
{
return $this->handleMessages($request, self::MESSAGES_BLOCK_WORDS);
}

/**
* @Route("/admin/spam/messages/processed", name="admin_spam_messages_processed")
*
Expand Down Expand Up @@ -165,6 +178,10 @@ private function getSubmenuItems()
'key' => 'reported.messages',
'url' => $this->generateUrl('admin_spam_messages'),
],
'blockwords' => [
'key' => 'block.words.messages',
'url' => $this->generateUrl('admin_spam_messages_block_words'),
],
'processed_messages' => [
'key' => 'reported.messages.processed',
'url' => $this->generateUrl('admin_spam_messages_processed'),
Expand Down Expand Up @@ -201,6 +218,10 @@ private function handleMessages(Request $request, int $type)
$active = 'processed_messages';
$messages = $this->checkerModel->getProcessedReportedMessages($page, $limit);
break;
case self::MESSAGES_BLOCK_WORDS:
$active = 'block.words.messages';
$messages = $this->checkerModel->getBlockWordsMessages($page, $limit);
break;
default:
throw new InvalidArgumentException();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private function addMessageAndSendNotification(
$em = $this->getDoctrine()->getManager();
$message = new Message();
$message->setMessage($body);
$message->setStatus('Sent');
if (null === $parent) {
$subject = new Subject();
$subject->setSubject($subjectText);
Expand All @@ -204,11 +205,10 @@ private function addMessageAndSendNotification(
$message->setParent($parent);
$message->setSender($sender);
$message->setReceiver($receiver);
$message->setStatus('Sent');
$em->persist($message);
$em->flush();

if (!strpos($message->getSpamInfo(), SpamInfoType::SPAM_BLOCKED_WORD)) {
if (strpos($message->getSpamInfo(), SpamInfoType::SPAM_BLOCKED_WORD) === false) {
$this->mailer->sendMessageNotificationEmail($sender, $receiver, 'message', [
'message' => $message,
'subject' => $subjectText,
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private function sendInitialRequestNotification(Member $host, Member $guest, Mes
{
$subject = $request->getSubject()->getSubject();

if (!strpos($request->getSpamInfo(), SpamInfoType::SPAM_BLOCKED_WORD)) {
if (strpos($request->getSpamInfo(), SpamInfoType::SPAM_BLOCKED_WORD) === false) {
$this->sendRequestNotification($guest, $host, $host, $request, $subject, 'request', false);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Model/Admin/CheckerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,12 @@ public function getProcessedReportedMessages(int $page = 1, int $limit = 10): Pa

return $repository->findProcessedReportedMessages($page, $limit);
}

public function getBlockWordsMessages(int $page = 1, int $limit = 10): Pagerfanta
{
/** @var MessageRepository $repository */
$repository = $this->entityManager->getRepository(Message::class);

return $repository->findBlockWordsMessages($page, $limit);
}
}
1 change: 1 addition & 0 deletions src/Model/ConversationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public function formatConversation(Message $message): Message

if ($found != 0) {
$message->setSpamInfo(SpamInfoType::SPAM_BLOCKED_WORD);
$message->setStatus(MessageStatusType::CHECK);
$message->setMessage($messageText);
}

Expand Down
31 changes: 31 additions & 0 deletions src/Repository/MessageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ public function findProcessedReportedMessages($page = 1, $items = 10): Pagerfant
return $paginator;
}

/**
* Returns a Pagerfanta object encapsulating the matching paginated processed reported messages.
*
* @param mixed $page
* @param mixed $items
*/
public function findBlockWordsMessages($page = 1, $items = 10): Pagerfanta
{
$queryBuilder = $this->queryBlockWordsMessages();
$adapter = new QueryAdapter($queryBuilder);
$paginator = new Pagerfanta($adapter);
$paginator->setMaxPerPage($items);
$paginator->setCurrentPage($page);

return $paginator;
}

public function getThread(Message $message)
{
$qb = $this->createNativeNamedQuery('get_thread')
Expand Down Expand Up @@ -333,6 +350,20 @@ private function queryProcessedReportedMessages(): QueryBuilder
return $qb;
}

private function queryBlockWordsMessages(): QueryBuilder
{
$qb = $this->createQueryBuilder('m');
$qb
->where('m.status = :status')
->setParameter('status', MessageStatusType::CHECK)
->andWhere('m.spamInfo LIKE :spamInfo')
->setParameter('spamInfo', '%' . SpamInfoType::SPAM_BLOCKED_WORD . '%')
->orderBy('m.created', 'DESC')
;

return $qb;
}

private function queryAllMessagesBetween(
Member $loggedInUser,
Member $member,
Expand Down
6 changes: 6 additions & 0 deletions translations/missing/checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
block.words.messages:
- 'Blocked Notifications'
- 'Menu item in Checker Volunteer tool. (Do not translate)'
- 'messages+intl-icu'
- 'no'

0 comments on commit 960ffc7

Please sign in to comment.