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

Don't default to document title if no notification title present #674

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/OneSignal.ts
Expand Up @@ -306,7 +306,6 @@ export default class OneSignal {
MainHelper.checkAndTriggerNotificationPermissionChanged();
});

await InitHelper.initSaveState(document.title);
await InitHelper.saveInitOptions();
if (SdkEnvironment.getWindowEnv() === WindowEnvironmentKind.CustomIframe)
await Event.trigger(OneSignal.EVENTS.SDK_INITIALIZED);
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/InitHelper.ts
Expand Up @@ -265,7 +265,7 @@ export default class InitHelper {
if (registration && registration.active) {
await OneSignal.context.serviceWorkerManager.establishServiceWorkerChannel();
}
} catch (e) {
} catch (e) {
Log.error(e);
}
}
Expand Down Expand Up @@ -475,7 +475,7 @@ export default class InitHelper {
public static async initSaveState(overridingPageTitle: string) {
const appId = await MainHelper.getAppId();
await Database.put('Ids', { type: 'appId', id: appId });
const initialPageTitle = overridingPageTitle || document.title || 'Notification';
const initialPageTitle = overridingPageTitle || '';
await Database.put('Options', { key: 'pageTitle', value: initialPageTitle });
Log.info(`OneSignal: Set pageTitle to be '${initialPageTitle}'.`);
const config: AppConfig = OneSignal.config;
Expand Down
36 changes: 8 additions & 28 deletions src/service-worker/ServiceWorker.ts
Expand Up @@ -102,7 +102,6 @@ export class ServiceWorker {
event.waitUntil(ServiceWorker.onPushSubscriptionChange(event))
});


self.addEventListener('message', (event: ExtendableMessageEvent) => {
const data: WorkerMessengerMessage = event.data;
if (!data || !data.command) {
Expand Down Expand Up @@ -213,7 +212,7 @@ export class ServiceWorker {

const timestamp = payload.timestamp;
if (self.clientsStatus.timestamp !== timestamp) { return; }

self.clientsStatus.receivedResponsesCount++;
if (payload.focused) {
self.clientsStatus.hasAnyActiveSessions = true;
Expand Down Expand Up @@ -357,18 +356,18 @@ export class ServiceWorker {
if (!hasRequiredParams) {
return null;
}

// JSON.stringify() does not include undefined values
// Our response will not contain those fields here which have undefined values
const postData = {
player_id : deviceId,
player_id : deviceId,
app_id : appId
};

Log.debug(`Called %csendConfirmedDelivery(${
JSON.stringify(notification, null, 4)
})`, Utils.getConsoleStyle('code'));

return await OneSignalApiBase.put(`notifications/${notification.id}/report_received`, postData);
}

Expand Down Expand Up @@ -432,7 +431,7 @@ export class ServiceWorker {
* if https -> getActiveClients -> check for the first focused
* unfortunately, not enough for safari, it always returns false for focused state of a client
* have to workaround it with messaging to the client.
*
*
* if http, also have to workaround with messaging:
* SW to iframe -> iframe to page -> page to iframe -> iframe to SW
*/
Expand Down Expand Up @@ -602,7 +601,8 @@ export class ServiceWorker {
Log.debug(`Called %cdisplayNotification(${JSON.stringify(notification, null, 4)}):`, Utils.getConsoleStyle('code'), notification);

// Use the default title if one isn't provided
const defaultTitle = await ServiceWorker._getTitle();
const defaultTitle = await Database.get("Options", "defaultTitle") || "";

// Use the default icon if one isn't provided
const defaultIcon = await Database.get('Options', 'defaultIcon');
// Get option of whether we should leave notification displaying indefinitely
Expand Down Expand Up @@ -1093,26 +1093,6 @@ export class ServiceWorker {
}
}

/**
* Returns a promise that is fulfilled with either the default title from the database (first priority) or the page title from the database (alternate result).
*/
static _getTitle() {
return new Promise(resolve => {
Promise.all([Database.get('Options', 'defaultTitle'), Database.get('Options', 'pageTitle')])
.then(([defaultTitle, pageTitle]) => {
if (defaultTitle !== null) {
resolve(defaultTitle);
}
else if (pageTitle != null) {
resolve(pageTitle);
}
else {
resolve('');
}
});
});
}

/**
* Returns an array of raw notification objects, read from the event.data.payload property
* @param event
Expand Down