rpaschoal / ng-chat

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

message history #51

Closed cprouveu closed 6 years ago

cprouveu commented 6 years ago

Hello,

iIm trying to use your ng-chat on 42's school project but I can't understand how work the history chat by demo (offline chat).

I see history from id : 1 to id : 999 on every window.

Can you give me some help ?

Thanks.

rpaschoal commented 6 years ago

Hi @cprouveu,

Sure thing! Could you please post your chat adapter code here?

Cheers!

cprouveu commented 6 years ago

Just with your chat demo code i have this. I don t understand why i have the same history message on each windows while your demo code write 1 to 999. Normally it s just Aria who have the history.

rpaschoal commented 6 years ago

@cprouveu The demo adapter that you're probably looking at is the one for the offline bot, right? It wasn't meant to bring any message history because the demo application does not have any database connectivity. The adapter I am referring to can be found here: https://github.com/rpaschoal/ng-chat/blob/master/demo/offline_bot/src/app/demo-adapter.ts

The adapter is the interface between the chat module and your API or backend services. You will most likely have to implement a REST call to an API to retrieve the history of any given user.

Assuming your chat has history enabled (You can disable this via setting if you have no interest in the chat history just like it was done in the online demo app), the module will invoke the "getMessageHistory" method from your adapter every time you open a new window.

So instead of this:

getMessageHistory(userId: any): Observable<Message[]> {
        let mockedHistory: Array<Message>;

        mockedHistory = [
            {
                fromId: 1,
                toId: 999,
                message: "Hi there, just type any message bellow to test this Angular module."
            }
        ];

        return Observable.of(mockedHistory);
    }

You should be doing this:

getMessageHistory(userId: any): Observable<Message[]> {
        // Invoke an http service call  here to retrieve a collection of messages from an API where your application user id equals to the userId parameter.
}

Let me know how you get on to it and if you've managed to make it work. If you need anymore help, don't hesitate in asking.

Cheers!

cprouveu commented 6 years ago

Thanks for your answer, i understand why all users send the same history.