Giter Site home page Giter Site logo

musonza / chat Goto Github PK

View Code? Open in Web Editor NEW
1.1K 36.0 299.0 414 KB

A Laravel chat package. You can use this package to create a chat/messaging Laravel application.

License: MIT License

PHP 100.00%
laravel-package laravel-chat laravel-messaging conversation laravel-messaging-package chat chatapp php-chat laravel participant-conversations

chat's People

Contributors

abdullahfaqeir avatar abhishekpaul avatar aleksandarsavic95 avatar ali4zimi avatar aren1989 avatar axe1987 avatar benqoder avatar danilopinotti avatar flyingcoder avatar laravel-shift avatar leohubert avatar mehranabi avatar mirzazulfan avatar moecasts avatar mostafanobaghi avatar musonza avatar owenvoke avatar pajkho avatar rez1dent3 avatar shacky avatar sonnysantino avatar tolgatasci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chat's Issues

Class name must be a valid object or a string

When I run Chat::createConversation() it does create a conversation in a conversations table, but nothing in conversation_user table. Gives an error: "Class name must be a valid object or a string" instead.

First 8 lines from error page...
in Model.php line 939
at Model->belongsToMany(null, 'conversation_user') in Conversation.php line 20
at Conversation->users() in Conversation.php line 65
at Conversation->addParticipants(array('1', '2')) in Conversation.php line 112
at Conversation->start(array('1', '2')) in Chat.php line 33
at Chat->createConversation(array('1', '2')) in Facade.php line 237
at Facade::__callStatic('createConversation', array(array('1', '2'))) in ConversationController.php line 57
at ConversationController->create('2')

Pagination...

I can't find mail on your profile..

Why pagination working only by request? Why I can't use pagination blade?

