@streamlayer/feature-gamification 0.40.1 → 0.41.1
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/background.js +1 -1
- package/lib/detail.d.ts +2 -2
- package/lib/gamification.js +12 -21
- package/lib/onboarding.js +1 -1
- package/lib/queries/index.d.ts +1 -1
- package/package.json +9 -9
package/lib/background.js
CHANGED
|
@@ -109,7 +109,7 @@ export class GamificationBackground {
|
|
|
109
109
|
this.activeQuestionId.invalidate();
|
|
110
110
|
});
|
|
111
111
|
}));
|
|
112
|
-
instance.sdk.onMount(() => {
|
|
112
|
+
instance.sdk.onMount({ name: 'gamification-background' }, () => {
|
|
113
113
|
return () => {
|
|
114
114
|
this.activeQuestionId.off();
|
|
115
115
|
for (const cancel of this.cancels) {
|
package/lib/detail.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ export declare const detail: (transport: Transport, $openedQuestionId: ReadableA
|
|
|
8
8
|
openedFrom?: 'list' | 'notification';
|
|
9
9
|
};
|
|
10
10
|
} | undefined>, $feedList: ReturnType<GamificationBackground['feedList']['getStore']>) => {
|
|
11
|
-
$store: ReadableAtom<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem | (import("@
|
|
11
|
+
$store: ReadableAtom<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem | (import("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem> & {
|
|
12
12
|
openedFrom?: "list" | "notification" | undefined;
|
|
13
13
|
}) | undefined>;
|
|
14
|
-
$extendedStore: import("@nanostores/query").FetcherStore<import("@
|
|
14
|
+
$extendedStore: import("@nanostores/query").FetcherStore<import("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>, any>;
|
|
15
15
|
updateExtendedQuestion: (question: ExtendedQuestion | undefined) => void;
|
|
16
16
|
};
|
package/lib/gamification.js
CHANGED
|
@@ -85,21 +85,6 @@ export class Gamification extends AbstractFeature {
|
|
|
85
85
|
this.leaderboardList.invalidate(); // verified, it's necessary
|
|
86
86
|
}
|
|
87
87
|
}));
|
|
88
|
-
this.cancels.add(this.leaderboardList.$store.subscribe((leaderboard) => {
|
|
89
|
-
const userSummary = { ...(this.userSummary.$store.get() || {}) };
|
|
90
|
-
const userId = userSummary?.summary?.userId;
|
|
91
|
-
if (leaderboard.data.length && userId) {
|
|
92
|
-
const userRank = leaderboard.data.find((item) => item.userId === userId)?.rank;
|
|
93
|
-
if (userRank !== undefined) {
|
|
94
|
-
if (userSummary?.summary) {
|
|
95
|
-
userSummary.fromLeaderboard = true;
|
|
96
|
-
userSummary.summary.friendsRank = userRank;
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
this.userSummary.$store.set(userSummary);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}));
|
|
103
88
|
/**
|
|
104
89
|
* listen for active question and show in-app notification
|
|
105
90
|
*/
|
|
@@ -110,7 +95,7 @@ export class Gamification extends AbstractFeature {
|
|
|
110
95
|
this.cancels.add(this.onboardingStatus.$store.listen(this.checkInteractiveFlag));
|
|
111
96
|
this.cancels.add(this.background.moderation.getStore().listen(this.checkInteractiveFlag));
|
|
112
97
|
this.cancels.add(this.settings.subscribe(this.checkInteractiveFlag));
|
|
113
|
-
instance.sdk.onMount(() => {
|
|
98
|
+
instance.sdk.onMount({ name: 'gamification', clear: true }, () => {
|
|
114
99
|
return () => {
|
|
115
100
|
for (const cancel of this.cancels) {
|
|
116
101
|
cancel();
|
|
@@ -306,6 +291,8 @@ export class Gamification extends AbstractFeature {
|
|
|
306
291
|
};
|
|
307
292
|
submitAnswer = async (questionId, answerId) => {
|
|
308
293
|
const data = $questionByUser(questionId, this.transport);
|
|
294
|
+
const cancel = data.subscribe(() => { });
|
|
295
|
+
const extendedQuestionBeforeVote = { ...(data.get().data || {}) };
|
|
309
296
|
const updateQuestionAndFieldList = () => {
|
|
310
297
|
const feedList = this.feedList.getValues().data;
|
|
311
298
|
if (!feedList) {
|
|
@@ -322,13 +309,13 @@ export class Gamification extends AbstractFeature {
|
|
|
322
309
|
questionType: question.questionType,
|
|
323
310
|
},
|
|
324
311
|
});
|
|
325
|
-
const cancel = data.subscribe(() => { });
|
|
326
312
|
const extendedQuestion = data.get().data;
|
|
327
313
|
cancel();
|
|
328
314
|
if (extendedQuestion) {
|
|
329
315
|
const correctAnswer = extendedQuestion.answers.find((answer) => answer.correct === true);
|
|
330
316
|
const votedAnswerIdx = extendedQuestion.answers.findIndex((answer) => answer.id === answerId);
|
|
331
317
|
const votedAnswer = extendedQuestion.answers[votedAnswerIdx];
|
|
318
|
+
const percentsEqual = extendedQuestion.answers.every(({ percentageDecimal }, index) => percentageDecimal === extendedQuestionBeforeVote?.answers[index].percentageDecimal);
|
|
332
319
|
// @ts-ignore
|
|
333
320
|
feedList[questionIndex].attributes.attributes.value.answerId = answerId;
|
|
334
321
|
// @ts-ignore
|
|
@@ -343,9 +330,11 @@ export class Gamification extends AbstractFeature {
|
|
|
343
330
|
this.feedList.getStore().mutate([...feedList]);
|
|
344
331
|
extendedQuestion.answers[votedAnswerIdx].correct = correctAnswer?.id === answerId;
|
|
345
332
|
extendedQuestion.answers[votedAnswerIdx].youVoted = true;
|
|
346
|
-
|
|
347
|
-
answer
|
|
348
|
-
|
|
333
|
+
if (percentsEqual) {
|
|
334
|
+
extendedQuestion.answers.forEach((answer) => {
|
|
335
|
+
answer.percentageDecimal = 0;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
349
338
|
if (correctAnswer?.id === answerId) {
|
|
350
339
|
extendedQuestion.answers[votedAnswerIdx].pointsEarned =
|
|
351
340
|
extendedQuestion.status === QuestionStatus.RESOLVED ? 0 : correctAnswer.points;
|
|
@@ -381,7 +370,9 @@ export class Gamification extends AbstractFeature {
|
|
|
381
370
|
this.notifications.close(this.background.getCurrentSessionId({
|
|
382
371
|
prefix: 'notification',
|
|
383
372
|
entity: questionId,
|
|
384
|
-
})
|
|
373
|
+
}), {
|
|
374
|
+
animateHiding: false,
|
|
375
|
+
});
|
|
385
376
|
let questionType = question?.attributes?.type;
|
|
386
377
|
if (!questionType) {
|
|
387
378
|
const feedList = this.feedList.getStore().value?.data || [];
|
package/lib/onboarding.js
CHANGED
|
@@ -90,7 +90,7 @@ const onboardingProcess = ($store, background, service, notifications, storage,
|
|
|
90
90
|
$store.set(OnboardingStatus.Disabled);
|
|
91
91
|
}
|
|
92
92
|
// close previous onboarding notification, f.e moderation was disabled onboarding
|
|
93
|
-
notifications.close(background.getCurrentSessionId({ prefix: 'onboarding' }), false);
|
|
93
|
+
notifications.close(background.getCurrentSessionId({ prefix: 'onboarding' }), { markAsViewed: false });
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
catch (error) {
|
package/lib/queries/index.d.ts
CHANGED
|
@@ -329,7 +329,7 @@ export declare const questionSubscription: (questionId: string, transport: Trans
|
|
|
329
329
|
}, QuestionSubscriptionRequest, QuestionSubscriptionResponse, "subscription" | "votingSubscription" | "questionSubscription" | "feedSubscription", ((request: import("@bufbuild/protobuf").PartialMessage<SubscriptionRequest>, options?: import("@connectrpc/connect").CallOptions | undefined) => AsyncIterable<SubscriptionResponse>) | ((request: import("@bufbuild/protobuf").PartialMessage<VotingSubscriptionRequest>, options?: import("@connectrpc/connect").CallOptions | undefined) => AsyncIterable<VotingSubscriptionResponse>) | ((request: import("@bufbuild/protobuf").PartialMessage<QuestionSubscriptionRequest>, options?: import("@connectrpc/connect").CallOptions | undefined) => AsyncIterable<QuestionSubscriptionResponse>) | ((request: import("@bufbuild/protobuf").PartialMessage<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedSubscriptionRequest>, options?: import("@connectrpc/connect").CallOptions | undefined) => AsyncIterable<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedSubscriptionResponse>)>;
|
|
330
330
|
export declare const getQuestionByUser: (questionId: string, transport: Transport) => Promise<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion | undefined>;
|
|
331
331
|
export declare const getQuestionDetail: (questionId: string, transport: Transport) => Promise<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").Question | undefined>;
|
|
332
|
-
export declare const $questionByUser: ($questionId: ReadableAtom<string | undefined> | string, transport: Transport) => import("@nanostores/query").FetcherStore<import("@
|
|
332
|
+
export declare const $questionByUser: ($questionId: ReadableAtom<string | undefined> | string, transport: Transport) => import("@nanostores/query").FetcherStore<import("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>, any>;
|
|
333
333
|
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>;
|
|
334
334
|
export declare const $feedList: ($slStreamId: ReadableAtom<string | undefined>, $interactiveAllowed: ReadableAtom<InteractiveAllowed>, transport: Transport) => import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem[], any>;
|
|
335
335
|
export { $userSummary, $leaderboardList } from './leaderboard';
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.1",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.8.0",
|
|
6
6
|
"@fastify/deepmerge": "^1.3.0",
|
|
7
|
-
"@streamlayer/sl-eslib": "^5.
|
|
7
|
+
"@streamlayer/sl-eslib": "^5.85.0",
|
|
8
8
|
"nanostores": "^0.10.0",
|
|
9
|
-
"@streamlayer/sdk-web-api": "^0.
|
|
10
|
-
"@streamlayer/sdk-web-core": "^0.
|
|
11
|
-
"@streamlayer/sdk-web-interfaces": "^0.
|
|
12
|
-
"@streamlayer/sdk-web-logger": "^0.5.
|
|
13
|
-
"@streamlayer/sdk-web-notifications": "^0.
|
|
14
|
-
"@streamlayer/sdk-web-storage": "^0.4.
|
|
15
|
-
"@streamlayer/sdk-web-types": "^0.23.
|
|
9
|
+
"@streamlayer/sdk-web-api": "^0.25.1",
|
|
10
|
+
"@streamlayer/sdk-web-core": "^0.23.1",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^0.22.1",
|
|
12
|
+
"@streamlayer/sdk-web-logger": "^0.5.21",
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.16.1",
|
|
14
|
+
"@streamlayer/sdk-web-storage": "^0.4.8",
|
|
15
|
+
"@streamlayer/sdk-web-types": "^0.23.3"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"tslib": "^2.6.2"
|