RTippin / messenger

Laravel messenger. A full messenger suite for your new / existing laravel app! Private and group threads between multiple models, with real-time messaging, reactions, attachments, calling, chat bots, and more!
https://tippindev.com
MIT License
416 stars 84 forks source link

How to search in all users? And add participants in a group? #40

Closed arifhossen-dev closed 2 years ago

arifhossen-dev commented 2 years ago

1. How can a user search all users (including new fresh users) for conversations?

In the users table

Getting only logged in user

I want to get search results from all new users. Logged in or not.

in user model

Implements

class User extends Authenticatable implements MessengerProvider

Using traite

use Messageable;

Setting method

   public static function getProviderSettings(): array
    {
        return [
            'alias' => 'user',
            'searchable' => true,
            'friendable' => true,
            'devices' => true,
            'default_avatar' => public_path('vendor/messenger/images/users.png'),
            'cant_message_first' => [],
            'cant_search' => [],
            'cant_friend' => [],
        ];
    }

Searchable method

   public static function getProviderSearchableBuilder(
        Builder $query,
        string $search,
        array $searchItems
    ) {
        $query->where(function (Builder $query) use ($searchItems) {
            foreach ($searchItems as $item) {
                $query->orWhere('name', 'LIKE', "%{$item}%");
            }
        })->orWhere('email', '=', $search);
    }

2. How can users add participants in a group without being friends?

I am using BIGINT id in the users table

RTippin commented 2 years ago
  1. How can a user search all users (including new fresh users) for conversations?

The search feature uses the messengers table, which requires you to implement creating my Messenger model upon your new user creation. Please see my docs on the matter for how/when to make/attach messenger models to your providers.

Messenger Model


  1. How can users add participants in a group without being friends?

Firstly, you can generate group thread invites and send the invite to anyone you want to join the group (similar to discord invites).

Second, to be able to add non-friends to the group directly, you can disable the friendship checks via the config MESSENGER_VERIFY_GROUP_THREAD_FRIENDSHIP.

Friendship Checks

The one caveat when disabling group thread friendship checks is that my optional messenger-ui UI, you can only "view" friends to add via the popup modal. If you want to be able to view all users and pick who to add to a group, you will have to build that UI / API integration yourself, as the current included endpoint ( Add participants ) filters out current group participants against your friends list. However, if you build the UI yourself, the ( Store Participants ) endpoint will accept any valid provider alias/ID combo.

Messenger v2 is still a ways out, but I am planning to give more control over these options, but that also includes me making a brand new optional UI (will be in react).