@streamlayer/feature-gamification 0.23.1 → 0.25.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/deepLink.d.ts +6 -0
- package/lib/deepLink.js +5 -0
- package/lib/gamification.d.ts +2 -0
- package/lib/gamification.js +19 -7
- package/lib/queries/deepLink.d.ts +6 -0
- package/lib/queries/deepLink.js +16 -0
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transport } from '@streamlayer/sdk-web-api';
|
|
2
|
+
import { ReadableAtom } from 'nanostores';
|
|
3
|
+
export declare const deepLink: (transport: Transport, $eventId: ReadableAtom<string | undefined>) => {
|
|
4
|
+
$store: import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/client/client_pb").DeepLink | undefined, any>;
|
|
5
|
+
fetch: typeof fetch;
|
|
6
|
+
};
|
package/lib/deepLink.js
ADDED
package/lib/gamification.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { PlainMessage } from '@bufbuild/protobuf';
|
|
|
6
6
|
import { WritableAtom } from 'nanostores';
|
|
7
7
|
import * as queries from './queries';
|
|
8
8
|
import { leaderboard } from './leaderboard';
|
|
9
|
+
import { deepLink } from './deepLink';
|
|
9
10
|
import { OnboardingStatus } from './onboarding';
|
|
10
11
|
import { LeaderboardItem } from './queries/leaderboard';
|
|
11
12
|
import { GamificationBackground } from './';
|
|
@@ -27,6 +28,7 @@ export declare class Gamification extends AbstractFeature<'games', PlainMessage<
|
|
|
27
28
|
leaderboardId: WritableAtom<string | undefined>;
|
|
28
29
|
/** leaderboard list */
|
|
29
30
|
leaderboardList: ReturnType<typeof leaderboard>;
|
|
31
|
+
deepLink: ReturnType<typeof deepLink>;
|
|
30
32
|
/** onboarding status */
|
|
31
33
|
onboardingStatus: {
|
|
32
34
|
$store: WritableAtom<OnboardingStatus | undefined>;
|
package/lib/gamification.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as queries from './queries';
|
|
|
6
6
|
import * as actions from './queries/actions';
|
|
7
7
|
import { GamificationStorage } from './storage';
|
|
8
8
|
import { leaderboard } from './leaderboard';
|
|
9
|
+
import { deepLink } from './deepLink';
|
|
9
10
|
import { onboarding } from './onboarding';
|
|
10
11
|
import { gamificationBackground } from './';
|
|
11
12
|
const GamificationQuestionTypes = new Set([QuestionType.POLL, QuestionType.PREDICTION, QuestionType.TRIVIA]);
|
|
@@ -27,6 +28,7 @@ export class Gamification extends AbstractFeature {
|
|
|
27
28
|
leaderboardId;
|
|
28
29
|
/** leaderboard list */
|
|
29
30
|
leaderboardList;
|
|
31
|
+
deepLink;
|
|
30
32
|
/** onboarding status */
|
|
31
33
|
onboardingStatus;
|
|
32
34
|
/** opened question */
|
|
@@ -55,6 +57,7 @@ export class Gamification extends AbstractFeature {
|
|
|
55
57
|
this.closeFeature = instance.sdk.closeFeature;
|
|
56
58
|
this.openFeature = () => instance.sdk.openFeature(FeatureType.GAMES);
|
|
57
59
|
this.openedQuestion = this.background.openedQuestion;
|
|
60
|
+
this.deepLink = deepLink(this.transport, this.background.slStreamId);
|
|
58
61
|
this.leaderboardList = leaderboard(this.transport, this.background.slStreamId);
|
|
59
62
|
this.status.subscribe((status) => {
|
|
60
63
|
if (status === FeatureStatus.Ready) {
|
|
@@ -89,14 +92,15 @@ export class Gamification extends AbstractFeature {
|
|
|
89
92
|
});
|
|
90
93
|
}
|
|
91
94
|
else if (question.data.question.type === QuestionType.FACTOID) {
|
|
95
|
+
const optionsValue = question.data.question.options?.options.value;
|
|
92
96
|
const instantView = {
|
|
93
|
-
heading:
|
|
94
|
-
body:
|
|
95
|
-
image:
|
|
97
|
+
heading: question.data.question.notification.title,
|
|
98
|
+
body: question.data.question.notification.body,
|
|
99
|
+
image: question.data.question.notification.image,
|
|
96
100
|
video: {
|
|
97
|
-
id: '',
|
|
98
|
-
url: '',
|
|
99
|
-
thumbnailUrl: '',
|
|
101
|
+
id: optionsValue?.video?.id || '',
|
|
102
|
+
url: optionsValue?.video?.url || '',
|
|
103
|
+
thumbnailUrl: optionsValue?.video?.thumbnailUrl || '',
|
|
100
104
|
},
|
|
101
105
|
webLink: {
|
|
102
106
|
label: '',
|
|
@@ -136,11 +140,12 @@ export class Gamification extends AbstractFeature {
|
|
|
136
140
|
});
|
|
137
141
|
const question = await queries.getQuestionByUser(id, transport);
|
|
138
142
|
const correctAnswer = question?.answers.find(({ correct }) => correct);
|
|
143
|
+
const votedAnswer = question?.answers.find(({ youVoted }) => youVoted);
|
|
139
144
|
this.notifications.add({
|
|
140
145
|
type: NotificationType.QUESTION_RESOLVED,
|
|
141
146
|
action: () => this.openQuestion(id),
|
|
142
147
|
close: () => this.closeQuestion(id),
|
|
143
|
-
autoHideDuration:
|
|
148
|
+
autoHideDuration: 35000,
|
|
144
149
|
id: notificationId,
|
|
145
150
|
data: {
|
|
146
151
|
questionType: QuestionType.PREDICTION,
|
|
@@ -148,6 +153,13 @@ export class Gamification extends AbstractFeature {
|
|
|
148
153
|
title: correctAnswer?.youVoted
|
|
149
154
|
? `Congratulations! You answered correctly! You won ${correctAnswer.points} pts!`
|
|
150
155
|
: `Better luck next time! Correct: ${correctAnswer?.text}!`,
|
|
156
|
+
votedAnswer: {
|
|
157
|
+
title: votedAnswer?.text,
|
|
158
|
+
points: votedAnswer?.points,
|
|
159
|
+
},
|
|
160
|
+
correctAnswerTitle: correctAnswer?.text,
|
|
161
|
+
correct: correctAnswer?.youVoted,
|
|
162
|
+
predictionResult: status === QuestionStatus.RESOLVED,
|
|
151
163
|
},
|
|
152
164
|
},
|
|
153
165
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transport } from '@streamlayer/sdk-web-api';
|
|
2
|
+
import { ReadableAtom } from 'nanostores';
|
|
3
|
+
import { DeepLink } from '@streamlayer/sl-eslib/sdkSettings/client/client_pb';
|
|
4
|
+
type EventId = ReadableAtom<string | undefined>;
|
|
5
|
+
export declare const $deepLink: (transport: Transport, params: [EventId]) => import("@nanostores/query").FetcherStore<DeepLink | undefined, any>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/client_connect';
|
|
2
|
+
export const $deepLink = (transport, params) => {
|
|
3
|
+
const { client, queryKey } = transport.createPromiseClient(Client, {
|
|
4
|
+
method: 'generateDeepLink',
|
|
5
|
+
params,
|
|
6
|
+
});
|
|
7
|
+
return transport.nanoquery.createFetcherStore(queryKey, {
|
|
8
|
+
fetcher: async (_, __, eventId) => {
|
|
9
|
+
if (!eventId) {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
const res = await client.generateDeepLink({ data: { eventId: eventId } });
|
|
13
|
+
return res.data?.attributes;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|