Skip to content

Commit

Permalink
Additional comments / comment fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jkasten2 committed Apr 22, 2021
1 parent 6f30b77 commit 874e689
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/managers/channelManager/shared/SecondaryChannel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Interface provided outside of this module.

import { TagsObject } from "../../../models/Tags";

// Interface provided outside of this module.
// Example: OneSignal.ts as a consumer.
export interface SecondaryChannel {
setIdentifier(identifier: string, authHash?: string): Promise<string | null>;
Expand Down
24 changes: 13 additions & 11 deletions src/managers/channelManager/shared/SecondaryChannelEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,40 @@ export class SecondaryChannelEmail implements SecondaryChannel, SecondaryChannel
) {}

async logout(): Promise<boolean> {
// TODO: Explain that email has a REST API logout with parent_player_id
const { deviceId } = await Database.getSubscription();
if (!deviceId) {
Log.warn(new NotSubscribedError(NotSubscribedReason.NoDeviceId));
return false;
}

// 1. Check if we have an registered email to logout to begin with.
const emailProfile = await Database.getEmailProfile();
if (!emailProfile.subscriptionId) {
Log.warn(new NotSubscribedError(NotSubscribedReason.NoEmailSet));
return false;
}

const appConfig = await Database.getAppConfig();
// 2. Logout only applies if we a de-linking email from a push record.
const { deviceId } = await Database.getSubscription();
if (!deviceId) {
Log.warn(new NotSubscribedError(NotSubscribedReason.NoDeviceId));
return false;
}

// 3. Make logout email REST API call
const appConfig = await Database.getAppConfig();
if (!await OneSignalApi.logoutEmail(appConfig, emailProfile, deviceId)) {
Log.warn("Failed to logout email.");
return false;
}

// 4. If above is successful clear the email profile.
await Database.setEmailProfile(new EmailProfile());
return true;
}

async setIdentifier(identifier: string, authHash?: string): Promise<string | null> {
const { profileProvider } = this.secondaryChannelIdentifierUpdater;
const existingEmailProfile = await profileProvider.getProfile();
const emailProfileBefore = await profileProvider.getProfile();
const newEmailSubscriptionId = await this.secondaryChannelIdentifierUpdater.setIdentifier(identifier, authHash);

if (newEmailSubscriptionId) {
const newEmailProfile = profileProvider.newProfile(newEmailSubscriptionId, identifier);
await this.updatePushPlayersRelationToEmailPlayer(existingEmailProfile, newEmailProfile);
const emailProfileAfter = profileProvider.newProfile(newEmailSubscriptionId, identifier);
await this.updatePushPlayersRelationToEmailPlayer(emailProfileBefore, emailProfileAfter);
}

return newEmailSubscriptionId;
Expand Down

0 comments on commit 874e689

Please sign in to comment.