Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: vbgamer45 on February 01, 2019, 05:29:54 AM

Title: Push Notifications
Post by: vbgamer45 on February 01, 2019, 05:29:54 AM
Link to Mod (https://custom.simplemachines.org/mods/index.php?mod=4202)

For SMF 2.0.x

Adds push notifications for Chrome and Firefox using the OneSignal api.
Works for replies and adds support for the following mods
Awesome Post Ratings
@Mentions Mod
Who Quoted Me

Requires an OneSignal account and cURl support for PHP


Install Information:
Install via the SMF's Package Manager via upload package.


############################################
Title: Re: Push Notifications
Post by: pocttopus on February 01, 2019, 06:56:33 AM
Interesting feature... these notifications were missing for SMF.
But where is Who Quoted Me mod?  ???
Title: Re: Push Notifications
Post by: Mick. on February 01, 2019, 07:21:47 AM
Bro, very cool. I was just thinking about this the other day as I noticed a few websites prompted me with a small popup if I wanted to be notified. Interesting, Im going to try this and see whats up  ;)
Title: Re: Push Notifications
Post by: Arantor on February 01, 2019, 07:40:43 AM
Interesting feature... these notifications were missing for SMF.
But where is Who Quoted Me mod?  ???

SMF 2.1 can do this but not with push notifications. Though I love how your first reaction is not “oh, a cool new thing” but essentially a criticism.
Title: Re: Push Notifications
Post by: Shambles on February 01, 2019, 07:46:24 AM
But where is Who Quoted Me mod?  ???

It's an SMFHACKS mod:    https://www.smfhacks.com/index.php?topic=9724.0
Title: Re: Push Notifications
Post by: pocttopus on February 01, 2019, 08:35:10 AM
Interesting feature... these notifications were missing for SMF.
But where is Who Quoted Me mod?  ???

SMF 2.1 can do this but not with push notifications. Though I love how your first reaction is not “oh, a cool new thing” but essentially a criticism.
I had tried to use 2.1 but only on localhost and that's not the real feeling how 2.1 behaves comparing to 2.0.15 which is our current version on our community, so I did not noticed that quote notifications are implemented on 2.1. :-\
I had no intention to write criticism, I was just curious about the mods which are supported by "push notifications".  :)

But where is Who Quoted Me mod?  ???

It's an SMFHACKS mod:    https://www.smfhacks.com/index.php?topic=9724.0
Thanks!  ;)
Title: Re: Push Notifications
Post by: Rock Lee on February 01, 2019, 09:48:23 AM
Great, that's what I was looking for. Now to test it on a test site and see if it's what I need... Thank you for your work @vbgamer45!


Regards!
Title: Re: Push Notifications
Post by: vbgamer45 on February 01, 2019, 09:57:39 AM
The who quoted mod is in the approval process as well.

I originally did the push notifications system for create a forum but then realized the service I used did not support wildcard dns subdomains without having it setup for each.

I can add some more notifications and toggles to turn then on and off depending on feedback.
Title: Re: Push Notifications
Post by: Mick. on February 01, 2019, 11:39:20 PM
Hey bro, whats' the difference between your mod and this tiny script you can add into the index.template in the <head> section taken from their website?  :o

Code: [Select]
<link rel="manifest" href="/manifest.json" />
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
  var OneSignal = window.OneSignal || [];
  OneSignal.push(function() {
    OneSignal.init({
      appId: "**********************************",
    });
  });
</script>
Title: Re: Push Notifications
Post by: vbgamer45 on February 02, 2019, 08:48:55 AM
That is a base script. That script doesn't track members. You can't do mass messages though their backend.
Doesn't have subscribe,unsubscribe options via html.  And you wouldn't be able to receive alerts if someone replied to your topic.
Title: Re: Push Notifications
Post by: Mick. on February 02, 2019, 08:54:22 AM
That is a base script. That script doesn't track members. You can't do mass messages though their backend.
Doesn't have subscribe,unsubscribe options via html.  And you wouldn't be able to receive alerts if someone replied to your topic.
Oh right on. Even better, I'm giving it a whirl
Title: Re: Push Notifications
Post by: vbgamer45 on February 02, 2019, 09:08:58 AM
Have some fun with it maybe you can make it look nicer. I am backend developer so I just try to build out the core functions.
Title: Re: Push Notifications
Post by: Shambles on February 02, 2019, 10:05:53 AM
Hmm might have a play with this mod - thanks for making it available.

I manually installed the code from OneSignal and it seems quite accurate with its stats, plus the instant messaging is decent.
Title: Re: Push Notifications
Post by: Shambles on February 02, 2019, 10:56:58 AM
The mod installs the .js files into $boarddir but the code is looking in the website root for them:

Quote
Failed to register/update a ServiceWorker for scope ‘https://www.i30ownersclub.com/’: Load failed with status 404 for script ‘https://www.i30ownersclub.com/OneSignalSDKWorker.js?appId=5212**********************202d’

