Skip to content

Commit 9cba949

Browse files
committed
[feat/card-comments] delay state changing api calls to save()
1 parent 4c13128 commit 9cba949

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

lib/Trello/Model/Card.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Card extends AbstractObject implements CardInterface
2727
);
2828

2929
protected $newChecklists = array();
30+
protected $newComments = array();
31+
protected $commentsToBeRemoved = array();
3032

3133
/**
3234
* {@inheritdoc}
@@ -778,22 +780,29 @@ public function getDateOfLastActivity()
778780
/**
779781
* {@inheritdoc}
780782
*/
781-
public function getActions($params = array()) {
783+
public function getActions($params = array())
784+
{
782785
return $this->api->actions()->all($this->id, $params);
783786
}
784-
787+
785788
/**
786789
* {@inheritdoc}
787790
*/
788-
public function addComment($text) {
789-
return $this->api->actions()->addComment($this->id, $text);
791+
public function addComment($text)
792+
{
793+
$this->newComments[] = $text;
794+
795+
return $this;
790796
}
791797

792798
/**
793799
* {@inheritdoc}
794800
*/
795-
public function removeComment($commentId) {
796-
return $this->api->actions()->removeComment($this->id, $commentId);
801+
public function removeComment($commentId)
802+
{
803+
$this->commentsToBeRemoved[] = $commentId;
804+
805+
return $this;
797806
}
798807

799808
/**
@@ -806,4 +815,20 @@ protected function preSave()
806815
$this->addChecklist($checklist);
807816
}
808817
}
818+
819+
/**
820+
* {@inheritdoc}
821+
*/
822+
protected function postSave()
823+
{
824+
foreach ($this->newComments as $key => $text) {
825+
$this->api->actions()->addComment($this->id, $text);
826+
unset($this->newComments[$key]);
827+
}
828+
829+
foreach ($this->commentsToBeRemoved as $key => $commentId) {
830+
$this->api->actions()->removeComment($this->id, $commentId);
831+
unset($this->commentsToBeRemoved[$key]);
832+
}
833+
}
809834
}

0 commit comments

Comments
 (0)