dazzz1er / confer

Easy real-time chat for laravel 5 based websites and applications
133 stars 47 forks source link

How can i choose with who i can chat ? #24

Closed perffy closed 8 years ago

perffy commented 8 years ago

Is there an option to choose with which users is possible to chat ?

huyle2607 commented 8 years ago

Did you mean this one? https://github.com/dazzz1er/confer/issues/2

perffy commented 8 years ago

No. I mean if i have a friend list i want only to be able to choose one of them, not to chat with strangers :)

huyle2607 commented 8 years ago

@perffy I still don't get it. Is it like you want to chat with one of your friends in private?

huglester commented 8 years ago

Yes, he is probably talking about private chat. not group chat

huyle2607 commented 8 years ago

I think it does support private chat by clicking on user icon. It'll open a window where you and your friend can chat privately.

hallmichael commented 8 years ago

I think he means he wants to choose the list of users that are visible to chat with. I had the same issue as the system I used it on had a table of users with a custom field 'status' users with status disabled needed to not display.

It is possible to change how users are selected here: /src/Confer.php in the getUsersState function, just adjust the database query.

M.

perffy commented 8 years ago

Thanks @hallmichael. That was what i needed :)

perffy commented 8 years ago

@hallmichael, i have looked the code in Confer.php, but i have never used Pusher before. As i read the code the following line is giving me all users:

$channel_info = Push::get('/channels/' . $this->global . '/users');

How can i make it work to give me return me the list of my friends, something like that:

$channel_info = Push::get('/channels/' . $this->global . '/friends/'.$user->id);

hallmichael commented 8 years ago

No worries @perffy - line 31 of Confer.php:

$users = User::ignoreMe()->get();

You just want to modify that query, it is currently just pulling all users except yourself. If you have a friends table in your database maybe join that where the user is your friend etc. It is really going to depend on your custom application schema/setup.

perffy commented 8 years ago

Thanks @hallmichael, but i do not have such function IgnoreMe() in the User Model. I searched also the whole laravel folder and there is no such method ?

hallmichael commented 8 years ago

@perffy no worries, are you getting an error for the ignoreMe() function? it should be part of eloquent so it will just work, I just meant you might change that query to something like below assuming you have a 'friends' table with columns userId & friend:

$me = Auth::user()->id;
User::join('friends','friends.friend','=','users.id')->where('friends.userIds','=',$me)->ignoreMe()->get();
dazzz1er commented 8 years ago

@perffy the ignoreMe method is declared here (line 53, CanConfer.php) which is a trait added to your user model to provide some confer functionality.

In order to show a list of just your friends, you will need to create some separate functionality for first declaring who a user's friends are through the db, and then you will have to modify some lines of code in confer to filter the users that are displayed when the user clicks on the user icon.

I haven't worked much with Pusher recently, and in fact have moved all my realtime work to a socket.io & Redis implementation, but from my point of view you would be best to leave the calls to Pusher alone, and simply modify the line @hallmichael mentioned above to show only offline/online statuses for your friends.

I would set a friends relationship on your User model that gets the user's friends from the database so that you could do something such as:

$friends = Auth::user()->friends;
$online_users = $friends->filter(function($user) use ($online_ids) {
  return in_array($user->id, $online_ids);
});
$offline_users = $friends->filter(function($user) use ($online_ids) {
  return ! in_array($user->id, $online_ids);
});

return ['online' => $online, 'offline' => $offline];

This will basically generate the list of users you see when clicking on the user icon (to choose who to speak to) being consisted entirely of your friends, split into online and offline.

perffy commented 8 years ago

Thanks guys. I have used the friends package (https://github.com/hootlex/laravel-friendships) with some corrections to the code and of course your help i have achieved success :)