rpaschoal / ng-chat

💬 A simple facebook/linkedin lookalike chat module for Angular applications.
MIT License
155 stars 92 forks source link

An explanation of the onMessageReceived() method? #119

Closed Nesbox314 closed 4 years ago

Nesbox314 commented 5 years ago

So, I'm trying to use this method to receive the messages, however, strange things have been happening, one of them is: I send the message, and when the socket returns the object, a window opens in the destination (correct) another on the shipping tab. I'm pretty lost in that regard. But my final question is, what are the features that I have to go through in the onMessageReceived method.

Here we have the method:

onMessageReceived (participant: IChatParticipant, message: Message): void;

Exact, but what should be passed in the first parameter? The sending participant or the destination participant? Who knows even both?

In the second parameter we just pass the message in a string? Do we send the entire body of the message with all the attributes? Even with "toId" and "fromId"?

Thanks.

Some example of what is happening.

Send tab: envio

Destiny tab destino

Please help!

rpaschoal commented 5 years ago

Hi @Nesbox314 ,

For onMessageReceived, the first argument IChatParticipant is who's sent this message to the receiving user. The second argument is not a string, it is of type Message, and yes you should fill your Message object.

Think of these adapter methods as "hookin up" your sockets implementation (Can be whatever you want, SignalR, Socket.io, etc) to the ng-chat component.

Let me know if this has helped. You can have a look at the .net core sample project or the nodejs one, here they are:

https://github.com/rpaschoal/ng-chat-netcoreapp https://github.com/rpaschoal/ng-chat-nodejs

Cheers!

Nesbox314 commented 5 years ago

Okay, thank you so much for the answer. Before I try anything else, I have one more question. In the first parameter of type IChatParticipant, do I have to fill the entire object?

Nesbox314 commented 5 years ago

I'll leave my code here. I've been doing a good search and in the configuration now, that's what happens. The code is in Portuguese, but I see that you came from Brazil, so it is likely that you do not have much trouble understanding. I'm using SockJS with an API in Spring.

Here's an example of how chat is reacting now.

Send example: envio 2

Receiver example: destino 2

Notice that, I send the message to "Fabiane", and in the other window, that I am logged in with "Fabiane", instead of opening a user window "Ricardo", which is the user that sent, opens a window by Fabiane.

Aqui vai o meu código.

image

Please help!

rpaschoal commented 5 years ago

Hi @Nesbox314 ,

Just checking out if this is still an issue for you? Reading your code above it seems you have to swap the fromId and toId message properties.