Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG FIXES: 'Did not receive a response status from last' & Prompt displaying when disabled. #316

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions notice.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
jQuery(document).ready(notice);

var state = {
post_id : ajax_object.post_id, // post id sent from php backend
first_modified : undefined, // when the post was first modified
started : false, // post notification requests started
interval: undefined, // global interval for reattempting requests
interval_count : 0, // how many times has the request been attempted
status : undefined // whether the post is scheduled or published
}
post_id: ajax_object.post_id, // post id sent from php backend
first_modified: undefined, // when the post was first modified
started: false, // post notification requests started
interval: undefined, // global interval for reattempting requests
interval_count: 0, // how many times has the request been attempted
status: undefined // whether the post is scheduled or published
}

function notice() {
if (!isWpCoreEditorDefined()) {
Expand All @@ -26,7 +26,7 @@ function notice() {
const post = editor.getCurrentPost();

// runs until post data loads
if(!post || post === {}){
if (!post || post === {}) {
return;
}

Expand All @@ -45,7 +45,7 @@ function notice() {
const htmlElement = jQuery("#send_onesignal_notification")[0];

if (!!htmlElement) {
send_os_notif = htmlElement.checked;
send_os_notif = htmlElement.checked;
}

// if last modified differs from first modified times, post_modified = true
Expand All @@ -54,7 +54,7 @@ function notice() {
const is_published = status === "publish";

// if hasn't started, change detected, box checked, and the status is 'publish'
if (!state.started && post_modified && send_os_notif && is_published ) {
if (!state.started && post_modified && send_os_notif && is_published) {
state.interval = setInterval(get_metadata, 3000); // starts requests
state.started = true;
}
Expand All @@ -70,22 +70,22 @@ function notice() {
post_id: state.post_id
};

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

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

const is_status_empty = status_code.length == 0;

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

// status 0: HTTP request failed
if (status_code === 0) {
error_notice("OneSignal Push: request failed with status code 0. "+response_body);
error_notice("OneSignal Push: request failed with status code 0. " + response_body);
reset_state();
return;
}
Expand All @@ -95,8 +95,8 @@ function notice() {
if (!response_body) {
error_notice(
"OneSignal Push: there was a " +
status_code +
" error sending your notification"
status_code +
" error sending your notification"
);
} else {
error_notice("OneSignal Push: there was a " + status_code + " error sending your notification: " + response_body);
Expand Down Expand Up @@ -131,7 +131,7 @@ function notice() {
if (state.status === "publish") {
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"){
} else if (state.status === "future") {
var notice_text = "OneSignal Push: Successfully scheduled a notification.";
}

Expand All @@ -141,16 +141,16 @@ function notice() {
"info",
notice_text + delivery_link_text,
{
id:'onesignal-notice',
isDismissible: true
id: 'onesignal-notice',
isDismissible: true
}
);
};

const error_notice = error => {
wp.data.dispatch("core/notices").createNotice("error", error, {
isDismissible: true,
id:'onesignal-error'
isDismissible: true,
id: 'onesignal-error'
});
};

Expand Down Expand Up @@ -194,8 +194,8 @@ const isWpCoreEditorDefined = () => {
* }
*/
window.OneSignal = {
debug : () => {
window.DEBUG_MODE = window.DEBUG_MODE ? !window.DEBUG_MODE : true;
notice();
}
debug: () => {
window.DEBUG_MODE = window.DEBUG_MODE ? !window.DEBUG_MODE : true;
notice();
}
};
Loading