public function inbox(Request $request) { $user = Auth::user(); //$conversations = Chat::commonConversations($user); //$LastMessages['partcipant'] = $conf->users[1]; $conversations = Chat::conversations()->for($user)->limit(1)->page($request->get('page'))->get(); }

Use pagination for chat

Hello, How I can use default pagination for chat messages, conversations?

Method paginate not working.

$conversations = Chat::conversations()->for($user)->paginate(10);

Two USER Controll exits

Have you been in a call between two users before?
If it is, you need to show the conversation.

Display Inbox messages

Hi,

I'm using your package to add messaging feature to my project. In the messaging feature there is
a user inbox that lists all conversations I had with other users. My problem I want to display the number
of my unread messages per conversation upon viewing the inbox just like when you view your phones inbox where it displays unread messages count per conversation. Is it possible or is there any way to get this done?

Hoping to hear your response.

Thanks!

Syntax error, access voilation for user Conversations

I did this piece of code

$user = Auth::user();
$mesages = Chat::conversations($user->id);

and it gave me this error:

SQLSTATE[42000]: Syntax error or access violation: 1055 'mydb.messages.id' isn't in GROUP BY (SQL: select messages.*, messages.idasmessage_id, conversation_user.* from conversation_userinner joinmessagesonmessages.conversation_id=conversation_user.conversation_idwhereconversation_user.user_id= 19 group bymessages.conversation_idorder bymessages.id desc)

My user is authenticated and I have some messages/conversations in table as well.

Fix the order for php artisan migrate

I dont know, but I got errors when I try to migrate table.
so I fix the order, and voila. Its work.

Maybe if you want to help me, you can share the demo/example from this package?
Btw you are awesome, this package is so nice

Check if message is read?

Hello, how I can check if message is read? In controller I send model of message, but how check if message read or not?

Cannot use the Chat Facade

Hello,

I'm using your package to create chat feature to my project.
I'm using Laravel 5.5 and I encounter issue when using the package chat facade.
Please check this link to see the error message.
Hope to hear your response/feedback about this issue.

Thanks

Order messages

How can i order the messages?
Or can i somehow only get the last N messages?

Also i have:
Chat::conversations()->for(\Auth::user())->limit(25)->page(1)->get();

How can i get the other users name in the conversation?

Thanks

Mark message is read function

I have function:

public function setMessagesSeen(Conversation $conversation, Request $request) {
$v = Validator::make($request->all(), [
    'message' => 'required|string|max:4000',
]);

$user = User::find(Auth::id());

$conversations = Chat::conversation($conversation->id);

//$message = Chat::conversations($conversations)->for($user)->getMessages()->where('body', $request->message)->where('user_id', '<>', $user->id);

//$message->markRead();

//var_dump($message); exit;

broadcast(new MessageIsSeen($message));

return response('ok'); }

I have a post request:

methods: {
    seenMessage() {
        if(this.message.length != 0) {
            axios.post('/setMessagesSeen/' + this.convId, {
                message: this.message,
            })
            .then( response => { $('li').removeClass('unread'); }) 
            .catch( response => { console.log(response) } )
        }
},

How I can correctly read message for users? I need add/remove class to div in app.js, when message is readed for user. But how check this and mark correctly read message, I need message id?

Getting SQL error

Hi Musonza,

I am getting an sql error when I used the getMessages method.

my code ::

public function chats()
{
$currentuser = Auth::user();

		$conversations = Chat::getConversationBetween($currentuser, 1);

		$messages = Chat::conversations()->for($currentuser)->limit(25)->page(1)->get();

		//return view('chats',['conversation' => $conversations, 'messages' => $messages]);

		//return $messages;
}

it shows the below error ::

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."message_id"' = mc_messages.id where mc_messages.conversation_id in ' at line 1 (SQL: select notifications., mc_messages. from mc_messages inner join notifications on notifications.data->'$."message_id"' = mc_messages.id where mc_messages.conversation_id in (1) order by mc_messages.id desc)

Please Suggest me something :)

MessageWasSent event not working

#66
Hello, I have:

Broadcast::channel('mc-chat-conversation.{conversation_id}', function($user) { return $user; });

App.js:

mounted() { Echo.private('mc-chat-conversation.' + this.convId) .listen('MessageWasSent', (e) => { console.log(e); this.chat.message.push(e.message); this.chat.user.push(e.user); this.chat.time.push(this.getTime()); console.log(e); }) .listenForWhisper('typing', (e) => { if(e.name != '') this.typing = 'Набирает сообщение..'; else this.typing = null; }); }

Controller:

broadcast(new MessageWasSent($message))->toOthers();

But event not received data to other user, why??? console.log(e) get empty result.

I think, that event MessageWasSent not know, that need send message to other user. He can only receive a message? Why??

Some issue while getting messages.

Hi,
I am using the following to fetch messages:
Chat::conversations($conversation)->for($user)->getMessages($perPage, $page)

But it throws an error.
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."message_id"' = mc_messages.id where mc_messages.conversation_id = ?' at line 1 (SQL: select count(*) as aggregate from mc_messages inner join notifications on notifications.data->'$."message_id"' = mc_messages.id where mc_messages.conversation_id = 1 and mc_messages.conversation_id is not null and notifications.notifiable_id = 4)

Any help ?
Thanks

How to run the test

C:\Users\bob\innermessage\blog\vendor\musonza\chat>phpunit

Fatal error: Class 'Musonza\Chat\Tests\TestCase' not found in C:\Users\bob\innermessage\blog\vendor\musonza\chat\tests\Unit\ChatTest.php on line 8

what's wrong one my testing running

offer

To list the messages of the user, to get information of the person who is not himself

In the meantime, the best class
foreach(Chat::conversation($user->conversation_id)->users as $kullanici){
if($kullanici->id !== $userId){
$us = $kullanici;
}

        }
public function conversations($userId)
    {
        $c = ConversationUser::join('messages', 'messages.conversation_id', '=', 'conversation_user.conversation_id')
            ->where('conversation_user.user_id', $userId)
            ->groupBy('messages.conversation_id')
            ->orderBy('messages.id', 'DESC')
            ->get(['messages.*', 'messages.id as message_id', 'conversation_user.*']);

        $messages = [];


        foreach ($c as $user) {

            foreach(Chat::conversation($user->conversation_id)->users as $kullanici){
            if($kullanici->id !== $userId){
            $us = $kullanici;
            }

            }

            $recent_message = $user->conversation->messages()->orderBy('id', 'desc')->first()->toArray();

            $notification = MessageNotification::where('user_id', $userId)
                ->where('message_id', $user->id)
                ->get(['message_notification.id',
                    'message_notification.is_seen',
                    'message_notification.is_sender']
                );

            $messages[] = array_merge(
                $recent_message, ['notification' => $notification,'users'=>$us]
            );



        }

        return $messages;
    }

How to get new messages ?

for example if I'm in a conversation and last message id is 10 then there are new messages came and how i get the message(s) greater than 10.
and also there are no any function to get a one single message, and Message send function doesn't return the message that sent so i have to recall a function to get the last message.

Chat class not found !!

I am facing this error !!

FatalErrorException in ConversationController.php line 14:
Class 'App\Http\Controllers\Chat' not found

How can i fix that ?

Real time chat

Hello, How I can integrate this package with vue and pusher?

Compatibility problems with MYSQL 5.6

Hi,
I installed this bundle in My Laravel project but I can’t stop having this error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>'$."message_id"' = mc_messages.id where mc_messages.conversation_id in ' at line 1 (SQL: select notifications., mc_messages. from mc_messages inner join notifications on notifications.data->'$."message_id"' = mc_messages.id where mc_messages.conversation_id in (16, 31, 7, 35, 36) order by mc_messages.id desc) `
Trying to understand the error makes me understand that it is about the version of MYSQL. I was actually using version 5.6.38
I used a different database with MyQL 5.7.18 and everything worked fine.
How could we address this issue? The problem is that i even tried to debug the code in other to find where the problem occurs and try to fix it but it seems really complicated. By the way I cannot just comment the package code in my local version cause it wouldn’t work on production anyway.
I should notice that the MYSQL requirements are not specified in the package documentation.

My Laravel version is 5.3.31

Migration error

The issue is that the messages table is created before the conversations table and the message table institutes foreign key restraints on the conversations table (that doesn't exist yet!).

[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table chat.#sql-644_132 (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table messages add constraint messages_conversation_id_foreign foreign key (conversation_id) references conversations (id))

[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table chat.#sql-644_132 (errno: 150 "Foreign key constraint is incorrectly formed")

On a clean install, the trick to getting the migration to work properly is to rename the messages table such that it'll be run after the conversation table is created.

I renamed mine to:
2016_03_05_060940_create_messages_table.php

After cleaning up the database I reran the migration without issues.

Alternatively, you could put the foreign key restraint code in the Conversations migration, but make sure it references the proper table.

Looking forward to playing with your Chat.

System bot in chat

Hello my friend! I have a question, if on site we have 2 users (admins), How I can create bot, which will respond to users by name these admins?

Nothing to migrate

I did follow your steps but my migration and config files didn't create in folder.

Getting conversation and No. of unread messages

How do i get conversations list from a user order by last updated, Chat::commonConversations doesn't return eloquent instance. And is there a way to get No. of unread messages for a user ? or do we have do it by manually ?

User model in different namespace

I keep User model in CustomName\Models\User namespace. Is there easy way I can change the settings or should I check each file and change it manually?

How do I check if conversation already exists between two users? Method getConversationBetweenUsers() gives you one only if there is one, otherwise throws error "Undefined offset: 0", instead of null or false...

GetMessage in Descending order

Hi
How can in get count no of total messages?

Help to update the below function for to getMessages in Descending order
musonza\chat\src\Chat.php
image

So i can call this like
$msgs =Chat::conversations($conversation)->for($user)->getMessages(10,1,'desc');

Compatibility issue with mariadb

Hi

Im getting the fol;owing error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '>'$."message_id"' = mc_messages.id where mc_messages.conversation_id = ?' at line 1 (SQL: select count(*) as aggregate from mc_messages inner join notifications on notifications.data->'$."message_id"' = mc_messages.id where mc_messages.conversation_id = 2 and mc_messages.conversation_id is not null and notifications.notifiable_id = 1)

Any tips fixing this?

Thanks

Error on getting messages from a conversation.

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>'$."message_id"' = mc_messages.id where mc_messages.conversation_id in ' at line 1 (SQL: select notifications., mc_messages. from mc_messages inner join notifications on notifications.data->'$."message_id"' = mc_messages.id where mc_messages.conversation_id in (1) order by mc_messages.id desc)

PHP: 7.0
MySQL: 5.6

Get all the messages in a conversation

Using Chat::messages() I get all the messages in a conversation, but they all come in under same sender or recipient (depending on which ID you put as first parameter) no matter if I am a sender or recipient.
Even if I'm a sender but using recipients ID in a function the message sender shows up as a recipient.
Is there a way to distinguish which message belongs to which user?

New method

Would it be possible for you to add a method to get ids and usernames of all open/started conversations for a logged in user? Something like getAllOpenChatsUsers(). Let's say I want to show just a list of all users I have started a conversation with (or they started with me)

Conversation clear

I get a non object on conversations, when click on conversation with people. Why??

Chat::conversations($conversation)->for($user)->clear();

This remove only my messages from conversation.
When I go to conversation with participant, I get error:

Trying to get property of non-object

In my blade


                              @foreach($conversations as $key => $confs)
                              <tr onclick="window.location.href = '{{ route('chatconv', $confs->last_message->conversation_id) }}?last=1'">
                                  <td><img class="user-avatar" src="{{ $recipient[$key]->avatar }}" alt="{{ $confs->last_message->sender->name }}"> <span class="name">{{ $recipient[$key]->name }}
                                    @if(Helper::getOnlineUser($recipient[$key]->id))
                                    <i data-toggle="tooltip" title="Online" class="material-icons online">fiber_manual_record</i>
                                    @else
                                    <i data-toggle="tooltip" title="Offline" class="material-icons offline">fiber_manual_record</i>
                                    @endif
                                  </span></td>
                                  <td>{{ $confs->last_message->body }}</td>
                                  <td>{{ $confs->last_message->updated_at->diffForHumans() }}</td>
                              </tr>
                              @endforeach

Controller:

public function inbox(Request $request) {
        $user = $this->user;
        //$conversations = Chat::commonConversations($user);
        //$LastMessages['partcipant'] = $conf->users[1];
        $conversations = Chat::conversations()->for($user)->limit(15)->page($request->page)->get();
        //dd($conversations); exit;
        //dd($conversations);
        $recipient = [];
        //dd($conversations);
        foreach($conversations as $conf) {
            $recipient[] = $conf->users()->where('user_id', '<>', $user->id)->first();
        }

        //dd($recipient);

        return view('inbox.index', compact('conversations', 'recipient'));
    }

I need remove dialog for user. But how I can check this?

I get messages in dialog with:

        $messages = Chat::conversations($conversation)->for($user)->getMessages($limit, $request->page);

JSON_EXTRACT function error

Hi, bro
I try to use your chat and i've a little problem.
JSON_EXTRACT function error

I know its because i'm using a mysql version without that function, but, have a solution about it?
I can't change the version of mysql, my production are in a shared host.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.