@streamlayer/feature-gamification 0.28.0 → 0.29.2

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.
Files changed (2) hide show
  1. package/lib/gamification.js +28 -24
  2. package/package.json +3 -3
@@ -7,7 +7,7 @@ import * as actions from './queries/actions';
7
7
  import { GamificationStorage } from './storage';
8
8
  import { leaderboard } from './leaderboard';
9
9
  import { deepLink } from './deepLink';
10
- import { onboarding } from './onboarding';
10
+ import { OnboardingStatus, onboarding } from './onboarding';
11
11
  import { gamificationBackground } from './';
12
12
  const GamificationQuestionTypes = new Set([QuestionType.POLL, QuestionType.PREDICTION, QuestionType.TRIVIA]);
13
13
  /**
@@ -74,25 +74,35 @@ export class Gamification extends AbstractFeature {
74
74
  * listen for active question and show in-app notification
75
75
  */
76
76
  this.background.activeQuestionId.listen((question) => {
77
- if (question && question.data && this.onboardingStatus.$store.get()) {
77
+ const onboardingStatus = this.onboardingStatus.$store.get();
78
+ if (question && question.data && onboardingStatus) {
78
79
  if (question.data.question?.id !== undefined &&
79
80
  question.data.question.notification !== undefined &&
80
- question.data.moderation?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
81
+ question.data.question?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
81
82
  question.data.question.status === QuestionStatus.ACTIVE) {
82
83
  if (GamificationQuestionTypes.has(question.data.question.type)) {
83
- this.notifications.add({
84
- type: NotificationType.QUESTION,
85
- action: () => question.data?.question && this.openQuestion(question.data.question.id),
86
- close: () => question.data?.question && this.closeQuestion(question.data.question.id),
87
- autoHideDuration: 1000 * 60,
88
- id: this.background.getCurrentSessionId({ prefix: 'notification', entity: question.data.question.id }),
89
- data: {
90
- questionType: question.data.question.type,
91
- question: {
92
- title: question.data.question.notification.title,
93
- },
94
- },
95
- });
84
+ const optInEnabled = this.settings.getValues().inplayGame?.titleCard?.optIn;
85
+ const onboardingCompleted = onboardingStatus === OnboardingStatus.Completed;
86
+ if (optInEnabled !== undefined) {
87
+ if (!optInEnabled || onboardingCompleted) {
88
+ this.notifications.add({
89
+ type: NotificationType.QUESTION,
90
+ action: () => question.data?.question && this.openQuestion(question.data.question.id),
91
+ close: () => question.data?.question && this.closeQuestion(question.data.question.id),
92
+ autoHideDuration: 1000 * 60,
93
+ id: this.background.getCurrentSessionId({
94
+ prefix: 'notification',
95
+ entity: question.data.question.id,
96
+ }),
97
+ data: {
98
+ questionType: question.data.question.type,
99
+ question: {
100
+ title: question.data.question.notification.title,
101
+ },
102
+ },
103
+ });
104
+ }
105
+ }
96
106
  }
97
107
  else if (question.data.question.type === QuestionType.FACTOID) {
98
108
  const optionsValue = question.data.question.options?.options.value;
@@ -128,14 +138,8 @@ export class Gamification extends AbstractFeature {
128
138
  title: question.data.question.notification.title,
129
139
  body: question.data.question.notification.body,
130
140
  image: question.data.question.notification.image,
131
- account: {
132
- // ToDo: add later
133
- image: '',
134
- name: optionsValue?.tweetMeta?.account || '',
135
- // ToDo: add later
136
- userName: '',
137
- verified: !!optionsValue?.tweetMeta?.accountVerified,
138
- },
141
+ account: optionsValue?.tweetMeta?.account || '',
142
+ accountVerified: !!optionsValue?.tweetMeta?.accountVerified,
139
143
  };
140
144
  this.notifications.add({
141
145
  type: NotificationType.QUESTION,
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@streamlayer/feature-gamification",
3
- "version": "0.28.0",
3
+ "version": "0.29.2",
4
4
  "peerDependencies": {
5
5
  "@bufbuild/protobuf": "^1.4.2",
6
6
  "@streamlayer/sl-eslib": "^5.53.6",
7
7
  "@fastify/deepmerge": "*",
8
8
  "nanostores": "^0.9.5",
9
9
  "@streamlayer/sdk-web-api": "^0.1.0",
10
- "@streamlayer/sdk-web-core": "^0.0.6",
10
+ "@streamlayer/sdk-web-core": "^0.0.7",
11
11
  "@streamlayer/sdk-web-interfaces": "^0.0.1",
12
12
  "@streamlayer/sdk-web-logger": "^0.0.1",
13
13
  "@streamlayer/sdk-web-notifications": "^0.1.0",
14
14
  "@streamlayer/sdk-web-storage": "^0.0.4",
15
- "@streamlayer/sdk-web-types": "^0.0.1"
15
+ "@streamlayer/sdk-web-types": "^0.1.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tslib": "^2.6.2"