@streamlayer/feature-gamification 1.16.8 → 1.16.10

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
@@ -61,7 +61,7 @@ export class GamificationBackground {
61
61
  this.notifications = instance.notifications;
62
62
  this.moderation = new ApiStore(queries.$moderation(this.slStreamId, instance.transport), 'gamification:moderation');
63
63
  const onlyBetPack = !!instance.sdk.options.get().betPack;
64
- this.feedList = new ApiStore(queries.$feedList(this.slStreamId, this.interactiveAllowed, onlyBetPack, instance.transport), 'gamification:feedList');
64
+ this.feedList = new ApiStore(queries.$feedList(this.slStreamId, this.interactiveAllowed, this.userId, this.organizationId, this.storage, onlyBetPack, instance.transport), 'gamification:feedList');
65
65
  this.betPack = new ApiStore(queries.$betPack(this.slStreamId, this.userId, this.organizationId, this.storage, instance.transport), 'gamification:betPack');
66
66
  this.activeQuestionId = queries.$activeQuestion(this.slStreamId, onlyBetPack, instance.transport);
67
67
  this.openedQuestion = detail(instance.transport, this.openedQuestionId, this.feedList.getStore());
@@ -400,7 +400,7 @@ export declare const getPromotionDetail: (promoId: string, transport: Transport)
400
400
  notification: import("@streamlayer/sl-eslib/interactive/interactive.common_pb").QuestionNotification | undefined;
401
401
  } | undefined>;
402
402
  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>;
403
- export declare const $feedList: ($slStreamId: ReadableAtom<string | undefined>, $interactiveAllowed: ReadableAtom<InteractiveAllowed>, onlyBetPack: boolean, transport: Transport) => import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem[], any>;
403
+ export declare const $feedList: ($slStreamId: ReadableAtom<string | undefined>, $interactiveAllowed: ReadableAtom<InteractiveAllowed>, $slUserId: ReadableAtom<string | undefined>, $slOrganizationId: ReadableAtom<string | undefined>, storage: GamificationStorage, onlyBetPack: boolean, transport: Transport) => import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/interactive/feed/interactive.feed_pb").FeedItem[], any>;
404
404
  export declare const $activePromotionId: ($slStreamId: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<{
405
405
  id: string;
406
406
  question: {
@@ -108,7 +108,7 @@ export const $pickHistory = (slStreamId, transport) => {
108
108
  },
109
109
  });
110
110
  };
