Skip to content

Commit

Permalink
Merge pull request #312 from OneSignal/update-recipient-count
Browse files Browse the repository at this point in the history
2.4.0 Release - remove recipient count
  • Loading branch information
rgomezp authored Mar 28, 2023
2 parents ec26ff9 + 31a289c commit 8540956
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 57 deletions.
39 changes: 14 additions & 25 deletions notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ function notice() {
}

const editor = wp.data.select("core/editor");
const get_wp_attr = attr => {
return editor.getEditedPostAttribute(attr);
};

/*
* Subscribes function to WP's state-change listener
Expand Down Expand Up @@ -46,7 +43,7 @@ function notice() {
// is checked
let send_os_notif;
const htmlElement = jQuery("#send_onesignal_notification")[0];

if (!!htmlElement) {
send_os_notif = htmlElement.checked;
}
Expand Down Expand Up @@ -75,18 +72,19 @@ function notice() {

jQuery.get(ajax_object.ajax_url, data, function(response) {
response = JSON.parse(response);
const { recipients, status_code, response_body } = response;
const { status_code, response_body } = response;

if(window.DEBUG_MODE){
console.log(response);
}

const is_status_empty = status_code.length == 0;
const is_recipients_empty = recipients.length == 0;

if(!is_status_empty && !is_recipients_empty){
if(!is_status_empty){
status_code = parseInt(status_code);

// status 0: HTTP request failed
if (status_code === "0") {
if (status_code === 0) {
error_notice("OneSignal Push: request failed with status code 0. "+response_body);
reset_state();
return;
Expand All @@ -108,16 +106,8 @@ function notice() {
return;
}

if (recipients === "0") {
error_notice(
"OneSignal Push: there were no recipients."
);
reset_state();

} else if (recipients) {
show_notice(recipients);
reset_state();
}
show_notice();
reset_state();
}
});

Expand All @@ -128,29 +118,28 @@ function notice() {
);
reset_state();
}

state.interval_count += 1;
};

/*
* Gets recipient count and shows notice
*/
const show_notice = recipients => {
const plural = recipients == 1 ? "" : "s";
const show_notice = () => {
var delivery_link_text = "";

if (state.status === "publish") {
var notice_text = "OneSignal Push: Successfully sent a notification to ";
delivery_link_text = ". Go to your app's \"Delivery\" tab to check sent messages: https://app.onesignal.com/apps";
var notice_text = "OneSignal Push: Successfully sent a notification.";
delivery_link_text = " Go to your app's Delivery tab to check sent messages: https://dashboard.onesignal.com/apps/";
} else if (state.status === "future"){
var notice_text = "OneSignal Push: Successfully scheduled a notification for ";
var notice_text = "OneSignal Push: Successfully scheduled a notification.";
}

wp.data
.dispatch("core/notices")
.createNotice(
"info",
notice_text + recipients + " recipient" + plural + delivery_link_text,
notice_text + delivery_link_text,
{
id:'onesignal-notice',
isDismissible: true
Expand Down
32 changes: 7 additions & 25 deletions onesignal-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,34 +949,16 @@ public static function send_notification_on_wp_post($new_status, $old_status, $p
}
} else {
if (!empty($response)) {

// API can send a 200 OK even if the notification failed to send
if (isset($response['body'])) {
$response_body = json_decode($response['body'], true);
if (isset($response_body['recipients'])) {
$recipient_count = $response_body['recipients'];
}
}

// updates meta so that recipient count is available for GET request from client
update_post_meta($post->ID, 'recipients', $recipient_count);

$sent_or_scheduled = array_key_exists('send_after', $fields) ? 'scheduled' : 'sent';
$config_show_notification_send_status_message = $onesignal_wp_settings['show_notification_send_status_message'] === true;

if ($config_show_notification_send_status_message) {
if ($recipient_count !== 0) {
$delivery_link_text = $sent_or_scheduled === 'sent' ? ' Go to your app\'s "Delivery" tab to check sent messages: <a target="_blank" href="https://app.onesignal.com/apps/">https://app.onesignal.com/apps/</a>' : '';
set_transient('onesignal_transient_success', '<div class="updated notice notice-success is-dismissible">
<div class="components-notice__content">
<p><strong>OneSignal Push:</strong><em> Successfully '.$sent_or_scheduled.' a notification to '.$recipient_count.' recipients.'.$delivery_link_text.'</em></p>
</div>
</div>', 86400);
} else {
set_transient('onesignal_transient_success', '<div class="updated notice notice-success is-dismissible">
<p><strong>OneSignal Push:</strong><em>There were no recipients. You likely have no subscribers.</em></p>
</div>', 86400);
}
$app_id = $onesignal_wp_settings['app_id'];
$delivery_link_text = ' Go to your app\'s Delivery tab to check sent messages: </em><a target="_blank" href="https://dashboard.onesignal.com/apps/' . $app_id . '/notifications">https://dashboard.onesignal.com/apps/' . $app_id . '/notifications</a><em>';
set_transient('onesignal_transient_success', '<div class="updated notice notice-success is-dismissible">
<div class="components-notice__content">
<p><strong>OneSignal Push:</strong><em> Successfully scheduled a notification.' . $delivery_link_text . '</em></p>
</div>
</div>', 86400);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions onesignal-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function add_async_for_script($url)
else if (is_admin())
return str_replace('#asyncload', '', $url);
else
return str_replace('#asyncload', '', $url)."' async='async";
return str_replace('#asyncload', '', $url)."' async='async";
}

class OneSignal_Public
Expand Down Expand Up @@ -321,15 +321,15 @@ public static function onesignal_header()
OneSignal.init(window._oneSignalInitOptions);
<?php
}

if (array_key_exists('prompt_auto_register', $onesignal_wp_settings) && $onesignal_wp_settings['prompt_auto_register'] === true) {
echo "OneSignal.showSlidedownPrompt();";
}

if (array_key_exists('use_native_prompt', $onesignal_wp_settings) && $onesignal_wp_settings['use_native_prompt'] === true) {
echo "OneSignal.showNativePrompt();";
}

} else {
?>
/* OneSignal: Using custom SDK initialization. */
Expand Down
2 changes: 1 addition & 1 deletion onesignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin Name: OneSignal Push Notifications
* Plugin URI: https://onesignal.com/
* Description: Free web push notifications.
* Version: 2.3.3
* Version: 2.4.0
* Author: OneSignal
* Author URI: https://onesignal.com
* License: MIT
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: OneSignal
Donate link: https://onesignal.com
Tags: push notification, push notifications, desktop notifications, mobile notifications, chrome push, android, android notification, android notifications, android push, desktop notification, firefox, firefox push, mobile, mobile notification, notification, notifications, notify, onesignal, push, push messages, safari, safari push, web push, chrome
Requires at least: 3.8
Tested up to: 6.1
Stable tag: 2.3.3
Tested up to: 6.3
Stable tag: 2.4.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -23,7 +23,7 @@ You can configure notification delivery at preset intervals, create user segment
OneSignal’s free plan allows targeting up to 10,000 subscribers with push notifications. Contact [email protected] if you have any questions. We’d love to hear from you!

= Company =
OneSignal is trusted by over 1,800,000 developers and marketing strategists. We power push notifications for everyone from early stage startups to Fortune 500 Companies, sending over 6 billion notifications per day. It is the most popular push notification plugin on Wordpress with 100,000+ installations.
OneSignal is trusted by over 1.8M+ developers and marketing strategists. We power push notifications for everyone from early stage startups to Fortune 500 Companies, sending over 6 billion notifications per day. It is the most popular push notification plugin on Wordpress with 100,000+ installations.

= Features =
* **Supports Chrome** (Desktop & Android), **Safari** (Mac OS X), **Microsoft Edge** (Desktop & Android), **Opera** (Desktop & Android) and **Firefox** (Desktop & Android) on both HTTP and HTTPS sites.
Expand Down Expand Up @@ -67,6 +67,9 @@ HTTPS Setup Video: [youtube https://www.youtube.com/watch?v=BeTZ2KgytC0]

== Changelog ==

= 2.4.0 =
- Remove recipient count after post publishing.

= 2.3.3 =
- Update "Tested up to" Wordpress version 6.1

Expand Down

0 comments on commit 8540956

Please sign in to comment.