|
4 | 4 |
|
5 | 5 | use Html2Text\Html2Text;
|
6 | 6 | use Illuminate\Database\Eloquent\Model;
|
| 7 | +use Andaletech\Inbox\Events\MessageCreated; |
7 | 8 | use Illuminate\Database\Eloquent\Collection;
|
8 | 9 | use Psr\Container\NotFoundExceptionInterface;
|
9 | 10 | use Psr\Container\ContainerExceptionInterface;
|
10 |
| -// use Andaletech\Inbox\Http\Contract\Models\IHasInbox; |
11 | 11 | use Andaletech\Inbox\Contracts\Models\IHasInbox;
|
12 | 12 | use Illuminate\Database\Eloquent\Relations\Relation;
|
13 | 13 | use Illuminate\Contracts\Container\BindingResolutionException;
|
|
18 | 18 | */
|
19 | 19 | trait HasInbox
|
20 | 20 | {
|
21 |
| - // protected static $inboxThreadsTable; |
22 |
| - |
23 |
| - // protected static $inboxMessagesTable; |
24 |
| - |
25 |
| - // protected static $inboxParticipantsTable; |
26 |
| - |
27 | 21 | /**
|
28 | 22 | * @var bool
|
29 | 23 | */
|
@@ -71,67 +65,23 @@ trait HasInbox
|
71 | 65 | */
|
72 | 66 | public function threads()
|
73 | 67 | {
|
74 |
| - // $threadClass = config('andale-inbox.eloquent.models.thread'); |
75 |
| - |
76 |
| - // return $threadClass::whereIn( |
77 |
| - // 'id', |
78 |
| - // ); |
79 | 68 | /**
|
80 | 69 | * @var \Illuminate\Database\Eloquent\Model $this
|
81 | 70 | */
|
82 | 71 | $query = $this->belongsToMany(
|
83 | 72 | config('andale-inbox.eloquent.models.thread'),
|
84 | 73 | config('andale-inbox.tables.participants'),
|
85 |
| - // config('andale-inbox.eloquent.models.participant'), |
86 | 74 | 'participant_id',
|
87 | 75 | 'thread_id'
|
88 | 76 | )->where('participant_type', get_class($this))->distinct();
|
89 | 77 |
|
90 |
| - // return $this->addMultitenancyColumnIfNeeded($query); |
91 | 78 | if ($this->isMultitenant()) {
|
92 | 79 | $query = $query->withPivot([config('andale-inbox.tenancy.tenant_id_column', 'tenant_id')]);
|
93 | 80 | }
|
94 | 81 |
|
95 | 82 | return $query;
|
96 |
| - // return $this->belongsToMany(); |
97 |
| - return $this->morphedByMany( |
98 |
| - config('andale-inbox.eloquent.models.thread'), |
99 |
| - 'participantxxx', |
100 |
| - config('andale-inbox.eloquent.models.participant'), |
101 |
| - 'xxxxxx' |
102 |
| - ); |
103 |
| - |
104 |
| - return $this->hasMany(config('andale-inbox.eloquent.models.thread')); |
105 |
| - // $query = $this->morphMany(config('andale-inbox.eloquent.models.thread'), 'owner'); |
106 |
| - // if ($this->isMultitenant()) { |
107 |
| - // $query = $query->with([config('andale-inbox.tenancy.tenant_id_column', 'tenant_id')]); |
108 |
| - // } |
109 |
| - |
110 |
| - // return $query; |
111 | 83 | }
|
112 | 84 |
|
113 |
| - // public function threadX() |
114 |
| - // { |
115 |
| - // return |
116 |
| - // } |
117 |
| - |
118 |
| - // /** |
119 |
| - // * |
120 |
| - // * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
121 |
| - // * @throws BindingResolutionException |
122 |
| - // * @throws NotFoundExceptionInterface |
123 |
| - // * @throws ContainerExceptionInterface |
124 |
| - // */ |
125 |
| - // public function threadsXXXX() |
126 |
| - // { |
127 |
| - // $query = $this->morphMany(config('andale-inbox.eloquent.models.thread'), 'owner'); |
128 |
| - // if ($this->isMultitenant()) { |
129 |
| - // $query = $query->with([config('andale-inbox.tenancy.tenant_id_column', 'tenant_id')]); |
130 |
| - // } |
131 |
| - |
132 |
| - // return $query; |
133 |
| - // } |
134 |
| - |
135 | 85 | public function messages()
|
136 | 86 | {
|
137 | 87 | $query = $this->morphMany(config('andale-inbox.eloquent.models.message'), 'from');
|
@@ -254,6 +204,7 @@ protected function createInboxMessage($thread, $sendingUser = null)
|
254 | 204 | }
|
255 | 205 | $thread->messages()->save($message);
|
256 | 206 | $message->addParticipants([$this, ...$this->inboxNewMessageRecipients]);
|
| 207 | + event(new MessageCreated($message)); |
257 | 208 |
|
258 | 209 | return $message;
|
259 | 210 | }
|
|
0 commit comments