@streamlayer/feature-gamification 0.15.1 → 0.17.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.d.ts +3 -3
- package/lib/gamification.js +19 -23
- package/lib/highlights.js +12 -11
- package/lib/queries/index.d.ts +1 -1
- package/lib/queries/index.js +1 -1
- package/package.json +6 -6
package/lib/gamification.d.ts
CHANGED
|
@@ -31,13 +31,13 @@ export declare enum OnboardingStatus {
|
|
|
31
31
|
*/
|
|
32
32
|
export declare class Gamification extends AbstractFeature<'games', PlainMessage<GamesOverlaySettings>> {
|
|
33
33
|
/** user statistics (leaderboard panel) */
|
|
34
|
-
userSummary
|
|
34
|
+
userSummary: ApiStore<GetApiResponseType<typeof queries.$userSummary>>;
|
|
35
35
|
/** questions list (pick history) */
|
|
36
|
-
questions
|
|
36
|
+
questions: ApiStore<GetApiResponseType<typeof queries.$pickHistory>>;
|
|
37
37
|
/** pinned leaderboard id */
|
|
38
38
|
leaderboardId: WritableAtom<string | undefined>;
|
|
39
39
|
/** leaderboard list */
|
|
40
|
-
leaderboardList
|
|
40
|
+
leaderboardList: ApiStore<GetApiResponseType<typeof queries.$leaderboardList>>;
|
|
41
41
|
/** onboarding status */
|
|
42
42
|
onboardingStatus: WritableAtom<OnboardingStatus | undefined>;
|
|
43
43
|
/** opened question */
|
package/lib/gamification.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractFeature, ApiStore, FeatureStatus, SingleStore, createSingleStore, createComputedStore, } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
-
import { QuestionStatus, QuestionType, FeatureType, } from '@streamlayer/sdk-web-types';
|
|
2
|
+
import { QuestionStatus, QuestionType, FeatureType, SilenceSetting, } from '@streamlayer/sdk-web-types';
|
|
3
3
|
import { NotificationType } from '@streamlayer/sdk-web-notifications';
|
|
4
4
|
import '@streamlayer/sdk-web-core/store';
|
|
5
5
|
import * as queries from './queries';
|
|
@@ -57,6 +57,8 @@ export class Gamification extends AbstractFeature {
|
|
|
57
57
|
super(config, source);
|
|
58
58
|
this.background = gamificationBackground(instance);
|
|
59
59
|
this.storage = new GamificationStorage();
|
|
60
|
+
this.userSummary = new ApiStore(queries.$userSummary(this.background.slStreamId, this.background.userId, instance.transport), 'gamification:userSummary');
|
|
61
|
+
this.questions = new ApiStore(queries.$pickHistory(this.background.slStreamId, instance.transport), 'gamification:questions');
|
|
60
62
|
this.leaderboardId = new SingleStore(createSingleStore(this.settings.getValue('pinnedLeaderboardId')), 'pinnedLeaderboardId').getStore();
|
|
61
63
|
this.onboardingStatus = new SingleStore(createSingleStore(OnboardingStatus.Unset), 'onboardingStatus').getStore();
|
|
62
64
|
this.notifications = instance.notifications;
|
|
@@ -69,6 +71,7 @@ export class Gamification extends AbstractFeature {
|
|
|
69
71
|
}
|
|
70
72
|
return undefined;
|
|
71
73
|
});
|
|
74
|
+
this.leaderboardList = new ApiStore(queries.$leaderboardList(this.background.slStreamId, this.leaderboardId, instance.transport), 'gamification:leaderboardList');
|
|
72
75
|
this.onboardingStatus.subscribe((onboardingStatus) => {
|
|
73
76
|
if (onboardingStatus === OnboardingStatus.Optional || OnboardingStatus.Required) {
|
|
74
77
|
this.showOnboardingInApp();
|
|
@@ -90,20 +93,23 @@ export class Gamification extends AbstractFeature {
|
|
|
90
93
|
});
|
|
91
94
|
this.background.activeQuestionId.listen((question) => {
|
|
92
95
|
if (question && question.data && this.onboardingStatus.get()) {
|
|
93
|
-
if (
|
|
96
|
+
if (question.data.question?.id !== undefined &&
|
|
97
|
+
question.data.question.notification !== undefined &&
|
|
98
|
+
question.data.moderation?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
|
|
99
|
+
GamificationQuestionTypes.has(question.data.question.type) &&
|
|
94
100
|
question.data.question.status === QuestionStatus.ACTIVE) {
|
|
95
101
|
this.notifications.add({
|
|
96
102
|
type: NotificationType.QUESTION,
|
|
97
|
-
action: () => this.openQuestion(question.data.question.id),
|
|
98
|
-
close: () => this.closeQuestion(question.data.question.id),
|
|
99
|
-
autoHideDuration:
|
|
103
|
+
action: () => question.data?.question && this.openQuestion(question.data.question.id),
|
|
104
|
+
close: () => question.data?.question && this.closeQuestion(question.data.question.id),
|
|
105
|
+
autoHideDuration: +(question.data.moderation?.question?.appearance?.autoHideInterval || '1000'),
|
|
100
106
|
id: this.background.getCurrentSessionId({ prefix: 'notification', entity: question.data.question.id }),
|
|
101
107
|
data: {
|
|
102
|
-
title: question.data.notification.title,
|
|
103
|
-
color: question.data.notification.indicatorColor,
|
|
104
|
-
icon: question.data.notification.image,
|
|
105
|
-
imageMode: question.data.notification.imageMode,
|
|
106
|
-
imagePosition: question.data.notification.imagePosition,
|
|
108
|
+
title: question.data.question.notification.title,
|
|
109
|
+
color: question.data.question.notification.indicatorColor,
|
|
110
|
+
icon: question.data.question.notification.image,
|
|
111
|
+
imageMode: question.data.question.notification.imageMode,
|
|
112
|
+
imagePosition: question.data.question.notification.imagePosition,
|
|
107
113
|
},
|
|
108
114
|
});
|
|
109
115
|
}
|
|
@@ -185,19 +191,9 @@ export class Gamification extends AbstractFeature {
|
|
|
185
191
|
});
|
|
186
192
|
};
|
|
187
193
|
connect = (transport) => {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
else {
|
|
192
|
-
this.userSummary.invalidate();
|
|
193
|
-
}
|
|
194
|
-
this.leaderboardList = new ApiStore(queries.$leaderboardList(this.background.slStreamId, this.leaderboardId, transport), 'gamification:leaderboardList');
|
|
195
|
-
if (!this.questions) {
|
|
196
|
-
this.questions = new ApiStore(queries.$pickHistory(this.background.slStreamId, transport), 'gamification:questions');
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
this.questions.invalidate();
|
|
200
|
-
}
|
|
194
|
+
this.userSummary.invalidate();
|
|
195
|
+
this.leaderboardList.invalidate();
|
|
196
|
+
this.questions.invalidate();
|
|
201
197
|
this.background.feedSubscription.addListener('feed-subscription-prediction-close', (response) => {
|
|
202
198
|
window.requestAnimationFrame(async () => {
|
|
203
199
|
const question = response.data?.attributes?.question;
|
package/lib/highlights.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractFeature, ApiStore, FeatureStatus, createComputedStore, } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
-
import { QuestionStatus, QuestionType, FeatureType } from '@streamlayer/sdk-web-types';
|
|
2
|
+
import { QuestionStatus, QuestionType, FeatureType, SilenceSetting } from '@streamlayer/sdk-web-types';
|
|
3
3
|
import { NotificationType } from '@streamlayer/sdk-web-notifications';
|
|
4
4
|
import '@streamlayer/sdk-web-core/store';
|
|
5
5
|
import * as queries from './queries';
|
|
@@ -28,22 +28,23 @@ export class Highlights extends AbstractFeature {
|
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
this.background.activeQuestionId.listen((question) => {
|
|
31
|
-
if (question &&
|
|
32
|
-
question
|
|
31
|
+
if (question?.data?.question?.id &&
|
|
32
|
+
question?.data?.question?.notification &&
|
|
33
|
+
question.data.moderation?.bypassNotifications?.inAppSilence !== SilenceSetting.ON &&
|
|
33
34
|
question.data.question.type === QuestionType.FACTOID &&
|
|
34
35
|
question.data.question.status === QuestionStatus.ACTIVE) {
|
|
35
36
|
this.notifications.add({
|
|
36
37
|
type: NotificationType.QUESTION,
|
|
37
|
-
action: () => this.openHighlight(question.data.question.id),
|
|
38
|
-
close: () => this.closeHighlight(question.data.question.id),
|
|
39
|
-
autoHideDuration:
|
|
38
|
+
action: () => question.data?.question && this.openHighlight(question.data.question.id),
|
|
39
|
+
close: () => question.data?.question && this.closeHighlight(question.data.question.id),
|
|
40
|
+
autoHideDuration: +(question.data.moderation?.question?.appearance?.autoHideInterval || '1000'),
|
|
40
41
|
id: this.background.getCurrentSessionId({ prefix: 'notification', entity: question.data.question.id }),
|
|
41
42
|
data: {
|
|
42
|
-
title: question.data.notification.title,
|
|
43
|
-
color: question.data.notification.indicatorColor,
|
|
44
|
-
icon: question.data.notification.image,
|
|
45
|
-
imageMode: question.data.notification.imageMode,
|
|
46
|
-
imagePosition: question.data.notification.imagePosition,
|
|
43
|
+
title: question.data.question.notification.title,
|
|
44
|
+
color: question.data.question.notification.indicatorColor,
|
|
45
|
+
icon: question.data.question.notification.image,
|
|
46
|
+
imageMode: question.data.question.notification.imageMode,
|
|
47
|
+
imagePosition: question.data.question.notification.imagePosition,
|
|
47
48
|
},
|
|
48
49
|
});
|
|
49
50
|
}
|
package/lib/queries/index.d.ts
CHANGED
|
@@ -292,7 +292,7 @@ export declare const questionSubscription: (questionId: string, transport: Trans
|
|
|
292
292
|
}, QuestionSubscriptionRequest, QuestionSubscriptionResponse, "subscription" | "votingSubscription" | "questionSubscription", ((request: import("@bufbuild/protobuf").PartialMessage<SubscriptionRequest>, messageCallback: (response: SubscriptionResponse) => void, closeCallback: (error: import("@connectrpc/connect").ConnectError | undefined) => void, options?: import("@connectrpc/connect").CallOptions | undefined) => () => void) | ((request: import("@bufbuild/protobuf").PartialMessage<VotingSubscriptionRequest>, messageCallback: (response: VotingSubscriptionResponse) => void, closeCallback: (error: import("@connectrpc/connect").ConnectError | undefined) => void, options?: import("@connectrpc/connect").CallOptions | undefined) => () => void) | ((request: import("@bufbuild/protobuf").PartialMessage<QuestionSubscriptionRequest>, messageCallback: (response: QuestionSubscriptionResponse) => void, closeCallback: (error: import("@connectrpc/connect").ConnectError | undefined) => void, options?: import("@connectrpc/connect").CallOptions | undefined) => () => void)>;
|
|
293
293
|
export declare const getQuestionByUser: (questionId: string, transport: Transport) => Promise<import("packages/sdk-web-types/lib").ExtendedQuestion | undefined>;
|
|
294
294
|
export declare const $questionByUser: ($questionId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<import("packages/sdk-web-types/lib").ExtendedQuestion | undefined, any>;
|
|
295
|
-
export declare const $pickHistory: (slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<(import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").PickHistory | undefined)[]
|
|
295
|
+
export declare const $pickHistory: (slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<(import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").PickHistory | undefined)[], any>;
|
|
296
296
|
export declare const $insightHistory: (slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<(import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").InsightHistory | undefined)[] | undefined, any>;
|
|
297
297
|
export { $userSummary, $leaderboardList } from './leaderboard';
|
|
298
298
|
export { $moderation } from './moderation';
|
package/lib/queries/index.js
CHANGED
|
@@ -58,7 +58,7 @@ export const $pickHistory = (slStreamId, transport) => {
|
|
|
58
58
|
return transport.nanoquery.createFetcherStore(queryKey, {
|
|
59
59
|
fetcher: async (_, __, eventId) => {
|
|
60
60
|
if (!eventId) {
|
|
61
|
-
return
|
|
61
|
+
return [];
|
|
62
62
|
}
|
|
63
63
|
const res = await client.pickHistory({
|
|
64
64
|
eventId: eventId,
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
6
|
"@streamlayer/sl-eslib": "^5.45.1",
|
|
7
7
|
"nanostores": "^0.9.4",
|
|
8
|
-
"@streamlayer/sdk-web-interfaces": "^0.
|
|
9
|
-
"@streamlayer/sdk-web-core": "^0.
|
|
10
|
-
"@streamlayer/sdk-web-api": "^0.0.
|
|
11
|
-
"@streamlayer/sdk-web-types": "^0.
|
|
8
|
+
"@streamlayer/sdk-web-interfaces": "^0.18.0",
|
|
9
|
+
"@streamlayer/sdk-web-core": "^0.13.0",
|
|
10
|
+
"@streamlayer/sdk-web-api": "^0.0.2",
|
|
11
|
+
"@streamlayer/sdk-web-types": "^0.16.0",
|
|
12
12
|
"@streamlayer/sdk-web-storage": "^0.3.2",
|
|
13
13
|
"@streamlayer/sdk-web-logger": "^0.5.2",
|
|
14
|
-
"@streamlayer/sdk-web-notifications": "^0.9.
|
|
14
|
+
"@streamlayer/sdk-web-notifications": "^0.9.4"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"tslib": "^2.6.2"
|