Skip to content

Commit

Permalink
Add ThreadInterface::getFirstMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 29, 2011
1 parent 65ee102 commit 3a4f6c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Document/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getCreatedBy()
* Sets the participant that created the thread
* Generally the sender of the first message
*
* @parm ParticipantInterface
* @param ParticipantInterface
*/
public function setCreatedBy(ParticipantInterface $participant)
{
Expand Down Expand Up @@ -241,13 +241,11 @@ protected function doCreatedByAndAt()
if (isset($this->createdBy)) {
return;
}
$messages = $this->getMessages();
if (empty($messages)) {
if (!$message = $this->getFirstMessage()) {
return;
}
$firstMessage = reset($messages);
$thread->setCreatedBy($firstMessage->getSender());
$thread->setCreatedAt($firstMessage->getCreatedAt());
$this->setCreatedBy($message->getSender());
$this->setCreatedAt($message->getCreatedAt());
}

/**
Expand Down
15 changes: 15 additions & 0 deletions Model/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public function setIsReadByParticipant(ParticipantInterface $participant, $isRea
}
}

/**
* Gets the first message of the thread
*
* @return MessageInterface the first message
*/
public function getFirstMessage()
{
$messages = $this->getMessages();
if(empty($messages)) {
return null;
}

return reset($messages);
}

/**
* Gets the last message of the thread
*
Expand Down
7 changes: 7 additions & 0 deletions Model/ThreadInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ function getMessages();
*/
function addMessage(MessageInterface $message);

/**
* Gets the first message of the thread
*
* @return MessageInterface the first message
*/
function getFirstMessage();

/**
* Gets the last message of the thread
*
Expand Down

0 comments on commit 3a4f6c2

Please sign in to comment.