Skip to content

Commit

Permalink
Undelete a thread for all paticipants when the thread is replied to
Browse files Browse the repository at this point in the history
  • Loading branch information
jseverson committed Jul 27, 2011
1 parent 5adf98d commit 21a1609
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 23 additions & 3 deletions Document/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,29 @@ public function isDeletedByParticipant(ParticipantInterface $participant)
public function setIsDeletedByParticipant(ParticipantInterface $participant, $isDeleted)
{
$this->isDeletedByParticipant[$participant->getId()] = (boolean) $isDeleted;
// also mark all thread messages as read
foreach ($this->getMessages() as $message) {
$message->setIsReadByParticipant($participant, true);
if($isDeleted) {
// also mark all thread messages as read
foreach ($this->getMessages() as $message) {
$message->setIsReadByParticipant($participant, true);
}
}
}

/**
* Sets the thread as deleted or not deleted for all participants
*
* @param boolean $isDeleted
*/
public function setIsDeleted($isDeleted)
{
foreach($this->isDeletedByParticipant as $participantId => $isCurrentlyDeleted) {
$this->isDeletedByParticipant[$participantId] = (boolean) $isDeleted;
}
if($isDeleted) {
// also mark all thread messages as read
foreach ($this->getMessages() as $message) {
$message->setIsReadByParticipant($participant, true);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sender/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ public function __construct(MessageManagerInterface $messageManager, ThreadManag
}

/**
* Sends the message by persisting it to the message manager
* Sends the message by persisting it to the message manager and undeletes the thread for all participants
*
* @param MessageInterface $message
*/
public function send(MessageInterface $message)
{
$this->threadManager->saveThread($message->getThread(), false);
$this->messageManager->saveMessage($message);
$message->getThread()->setIsDeleted(false);

$this->dispatcher->dispatch(OrnicarMessageEvents::POST_SEND, new MessageEvent($message));
}
Expand Down

0 comments on commit 21a1609

Please sign in to comment.