conversation->participants()->count(); $this->dispatch('participantsCountUpdated', $actualCount)->to(Info::class); } /** * Add all linked users of the active Organization, Bank, or Admin profile * to the selected members list, up to the group member limit. */ public function addLinkedMembers(): void { $activeProfile = getActiveProfile(); if (!$activeProfile) { return; } \App\Helpers\ProfileAuthorizationHelper::authorize($activeProfile); $activeProfileType = getActiveProfileType(); if (!in_array($activeProfileType, ['Organization', 'Bank', 'Admin'])) { return; } $relationMethod = $activeProfileType === 'Bank' ? 'managers' : 'users'; $linkedUsers = $activeProfile->$relationMethod() ->select('users.id') ->get(); foreach ($linkedUsers as $linkedUser) { // Stop if we've hit the group member limit if ($this->newTotalCount >= WireChat::maxGroupMembers()) { $this->dispatch('show-member-limit-error'); break; } $user = User::find($linkedUser->id); if (!$user) { continue; } // Skip if already a participant in the conversation if ($user->belongsToConversation($this->conversation)) { continue; } // Skip if already selected if ($this->selectedMembers->contains(fn ($m) => $m->id == $user->id && get_class($m) == get_class($user))) { continue; } $this->selectedMembers->push($user); $this->newTotalCount = count($this->selectedMembers) + $this->exitingMembersCount; } } }