@streamlayer/feature-gamification 0.21.2 → 0.22.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.
- package/lib/gamification.js +62 -26
- package/lib/highlights.js +5 -6
- package/package.json +5 -5
package/lib/gamification.js
CHANGED
|
@@ -90,27 +90,57 @@ export class Gamification extends AbstractFeature {
|
|
|
90
90
|
this.background.activeQuestionId.invalidate();
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
+
/**
|
|
94
|
+
* listen for active question and show in-app notification
|
|
95
|
+
*/
|
|
93
96
|
this.background.activeQuestionId.listen((question) => {
|
|
94
97
|
if (question && question.data && this.onboardingStatus.get()) {
|
|
95
98
|
if (question.data.question?.id !== undefined &&
|
|
96
99
|
question.data.question.notification !== undefined &&
|
|
97
100
|
question.data.moderation?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
|
|
98
|
-
GamificationQuestionTypes.has(question.data.question.type) &&
|
|
99
101
|
question.data.question.status === QuestionStatus.ACTIVE) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
if (GamificationQuestionTypes.has(question.data.question.type)) {
|
|
103
|
+
this.notifications.add({
|
|
104
|
+
type: NotificationType.QUESTION,
|
|
105
|
+
action: () => question.data?.question && this.openQuestion(question.data.question.id),
|
|
106
|
+
close: () => question.data?.question && this.closeQuestion(question.data.question.id),
|
|
107
|
+
autoHideDuration: 1000 * +(question.data.question?.appearance?.autoHideInterval || '5'),
|
|
108
|
+
id: this.background.getCurrentSessionId({ prefix: 'notification', entity: question.data.question.id }),
|
|
109
|
+
data: {
|
|
110
|
+
questionType: question.data.question.type,
|
|
111
|
+
question: {
|
|
112
|
+
title: question.data.question.notification.title,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else if (question.data.question.type === QuestionType.FACTOID) {
|
|
118
|
+
const instantView = {
|
|
119
|
+
heading: '',
|
|
120
|
+
body: '',
|
|
121
|
+
image: '',
|
|
122
|
+
video: {
|
|
123
|
+
id: '',
|
|
124
|
+
url: '',
|
|
125
|
+
thumbnailUrl: '',
|
|
126
|
+
},
|
|
127
|
+
webLink: {
|
|
128
|
+
label: '',
|
|
129
|
+
url: '',
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
this.notifications.add({
|
|
133
|
+
type: NotificationType.QUESTION,
|
|
134
|
+
action: () => question.data?.question && this.openQuestion(question.data.question.id),
|
|
135
|
+
close: () => question.data?.question && this.closeQuestion(question.data.question.id),
|
|
136
|
+
autoHideDuration: 1000 * +(question.data.question?.appearance?.autoHideInterval || '5'),
|
|
137
|
+
id: this.background.getCurrentSessionId({ prefix: 'notification', entity: question.data.question.id }),
|
|
138
|
+
data: {
|
|
139
|
+
questionType: question.data.question.type,
|
|
140
|
+
insight: instantView,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
114
144
|
}
|
|
115
145
|
}
|
|
116
146
|
});
|
|
@@ -179,13 +209,16 @@ export class Gamification extends AbstractFeature {
|
|
|
179
209
|
close: this.closeFeature,
|
|
180
210
|
autoHideDuration: 100000,
|
|
181
211
|
data: {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
212
|
+
questionType: QuestionType.UNSET,
|
|
213
|
+
onboarding: {
|
|
214
|
+
header: titleCard?.header,
|
|
215
|
+
title: titleCard?.title,
|
|
216
|
+
subtitle: titleCard?.subtitle,
|
|
217
|
+
graphicBg: titleCard?.appearance?.graphic,
|
|
218
|
+
icon: titleCard?.media?.icon,
|
|
219
|
+
sponsorLogo: titleCard?.media?.sponsorLogo,
|
|
220
|
+
primaryColor: overview?.appearance?.primaryColor,
|
|
221
|
+
},
|
|
189
222
|
},
|
|
190
223
|
});
|
|
191
224
|
};
|
|
@@ -207,15 +240,18 @@ export class Gamification extends AbstractFeature {
|
|
|
207
240
|
const question = await queries.getQuestionByUser(id, transport);
|
|
208
241
|
const correctAnswer = question?.answers.find(({ correct }) => correct);
|
|
209
242
|
this.notifications.add({
|
|
210
|
-
type: NotificationType.
|
|
243
|
+
type: NotificationType.QUESTION_RESOLVED,
|
|
211
244
|
action: () => this.openQuestion(id),
|
|
212
245
|
close: () => this.closeQuestion(id),
|
|
213
246
|
autoHideDuration: 5000,
|
|
214
247
|
id: notificationId,
|
|
215
248
|
data: {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
:
|
|
249
|
+
questionType: QuestionType.PREDICTION,
|
|
250
|
+
question: {
|
|
251
|
+
title: correctAnswer?.youVoted
|
|
252
|
+
? `Congratulations! You answered correctly! You won ${correctAnswer.points} pts!`
|
|
253
|
+
: `Better luck next time! Correct: ${correctAnswer?.text}!`,
|
|
254
|
+
},
|
|
219
255
|
},
|
|
220
256
|
});
|
|
221
257
|
}
|
package/lib/highlights.js
CHANGED
|
@@ -37,14 +37,13 @@ export class Highlights extends AbstractFeature {
|
|
|
37
37
|
type: NotificationType.QUESTION,
|
|
38
38
|
action: () => question.data?.question && this.openHighlight(question.data.question.id),
|
|
39
39
|
close: () => question.data?.question && this.closeHighlight(question.data.question.id),
|
|
40
|
-
autoHideDuration: +(question.data.
|
|
40
|
+
autoHideDuration: 1000 * +(question.data.question?.appearance?.autoHideInterval || '5'),
|
|
41
41
|
id: this.background.getCurrentSessionId({ prefix: 'notification', entity: question.data.question.id }),
|
|
42
42
|
data: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
imagePosition: question.data.question.notification.imagePosition,
|
|
43
|
+
questionType: question.data.question.type,
|
|
44
|
+
question: {
|
|
45
|
+
title: question.data.question.notification.title,
|
|
46
|
+
},
|
|
48
47
|
},
|
|
49
48
|
});
|
|
50
49
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
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.0.1",
|
|
10
|
-
"@streamlayer/sdk-web-core": "^0.17.
|
|
11
|
-
"@streamlayer/sdk-web-interfaces": "^0.18.
|
|
10
|
+
"@streamlayer/sdk-web-core": "^0.17.6",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^0.18.13",
|
|
12
12
|
"@streamlayer/sdk-web-logger": "^0.0.2",
|
|
13
|
-
"@streamlayer/sdk-web-notifications": "^0.
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.11.0",
|
|
14
14
|
"@streamlayer/sdk-web-storage": "^0.0.2",
|
|
15
|
-
"@streamlayer/sdk-web-types": "^0.
|
|
15
|
+
"@streamlayer/sdk-web-types": "^0.19.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"tslib": "^2.6.2"
|