duytq94/flutter-chat-demo

Allow notifications

Closed this issue · 15 comments

Hi @duytq94

Can you please advise how can we add the message notifications using the firebase messaging? I guess it will get the messages we store right?

Hi @FilipeOS
In my case, I'll check the status user (on/offline) and then use firebase functions to listen messages coming, then using firebase cloud messaging to push to the appropriate user.
Here is an example of how to use firebase function, it does not match exactly for this project, but basically should be implemented similar it

@duytq94

When you say that that code doesn't match this project, what part do you mean?

I'm still trying to change online status to on and off, is that the code?

What is the difference between firestore we used and cloud messaging?

Best regards

I said "does not match exactly for this project" because the code I gave you serve my private project (it has a little bit different about structure data from the public demo) so you just use it for reference and need change something to apply to your case.

My public demo doesn't implement on/off line status, but you can add it like a field in node user (and add a field named pushToken too).

Firestore is database and cloud messaging is a push notification service. They are completely different because they serve different purposes.

Btw, I have a plan to write a new part to demo how to implement push notification for both Android and iOS since many people need it.

My code is very similar of yours, I have a field under user of "online" (bool).

My last message I do a bit different, I don't save the last message, I get a FutureBuilder of the messages QuerySnapshot (limit 1, reverse) and show, this makes more sense. I'm trying to get Firebase costs at low possible (this is a personal project, mostly to learn).

Cloud Functions I tried to setup (online/offline) but always fail to connect, tried to follow some medium posts but way too obsolete/complicated.

My main issue now it's the online (cloud functions) and the notifications specially. If you want I can try to use git and show you

Hi, I'm writing a new article to guide How to push notification with firebase messaging and maybe will solve all your questions. Please wait.

Hi @FilipeOS
Please read the new article here.
Hope it can help you.

Hi @duytq94

Great article but I have a question, why you add chattingWith and push token on the user profile?

How can we handle when user have multiple chats?

Actually, my idea, in this case, is simple: a user only can chat with one person at a time (if they go back to the main screen ~ list users => set chattingWith = null immediately.
And I focused on how to implement push notification, not focused on how to handle all things about push new message chat.
And yes, of course, if you would like to implement an advanced chat like the others in the market, you have a lot of things to do, and I think firebase at this time just a support service, cannot serve all your purpose.
Btw, what you mean multiples chats? Is that an account log in to multiple devices, right? If it is, simply just change chattingWith to an array so it's can contain multiples id for your checking.

@duytq94 I'm talking like a normal chat app, you have a list of X users and when some of them send you a message (or vice versa) you get a notification

The current implementation did what you said.

Hi @duytq94 ,

I tested the code on my chat list and did not work, tried again on the chat screen and it's showing the Notification channel on the App Info BUT nothing happens. (but firestore is updated)

Also when I go to Grow - Cloud Messaging, I don't have data and If I try to send a test notification it says that don't have any FCM?

Please follow the article carefully, I think you miss something or step (maybe check the trigger log, bundle ID...).

Yeah I read and checked everything, for example I receive notification but the other test phone have the notification trigger on settings but don't notify.. I'm even using the paid plan.

Why we use local notifications and not push notifications? Still trying to understand.

Also when I press the notification the app don't open

  • For the trigger, you should check the log to know what happens, and that receive-device has a push token? I think you haven't sent the token to user profile.

  • Why we use local notifications and not push notifications? Still trying to understand.
    I think you haven't read the article carefully, I've already noticed about this problem
    Capture

  1. Yes it has pushToken but I'll investigate.

  2. So, if the app is totally closed it never opens app? Any work around by this time or too soon?

  3. Is possible use the notification reply (like messenger, whatsapp, etc) that allow you to write on the notification?

note: Are you available for future jobs?