@streamlayer/feature-gamification 1.16.11 → 1.16.13
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 +4 -2
- package/lib/gamification.js +12 -0
- package/lib/queries/index.js +10 -4
- package/package.json +8 -8
package/lib/background.js
CHANGED
|
@@ -77,7 +77,8 @@ export class GamificationBackground {
|
|
|
77
77
|
this.questionSubscription.addListener('feed-subscription-opened-question', (response) => {
|
|
78
78
|
const question = response.data?.attributes?.question;
|
|
79
79
|
this.openedQuestion.updateExtendedQuestion(question);
|
|
80
|
-
if (
|
|
80
|
+
if (this.betPack &&
|
|
81
|
+
question?.type === QuestionType.PREDICTION &&
|
|
81
82
|
(question.status === QuestionStatus.ACTIVE || question.status === QuestionStatus.RESOLVED)) {
|
|
82
83
|
const betPackData = this.betPack.getValues().data?.data || {};
|
|
83
84
|
const betPackItem = betPackData?.[question.id];
|
|
@@ -129,7 +130,8 @@ export class GamificationBackground {
|
|
|
129
130
|
this.feedSubscription = queries.feedSubscription(this.slStreamId, instance.transport);
|
|
130
131
|
this.cancels.add(this.feedSubscription.addListener('bet-pack-update', async (response) => {
|
|
131
132
|
const question = response.data?.attributes?.question;
|
|
132
|
-
if (
|
|
133
|
+
if (this.betPack &&
|
|
134
|
+
question?.type === QuestionType.PREDICTION &&
|
|
133
135
|
(question.status === QuestionStatus.ACTIVE || question.status === QuestionStatus.RESOLVED)) {
|
|
134
136
|
const betPackData = this.betPack.getValues().data?.data || {};
|
|
135
137
|
const betPackItem = betPackData?.[question.id];
|
package/lib/gamification.js
CHANGED
|
@@ -354,6 +354,9 @@ export class Gamification extends AbstractFeature {
|
|
|
354
354
|
this.background.feedSubscription.removeListener('feed-subscription-questions-list');
|
|
355
355
|
};
|
|
356
356
|
betPackVote = async (questionId, answerId) => {
|
|
357
|
+
if (!this.betPack) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
357
360
|
try {
|
|
358
361
|
await actions.submitAnswer(this.transport, { questionId, answerId });
|
|
359
362
|
}
|
|
@@ -478,6 +481,15 @@ export class Gamification extends AbstractFeature {
|
|
|
478
481
|
const feedList = this.feedList.getStore().value?.data || [];
|
|
479
482
|
questionType = feedList.find((item) => item.id === questionId)?.attributes?.type;
|
|
480
483
|
}
|
|
484
|
+
if (!openedFromBetPack &&
|
|
485
|
+
(questionType === QuestionType.POLL ||
|
|
486
|
+
questionType === QuestionType.TRIVIA ||
|
|
487
|
+
questionType === QuestionType.PREDICTION)) {
|
|
488
|
+
const query = queries.$questionByUser(questionId, this.transport);
|
|
489
|
+
void queries.questionByUser(questionId, this.transport).then((d) => {
|
|
490
|
+
query.mutate(d);
|
|
491
|
+
});
|
|
492
|
+
}
|
|
481
493
|
const flags = {
|
|
482
494
|
eventId: this.background.slStreamId.get() || '',
|
|
483
495
|
userId: this.background.userId.get() || '',
|
package/lib/queries/index.js
CHANGED
|
@@ -67,14 +67,20 @@ export const questionByUser = async ($questionId, transport) => {
|
|
|
67
67
|
});
|
|
68
68
|
return res.data?.attributes?.question;
|
|
69
69
|
};
|
|
70
|
-
const storeCache = new Map();
|
|
71
70
|
export const $questionByUser = ($questionId, transport) => {
|
|
72
71
|
const { client, queryKey, queryKeyStr } = transport.createPromiseClient(Feed, {
|
|
73
72
|
method: 'questionByUser',
|
|
74
73
|
params: [$questionId],
|
|
75
74
|
});
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
let cacheKey = queryKeyStr;
|
|
76
|
+
if (typeof $questionId !== 'object') {
|
|
77
|
+
cacheKey += $questionId;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
cacheKey += 'atom';
|
|
81
|
+
}
|
|
82
|
+
if (transport.storeCache.has(cacheKey)) {
|
|
83
|
+
return transport.storeCache.get(cacheKey);
|
|
78
84
|
}
|
|
79
85
|
else {
|
|
80
86
|
const store = transport.nanoquery.createFetcherStore(queryKey, {
|
|
@@ -87,7 +93,7 @@ export const $questionByUser = ($questionId, transport) => {
|
|
|
87
93
|
dedupeTime: Infinity,
|
|
88
94
|
refetchInterval: Infinity,
|
|
89
95
|
});
|
|
90
|
-
storeCache.set(
|
|
96
|
+
transport.storeCache.set(cacheKey, store);
|
|
91
97
|
return store;
|
|
92
98
|
}
|
|
93
99
|
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.13",
|
|
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.
|
|
11
|
-
"@streamlayer/sdk-web-core": "^1.11.
|
|
12
|
-
"@streamlayer/sdk-web-interfaces": "^1.5.
|
|
13
|
-
"@streamlayer/sdk-web-logger": "^1.0.
|
|
14
|
-
"@streamlayer/sdk-web-notifications": "^1.3.
|
|
15
|
-
"@streamlayer/sdk-web-storage": "^1.0.
|
|
16
|
-
"@streamlayer/sdk-web-types": "^1.10.
|
|
10
|
+
"@streamlayer/sdk-web-api": "^1.8.13",
|
|
11
|
+
"@streamlayer/sdk-web-core": "^1.11.15",
|
|
12
|
+
"@streamlayer/sdk-web-interfaces": "^1.5.4",
|
|
13
|
+
"@streamlayer/sdk-web-logger": "^1.0.60",
|
|
14
|
+
"@streamlayer/sdk-web-notifications": "^1.3.22",
|
|
15
|
+
"@streamlayer/sdk-web-storage": "^1.0.60",
|
|
16
|
+
"@streamlayer/sdk-web-types": "^1.10.17"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tslib": "^2.7.0"
|