diff --git a/packages/Webkul/Activity/src/Models/File.php b/packages/Webkul/Activity/src/Models/File.php index 7d1db3127..27a87fa82 100644 --- a/packages/Webkul/Activity/src/Models/File.php +++ b/packages/Webkul/Activity/src/Models/File.php @@ -8,8 +8,20 @@ class File extends Model implements FileContract { + /** + * The table associated with the model. + * + * @var string + */ protected $table = 'activity_files'; + /** + * The attributes that should be appended to the model. + * + * @var array + */ + protected $appends = ['url']; + /** * The attributes that are mass assignable. * diff --git a/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php b/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php index 66822141c..49292c5e8 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php @@ -2,9 +2,11 @@ namespace Webkul\Admin\Http\Controllers\Contact\Persons; +use Illuminate\Support\Facades\DB; use Webkul\Activity\Repositories\ActivityRepository; use Webkul\Admin\Http\Controllers\Controller; use Webkul\Admin\Http\Resources\ActivityResource; +use Webkul\Email\Repositories\AttachmentRepository; use Webkul\Email\Repositories\EmailRepository; class ActivityController extends Controller @@ -16,7 +18,8 @@ class ActivityController extends Controller */ public function __construct( protected ActivityRepository $activityRepository, - protected EmailRepository $emailRepository + protected EmailRepository $emailRepository, + protected AttachmentRepository $attachmentRepository ) {} /** @@ -32,14 +35,54 @@ public function index($id) ->where('person_activities.person_id', $id) ->get(); - return ActivityResource::collection($this->concatEmail($activities)); + return ActivityResource::collection($this->concatEmailAsActivities($id, $activities)); } /** * Store a newly created resource in storage. */ - public function concatEmail($activities) + public function concatEmailAsActivities($personId, $activities) { - return $activities->sortByDesc('id')->sortByDesc('created_at'); + $emails = DB::table('emails as child') + ->select('child.*') + ->join('emails as parent', 'child.parent_id', '=', 'parent.id') + ->where('parent.person_id', $personId) + ->union(DB::table('emails as parent')->where('parent.person_id', $personId)) + ->get(); + + return $activities->concat($emails->map(function ($email) { + return (object) [ + 'id' => $email->id, + 'parent_id' => $email->parent_id, + 'title' => $email->subject, + 'type' => 'email', + 'is_done' => 1, + 'comment' => $email->reply, + 'schedule_from' => null, + 'schedule_to' => null, + 'user' => auth()->guard('user')->user(), + 'participants' => [], + 'location' => null, + 'additional' => [ + 'folders' => json_decode($email->folders), + 'from' => json_decode($email->from), + 'to' => json_decode($email->reply_to), + 'cc' => json_decode($email->cc), + 'bcc' => json_decode($email->bcc), + ], + 'files' => $this->attachmentRepository->findWhere(['email_id' => $email->id])->map(function ($attachment) { + return (object) [ + 'id' => $attachment->id, + 'name' => $attachment->name, + 'path' => $attachment->path, + 'url' => $attachment->url, + 'created_at' => $attachment->created_at, + 'updated_at' => $attachment->updated_at, + ]; + }), + 'created_at' => $email->created_at, + 'updated_at' => $email->updated_at, + ]; + }))->sortByDesc('id')->sortByDesc('created_at'); } } diff --git a/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php b/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php index 107225118..f12e14440 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php @@ -75,6 +75,7 @@ public function concatEmailAsActivities($leadId, $activities) 'id' => $attachment->id, 'name' => $attachment->name, 'path' => $attachment->path, + 'url' => $attachment->url, 'created_at' => $attachment->created_at, 'updated_at' => $attachment->updated_at, ]; diff --git a/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php b/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php index 2c0008b07..8a30dc88c 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php @@ -101,8 +101,9 @@ public function view() public function store() { $this->validate(request(), [ - 'reply_to' => 'required|array|min:1', - 'reply' => 'required', + 'reply_to' => 'required|array|min:1', + 'reply_to.*' => 'email', + 'reply' => 'required', ]); Event::dispatch('email.create.before'); diff --git a/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php b/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php index ee736275e..85d73c194 100644 --- a/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php +++ b/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php @@ -18,6 +18,7 @@ public function toArray($request) 'id' => $this->id, 'name' => $this->name, 'path' => $this->path, + 'url' => $this->url, 'size' => $this->size, 'content_type' => $this->content_type, 'content_id' => $this->content_id, diff --git a/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php b/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php index 96083861e..34451d68f 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php @@ -199,7 +199,7 @@ class="cursor-pointer font-medium hover:underline dark:text-white"