|
20 | 20 | class Conversation extends BaseModel |
21 | 21 | { |
22 | 22 | protected $table = ConfigurationManager::CONVERSATIONS_TABLE; |
23 | | - protected $fillable = ['data']; |
| 23 | + protected $fillable = ['data', 'direct_message']; |
24 | 24 | protected $casts = [ |
25 | 25 | 'data' => 'array', |
26 | 26 | 'direct_message' => 'boolean', |
@@ -148,18 +148,23 @@ public function removeParticipant($participants) |
148 | 148 | /** |
149 | 149 | * Starts a new conversation. |
150 | 150 | * |
151 | | - * @param array $participants |
152 | | - * @param array $data |
| 151 | + * @param array $payload |
| 152 | + * |
| 153 | + * @throws InvalidDirectMessageNumberOfParticipants |
153 | 154 | * |
154 | 155 | * @return Conversation |
155 | 156 | */ |
156 | | - public function start(array $participants, $data = []): self |
| 157 | + public function start(array $payload): self |
157 | 158 | { |
| 159 | + if ($payload['direct_message'] && count($payload['participants']) > 2) { |
| 160 | + throw new InvalidDirectMessageNumberOfParticipants(); |
| 161 | + } |
| 162 | + |
158 | 163 | /** @var Conversation $conversation */ |
159 | | - $conversation = $this->create(['data' => $data]); |
| 164 | + $conversation = $this->create(['data' => $payload['data'], 'direct_message' => (bool) $payload['direct_message']]); |
160 | 165 |
|
161 | | - if ($participants) { |
162 | | - $conversation->addParticipants($participants); |
| 166 | + if ($payload['participants']) { |
| 167 | + $conversation->addParticipants($payload['participants']); |
163 | 168 | } |
164 | 169 |
|
165 | 170 | return $conversation; |
@@ -210,6 +215,7 @@ public function makeDirect($isDirect = true) |
210 | 215 | private function ensureNoDirectMessagingExist() |
211 | 216 | { |
212 | 217 | $participants = $this->participants()->get()->pluck('messageable'); |
| 218 | + /** @var Conversation $common */ |
213 | 219 | $common = Chat::conversations()->between($participants[0], $participants[1]); |
214 | 220 |
|
215 | 221 | if (!is_null($common)) { |
|
0 commit comments