Skip to content

Commit fb4a2f7

Browse files
authored
Add resubgift and anonresubgift contexts to the pubsub subscription message (twurple#271)
* Add resubgift and anonresubgift contexts to the pubsub subscription message * Add anonsubgift and anonresubgift contexts to the isGift function * Fix code style according to prettier
1 parent 3ce8f55 commit fb4a2f7

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

packages/twitch-pubsub-client/src/Messages/PubSubSubscriptionMessage.ts

+32-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface PubSubSubscriptionDetail {
1212

1313
/** @private */
1414
export interface PubSubSubscriptionGiftDetail {
15-
context: 'subgift' | 'anonsubgift';
15+
context: 'subgift' | 'anonsubgift' | 'resubgift' | 'anonresubgift';
1616
recipient_id: string;
1717
recipient_user_name: string;
1818
recipient_display_name: string;
@@ -46,7 +46,10 @@ export class PubSubSubscriptionMessage {
4646
* The ID of the user subscribing to the channel.
4747
*/
4848
get userId(): string {
49-
return this._data.context === 'subgift' || this._data.context === 'anonsubgift'
49+
return this._data.context === 'subgift' ||
50+
this._data.context === 'anonsubgift' ||
51+
this._data.context === 'resubgift' ||
52+
this._data.context === 'anonresubgift'
5053
? this._data.recipient_id
5154
: this._data.user_id;
5255
}
@@ -55,7 +58,10 @@ export class PubSubSubscriptionMessage {
5558
* The name of the user subscribing to the channel.
5659
*/
5760
get userName(): string {
58-
return this._data.context === 'subgift' || this._data.context === 'anonsubgift'
61+
return this._data.context === 'subgift' ||
62+
this._data.context === 'anonsubgift' ||
63+
this._data.context === 'resubgift' ||
64+
this._data.context === 'anonresubgift'
5965
? this._data.recipient_user_name
6066
: this._data.user_name;
6167
}
@@ -64,7 +70,10 @@ export class PubSubSubscriptionMessage {
6470
* The display name of the user subscribing to the channel.
6571
*/
6672
get userDisplayName(): string {
67-
return this._data.context === 'subgift' || this._data.context === 'anonsubgift'
73+
return this._data.context === 'subgift' ||
74+
this._data.context === 'anonsubgift' ||
75+
this._data.context === 'resubgift' ||
76+
this._data.context === 'anonresubgift'
6877
? this._data.recipient_display_name
6978
: this._data.display_name;
7079
}
@@ -75,7 +84,10 @@ export class PubSubSubscriptionMessage {
7584
* Returns 0 if a gift sub or the streaks months.
7685
*/
7786
get streakMonths(): number {
78-
return this._data.context === 'subgift' || this._data.context === 'anonsubgift'
87+
return this._data.context === 'subgift' ||
88+
this._data.context === 'anonsubgift' ||
89+
this._data.context === 'resubgift' ||
90+
this._data.context === 'anonresubgift'
7991
? 0
8092
: (this._data as PubSubSubscriptionDetail).streak_months;
8193
}
@@ -86,7 +98,10 @@ export class PubSubSubscriptionMessage {
8698
* Returns the months if a gift sub or the cumulative months.
8799
*/
88100
get cumulativeMonths(): number {
89-
return this._data.context === 'subgift' || this._data.context === 'anonsubgift'
101+
return this._data.context === 'subgift' ||
102+
this._data.context === 'anonsubgift' ||
103+
this._data.context === 'resubgift' ||
104+
this._data.context === 'anonresubgift'
90105
? this._data.months
91106
: (this._data as PubSubSubscriptionDetail).cumulative_months;
92107
}
@@ -134,14 +149,19 @@ export class PubSubSubscriptionMessage {
134149
* Whether the subscription is a gift.
135150
*/
136151
get isGift(): boolean {
137-
return this._data.context === 'subgift';
152+
return (
153+
this._data.context === 'subgift' ||
154+
this._data.context === 'resubgift' ||
155+
this._data.context === 'anonsubgift' ||
156+
this._data.context === 'anonresubgift'
157+
);
138158
}
139159

140160
/**
141161
* Whether the subscription is from an anonymous gifter.
142162
*/
143163
get isAnonymous(): boolean {
144-
return this._data.context === 'anonsubgift';
164+
return this._data.context === 'anonsubgift' || this._data.context === 'anonresubgift';
145165
}
146166

147167
/**
@@ -177,7 +197,10 @@ export class PubSubSubscriptionMessage {
177197
* Returns null if the subscription is not a gift.
178198
*/
179199
get giftDuration(): number | null {
180-
return this._data.context === 'subgift' || this._data.context === 'anonsubgift'
200+
return this._data.context === 'subgift' ||
201+
this._data.context === 'resubgift' ||
202+
this._data.context === 'anonsubgift' ||
203+
this._data.context === 'anonresubgift'
181204
? this._data.multi_month_duration
182205
: null;
183206
}

0 commit comments

Comments
 (0)