Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Limiting users who can be messaged/found. #10

Closed
Braunson opened this issue Oct 31, 2018 · 4 comments
Closed

Feature Request: Limiting users who can be messaged/found. #10

Braunson opened this issue Oct 31, 2018 · 4 comments
Labels
feature New feature or request info Generic information Laravel Spark Mercurius with Laravel Spark

Comments

@Braunson
Copy link

Description

In my case I'm using Laravel Spark, I only want a user to be able to message users within their team/teams. Regardless of Spark it would be nice to be able to "filter" the people they search/can have a conversation with.

@akazorg akazorg mentioned this issue Oct 31, 2018
14 tasks
@akazorg
Copy link
Member

akazorg commented Oct 31, 2018

Hello @Braunson, thanks for your message, we should work on this feature for sure.

We can add some options to the config\mercurius.php, whether we enable that "filter", and specify the model used in that logic, something like this:

...
    'models' => [
        'user'          => App\User::class,
        'contacts'      => Launcher\Mercurius\Models\Contacts::class,    <-- new
        'conversations' => Launcher\Mercurius\Models\Conversation::class,
        'messages'      => Launcher\Mercurius\Models\Message::class,
    ],
...
    'filter_contacts' => true,    <-- new

Thoughts? Thanks!

@akazorg akazorg added the feature New feature or request label Oct 31, 2018
@akazorg akazorg added this to To do in Beta Version 1.0 Oct 31, 2018
@akazorg
Copy link
Member

akazorg commented Nov 1, 2018

Hey @Braunson, for a quick solution to have Mercurius working with Teams in a Laravel Spark app, you can try this steps. Was not tested but will give you an idea.

  1. Add Route on routes\web.php
Route::post('/receivers', 'App\Controllers\ReceiversController@search');
  1. Create ReceiversController
php artisan make:controller ReceiversController
  1. Apply filter logic to ReceiversController

Open App\Http\Controllers\ReceiversController and code something like this:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;

class ReceiversController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Search for receivers.
     *
     * @param Request        $request
     * @param UserRepository $userRepository
     *
     * @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
     */
    public function search(Request $request, UserRepository $userRepository): Response
    {
        if (($query = $request->input('q')) === null) {
            return response([
                'hits'  => [],
                'total' => 0,
            ]);
        }

        // Apply filter to the Users in Teams/Users
        // you will find this code on the UserRepository
        // ------------------------------------------------
        $limit = 6;
        $userFqcn = config('mercurius.models.user');
        $paginator = $userFqcn::where('name', 'LIKE', '%'.$query.'%')
            ->paginate($limit, [
                'id',
                'name',
                'avatar',
                'is_online',
            ]);
        // ------------------------------------------------


        $result = [
            'total' => $paginator->total(),
            'hits'  => $paginator->items(),
        ];

        return response($result);
    }
}

In a future release of Mercurius we will be able to load custom Controllers, using the config, and this configuration wont be required anymore.

Let us know the result. TY

@akazorg akazorg added info Generic information Laravel Spark Mercurius with Laravel Spark labels Nov 1, 2018
@OwenMelbz
Copy link

Hey - random thought that might be easier....

As Laravel you can apply scope classes via service providers. Just make a scope class that adds a new condition to only show users who should be visible?

That way it’s as flexible as humanly possible as the scoping is 100% in the hands of the developer?

@akazorg
Copy link
Member

akazorg commented Nov 1, 2018

Great idea @OwenMelbz, thanks for the tip.

@akazorg akazorg moved this from To do to In progress in Beta Version 1.0 Nov 13, 2018
Beta Version 1.0 automation moved this from In progress to Done Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request info Generic information Laravel Spark Mercurius with Laravel Spark
Projects
Development

No branches or pull requests

3 participants