@streamlayer/feature-gamification 1.9.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,8 +12,10 @@ export type Advertisement = {
|
|
|
12
12
|
hiding?: boolean;
|
|
13
13
|
isViewed?: boolean;
|
|
14
14
|
isOpened?: boolean;
|
|
15
|
+
isPaused?: boolean;
|
|
15
16
|
hasNotification?: boolean;
|
|
16
17
|
close?: () => void;
|
|
18
|
+
togglePause?: (flag: boolean) => void;
|
|
17
19
|
error?: string;
|
|
18
20
|
ctx?: Record<string, unknown>;
|
|
19
21
|
};
|
|
@@ -93,6 +93,7 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
|
|
|
93
93
|
data: response,
|
|
94
94
|
hasNotification: response?.notification?.enabled === NotificationEnabled.NOTIFICATION_ENABLED,
|
|
95
95
|
close: () => hide(response?.question.id),
|
|
96
|
+
togglePause: (status) => pause(response?.question.id, status),
|
|
96
97
|
isViewed: response && !!storage.isViewed(response.question.id),
|
|
97
98
|
}))
|
|
98
99
|
.catch((error) => $store.set({
|
|
@@ -108,11 +109,16 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
|
|
|
108
109
|
data,
|
|
109
110
|
hasNotification: data?.notification?.enabled === NotificationEnabled.NOTIFICATION_ENABLED,
|
|
110
111
|
close: () => hide(data.question.id),
|
|
112
|
+
togglePause: (status) => pause(data.question.id, status),
|
|
111
113
|
isViewed: !!storage.isViewed(data.question.id),
|
|
112
114
|
});
|
|
113
115
|
}
|
|
114
116
|
};
|
|
115
117
|
$store.subscribe((active, prevActive) => {
|
|
118
|
+
// skip update on pause
|
|
119
|
+
if (active.data?.id === prevActive?.data?.id && active.isPaused !== prevActive?.isPaused) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
116
122
|
if (active.data?.promotion?.type === PromotionType.EXTERNAL_AD && !active?.externalAd) {
|
|
117
123
|
if (active.data.promotion.adCampaigns?.gamOptions && active.data.promotion.adCampaigns?.gamBaseUrl) {
|
|
118
124
|
const gamUrl = processGamAdvertisement(active.data.promotion.adCampaigns);
|
|
@@ -149,6 +155,11 @@ export const advertisement = ($slStreamId, $feedSubscription, instance) => {
|
|
|
149
155
|
$store.set({});
|
|
150
156
|
}
|
|
151
157
|
};
|
|
158
|
+
const pause = (notificationId, status) => {
|
|
159
|
+
if ($store.get()?.data?.question.id === notificationId) {
|
|
160
|
+
$store.setKey('isPaused', status);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
152
163
|
const connect = () => {
|
|
153
164
|
if (connected) {
|
|
154
165
|
return;
|
package/lib/gamification.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare class Gamification extends AbstractFeature<'games', PlainMessage<
|
|
|
50
50
|
openedQuestionId: GamificationBackground['openedQuestionId'];
|
|
51
51
|
advertisement: GamificationBackground['advertisement'];
|
|
52
52
|
onboardingProcessed: WritableAtom<boolean>;
|
|
53
|
+
friendsTabEnabled: WritableAtom<boolean>;
|
|
53
54
|
private notifications;
|
|
54
55
|
private transport;
|
|
55
56
|
/** gamification background class, handle subscriptions and notifications for closed overlay */
|
package/lib/gamification.js
CHANGED
|
@@ -51,6 +51,7 @@ export class Gamification extends AbstractFeature {
|
|
|
51
51
|
openedQuestionId;
|
|
52
52
|
advertisement;
|
|
53
53
|
onboardingProcessed;
|
|
54
|
+
friendsTabEnabled;
|
|
54
55
|
notifications;
|
|
55
56
|
transport;
|
|
56
57
|
/** gamification background class, handle subscriptions and notifications for closed overlay */
|
|
@@ -103,6 +104,20 @@ export class Gamification extends AbstractFeature {
|
|
|
103
104
|
}
|
|
104
105
|
}));
|
|
105
106
|
this.background.activeQuestionId.listen(this.showInApp);
|
|
107
|
+
this.friendsTabEnabled = createSingleStore(false);
|
|
108
|
+
this.cancels.add(instance.sdk.options.subscribe((data) => {
|
|
109
|
+
if (data.friendsTab === 'disabled') {
|
|
110
|
+
this.friendsTabEnabled.set(false);
|
|
111
|
+
}
|
|
112
|
+
else if (data.friendsTab === 'enabled') {
|
|
113
|
+
this.friendsTabEnabled.set(true);
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
this.cancels.add(this.settings.subscribe((settings) => {
|
|
117
|
+
if (instance.sdk.options.get().friendsTab === 'activatedGame') {
|
|
118
|
+
this.friendsTabEnabled.set(!!settings.inplayGame?.titleCard?.optIn);
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
106
121
|
instance.sdk.onMount({ name: 'gamification', clear: true }, () => {
|
|
107
122
|
return () => {
|
|
108
123
|
for (const cancel of this.cancels) {
|
|
@@ -470,12 +485,11 @@ export class Gamification extends AbstractFeature {
|
|
|
470
485
|
const onboardingStatus = this.onboardingStatus.$store.get();
|
|
471
486
|
if (question && question.data && onboardingStatus && onboardingStatus !== OnboardingStatus.Unset) {
|
|
472
487
|
if (question.data.question?.id !== undefined &&
|
|
473
|
-
question.data.question.notification !== undefined &&
|
|
474
488
|
question.data.question?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
|
|
475
489
|
question.data.question.status === QuestionStatus.ACTIVE &&
|
|
476
490
|
!question.data.question.marketClosed) {
|
|
477
491
|
if (InteractiveQuestionTypes.has(question.data.question.type)) {
|
|
478
|
-
if (this.isInteractiveAllowed) {
|
|
492
|
+
if (this.isInteractiveAllowed && question.data.question.notification !== undefined) {
|
|
479
493
|
this.notifications.add({
|
|
480
494
|
type: NotificationType.QUESTION,
|
|
481
495
|
action: () => this.openQuestion(question.data?.question?.id, question.data?.feedItem),
|
|
@@ -498,9 +512,11 @@ export class Gamification extends AbstractFeature {
|
|
|
498
512
|
}
|
|
499
513
|
else if (question.data.question.type === QuestionType.FACTOID) {
|
|
500
514
|
const optionsValue = question.data.question.options?.options.value;
|
|
515
|
+
const heading = question.data.question.notification?.title || question.data.question.subject || '';
|
|
516
|
+
const body = question.data.question.notification?.body || optionsValue.body;
|
|
501
517
|
const instantView = {
|
|
502
|
-
heading
|
|
503
|
-
body
|
|
518
|
+
heading,
|
|
519
|
+
body,
|
|
504
520
|
imageMode: optionsValue?.imageMode,
|
|
505
521
|
image: optionsValue?.image,
|
|
506
522
|
video: {
|
|
@@ -527,7 +543,8 @@ export class Gamification extends AbstractFeature {
|
|
|
527
543
|
},
|
|
528
544
|
});
|
|
529
545
|
}
|
|
530
|
-
else if (question.data.question.type === QuestionType.TWEET
|
|
546
|
+
else if (question.data.question.type === QuestionType.TWEET &&
|
|
547
|
+
question.data.question.notification !== undefined) {
|
|
531
548
|
const optionsValue = question.data.question.options?.options.value;
|
|
532
549
|
const tweetView = {
|
|
533
550
|
title: question.data.question.notification?.title,
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.10.0",
|
|
6
6
|
"@fastify/deepmerge": "^2.0.0",
|
|
7
7
|
"@streamlayer/sl-eslib": "^5.130.0",
|
|
8
8
|
"nanostores": "^0.10.3",
|
|
9
|
-
"@streamlayer/sdk-web-api": "^1.6.
|
|
10
|
-
"@streamlayer/sdk-web-core": "^1.
|
|
11
|
-
"@streamlayer/sdk-web-interfaces": "^1.2.
|
|
12
|
-
"@streamlayer/sdk-web-logger": "^1.0.
|
|
13
|
-
"@streamlayer/sdk-web-notifications": "^1.2.
|
|
14
|
-
"@streamlayer/sdk-web-storage": "^1.0.
|
|
15
|
-
"@streamlayer/sdk-web-types": "^1.8.
|
|
9
|
+
"@streamlayer/sdk-web-api": "^1.6.9",
|
|
10
|
+
"@streamlayer/sdk-web-core": "^1.7.1",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^1.2.9",
|
|
12
|
+
"@streamlayer/sdk-web-logger": "^1.0.30",
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^1.2.9",
|
|
14
|
+
"@streamlayer/sdk-web-storage": "^1.0.30",
|
|
15
|
+
"@streamlayer/sdk-web-types": "^1.8.3"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"tslib": "^2.7.0"
|