@streamlayer/feature-gamification 0.40.0 → 0.41.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/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("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem> & {
11
+ $store: ReadableAtom<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem | (import("@streamlayer/sdk-web-types").PickHistory<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("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>, any>;
14
+ $extendedStore: import("@nanostores/query").FetcherStore<import("@streamlayer/sdk-web-types").PickHistory<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>, any>;
15
15
  updateExtendedQuestion: (question: ExtendedQuestion | undefined) => void;
16
16
  };
@@ -110,7 +110,7 @@ export class Gamification extends AbstractFeature {
110
110
  this.cancels.add(this.onboardingStatus.$store.listen(this.checkInteractiveFlag));
111
111
  this.cancels.add(this.background.moderation.getStore().listen(this.checkInteractiveFlag));
112
112
  this.cancels.add(this.settings.subscribe(this.checkInteractiveFlag));
113
- instance.sdk.onMount(() => {
113
+ instance.sdk.onMount({ name: 'gamification', clear: true }, () => {
114
114
  return () => {
115
115
  for (const cancel of this.cancels) {
116
116
  cancel();
@@ -306,6 +306,8 @@ export class Gamification extends AbstractFeature {
306
306
  };
307
307
  submitAnswer = async (questionId, answerId) => {
308
308
  const data = $questionByUser(questionId, this.transport);
309
+ const cancel = data.subscribe(() => { });
310
+ const extendedQuestionBeforeVote = { ...(data.get().data || {}) };
309
311
  const updateQuestionAndFieldList = () => {
310
312
  const feedList = this.feedList.getValues().data;
311
313
  if (!feedList) {
@@ -322,13 +324,13 @@ export class Gamification extends AbstractFeature {
322
324
  questionType: question.questionType,
323
325
  },
324
326
  });
325
- const cancel = data.subscribe(() => { });
326
327
  const extendedQuestion = data.get().data;
327
328
  cancel();
328
329
  if (extendedQuestion) {
329
330
  const correctAnswer = extendedQuestion.answers.find((answer) => answer.correct === true);
330
331
  const votedAnswerIdx = extendedQuestion.answers.findIndex((answer) => answer.id === answerId);
331
332
  const votedAnswer = extendedQuestion.answers[votedAnswerIdx];
333
+ const percentsEqual = extendedQuestion.answers.every(({ percentageDecimal }, index) => percentageDecimal === extendedQuestionBeforeVote?.answers[index].percentageDecimal);
332
334
  // @ts-ignore
333
335
  feedList[questionIndex].attributes.attributes.value.answerId = answerId;
334
336
  // @ts-ignore
@@ -343,9 +345,11 @@ export class Gamification extends AbstractFeature {
343
345
  this.feedList.getStore().mutate([...feedList]);
344
346
  extendedQuestion.answers[votedAnswerIdx].correct = correctAnswer?.id === answerId;
345
347
  extendedQuestion.answers[votedAnswerIdx].youVoted = true;
346
- extendedQuestion.answers.forEach((answer) => {
347
- answer.percentageDecimal = 0;
348
- });
348
+ if (percentsEqual) {
349
+ extendedQuestion.answers.forEach((answer) => {
350
+ answer.percentageDecimal = 0;
351
+ });
352
+ }
349
353
  if (correctAnswer?.id === answerId) {
350
354
  extendedQuestion.answers[votedAnswerIdx].pointsEarned =
351
355
  extendedQuestion.status === QuestionStatus.RESOLVED ? 0 : correctAnswer.points;
@@ -381,7 +385,9 @@ export class Gamification extends AbstractFeature {
381
385
  this.notifications.close(this.background.getCurrentSessionId({
382
386
  prefix: 'notification',
383
387
  entity: questionId,
384
- }));
388
+ }), {
389
+ animateHiding: false,
390
+ });
385
391
  let questionType = question?.attributes?.type;
386
392
  if (!questionType) {
387
393
  const feedList = this.feedList.getStore().value?.data || [];
@@ -39,7 +39,7 @@ export const leaderboard = (transport, $eventId, $userId, $friends, options) =>
39
39
  $store.set({
40
40
  data: newData.data.map((item, i) => ({
41
41
  ...item.attributes,
42
- rank: i + 1,
42
+ friendsRank: i + 1,
43
43
  })),
44
44
  hasMore: false,
45
45
  key: Date.now(),
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) {
@@ -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("@bufbuild/protobuf").PlainMessage<import("@streamlayer/sl-eslib/interactive/interactive.common_pb").ExtendedQuestion>, any>;
332
+ export declare const $questionByUser: ($questionId: ReadableAtom<string | undefined> | string, transport: Transport) => import("@nanostores/query").FetcherStore<import("@streamlayer/sdk-web-types").PickHistory<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.40.0",
3
+ "version": "0.41.0",
4
4
  "peerDependencies": {
5
- "@bufbuild/protobuf": "^1.7.2",
5
+ "@bufbuild/protobuf": "^1.8.0",
6
6
  "@fastify/deepmerge": "^1.3.0",
7
- "@streamlayer/sl-eslib": "^5.83.1",
7
+ "@streamlayer/sl-eslib": "^5.85.0",
8
8
  "nanostores": "^0.10.0",
9
- "@streamlayer/sdk-web-api": "^0.24.2",
10
- "@streamlayer/sdk-web-core": "^0.22.2",
11
- "@streamlayer/sdk-web-interfaces": "^0.21.0",
12
- "@streamlayer/sdk-web-logger": "^0.5.18",
13
- "@streamlayer/sdk-web-notifications": "^0.15.1",
14
- "@streamlayer/sdk-web-storage": "^0.4.5",
15
- "@streamlayer/sdk-web-types": "^0.23.0"
9
+ "@streamlayer/sdk-web-api": "^0.25.0",
10
+ "@streamlayer/sdk-web-core": "^0.23.0",
11
+ "@streamlayer/sdk-web-logger": "^0.5.20",
12
+ "@streamlayer/sdk-web-interfaces": "^0.22.0",
13
+ "@streamlayer/sdk-web-notifications": "^0.16.0",
14
+ "@streamlayer/sdk-web-storage": "^0.4.7",
15
+ "@streamlayer/sdk-web-types": "^0.23.2"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tslib": "^2.6.2"