@streamlayer/feature-gamification 0.24.0 → 0.26.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 +39 -1
- package/lib/queries/deepLink.d.ts +6 -0
- package/lib/queries/deepLink.js +16 -0
- package/package.json +2 -2
|
@@ -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) {
|
|
@@ -116,6 +119,33 @@ export class Gamification extends AbstractFeature {
|
|
|
116
119
|
},
|
|
117
120
|
});
|
|
118
121
|
}
|
|
122
|
+
else if (question.data.question.type === QuestionType.TWEET) {
|
|
123
|
+
const optionsValue = question.data.question.options?.options.value;
|
|
124
|
+
const tweetView = {
|
|
125
|
+
title: question.data.question.notification.title,
|
|
126
|
+
body: question.data.question.notification.body,
|
|
127
|
+
image: question.data.question.notification.image,
|
|
128
|
+
account: {
|
|
129
|
+
// ToDo: add later
|
|
130
|
+
image: '',
|
|
131
|
+
name: optionsValue?.tweetMeta?.account || '',
|
|
132
|
+
// ToDo: add later
|
|
133
|
+
userName: '',
|
|
134
|
+
verified: !!optionsValue?.tweetMeta?.accountVerified,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
this.notifications.add({
|
|
138
|
+
type: NotificationType.QUESTION,
|
|
139
|
+
action: () => question.data?.question && this.openQuestion(question.data.question.id),
|
|
140
|
+
close: () => question.data?.question && this.closeQuestion(question.data.question.id),
|
|
141
|
+
autoHideDuration: 1000 * +(question.data.question?.appearance?.autoHideInterval || '5'),
|
|
142
|
+
id: this.background.getCurrentSessionId({ prefix: 'notification', entity: question.data.question.id }),
|
|
143
|
+
data: {
|
|
144
|
+
questionType: question.data.question.type,
|
|
145
|
+
tweet: tweetView,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
119
149
|
}
|
|
120
150
|
}
|
|
121
151
|
});
|
|
@@ -137,11 +167,12 @@ export class Gamification extends AbstractFeature {
|
|
|
137
167
|
});
|
|
138
168
|
const question = await queries.getQuestionByUser(id, transport);
|
|
139
169
|
const correctAnswer = question?.answers.find(({ correct }) => correct);
|
|
170
|
+
const votedAnswer = question?.answers.find(({ youVoted }) => youVoted);
|
|
140
171
|
this.notifications.add({
|
|
141
172
|
type: NotificationType.QUESTION_RESOLVED,
|
|
142
173
|
action: () => this.openQuestion(id),
|
|
143
174
|
close: () => this.closeQuestion(id),
|
|
144
|
-
autoHideDuration:
|
|
175
|
+
autoHideDuration: 35000,
|
|
145
176
|
id: notificationId,
|
|
146
177
|
data: {
|
|
147
178
|
questionType: QuestionType.PREDICTION,
|
|
@@ -149,6 +180,13 @@ export class Gamification extends AbstractFeature {
|
|
|
149
180
|
title: correctAnswer?.youVoted
|
|
150
181
|
? `Congratulations! You answered correctly! You won ${correctAnswer.points} pts!`
|
|
151
182
|
: `Better luck next time! Correct: ${correctAnswer?.text}!`,
|
|
183
|
+
votedAnswer: {
|
|
184
|
+
title: votedAnswer?.text,
|
|
185
|
+
points: votedAnswer?.points,
|
|
186
|
+
},
|
|
187
|
+
correctAnswerTitle: correctAnswer?.text,
|
|
188
|
+
correct: correctAnswer?.youVoted,
|
|
189
|
+
predictionResult: status === QuestionStatus.RESOLVED,
|
|
152
190
|
},
|
|
153
191
|
},
|
|
154
192
|
});
|
|
@@ -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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
6
|
"@streamlayer/sl-eslib": "^5.53.6",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@streamlayer/sdk-web-core": "^0.17.8",
|
|
11
11
|
"@streamlayer/sdk-web-interfaces": "^0.18.15",
|
|
12
12
|
"@streamlayer/sdk-web-logger": "^0.0.4",
|
|
13
|
-
"@streamlayer/sdk-web-notifications": "^0.
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.13.0",
|
|
14
14
|
"@streamlayer/sdk-web-storage": "^0.0.4",
|
|
15
15
|
"@streamlayer/sdk-web-types": "^0.20.1"
|
|
16
16
|
},
|