111
- export const $feedList = ($slStreamId, $interactiveAllowed, onlyBetPack, transport) => {
111
+ export const $feedList = ($slStreamId, $interactiveAllowed, $slUserId, $slOrganizationId, storage, onlyBetPack, transport) => {
112
112
  const { client, queryKey } = transport.createPromiseClient(Feed, {
113
113
  method: 'list',
114
114
  params: [$slStreamId, $interactiveAllowed, onlyBetPack ? 'true' : ''],
@@ -127,6 +127,23 @@ export const $feedList = ($slStreamId, $interactiveAllowed, onlyBetPack, transpo
127
127
  statuses: [QuestionStatus.ACTIVE, QuestionStatus.RESOLVED],
128
128
  },
129
129
  });
130
+ const flags = {
131
+ eventId: slStreamId,
132
+ userId: $slUserId.get(),
133
+ organizationId: $slOrganizationId.get(),
134
+ };
135
+ for (const question of res.data) {
136
+ if (!storage.isQuestionReceived(flags, question.id)) {
137
+ eventBus.emit('poll', {
138
+ action: 'received',
139
+ payload: {
140
+ questionId: question.id,
141
+ questionType: question.attributes?.type,
142
+ },
143
+ });
144
+ storage.saveQuestionReceived(flags, question.id);
145
+ }
146
+ }
130
147
  return res.data;
131
148
  },
132
149
  dedupeTime: 0,
@@ -208,7 +225,7 @@ export const $betPack = ($slStreamId, $slUserId, $slOrganizationId, storage, tra
208
225
  userId: userId,
209
226
  organizationId: organizationId,
210
227
  };
211
- if (!storage.isBetPackQuestionReceived(flags, question.id)) {
228
+ if (!storage.isQuestionReceived(flags, question.id)) {
212
229
  eventBus.emit('poll', {
213
230
  action: 'received',
214
231
  payload: {
@@ -216,7 +233,7 @@ export const $betPack = ($slStreamId, $slUserId, $slOrganizationId, storage, tra
216
233
  questionType: question.type,
217
234
  },
218
235
  });
219
- storage.saveBetPackQuestionReceived(flags, question.id);
236
+ storage.saveQuestionReceived(flags, question.id);
220
237
  }
221
238
  return { ...acc, [question.id]: question };
222
239
  }, {}),
package/lib/storage.d.ts CHANGED
@@ -8,8 +8,8 @@ type UserProps = {
8
8
  export declare class GamificationStorage extends Storage {
9
9
  private sessionStorage;
10
10
  constructor();
11
- saveBetPackQuestionReceived: ({ userId, eventId, organizationId }: UserProps, questionId: string) => void;
12
- isBetPackQuestionReceived: ({ userId, eventId, organizationId }: UserProps, questionId: string) => boolean;
11
+ saveQuestionReceived: ({ userId, eventId, organizationId }: UserProps, questionId: string) => void;
12
+ isQuestionReceived: ({ userId, eventId, organizationId }: UserProps, questionId: string) => boolean;
13
13
  saveQuestionOpened: ({ userId, eventId, organizationId }: UserProps, questionId: string) => void;
14
14
  isQuestionOpened: ({ userId, eventId, organizationId }: UserProps, questionId: string) => boolean;
15
15
  saveOnboardingStatus: ({ userId, eventId, organizationId }: UserProps, status: OnboardingStatus) => void;
package/lib/storage.js CHANGED
@@ -3,7 +3,7 @@ var KEY_PREFIX;
3
3
  (function (KEY_PREFIX) {
4
4
  KEY_PREFIX["ONBOARDING"] = "onboarding";
5
5
  KEY_PREFIX["ONBOARDING_IO"] = "onboarding_io";
6
- KEY_PREFIX["BET_PACK_ITEM_RECEIVED"] = "bp-item-received";
6
+ KEY_PREFIX["QUESTION_RECEIVED"] = "q-received";
7
7
  KEY_PREFIX["QUESTION_OPENED"] = "q-opened";
8
8
  })(KEY_PREFIX || (KEY_PREFIX = {}));
9
9
  class GamificationSessionStorage extends Storage {
@@ -23,11 +23,11 @@ export class GamificationStorage extends Storage {
23
23
  super('gamification');
24
24
  this.sessionStorage = new GamificationSessionStorage();
25
25
  }
26
- saveBetPackQuestionReceived = ({ userId, eventId, organizationId }, questionId) => {
27
- this.write(KEY_PREFIX.BET_PACK_ITEM_RECEIVED, organizationId, userId, eventId, questionId);
26
+ saveQuestionReceived = ({ userId, eventId, organizationId }, questionId) => {
27
+ this.write(KEY_PREFIX.QUESTION_RECEIVED, organizationId, userId, eventId, questionId, '1');
28
28
  };
29
- isBetPackQuestionReceived = ({ userId, eventId, organizationId }, questionId) => {
30
- return !!this.read(KEY_PREFIX.BET_PACK_ITEM_RECEIVED, organizationId, userId, eventId, questionId);
29
+ isQuestionReceived = ({ userId, eventId, organizationId }, questionId) => {
30
+ return !!this.read(KEY_PREFIX.QUESTION_RECEIVED, organizationId, userId, eventId, questionId);
31
31
  };
32
32
  saveQuestionOpened = ({ userId, eventId, organizationId }, questionId) => {
33
33
  this.write(KEY_PREFIX.QUESTION_OPENED, organizationId, userId, eventId, questionId, '1');
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@streamlayer/feature-gamification",
3
- "version": "1.16.8",
3
+ "version": "1.16.10",
4
4
  "peerDependencies": {
5
5
  "@bufbuild/protobuf": "^1.10.0",
6
6
  "@fastify/deepmerge": "^2.0.0",
7
7
  "@streamlayer/sl-eslib": "^5.149.1",
8
8
  "uuid": "^11.1.0",
9
9
  "nanostores": "^0.11.4",
10
- "@streamlayer/sdk-web-api": "^1.8.8",
11
- "@streamlayer/sdk-web-core": "^1.11.10",
12
- "@streamlayer/sdk-web-interfaces": "^1.4.21",
13
- "@streamlayer/sdk-web-logger": "^1.0.55",
14
- "@streamlayer/sdk-web-notifications": "^1.3.17",
15
- "@streamlayer/sdk-web-storage": "^1.0.55",
16
- "@streamlayer/sdk-web-types": "^1.10.12"
10
+ "@streamlayer/sdk-web-api": "^1.8.10",
11
+ "@streamlayer/sdk-web-core": "^1.11.12",
12
+ "@streamlayer/sdk-web-interfaces": "^1.5.1",
13
+ "@streamlayer/sdk-web-logger": "^1.0.57",
14
+ "@streamlayer/sdk-web-notifications": "^1.3.19",
15
+ "@streamlayer/sdk-web-storage": "^1.0.57",
16
+ "@streamlayer/sdk-web-types": "^1.10.14"
17
17
  },
18
18
  "devDependencies": {
19
19
  "tslib": "^2.7.0"