Skip to content

Commit

Permalink
Add deleted threads list
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelVella committed Oct 8, 2013
1 parent 0890c8c commit 374823f
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Controller/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ public function sentAction()
));
}

/**
* Displays the authenticated participant deleted threads
*
* @return Response
*/
public function deletedAction()
{
$threads = $this->getProvider()->getDeletedThreads();

return $this->container->get('templating')->renderResponse('FOSMessageBundle:Message:deleted.html.twig', array(
'threads' => $threads
));
}

/**
* Displays a thread, also allows to reply to it
*
Expand Down
19 changes: 19 additions & 0 deletions DocumentManager/ThreadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ public function findParticipantSentThreads(ParticipantInterface $participant)
return $this->getParticipantSentThreadsQueryBuilder($participant)->getQuery()->execute();
}

/**
* {@inheritDoc}
*/
public function getParticipantDeletedThreadsQueryBuilder(ParticipantInterface $participant)
{
return $this->repository->createQueryBuilder()
->field('metadata.isDeleted')->equals(true)
->field('metadata.participantId')->equals($participant->getId())
->sort('lastMessageDate', 'desc');
}

/**
* {@inheritDoc}
*/
public function findParticipantDeletedThreads(ParticipantInterface $participant)
{
return $this->getParticipantDeletedThreadsQueryBuilder($participant)->getQuery()->execute();
}

/**
* Finds not deleted threads for a participant,
* matching the given search term
Expand Down
32 changes: 32 additions & 0 deletions EntityManager/ThreadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,38 @@ public function findParticipantSentThreads(ParticipantInterface $participant)
->execute();
}

/**
* {@inheritDoc}
*/
public function getParticipantDeletedThreadsQueryBuilder(ParticipantInterface $participant)
{
return $this->repository->createQueryBuilder('t')
->innerJoin('t.metadata', 'tm')
->innerJoin('tm.participant', 'p')

// the participant is in the thread participants
->andWhere('p.id = :user_id')
->setParameter('user_id', $participant->getId())

// the thread is deleted by this participant
->andWhere('tm.isDeleted = :isDeleted')
->setParameter('isDeleted', true, \PDO::PARAM_BOOL)

// sort by date of last message
->orderBy('tm.lastMessageDate', 'DESC')
;
}

/**
* {@inheritDoc}
*/
public function findParticipantDeletedThreads(ParticipantInterface $participant)
{
return $this->getParticipantDeletedThreadsQueryBuilder($participant)
->getQuery()
->execute();
}

/**
* Finds not deleted threads for a participant,
* matching the given search term
Expand Down
18 changes: 18 additions & 0 deletions ModelManager/ThreadManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ function getParticipantSentThreadsQueryBuilder(ParticipantInterface $participant
*/
function findParticipantSentThreads(ParticipantInterface $participant);

/**
* Finds deleted threads from a participant,
* ordered by last message date
*
* @param ParticipantInterface $participant
* @return Builder a query builder suitable for pagination
*/
function getParticipantDeletedThreadsQueryBuilder(ParticipantInterface $participant);

/**
* Finds deleted threads from a participant,
* ordered by last message date
*
* @param ParticipantInterface $participant
* @return ThreadInterface[]
*/
function findParticipantDeletedThreads(ParticipantInterface $participant);

/**
* Finds not deleted threads for a participant,
* matching the given search term
Expand Down
10 changes: 10 additions & 0 deletions Provider/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public function getSentThreads()
return $this->threadManager->findParticipantSentThreads($participant);
}

/**
* {@inheritDoc}
*/
public function getDeletedThreads()
{
$participant = $this->getAuthenticatedParticipant();

return $this->threadManager->findParticipantDeletedThreads($participant);
}

/**
* Gets a thread by its ID
* Performs authorization checks
Expand Down
7 changes: 7 additions & 0 deletions Provider/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ function getInboxThreads();
*/
function getSentThreads();

/**
* Gets the deleted threads of the current user
*
* @return ThreadInterface[]
*/
function getDeletedThreads();

/**
* Gets a thread by its ID
* Performs authorization checks
Expand Down
4 changes: 4 additions & 0 deletions Resources/config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<default key="_controller">FOSMessageBundle:Message:sent</default>
</route>

<route id="fos_message_deleted" pattern="/deleted">
<default key="_controller">FOSMessageBundle:Message:deleted</default>
</route>

<route id="fos_message_search" pattern="/search">
<default key="_controller">FOSMessageBundle:Message:search</default>
</route>
Expand Down
1 change: 1 addition & 0 deletions Resources/translations/FOSMessageBundle.en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
messenger: Messenger
inbox: Inbox
sent: Sent
deleted: Deleted
send_new: Send a new message
search: Search
threads_found: %num% thread found with | %num% threads found with
Expand Down
1 change: 1 addition & 0 deletions Resources/translations/FOSMessageBundle.fr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
messenger: Messagerie
inbox: Boîte de réception
sent: Envoyés
deleted: Supprimés
send_new: Envoyer un nouveau message
search: Rechercher
threads_found: %num% conversations trouvé avec | %num% conversations trouvés avec
Expand Down
9 changes: 9 additions & 0 deletions Resources/views/Message/deleted.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'FOSMessageBundle::layout.html.twig' %}

{% block fos_message_content %}

<h2>{% trans from 'FOSMessageBundle' %}deleted{% endtrans %}</h2>

{% include 'FOSMessageBundle:Message:threads_list.html.twig' with {'threads': threads} %}

{% endblock %}

0 comments on commit 374823f

Please sign in to comment.