Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

How to use or integrate this library with fire-base real time database #52

Closed
prashantpimpale93 opened this issue May 24, 2018 · 27 comments

Comments

@prashantpimpale93
Copy link

I am using firebase real-time database for chat feature so how do I integrate this library with firebase.

@prashantpimpale93 prashantpimpale93 changed the title Unable to use or integrate with firebase real time database How to use or integrate this library with fire-base real time database May 24, 2018
@prashantpimpale93
Copy link
Author

I manage to get the user list on the current UI
Here is the screenshot:
success

Every response will be highly appreciated!

@rpaschoal
Copy link
Owner

Hi @prashantpimpale93 ,

I have no experience using Firebase, but as long as you can implement your logic inside your ChatAdapter, you should manage to get the chat working as per your requirements.

On the NodeJS demo I have setup, you can check the message being broadcast to other users with Socket.IO. I believe you have to find a similar way of broadcasting your messages by using Firebase.

Have a look at this and see if it is of any help: https://firebase.google.com/docs/cloud-messaging/android/send-multiple

Cheers!

@prashantpimpale93
Copy link
Author

Thanks for reply @rpaschoal. I have created one adapter (demo-adapter) in that I am writing my logic or firebase queries. But I want to modify that method which gets called on user click. I checked but need your help!

@prashantpimpale93
Copy link
Author

Currently, I have developed the whole chat module with the help of Angular Material design and chat app and firebase queries are working fine on production but for UI this one is quite good and which I loved most.

@prashantpimpale93
Copy link
Author

Can I use only HTML (UI part) of this library?

@rpaschoal
Copy link
Owner

@prashantpimpale93 What would you like to do when a user gets clicked? Perhaps we can start creating events that you could potentially bind into this module.

@rpaschoal
Copy link
Owner

rpaschoal commented May 28, 2018

@prashantpimpale93 This is a very good idea, could you please suggest a couple of events you would like to bind to?

EG: OnChatWindowOpened

We can elaborate a few and I will implement them for a next release 👍

@prashantpimpale93
Copy link
Author

prashantpimpale93 commented May 28, 2018

Yes.

  1. There is a right side window in that list of user's is available on user click a new tab is created but that method or event should be available in demo-adapter.ts where we can call firebase query with userId and fetch the message for this userId (If that is already available then please suggest).
  2. On message send which is currently fine.
    in addition, to above I have implemented the notification part for browsers.

@rpaschoal
Copy link
Owner

rpaschoal commented May 28, 2018

@prashantpimpale93

  1. This is already available on the ChatAdapter through the method public abstract getMessageHistory(userId: any): Observable<Message[]>;. This is invoked every time you click to open a window and the Observale collection from the response will be parsed on the new chat window. Just make sure you have the property historyEnabled enabled (Which is enabled by default).
  2. This a great feature! I haven't thought of that before. Could you send a pull request with the code addition to send browser notifications? (I assume you are talking about Chrome toast notifications or something similar)

Here is the contributing guide: https://github.com/rpaschoal/ng-chat/blob/master/CONTRIBUTING.md

@prashantpimpale93
Copy link
Author

Yes. Will look at getMessageHistory() Method

@prashantpimpale93
Copy link
Author

For the second point:
I am new to GitHub, please define the set of the step (For pull or add code and then push) where I can implement the code in this library

@prashantpimpale93
Copy link
Author

Ohh sorry I didn't see that shared link. Will check it out

@prashantpimpale93
Copy link
Author

@rpaschoal Expect more detailed information to contribute.

  1. Repository forked in my personal account
  2. Then tried to clone using git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
    But got an error:

remote: Not Found
fatal: repository 'https://github.com/prashantpimpale93/https://github.com/prashantpimpale93/ng-chat.git/' not found

@rpaschoal
Copy link
Owner

@prashantpimpale93 Just had a look at your fork, your clone URL is: https://github.com/prashantpimpale93/ng-chat.git

@prashantpimpale93
Copy link
Author

Got that! I was trying with userName and then repo URL. Successfully cloned.
Where do I implement notification code, In demo folder or in src folder?
Please share any document related to that contribute.

@prashantpimpale93
Copy link
Author

@rpaschoal can u please suggest which dependencies are required to run the project? Ex. Angular version and other third-party dependencies etc. It would better for me if you list down the commands

@rpaschoal
Copy link
Owner

@prashantpimpale93

