Skip to content

Commit

Permalink
feat(pubsub): add subscription duration (#439)
Browse files Browse the repository at this point in the history
Removed "giftDuration" accessor and created "duration" accessor instead that refers to all subscription contexts.
  • Loading branch information
StimulCross committed Dec 29, 2022
1 parent 538f3a9 commit 4d4b191
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Expand Up @@ -14,7 +14,6 @@ export interface PubSubSubscriptionGiftDetail {
recipient_user_name: string;
recipient_display_name: string;
months: number;
multi_month_duration: number;
}

/** @private */
Expand All @@ -23,4 +22,5 @@ export type PubSubSubscriptionMessageData = PubSubBasicMessageInfo & {
sub_plan: 'Prime' | '1000' | '2000' | '3000';
sub_plan_name: string;
sub_message: PubSubChatMessage;
multi_month_duration?: number;
} & (PubSubSubscriptionDetail | PubSubSubscriptionGiftDetail);
15 changes: 5 additions & 10 deletions packages/pubsub/src/messages/PubSubSubscriptionMessage.ts
Expand Up @@ -167,17 +167,12 @@ export class PubSubSubscriptionMessage extends DataObject<PubSubSubscriptionMess
}

/**
* The duration of the gifted subscription, in months.
* The duration of subscription, in months.
*
* Returns null if the subscription is not a gift.
* This refers to first-time subscriptions, auto-renewal subscriptions, re-subscriptions, or gifted subscriptions.
*/
get giftDuration(): number | null {
const data = this[rawDataSymbol];
return data.context === 'subgift' ||
data.context === 'resubgift' ||
data.context === 'anonsubgift' ||
data.context === 'anonresubgift'
? data.multi_month_duration
: null;
get duration(): number {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return this[rawDataSymbol].multi_month_duration || 1;
}
}

0 comments on commit 4d4b191

Please sign in to comment.