$boarddir for me is https://www.i30ownersclub.com/forum/

Guess I'll just move the files up a level...
Title: Re: Push Notifications
Post by: vbgamer45 on February 02, 2019, 11:09:37 AM
Yeah forgot about people in subfolders.
Title: Re: Push Notifications
Post by: Shambles on February 02, 2019, 11:13:31 AM
I've moved the three files up to the root but not a great deal is happening (no further errors in the console though).

Question:

Both the .js files contain the same importScripts command. Is this by design?

Code: [Select]
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
Title: Re: Push Notifications
Post by: vbgamer45 on February 02, 2019, 11:18:34 AM
I believe so
Title: Re: Push Notifications
Post by: Shambles on February 02, 2019, 11:44:27 AM
Just trying to work out why nothing happens when the mod is installed (ie, messages aren't received, notifications not requested).

Does the mod not require a manifest.json file?
Title: Re: Push Notifications
Post by: vbgamer45 on February 02, 2019, 11:46:03 AM
Requires manifest.json

cURL needs to be installed.

After you click the subscribe to notifications in your user account and some replies. You should get a push notification in your browser. Tested on firefox and chrome.
Title: Re: Push Notifications
Post by: Shambles on February 02, 2019, 11:53:07 AM
I can see the manifest is built by the mod, just wondered if it needed <link rel="manifest" href="/manifest.json" />

When I inserted the OneSignal code manually in my index.template.php the whole thing worked perfectly.

Title: Re: Push Notifications
Post by: vbgamer45 on February 02, 2019, 12:06:59 PM
I would include that as well just in case.
For the onesignal code it should be inserted automatically by the mod. And the code the mod uses passes the member id without it you will not get notified.
Title: Re: Push Notifications
Post by: Shambles on February 02, 2019, 12:41:22 PM
Should this class be declared somewhere?

Code: [Select]
<li><div class="onesignal-customlink-container"></div></li>
Title: Re: Push Notifications
Post by: vbgamer45 on February 02, 2019, 12:46:11 PM
You can check how I ran it on https://demoforum.createaforum.com/
Title: Re: Push Notifications
Post by: Mick. on February 03, 2019, 01:34:59 PM
Have some fun with it maybe you can make it look nicer. I am backend developer so I just try to build out the core functions.
There's nothing to style! Hahaha other than that default red unsubscribe button but I think the user can do that directly from the mod's site.

ps,....I know I've been styling your stuff lol, I take no credit for your work. I just hack it. lol
Title: Re: Push Notifications
Post by: Mick. on February 04, 2019, 07:49:28 PM
Just realized that this is a browser basis thing. I logged in with diff users and it showed i was already subscribed. No big deal, That works for me.
Title: Re: Push Notifications
Post by: vbgamer45 on February 04, 2019, 07:58:29 PM
Hmm will need to look into that.
Title: Re: Push Notifications
Post by: Mick. on February 04, 2019, 08:02:38 PM
Hmm will need to look into that.
There's a good chance this is all on OneSignal
Title: Re: Push Notifications
Post by: Study Force on February 05, 2019, 01:47:56 AM
Ahmmm... 1.x?
Title: Re: Push Notifications
Post by: Arantor on February 05, 2019, 02:45:39 AM
Ahmmm... 1.x?

You know 1.1 is in all practical senses EOL, right?
Title: Re: Push Notifications
Post by: Study Force on February 05, 2019, 03:00:44 PM
Thanks for the reminder, looking forward to the next
Title: Re: Push Notifications
Post by: addlife on February 10, 2019, 05:36:29 PM
Link to Mod (https://custom.simplemachines.org/mods/index.php?mod=4202)

For SMF 2.0.x

Adds push notifications for Chrome and Firefox using the OneSignal api.
Works for replies and adds support for the following mods
Awesome Post Ratings
@Mentions Mod
Who Quoted Me

Requires an OneSignal account and cURl support for PHP


Install Information:
Install via the SMF's Package Manager via upload package.


############################################

Hi thanks for this mod. I don't really know how to code.

I installed the mod. Signed up for a onesignal account. I think I set up the webpush thing on onesignals website correctly. Just a FYI my test website isn't https, I don't know if that makes a difference.

I'm holding by the part where it tells me to insert some code into the <head> of my website. Which file would that be? I'm assuming it's one of the files in the public_html folder on my cpanel file manager (maybe index.html_ or index.php), is that correct?

Also how do I know if my website supports that cURl thing mentioned?

Any help would be appreciated.
Thanks.

One more thing is it possible to only have notifications sent for mentions and quotes, but not for replies?
Title: Re: Push Notifications
Post by: Mick. on February 10, 2019, 05:57:01 PM
When you install the mod, everything its already installed. No need to add any codes from Onesignal. Just sign up, get your numbers.
Title: Re: Push Notifications
Post by: vbgamer45 on February 10, 2019, 07:26:07 PM

Quote
One more thing is it possible to only have notifications sent for mentions and quotes, but not for replies?
Not at the moment but would be possible to do.
Title: Re: Push Notifications
Post by: addlife on February 10, 2019, 07:45:04 PM
When you install the mod, everything its already installed. No need to add any codes from Onesignal. Just sign up, get your numbers.
Thanks. I see it now in the default theme. At first I didn't see the button. Sometimes it's there and sometimes not.

I tested it out and it worked so apparently I have the curl thing.


Quote
One more thing is it possible to only have notifications sent for mentions and quotes, but not for replies?
Not at the moment but would be possible to do.
Ok. thanks for responding.

Also it seems like that for any post that's made anywhere on the forum it sends a notification. Is that the way it's supposed to be?
Title: Re: Push Notifications
Post by: vbgamer45 on February 10, 2019, 09:11:31 PM
It should be any reply made to your post.
Title: Re: Push Notifications
Post by: Mick. on February 15, 2019, 07:31:42 AM
Alright bro, It seems that notifications are for desktop browser only. All this time I thought i'd get notifications on my mobile but didnt. I ended up creating an app on Firebase using One Signal docs and now I get notified on my Android phone. It only took 3 minutes to setup. Thought you should now.
Title: Re: Push Notifications
Post by: vbgamer45 on February 15, 2019, 08:09:23 AM
Is that another code you had to the website?
Title: Re: Push Notifications
Post by: Mick. on February 15, 2019, 08:33:26 AM
Is that another code you had to the website?
Nope. No need. Just direct the mod users to generate a Firebase server key and add it to the mobile section in OneSignal settings.

In OneSignal App settings, we have the browser settings, like for Chrome and other browsers minus Safari. Below it You'll see Native App Platforms, click on Google Android and will ask for Firebase Server key.

Follow this doc https://documentation.onesignal.com/docs/generate-a-google-server-api-key very simple to setup.
Title: Re: Push Notifications
Post by: Mick. on February 15, 2019, 08:37:58 AM
I would think this can be added to admin settings as well but for iOS, well, I looked at it and that seems a whole 'nother ball game especially for users that have no knowledge
Title: Re: Push Notifications
Post by: Mick. on February 15, 2019, 10:26:24 AM
Also, I just noticed that you have to be logged on to the forum to receive notifications. At least on mobile. I'll check on browser later today.
Title: Re: Push Notifications
Post by: vbgamer45 on February 15, 2019, 10:30:49 AM
Yeah it is based on member id thats how notifications gets sent to right person. I add member id as a filter from onesignal.
Title: Re: Push Notifications
Post by: addlife on April 16, 2019, 04:37:53 AM
Is it possible to have the button only displayed on a certain page? For example I would create a thread titled "Push Notifications" then on that page the button will show up.
Title: Re: Push Notifications
Post by: vbgamer45 on April 16, 2019, 08:23:18 AM
yes but you would have to change the logic for it.
Title: Re: Push Notifications
Post by: refx on May 13, 2019, 02:01:59 PM
Yeah it is based on member id thats how notifications gets sent to right person. I add member id as a filter from onesignal.

Hello,
I've installed the plugin, after copying .js files to root, it started working (before that I got 404 errors on onesignal panel). But I got many user reports who are unable to subscribe. When I check oneSignal users/allusers page, under tags column,  While I get couple of user id and uname correct, I see that there are multiple entries tagged "{uid: 0}" with different player ids. Also most of the tags are empty, totally blank tag information. App Version column is also completely blank.

Any ideas what's wrong with my installation?
Title: Re: Push Notifications
Post by: Christopher Scott Case on August 09, 2019, 12:27:38 PM
@vbgamer45 Hey, I've noticed that on replies to forum messages, I get notified when I reply to a topic I started, not just other people. It's annoying enough both myself and several of my users have decided not to use the notifications, because it's frustrating to get that extra notification.

If you can point me in the right direction, I'll gladly make the modification to filter out self replies myself. I was looking at the code, and I think I see where you're setting up a filter by user id, but as a JS dev with little PHP knowledge (and no SMF modding knowledge), I might not be following it correctly.
Title: Re: Push Notifications
Post by: Study Force on August 09, 2019, 02:08:09 PM
@vbgamer45 Hey, I've noticed that on replies to forum messages, I get notified when I reply to a topic I started, not just other people. It's annoying enough both myself and several of my users have decided not to use the notifications, because it's frustrating to get that extra notification.

If you can point me in the right direction, I'll gladly make the modification to filter out self replies myself. I was looking at the code, and I think I see where you're setting up a filter by user id, but as a JS dev with little PHP knowledge (and no SMF modding knowledge), I might not be following it correctly.

Let me get this straight, you start a topic, you reply to your topic, then you get notified (that's odd)
However, when others reply to your topic, you do not get notified (another oddity). Am I reading this correctly?