All changes must go to the SRC directory, that is the core of the module. You should have everything you need from NPM dependency wise.

If you're not comfortable with doing the change, I can do it. Just list your main ideas here and I will work them out as soon as I have a spare time. I can then show you the pull request with the changes so you can grasp the idea around developing for this package.

If you have the code snippet for the browser notification, post it here as well, that will save me some time while adding everything to the main module :)

@prashantpimpale93
Copy link
Author

@rpaschoal Yes exaclty!

  1. That is what I was thought yesterday but by doing it by myself I will get to know how the actual process works to contribute on GitHub as I new here, that is why I trying to get all information from you!

Here is the code snippet:
For user permission:

Notification.requestPermission().then(function (permission) {
  if (permission == 'denied') {
    alert('You denied to show notification');
  } else if (permission == 'granted') {
    alert('You allowed to show notification');
  }
});

Notification trigger code:

if (Notification.requestPermission) {
    var notify;
    notify = new Notification('New message from ' + data.val().userName, {
      'body': data.val().message,
      'icon': 'image_url',
      'tag': data.val().userName
    });
    notify.onclick = function () {
     // Method which will be called after click event of notification panel
    }
  }
else {
    alert('Please allow the notification first');
  } 

The above code will reside in your sendMessage(message: Message): void {} method.

Will expect some help from you on point no 1! 🎉

@rpaschoal
Copy link
Owner

rpaschoal commented Jun 2, 2018

@prashantpimpale93 I've started working on the browser notifications. I will be releasing version 1.0.11 in the following days and it will include both notification and event features that you have suggested.

Have a look at the following commit to see how I usually add features to this chat module:

afee655

Bits of code blocks here and there, test the package with the demo project via NPM link and then after it is all working sweet I just add unit tests around the new feature.

You asked earlier in this thread about using the HTML part of this project. I suggest that we develop all new features here. By doing this, a lot of people will get new features for the package and it will grow both in code base and adoption from the community.

@prashantpimpale93
Copy link
Author

prashantpimpale93 commented Jun 2, 2018

@rpaschoal I am stuck at one problem. I have asked one question in StackOverflow Here is the link to the question - https://stackoverflow.com/questions/50654263/unable-to-bind-data-to-the-list

Please look once n get back to me if you're familiar with this.

@rpaschoal
Copy link
Owner

@prashantpimpale93 I think there is something wrong with the link you've posted.

Version 1.0.11 is almost ready, have implemented the changes and ideas we have discussed, added unit tests and updated the docs. I just have to do a bit of smoke testing before releasing it to NPM.

Have a look at the events that will be exposed in the new version:

Events

(onUserChatClicked): Event emitted every time a user is clicked on the chat window and a new chat window is opened.
(onUserChatOpened): Event emitted every time a chat window is opened, regardless if it was due to a user click on the friends list or via new message received.
(onUserChatClosed): Event emitted every time a chat window is closed.

What do you think? Will these fulfill the requirements of your implementation? The onUserChatClicked event is only invoked if the window is not already opened. Do you believe we should invoke this every time a user is clicked on the friends list even if the window is already opened, or is it good the way I've designed and implemented it?

By the way, I am keeping the pull request open for you to have a look on how I've implemented the code: #53

Cheers!

@rpaschoal
Copy link
Owner

Hmm, looking at this event list, I might refactor the name of the first event to onUserClicked

@prashantpimpale93
Copy link
Author

prashantpimpale93 commented Jun 4, 2018 via email

@rpaschoal
Copy link
Owner

rpaschoal commented Jun 4, 2018

@prashantpimpale93 Can't you just return an Observable from your Firebase call? Just wrap it inside an Observable.

@prashantpimpale93
Copy link
Author

prashantpimpale93 commented Jun 4, 2018 via email

@rpaschoal
Copy link
Owner

I know a few @prashantpimpale93, but they are busy professionals. If you have a Firebase related question, I would advise you to post it on StackOverflow.

1.0.12 is now published on NPM: https://www.npmjs.com/package/ng-chat

Have a look at the new features that you've suggested. Thank you for the ideas.

I am closing this issue as the thread has gone too long and we have deviated from the main issue. If you have any further questions, please open a new issue here in GitHub. Feel encouraged to post your Firebase doubts here too, but if you do, please post your full adapter code so I or someone else can have more information to help you.

@prashantpimpale93
Copy link
Author

Ok thanks for your help @rpaschoal!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants