@streamlayer/feature-gamification 1.9.2 → 1.10.1

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;
@@ -485,12 +485,11 @@ export class Gamification extends AbstractFeature {
485
485
  const onboardingStatus = this.onboardingStatus.$store.get();
486
486
  if (question && question.data && onboardingStatus && onboardingStatus !== OnboardingStatus.Unset) {
487
487
  if (question.data.question?.id !== undefined &&
488
- question.data.question.notification !== undefined &&
489
488
  question.data.question?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
490
489
  question.data.question.status === QuestionStatus.ACTIVE &&
491
490
  !question.data.question.marketClosed) {
492
491
  if (InteractiveQuestionTypes.has(question.data.question.type)) {
493
- if (this.isInteractiveAllowed) {
492
+ if (this.isInteractiveAllowed && question.data.question.notification !== undefined) {
494
493
  this.notifications.add({
495
494
  type: NotificationType.QUESTION,
496
495
  action: () => this.openQuestion(question.data?.question?.id, question.data?.feedItem),
@@ -513,9 +512,11 @@ export class Gamification extends AbstractFeature {
513
512
  }
514
513
  else if (question.data.question.type === QuestionType.FACTOID) {
515
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;
516
517
  const instantView = {
517
- heading: question.data.question.notification.title,
518
- body: question.data.question.notification.body,
518
+ heading,
519
+ body,
519
520
  imageMode: optionsValue?.imageMode,
520
521
  image: optionsValue?.image,
521
522
  video: {
@@ -542,7 +543,8 @@ export class Gamification extends AbstractFeature {
542
543
  },
543
544
  });
544
545
  }
545
- else if (question.data.question.type === QuestionType.TWEET) {
546
+ else if (question.data.question.type === QuestionType.TWEET &&
547
+ question.data.question.notification !== undefined) {
546
548
  const optionsValue = question.data.question.options?.options.value;
547
549
  const tweetView = {
548
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.9.2",
3
+ "version": "1.10.1",
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.8",
10
- "@streamlayer/sdk-web-core": "^1.7.0",
11
- "@streamlayer/sdk-web-interfaces": "^1.2.8",
12
- "@streamlayer/sdk-web-logger": "^1.0.29",
13
- "@streamlayer/sdk-web-notifications": "^1.2.8",
14
- "@streamlayer/sdk-web-storage": "^1.0.29",
15
- "@streamlayer/sdk-web-types": "^1.8.2"
9
+ "@streamlayer/sdk-web-api": "^1.6.10",
10
+ "@streamlayer/sdk-web-core": "^1.7.2",
11
+ "@streamlayer/sdk-web-interfaces": "^1.2.10",
12
+ "@streamlayer/sdk-web-logger": "^1.0.31",
13
+ "@streamlayer/sdk-web-notifications": "^1.2.10",
14
+ "@streamlayer/sdk-web-storage": "^1.0.31",
15
+ "@streamlayer/sdk-web-types": "^1.8.4"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tslib": "^2.7.0"