How can we trigger push notifications when user sent a new message to others?
Should we do it in client or server side and how?
thanks much!
Since Combu is running in a connectionless environment then there's no "push" of any update, instead your client needs to poll from server to get updates.
You could have a script that periodically check for new messages:
using UnityEngine; using System.Collections.Generic; using Combu; public class CheckMail : MonoBehaviour { static CheckMail instance; public float tick = 30f; float nextTick = 0; bool checking = false; List<System.Action<int>> onNewMessages = new List<System.Action<int>>(); void Start() { instance = this; } public static void RegisterNotification(System.Action<int> callback) { if (instance != null && callback != null) { instance.onNewMessages.Add (callback); } } public static void UnregisterNotification(System.Action<int> callback) { if (instance != null) { instance.onNewMessages.Remove (callback); } } void FixedUpdate () { if (CombuManager.isInitialized && CombuManager.localUser.authenticated && Time.time >= nextTick && !checking) { checking = true; Debug.Log ("Checking new messages"); Mail.Load (eMailList.Unread, 1, 1, (Mail[] messages, int countMessages, int countPages, string error) => { int unread = 0; foreach (var message in messages) { if (!message.isRead) ++unread; } if (unread > 0) { foreach (var action in onNewMessages) { action(unread); } } nextTick = Time.time + tick; checking = false; }); } } }
Attach this script to a GameObject and use it in your own script like this:
CheckMail.RegisterNotification ((int unread) => { Debug.LogWarning("You have " + unread + " new messages"); });
FRANCESCO CROCETTI @ SKARED CREATIONS
wow, prompt and useful answer.
I'm waiting for 3.x live on the AssetStore then buy it. Just can't wait for that.
No problem, anyway it could be useful to have only the list of unread messages so I'll probably add eMailList.Unread so that the query will filter only those messages for better performance and more control. Will add in 3.0.1
FRANCESCO CROCETTI @ SKARED CREATIONS
Sound great! I will buy all of your Assets on the assetStore. Cause my in-app community need them all.
Once more missing thing that would be helpful is Chat. Do you have any plan adding Chat/Room into main pack or create it separately?
I know there are many chat packages out there but it be better to have it as closed-cycle of Combu
Yes I'm already working on a poll-based (not real-time of course) Chat add-on, it'll be a paid add-on like Forum etc. But there's currently no ETA for its completion, I was too busy on refactoring Combu core for version 3.
Probably now that Combu 3 is released I can have more time to continue its development, if you've subscribed to the newsletter then will be notified when it will be out.
Though I'm thinking to the implementation of auto-updater for the server, before releasing more content, I will see.
FRANCESCO CROCETTI @ SKARED CREATIONS
I bought 3.0 on the AssetStore. Can I show you the invoice number to get instant updates in here?
Sure, insert your invoice number at here.
FRANCESCO CROCETTI @ SKARED CREATIONS
Hi Francesco, I tried you example with auto-check messages, but I got ...
Oh I suppose the forum scripts had altered my code when I sent the post: where ever you see System.Action it was meant to be System.Action<int> (I edited that post right now with the correct code).
PS: sorry I clicked EDIT instead of REPLY on your message and replaced it with my answer, then I re-edited it and pasted a part of your original message 😆
FRANCESCO CROCETTI @ SKARED CREATIONS
Francesco, thanks for helping 😛 ...what is the progress for Chat addon? Thanks!
what is the progress for Chat addon?
Unfortunately I was very busy in the last few months, so the development of the Chat addon has been currently paused. I will probably continue it by September.
FRANCESCO CROCETTI @ SKARED CREATIONS