Push Notification b...
 
Notifications
Clear all

Push Notification by Onesignal?

12 Posts
3 Users
0 Likes
1,266 Views
(@zillink)
Posts: 8
Active Member
Topic starter
 

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!

 
Posted : 08/05/2017 2:21 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

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

 
Posted : 08/05/2017 2:59 am
(@zillink)
Posts: 8
Active Member
Topic starter
 

wow, prompt and useful answer.

I'm waiting for 3.x live on the AssetStore then buy it. Just can't wait for that.wub

 
Posted : 08/05/2017 3:01 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

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

 
Posted : 08/05/2017 3:16 am
(@zillink)
Posts: 8
Active Member
Topic starter
 

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

 
Posted : 08/05/2017 3:49 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

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

 
Posted : 08/05/2017 1:04 pm
(@zillink)
Posts: 8
Active Member
Topic starter
 

I bought 3.0 on the AssetStore. Can I show you the invoice number to get instant updates in here?

 
Posted : 09/05/2017 7:29 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Sure, insert your invoice number at here.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 09/05/2017 11:52 am
(@pixelcoder)
Posts: 7
Active Member
 

Hi Francesco, I tried you example with auto-check messages, but I got ...

 
Posted : 11/07/2018 4:25 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

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

 
Posted : 11/07/2018 7:15 pm
(@pixelcoder)
Posts: 7
Active Member
 

Francesco, thanks for helping 😛 ...what is the progress for Chat addon? Thanks!

 
Posted : 13/07/2018 11:05 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 
Posted by: PixelCoder

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

 
Posted : 13/07/2018 1:03 pm
Share: